Skip to content

Commit

Permalink
wip 13
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed Oct 28, 2023
1 parent f50f779 commit 986dcb5
Show file tree
Hide file tree
Showing 14 changed files with 864 additions and 332 deletions.
31 changes: 7 additions & 24 deletions agent/agent-base.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
/**
Fadroma: Base Console and Error Types
Copyright (C) 2023 Hack.bg
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**/

/** Fadroma. Copyright (C) 2023 Hack.bg. License: GNU AGPLv3 or custom.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. **/
import { Error as BaseError } from '@hackbg/oops'
import { Console, bold, colors } from '@hackbg/logs'
import type { Chain } from './agent-chain'
Expand Down Expand Up @@ -232,11 +215,11 @@ class AgentConsole extends Console {
codeHashMismatch (address: string, expected: string|undefined, fetched: string) {
return this.warn(`code hash mismatch for ${address}: expected ${expected}, fetched ${fetched}`)
}
waitingForBlock (height: number, elapsed?: number) {
return this.log(`waiting for block > ${height}...`, elapsed ? `${elapsed}ms elapsed` : '')
}
confirmCodeHash (address: string, codeHash: string) {
return this.info(`confirmed code hash of ${address}: ${codeHash}`)
return this.info(`Confirmed code hash of ${address}: ${codeHash}`)
}
waitingForBlock (height: number, elapsed?: number) {
return this.log(`Waiting for block > ${bold(String(height))}...`, elapsed ? `${elapsed}ms elapsed` : '')
}
batchMessages (msgs: any, N: number) {
this.info(`Messages in batch`, `#${N}:`)
Expand Down
30 changes: 17 additions & 13 deletions agent/agent-batch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/** Fadroma. Copyright (C) 2023 Hack.bg. License: GNU AGPLv3 or custom.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. **/
import { Error, Console, into } from './agent-base'
import type {
Class, Message, CodeId, Address, Name, Into, ICoin, Many, CodeHash
Expand Down Expand Up @@ -62,14 +65,15 @@ export abstract class Batch implements BatchAgent {
memo: string,
save: boolean
}> = {}): Promise<unknown> {
this.log(options.save ? 'Saving' : 'Submitting')
if (this.depth > 0) {
this.log.warn('Unnesting batch. Depth:', --this.depth)
this.depth--
return null as any // result ignored
} else if (options.save) {
this.log('Saving batch')
return this.save(options.memo)
} else {
this.log('Submitting batch')
return this.submit(options.memo)
}
}
Expand Down Expand Up @@ -111,11 +115,11 @@ export abstract class Batch implements BatchAgent {
async instantiate (
contract: CodeId|Partial<ContractInstance>,
options: {
label: Name,
initMsg: Into<Message>,
initFee?: unknown,
initFunds?: ICoin[],
initMemo?: string,
label: Name,
initMsg: Into<Message>,
initFee?: unknown,
initSend?: ICoin[],
initMemo?: string,
}
): Promise<ContractInstance & {
address: Address,
Expand All @@ -129,7 +133,7 @@ export abstract class Batch implements BatchAgent {
label: options.label,
msg: await into(options.initMsg),
sender: this.address,
funds: options.initFunds || [],
funds: options.initSend || [],
memo: options.initMemo || ''
} })
return new ContractInstance({
Expand Down Expand Up @@ -158,7 +162,7 @@ export abstract class Batch implements BatchAgent {
contracts: M,
options: {
initFee?: ICoin[]|'auto',
initFunds?: ICoin[],
initSend?: ICoin[],
initMemo?: string,
} = {}
): Promise<M> {
Expand All @@ -171,11 +175,11 @@ export abstract class Batch implements BatchAgent {
outputs[key] = contract.address
} else {
outputs[key] = await this.instantiate(contract, {
label: contract.label!,
initMsg: contract.initMsg!,
initFee: contract.initFee || options.initFee,
initFunds: contract.initFunds || options.initFunds,
initMemo: contract.initMemo || options.initMemo
label: contract.label!,
initMsg: contract.initMsg!,
initFee: contract.initFee || options.initFee,
initSend: contract.initSend || options.initSend,
initMemo: contract.initMemo || options.initMemo
})
}
}))
Expand Down
37 changes: 10 additions & 27 deletions agent/agent-chain.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
/**
Fadroma: Base Agent/Chain API
Copyright (C) 2023 Hack.bg
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**/

/** Fadroma. Copyright (C) 2023 Hack.bg. License: GNU AGPLv3 or custom.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. **/
import type {
Address, Message, ICoin, IFee, CodeHash,
Class, Name, Many, CodeId,
Expand Down Expand Up @@ -228,7 +211,7 @@ export abstract class Chain {
return this.height.then(async startingHeight=>{
startingHeight = Number(startingHeight)
if (isNaN(startingHeight)) {
this.log.warn('current block height undetermined. not waiting for next block')
this.log.warn('Current block height undetermined. not waiting for next block')
return Promise.resolve(NaN)
}
this.log.waitingForBlock(startingHeight)
Expand All @@ -240,7 +223,7 @@ export abstract class Chain {
this.log.waitingForBlock(startingHeight, + new Date() - t)
const height = await this.height
if (height > startingHeight) {
this.log.info(`block height incremented to ${height}, continuing`)
this.log.info(`Block height incremented to ${bold(String(height))}, continuing`)
return resolve(height)
}
}
Expand Down Expand Up @@ -369,8 +352,8 @@ export abstract class Agent {
}

/** The wallet's mnemonic (write-only). */
get mnemonic (): Promise<string> {
throw new Error('mnemonic is write-only')
get mnemonic (): boolean {
return false
}

set mnemonic (mnemonic: string) {
Expand Down Expand Up @@ -581,9 +564,9 @@ export abstract class Agent {
async instantiateMany <M extends Many<ContractInstance>> (
contracts: M,
options: {
initFee?: ICoin[]|'auto',
initFunds?: ICoin[],
initMemo?: string,
initFee?: ICoin[]|'auto',
initSend?: ICoin[],
initMemo?: string,
} = {}
): Promise<M> {
// Returns an array of TX results.
Expand Down
Loading

0 comments on commit 986dcb5

Please sign in to comment.