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

[BP: v7 <- #810] add extraExecTxArgs to other CosmWasm methods #815

Merged
merged 1 commit into from
Oct 10, 2023
Merged
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
30 changes: 20 additions & 10 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,16 +465,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 @@ -799,14 +802,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 @@ -975,10 +981,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 @@ -996,7 +1003,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 @@ -1007,7 +1014,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 @@ -496,8 +496,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 @@ -506,8 +506,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 @@ -521,8 +521,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