Skip to content

Commit

Permalink
Split TerraCommand operations into prepare and broadcast
Browse files Browse the repository at this point in the history
call() now calls prepareCall(), which creates and signs the
tx, followed by broadcast()
Similarly:
deploy() calls prepareDeploy(), then broadcasts
upload() calls prepareUpload(), then broadcasts
  • Loading branch information
reductionista committed Feb 15, 2022
1 parent 1819512 commit 201ab1f
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions packages-ts/gauntlet-terra/src/commands/internal/terra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,56 +63,66 @@ export default abstract class TerraCommand extends WriteCommand<TransactionRespo
return await this.provider.wasm.contractQuery(address, input, params)
}

async call(address, input) {
async prepareCall(address, input) {
const msg = new MsgExecuteContract(this.wallet.key.accAddress, address, input)

const tx = await this.wallet.createAndSignTx({
return await this.wallet.createAndSignTx({
msgs: [msg],
...(this.wallet.key instanceof LedgerKey && {
signMode: SignMode.SIGN_MODE_LEGACY_AMINO_JSON,
}),
})
}

async call(address, input) {
const tx = await this.prepareCall(address, input)
const res = await this.provider.tx.broadcast(tx)

logger.debug(res)

return this.wrapResponse(res)
}

async deploy(codeId, instantiateMsg, migrationContract = undefined) {
async prepareDeploy(codeId, instantiateMsg, migrationContract = undefined) {
const instantiate = new MsgInstantiateContract(
this.wallet.key.accAddress,
migrationContract,
codeId,
instantiateMsg,
)
const instantiateTx = await this.wallet.createAndSignTx({
return await this.wallet.createAndSignTx({
msgs: [instantiate],
memo: 'Instantiating',
...(this.wallet.key instanceof LedgerKey && {
signMode: SignMode.SIGN_MODE_LEGACY_AMINO_JSON,
}),
})
}

async deploy(codeId, instantiateMsg, migrationContract = undefined) {
const instantiateTx = await this.prepareDeploy(codeId, instantiateMsg, migrationContract = undefined)
logger.loading(`Deploying contract...`)
const res = await this.provider.tx.broadcast(instantiateTx)

return this.wrapResponse(res)
}

async upload(wasm, contractName) {
async prepareUpload(wasm, contractName) {
const code = new MsgStoreCode(this.wallet.key.accAddress, wasm)

const tx = await this.wallet.createAndSignTx({
return await this.wallet.createAndSignTx({
msgs: [code],
memo: `Storing ${contractName}`,
...(this.wallet.key instanceof LedgerKey && {
signMode: SignMode.SIGN_MODE_LEGACY_AMINO_JSON,
}),
})
}

async upload(wasm, contractName) {
const tx = await this.prepareUpload(wasm, contractName)
logger.loading(`Uploading ${contractName} contract code...`)
const res = await this.provider.tx.broadcast(tx)

return this.wrapResponse(res)
}
}
}

0 comments on commit 201ab1f

Please sign in to comment.