Skip to content

Commit

Permalink
add extraExecTxArgs to other CosmWasm methods (#810)
Browse files Browse the repository at this point in the history
* add extraExecTxArgs to other CosmWasm methods

* check for --fees on Txs instead of gas prices
  • Loading branch information
Reecepbcups authored Oct 10, 2023
1 parent c07fe15 commit 6c48fd1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
30 changes: 20 additions & 10 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,16 +444,19 @@ func (tn *ChainNode) FindTxs(ctx context.Context, height uint64) ([]blockdb.Tx,
// with the chain node binary.
func (tn *ChainNode) TxCommand(keyName string, command ...string) []string {
command = append([]string{"tx"}, command...)
var gasPriceFound, gasAdjustmentFound = false, false
var gasPriceFound, gasAdjustmentFound, feesFound = false, false, false
for i := 0; i < len(command); i++ {
if command[i] == "--gas-prices" {
gasPriceFound = true
}
if command[i] == "--gas-adjustment" {
gasAdjustmentFound = true
}
if command[i] == "--fees" {
feesFound = true
}
}
if !gasPriceFound {
if !gasPriceFound && !feesFound {
command = append(command, "--gas-prices", tn.Chain.Config().GasPrices)
}
if !gasAdjustmentFound {
Expand Down Expand Up @@ -779,14 +782,17 @@ type CodeInfosResponse struct {
}

// StoreContract takes a file path to smart contract and stores it on-chain. Returns the contracts code id.
func (tn *ChainNode) StoreContract(ctx context.Context, keyName string, fileName string) (string, error) {
func (tn *ChainNode) StoreContract(ctx context.Context, keyName string, fileName string, extraExecTxArgs ...string) (string, error) {
_, file := filepath.Split(fileName)
err := tn.CopyFile(ctx, fileName, file)
if err != nil {
return "", fmt.Errorf("writing contract file to docker volume: %w", err)
}

if _, err := tn.ExecTx(ctx, keyName, "wasm", "store", path.Join(tn.HomeDir(), file), "--gas", "auto"); err != nil {
cmd := []string{"wasm", "store", path.Join(tn.HomeDir(), file), "--gas", "auto"}
cmd = append(cmd, extraExecTxArgs...)

if _, err := tn.ExecTx(ctx, keyName, cmd...); err != nil {
return "", err
}

Expand Down Expand Up @@ -955,10 +961,11 @@ func (tn *ChainNode) InstantiateContract(ctx context.Context, keyName string, co
}

// ExecuteContract executes a contract transaction with a message using it's address.
func (tn *ChainNode) ExecuteContract(ctx context.Context, keyName string, contractAddress string, message string) (txHash string, err error) {
return tn.ExecTx(ctx, keyName,
"wasm", "execute", contractAddress, message,
)
func (tn *ChainNode) ExecuteContract(ctx context.Context, keyName string, contractAddress string, message string, extraExecTxArgs ...string) (txHash string, err error) {
cmd := []string{"wasm", "execute", contractAddress, message}
cmd = append(cmd, extraExecTxArgs...)

return tn.ExecTx(ctx, keyName, cmd...)
}

// QueryContract performs a smart query, taking in a query struct and returning a error with the response struct populated.
Expand All @@ -976,7 +983,7 @@ func (tn *ChainNode) QueryContract(ctx context.Context, contractAddress string,
}

// StoreClientContract takes a file path to a client smart contract and stores it on-chain. Returns the contracts code id.
func (tn *ChainNode) StoreClientContract(ctx context.Context, keyName string, fileName string) (string, error) {
func (tn *ChainNode) StoreClientContract(ctx context.Context, keyName string, fileName string, extraExecTxArgs ...string) (string, error) {
content, err := os.ReadFile(fileName)
if err != nil {
return "", err
Expand All @@ -987,7 +994,10 @@ func (tn *ChainNode) StoreClientContract(ctx context.Context, keyName string, fi
return "", fmt.Errorf("writing contract file to docker volume: %w", err)
}

_, err = tn.ExecTx(ctx, keyName, "ibc-wasm", "store-code", path.Join(tn.HomeDir(), file), "--gas", "auto")
cmd := []string{"ibc-wasm", "store-code", path.Join(tn.HomeDir(), file), "--gas", "auto"}
cmd = append(cmd, extraExecTxArgs...)

_, err = tn.ExecTx(ctx, keyName, cmd...)
if err != nil {
return "", err
}
Expand Down
12 changes: 6 additions & 6 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ func (c *CosmosChain) txProposal(txHash string) (tx TxProposal, _ error) {
}

// StoreContract takes a file path to smart contract and stores it on-chain. Returns the contracts code id.
func (c *CosmosChain) StoreContract(ctx context.Context, keyName string, fileName string) (string, error) {
return c.getFullNode().StoreContract(ctx, keyName, fileName)
func (c *CosmosChain) StoreContract(ctx context.Context, keyName string, fileName string, extraExecTxArgs ...string) (string, error) {
return c.getFullNode().StoreContract(ctx, keyName, fileName, extraExecTxArgs...)
}

// InstantiateContract takes a code id for a smart contract and initialization message and returns the instantiated contract address.
Expand All @@ -507,8 +507,8 @@ func (c *CosmosChain) InstantiateContract(ctx context.Context, keyName string, c
}

// ExecuteContract executes a contract transaction with a message using it's address.
func (c *CosmosChain) ExecuteContract(ctx context.Context, keyName string, contractAddress string, message string) (txHash string, err error) {
return c.getFullNode().ExecuteContract(ctx, keyName, contractAddress, message)
func (c *CosmosChain) ExecuteContract(ctx context.Context, keyName string, contractAddress string, message string, extraExecTxArgs ...string) (txHash string, err error) {
return c.getFullNode().ExecuteContract(ctx, keyName, contractAddress, message, extraExecTxArgs...)
}

// QueryContract performs a smart query, taking in a query struct and returning a error with the response struct populated.
Expand All @@ -522,8 +522,8 @@ func (c *CosmosChain) DumpContractState(ctx context.Context, contractAddress str
}

// StoreClientContract takes a file path to a client smart contract and stores it on-chain. Returns the contracts code id.
func (c *CosmosChain) StoreClientContract(ctx context.Context, keyName string, fileName string) (string, error) {
return c.getFullNode().StoreClientContract(ctx, keyName, fileName)
func (c *CosmosChain) StoreClientContract(ctx context.Context, keyName string, fileName string, extraExecTxArgs ...string) (string, error) {
return c.getFullNode().StoreClientContract(ctx, keyName, fileName, extraExecTxArgs...)
}

// QueryClientContractCode performs a query with the contract codeHash as the input and code as the output
Expand Down

0 comments on commit 6c48fd1

Please sign in to comment.