From 19b421e35cb3ed82138404507de4a384256d9f8b Mon Sep 17 00:00:00 2001 From: Salvo Date: Sat, 11 Nov 2023 09:43:46 +0100 Subject: [PATCH 1/6] feat(faucet): set tx fee amount as option --- ignite/pkg/chaincmd/chaincmd.go | 22 ++++++++++++++++++- ignite/pkg/chaincmd/runner/chain.go | 4 ++-- .../pkg/cosmosanalysis/testdata/chain/go.sum | 1 + ignite/pkg/cosmosfaucet/cosmosfaucet.go | 10 +++++++++ ignite/pkg/cosmosfaucet/transfer.go | 3 ++- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/ignite/pkg/chaincmd/chaincmd.go b/ignite/pkg/chaincmd/chaincmd.go index f981804a1c..fdf582298e 100644 --- a/ignite/pkg/chaincmd/chaincmd.go +++ b/ignite/pkg/chaincmd/chaincmd.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/cosmos/cosmos-sdk/client/flags" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ignite/cli/ignite/pkg/cmdrunner/step" "github.com/ignite/cli/ignite/pkg/cosmosver" @@ -33,6 +34,7 @@ const ( optionRecover = "--recover" optionAddress = "--address" optionAmount = "--amount" + optionFees = "--fees" optionValidatorMoniker = "--moniker" optionValidatorCommissionRate = "--commission-rate" optionValidatorCommissionMaxRate = "--commission-max-rate" @@ -470,8 +472,21 @@ func (c ChainCmd) ExportCommand() step.Option { return c.daemonCommand(command) } +// BankSendOption for the BankSendCommand. +type BankSendOption func([]string) []string + +// BankSendWithFees sets fees to pay along with transaction for the bank send command. +func BankSendWithFees(fee sdk.Coin) BankSendOption { + return func(command []string) []string { + if !fee.IsZero() { + return append(command, optionFees, fee.String()) + } + return command + } +} + // BankSendCommand returns the command for transferring tokens. -func (c ChainCmd) BankSendCommand(fromAddress, toAddress, amount string) step.Option { +func (c ChainCmd) BankSendCommand(fromAddress, toAddress, amount string, options ...BankSendOption) step.Option { command := []string{ commandTx, } @@ -486,6 +501,11 @@ func (c ChainCmd) BankSendCommand(fromAddress, toAddress, amount string) step.Op optionYes, ) + // Apply the options provided by the user + for _, applyOption := range options { + command = applyOption(command) + } + command = c.attachChainID(command) command = c.attachKeyringBackend(command) command = c.attachNode(command) diff --git a/ignite/pkg/chaincmd/runner/chain.go b/ignite/pkg/chaincmd/runner/chain.go index 2b89e5258f..d235faa0b0 100644 --- a/ignite/pkg/chaincmd/runner/chain.go +++ b/ignite/pkg/chaincmd/runner/chain.go @@ -142,10 +142,10 @@ func (r Runner) Status(ctx context.Context) (NodeStatus, error) { } // BankSend sends amount from fromAccount to toAccount. -func (r Runner) BankSend(ctx context.Context, fromAccount, toAccount, amount string) (string, error) { +func (r Runner) BankSend(ctx context.Context, fromAccount, toAccount, amount string, options ...chaincmd.BankSendOption) (string, error) { b := newBuffer() opt := []step.Option{ - r.chainCmd.BankSendCommand(fromAccount, toAccount, amount), + r.chainCmd.BankSendCommand(fromAccount, toAccount, amount, options...), } if r.chainCmd.KeyringPassword() != "" { diff --git a/ignite/pkg/cosmosanalysis/testdata/chain/go.sum b/ignite/pkg/cosmosanalysis/testdata/chain/go.sum index 4e66ab4cad..5dad4f8a10 100644 --- a/ignite/pkg/cosmosanalysis/testdata/chain/go.sum +++ b/ignite/pkg/cosmosanalysis/testdata/chain/go.sum @@ -261,6 +261,7 @@ github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:z github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coinbase/rosetta-sdk-go/types v1.0.0/go.mod h1:eq7W2TMRH22GTW0N0beDnN931DW0/WOI1R2sdHNHG4c= github.com/cometbft/cometbft v0.37.1/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs= +github.com/cometbft/cometbft v0.37.2/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs= github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= github.com/confio/ics23/go v0.9.0/go.mod h1:4LPZ2NYqnYIVRklaozjNR1FScgDJ2s5Xrp+e/mYVRak= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= diff --git a/ignite/pkg/cosmosfaucet/cosmosfaucet.go b/ignite/pkg/cosmosfaucet/cosmosfaucet.go index e64ba81f10..c292c77c62 100644 --- a/ignite/pkg/cosmosfaucet/cosmosfaucet.go +++ b/ignite/pkg/cosmosfaucet/cosmosfaucet.go @@ -56,6 +56,9 @@ type Faucet struct { // it holds the maximum amounts of coins that can be sent to a single account. coinsMax map[string]sdkmath.Int + // fee to pay along with the transaction + feeAmount sdk.Coin + limitRefreshWindow time.Duration // openAPIData holds template data customizations for serving OpenAPI page & spec. @@ -102,6 +105,13 @@ func ChainID(id string) Option { } } +// FeeAmount sets a fee that it will be paid during the transaction +func FeeAmount(amount sdkmath.Int, denom string) Option { + return func(f *Faucet) { + f.feeAmount = sdk.NewCoin(denom, amount) + } +} + // OpenAPI configures how to serve Open API page and spec. func OpenAPI(apiAddress string) Option { return func(f *Faucet) { diff --git a/ignite/pkg/cosmosfaucet/transfer.go b/ignite/pkg/cosmosfaucet/transfer.go index 37a437e648..0eb62fbb32 100644 --- a/ignite/pkg/cosmosfaucet/transfer.go +++ b/ignite/pkg/cosmosfaucet/transfer.go @@ -9,6 +9,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ignite/cli/ignite/pkg/chaincmd" chaincmdrunner "github.com/ignite/cli/ignite/pkg/chaincmd/runner" ) @@ -91,7 +92,7 @@ func (f *Faucet) Transfer(ctx context.Context, toAccountAddress string, coins sd if err != nil { return err } - txHash, err := f.runner.BankSend(ctx, fromAccount.Address, toAccountAddress, strings.Join(coinsStr, ",")) + txHash, err := f.runner.BankSend(ctx, fromAccount.Address, toAccountAddress, strings.Join(coinsStr, ","), chaincmd.BankSendWithFees(f.feeAmount)) if err != nil { return err } From 67b2e8b44c4814877e58208c2fe21e2493c396a1 Mon Sep 17 00:00:00 2001 From: Salvo Date: Sat, 11 Nov 2023 21:43:16 +0100 Subject: [PATCH 2/6] add changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 1dc1d03e52..f603f82022 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ ### Changes - [#3529](https://github.com/ignite/cli/pull/3529) Refactor plugin system to use gRPC +- [#3745](https://github.com/ignite/cli/pull/3745) Set tx fee amount as option ## [`v0.27.1`](https://github.com/ignite/cli/releases/tag/v0.27.1) From 87e4e18c235ff94a4fed7eaac5d6d011bce075b8 Mon Sep 17 00:00:00 2001 From: Salvo Date: Sat, 11 Nov 2023 21:43:26 +0100 Subject: [PATCH 3/6] fix golangci-lint --- ignite/pkg/cosmosfaucet/cosmosfaucet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/pkg/cosmosfaucet/cosmosfaucet.go b/ignite/pkg/cosmosfaucet/cosmosfaucet.go index c292c77c62..cf022955bd 100644 --- a/ignite/pkg/cosmosfaucet/cosmosfaucet.go +++ b/ignite/pkg/cosmosfaucet/cosmosfaucet.go @@ -105,7 +105,7 @@ func ChainID(id string) Option { } } -// FeeAmount sets a fee that it will be paid during the transaction +// FeeAmount sets a fee that it will be paid during the transaction. func FeeAmount(amount sdkmath.Int, denom string) Option { return func(f *Faucet) { f.feeAmount = sdk.NewCoin(denom, amount) From 05f467ced1be648ec34fd30ae46bd9ce72928e53 Mon Sep 17 00:00:00 2001 From: Salvo Date: Sat, 11 Nov 2023 23:46:39 +0100 Subject: [PATCH 4/6] fix nil exception --- ignite/pkg/chaincmd/chaincmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/pkg/chaincmd/chaincmd.go b/ignite/pkg/chaincmd/chaincmd.go index fdf582298e..5df189751f 100644 --- a/ignite/pkg/chaincmd/chaincmd.go +++ b/ignite/pkg/chaincmd/chaincmd.go @@ -478,7 +478,7 @@ type BankSendOption func([]string) []string // BankSendWithFees sets fees to pay along with transaction for the bank send command. func BankSendWithFees(fee sdk.Coin) BankSendOption { return func(command []string) []string { - if !fee.IsZero() { + if !fee.IsNil() { return append(command, optionFees, fee.String()) } return command From 51daf42319638a926c8a6f8ad705ddbbcc087b32 Mon Sep 17 00:00:00 2001 From: Salvatore Mazzarino Date: Mon, 13 Nov 2023 12:10:10 +0100 Subject: [PATCH 5/6] chore: rename applyOptions to apply --- ignite/pkg/chaincmd/chaincmd.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ignite/pkg/chaincmd/chaincmd.go b/ignite/pkg/chaincmd/chaincmd.go index 5df189751f..6a87f5079c 100644 --- a/ignite/pkg/chaincmd/chaincmd.go +++ b/ignite/pkg/chaincmd/chaincmd.go @@ -103,8 +103,8 @@ func (c ChainCmd) Copy(options ...Option) ChainCmd { type Option func(*ChainCmd) func applyOptions(c *ChainCmd, options []Option) { - for _, applyOption := range options { - applyOption(c) + for _, apply := range options { + apply(c) } } @@ -416,8 +416,8 @@ func (c ChainCmd) GentxCommand( } // Apply the options provided by the user - for _, applyOption := range options { - command = applyOption(command) + for _, apply := range options { + command = apply(command) } command = c.attachChainID(command) @@ -502,8 +502,8 @@ func (c ChainCmd) BankSendCommand(fromAddress, toAddress, amount string, options ) // Apply the options provided by the user - for _, applyOption := range options { - command = applyOption(command) + for _, apply := range options { + command = apply(command) } command = c.attachChainID(command) From d407c51b5780396b679b7707403faeea3feb7360 Mon Sep 17 00:00:00 2001 From: Salvatore Mazzarino Date: Mon, 13 Nov 2023 12:10:58 +0100 Subject: [PATCH 6/6] remove toolchain --- integration/plugin/testdata/example-plugin/go.mod | 2 -- 1 file changed, 2 deletions(-) diff --git a/integration/plugin/testdata/example-plugin/go.mod b/integration/plugin/testdata/example-plugin/go.mod index cca0149dad..92dd113591 100644 --- a/integration/plugin/testdata/example-plugin/go.mod +++ b/integration/plugin/testdata/example-plugin/go.mod @@ -2,8 +2,6 @@ module example-plugin go 1.21.1 -toolchain go1.21.4 - require ( github.com/hashicorp/go-plugin v1.4.9 github.com/ignite/cli v0.27.1