Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands export transaction message #108

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AbstractCommand, { makeAbstractCommand } from '.'
import { Result } from '@chainlink/gauntlet-core'
import { TerraCommand, TransactionResponse } from '@chainlink/gauntlet-terra'
import { MsgExecuteContract } from '@terra-money/terra.js'

export interface AbstractInstruction<Input, ContractInput> {
instruction: {
Expand All @@ -25,15 +26,25 @@ export const instructionToCommand = (instruction: AbstractInstruction<any, any>)
super(flags, args)
}

execute = async (): Promise<Result<TransactionResponse>> => {
buildCommand = async (): Promise<TerraCommand> => {
const commandInput = await instruction.makeInput(this.flags, this.args)
if (!instruction.validateInput(commandInput)) {
throw new Error(`Invalid input params: ${JSON.stringify(commandInput)}`)
}
const input = await instruction.makeContractInput(commandInput)
const abstractCommand = await makeAbstractCommand(id, this.flags, this.args, input)
await abstractCommand.invokeMiddlewares(abstractCommand, abstractCommand.middlewares)
return abstractCommand.execute()
return abstractCommand
}

makeRawTransaction = async (): Promise<MsgExecuteContract> => {
const command = await this.buildCommand()
return command.makeRawTransaction()
}

execute = async (): Promise<Result<TransactionResponse>> => {
const command = await this.buildCommand()
return command.execute()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Result } from '@chainlink/gauntlet-core'
import { MsgExecuteContract } from '@terra-money/terra.js'
import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils'
import { TransactionResponse, TerraCommand } from '@chainlink/gauntlet-terra'
import { Contract, CONTRACT_LIST, getContract, TerraABI, TERRA_OPERATIONS } from '../../lib/contracts'
Expand Down Expand Up @@ -125,6 +126,11 @@ export default class AbstractCommand extends TerraCommand {
this.contracts = [this.opts.contract.id]
}

makeRawTransaction = async (): Promise<MsgExecuteContract> => {
const address = this.args[0]
return new MsgExecuteContract(this.wallet.key.accAddress, address, this.params)
}

abstractDeploy: AbstractExecute = async (params: any) => {
logger.loading(`Deploying contract ${this.opts.contract.id}`)
const codeId = this.codeIds[this.opts.contract.id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export const instructionToInspectCommand = <CommandInput, Expected>(
super(flags, args)
}

makeRawTransaction = () => {
throw new Error('Inspection command does not involve any transaction')
}

execute = async (): Promise<Result<TransactionResponse>> => {
const input = await inspectInstruction.makeInput(this.flags, this.args)
const commands = await Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default class DeployLink extends TerraCommand {
super(flags, args)
}

makeRawTransaction = async () => {
throw new Error('Deploy LINK command: makeRawTransaction method not implemented')
}

execute = async () => {
await prompt(`Begin deploying LINK Token?`)
const deploy = await this.deploy(CW20_BASE_CODE_IDs[this.flags.network], {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export default class TransferLink extends TerraCommand {
super(flags, args)
}

makeRawTransaction = async () => {
throw new Error('Transfer LINK command: makeRawTransaction method not implemented')
}

execute = async () => {
const decimals = this.flags.decimals || 18
const link = this.flags.link || process.env.LINK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export default class UploadContractCode extends TerraCommand {
super(flags, args)
}

makeRawTransaction = async () => {
throw new Error('Upload command: makeRawTransaction method not implemented')
}

getCodeId(response): number | undefined {
return Number(this.parseResponseValue(response, 'store_code', 'code_id'))
}
Expand Down
1 change: 1 addition & 0 deletions packages-ts/gauntlet-terra/src/commands/internal/terra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default abstract class TerraCommand extends WriteCommand<TransactionRespo
contracts: string[]
public codeIds: CodeIds
abstract execute: () => Promise<Result<TransactionResponse>>
abstract makeRawTransaction: () => Promise<MsgExecuteContract>

constructor(flags, args) {
super(flags, args)
Expand Down