From 7d8b68c309ac1646c3c098e9b3f49c85da49f08b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 9 Apr 2020 11:05:11 -0400 Subject: [PATCH 01/48] WIP --- client/tx/cmd.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 client/tx/cmd.go diff --git a/client/tx/cmd.go b/client/tx/cmd.go new file mode 100644 index 000000000000..cab035f304d1 --- /dev/null +++ b/client/tx/cmd.go @@ -0,0 +1,20 @@ +package tx + +import ( + "bufio" + + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/spf13/cobra" +) + +type TxCmdContext struct { + Marshaler codec.Marshaler + AccountRetriever AccountRetriever + TxGenerator Generator +} + +func NewCLIContextFromTxCmd(ctx TxCmdContext, cmd *cobra.Command) context.CLIContext { + inBuf := bufio.NewReader(cmd.InOrStdin()) + cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(ctx.Marshaler) +} From c37ce566102923fad6509d58755c3326478b1e7f Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 9 Apr 2020 11:05:25 -0400 Subject: [PATCH 02/48] WIP --- types/module/client.go | 10 ++++++++++ types/module/module.go | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 types/module/client.go diff --git a/types/module/client.go b/types/module/client.go new file mode 100644 index 000000000000..a8323b2a69c7 --- /dev/null +++ b/types/module/client.go @@ -0,0 +1,10 @@ +package module + +import ( + "github.com/spf13/cobra" +) + +type ClientModule interface { + // cli + NewTxCmd(TxCmdContext) *cobra.Command +} diff --git a/types/module/module.go b/types/module/module.go index 4a3447230878..6cd21f53f21f 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -186,6 +186,10 @@ func (GenesisOnlyAppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []ab return []abci.ValidatorUpdate{} } +func (gam GenesisOnlyAppModule) NewTxCmd(TxCmdContext) *cobra.Command { + return nil +} + //____________________________________________________________________________ // Manager defines a module manager that provides the high level utility for managing and executing From 11947b18c26f60c6ecd396feb13317257ca426cd Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 13 Apr 2020 14:49:24 -0400 Subject: [PATCH 03/48] WIP on removing x/auth dependency from client/tx --- client/context/context.go | 6 ++-- client/tx/cmd.go | 3 +- client/tx/tx.go | 57 ++++++++++++++++++++++++++++++----- codec/std/tx.go | 14 +++++++-- types/module/client.go | 10 ------ types/module/client/client.go | 11 +++++++ types/module/module.go | 4 --- x/auth/client/rest.go | 4 ++- x/auth/types/errors.go | 3 +- x/auth/types/stdtx.go | 21 +++++++++++++ x/auth/types/types.pb.go | 7 +++-- 11 files changed, 106 insertions(+), 34 deletions(-) delete mode 100644 types/module/client.go create mode 100644 types/module/client/client.go diff --git a/client/context/context.go b/client/context/context.go index c908a2044a82..09f4b022f15e 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -24,7 +24,7 @@ type CLIContext struct { FromAddress sdk.AccAddress Client rpcclient.Client ChainID string - Marshaler codec.Marshaler + Marshaler codec.JSONMarshaler Input io.Reader Keyring keyring.Keyring Output io.Writer @@ -153,8 +153,8 @@ func (ctx CLIContext) WithInput(r io.Reader) CLIContext { return ctx } -// WithMarshaler returns a copy of the CLIContext with an updated Marshaler. -func (ctx CLIContext) WithMarshaler(m codec.Marshaler) CLIContext { +// WithMarshaler returns a copy of the CLIContext with an updated JSONMarshaler. +func (ctx CLIContext) WithMarshaler(m codec.JSONMarshaler) CLIContext { ctx.Marshaler = m return ctx } diff --git a/client/tx/cmd.go b/client/tx/cmd.go index cab035f304d1..118b89c99e26 100644 --- a/client/tx/cmd.go +++ b/client/tx/cmd.go @@ -9,7 +9,7 @@ import ( ) type TxCmdContext struct { - Marshaler codec.Marshaler + Marshaler codec.JSONMarshaler AccountRetriever AccountRetriever TxGenerator Generator } @@ -17,4 +17,5 @@ type TxCmdContext struct { func NewCLIContextFromTxCmd(ctx TxCmdContext, cmd *cobra.Command) context.CLIContext { inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(ctx.Marshaler) + return cliCtx } diff --git a/client/tx/tx.go b/client/tx/tx.go index 0cd4e71f3dd9..65aef9746f0c 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -8,6 +8,10 @@ import ( "os" "strings" + errors2 "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/tendermint/tendermint/crypto" + "github.com/gogo/protobuf/jsonpb" "github.com/cosmos/cosmos-sdk/client/context" @@ -17,16 +21,31 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/types" ) +var ErrorInvalidGasAdjustment = errors2.Register(types.ModuleName, 3, "invalid gas adjustment") + type ( // Generator defines an interface a client can utilize to generate an // application-defined concrete transaction type. The type returned must // implement ClientTx. Generator interface { NewTx() ClientTx + NewFee() ClientFee + NewSignature() ClientSignature + } + + ClientFee interface { + sdk.Fee + SetGas(uint64) + SetAmount(sdk.Coins) + } + + ClientSignature interface { + sdk.Signature + SetPubKey(crypto.PubKey) error + SetSignature([]byte) } // ClientTx defines an interface which an application-defined concrete transaction @@ -39,9 +58,9 @@ type ( SetMsgs(...sdk.Msg) error GetSignatures() []sdk.Signature - SetSignatures(...sdk.Signature) + SetSignatures(...ClientSignature) error GetFee() sdk.Fee - SetFee(sdk.Fee) + SetFee(ClientFee) error GetMemo() string SetMemo(string) @@ -176,7 +195,7 @@ func WriteGeneratedTxResponse( if br.Simulate || simAndExec { if gasAdj < 0 { - rest.WriteErrorResponse(w, http.StatusBadRequest, types.ErrorInvalidGasAdjustment.Error()) + rest.WriteErrorResponse(w, http.StatusBadRequest, ErrorInvalidGasAdjustment.Error()) return } @@ -234,9 +253,18 @@ func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (ClientTx, error) { } tx := txf.txGenerator.NewTx() - tx.SetFee(auth.NewStdFee(txf.gas, fees)) + clientFee := txf.txGenerator.NewFee() + clientFee.SetAmount(fees) + clientFee.SetGas(txf.gas) + err := tx.SetFee(clientFee) + if err != nil { + return nil, err + } tx.SetMemo(txf.memo) - tx.SetSignatures() + err = tx.SetSignatures() + if err != nil { + return nil, err + } if err := tx.SetMsgs(msgs...); err != nil { return nil, err @@ -256,7 +284,11 @@ func BuildSimTx(txf Factory, msgs ...sdk.Msg) ([]byte, error) { // Create an empty signature literal as the ante handler will populate with a // sentinel pubkey. - tx.SetSignatures(auth.NewStdSignature(nil, nil)) + sig := txf.txGenerator.NewSignature() + err = tx.SetSignatures(sig) + if err != nil { + return nil, err + } return tx.Marshal() } @@ -337,7 +369,16 @@ func Sign(txf Factory, name, passphrase string, tx ClientTx) ([]byte, error) { return nil, err } - tx.SetSignatures(auth.NewStdSignature(pubkey, sigBytes)) + sig := txf.txGenerator.NewSignature() + err = sig.SetPubKey(pubkey) + if err != nil { + return nil, err + } + sig.SetSignature(sigBytes) + err = tx.SetSignatures(sig) + if err != nil { + return nil, err + } return tx.Marshal() } diff --git a/codec/std/tx.go b/codec/std/tx.go index 8305c751775f..9131eaa22893 100644 --- a/codec/std/tx.go +++ b/codec/std/tx.go @@ -17,6 +17,14 @@ var ( // transactions. type TxGenerator struct{} +func (g TxGenerator) NewFee() clientx.ClientFee { + return &auth.StdFee{} +} + +func (g TxGenerator) NewSignature() clientx.ClientSignature { + return &auth.StdSignature{} +} + // NewTx returns a reference to an empty Transaction type. func (TxGenerator) NewTx() clientx.ClientTx { return &Transaction{} @@ -121,7 +129,7 @@ func (tx Transaction) GetSignatures() []sdk.Signature { // SetSignatures sets the transaction's signatures. It will overwrite any // existing signatures set. -func (tx *Transaction) SetSignatures(sdkSigs ...sdk.Signature) { +func (tx *Transaction) SetSignatures(sdkSigs ...clientx.ClientSignature) error { sigs := make([]auth.StdSignature, len(sdkSigs)) for i, sig := range sdkSigs { if sig != nil { @@ -130,6 +138,7 @@ func (tx *Transaction) SetSignatures(sdkSigs ...sdk.Signature) { } tx.Signatures = sigs + return nil } // GetFee returns the transaction's fee. @@ -138,8 +147,9 @@ func (tx Transaction) GetFee() sdk.Fee { } // SetFee sets the transaction's fee. It will overwrite any existing fee set. -func (tx *Transaction) SetFee(fee sdk.Fee) { +func (tx *Transaction) SetFee(fee clientx.ClientFee) error { tx.Fee = auth.NewStdFee(fee.GetGas(), fee.GetAmount()) + return nil } // GetMemo returns the transaction's memo. diff --git a/types/module/client.go b/types/module/client.go deleted file mode 100644 index a8323b2a69c7..000000000000 --- a/types/module/client.go +++ /dev/null @@ -1,10 +0,0 @@ -package module - -import ( - "github.com/spf13/cobra" -) - -type ClientModule interface { - // cli - NewTxCmd(TxCmdContext) *cobra.Command -} diff --git a/types/module/client/client.go b/types/module/client/client.go new file mode 100644 index 000000000000..bfb173753db4 --- /dev/null +++ b/types/module/client/client.go @@ -0,0 +1,11 @@ +package client + +import ( + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/spf13/cobra" +) + +type ClientModule interface { + // cli + NewTxCmd(ctx tx.TxCmdContext) *cobra.Command +} diff --git a/types/module/module.go b/types/module/module.go index 6cd21f53f21f..4a3447230878 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -186,10 +186,6 @@ func (GenesisOnlyAppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []ab return []abci.ValidatorUpdate{} } -func (gam GenesisOnlyAppModule) NewTxCmd(TxCmdContext) *cobra.Command { - return nil -} - //____________________________________________________________________________ // Manager defines a module manager that provides the high level utility for managing and executing diff --git a/x/auth/client/rest.go b/x/auth/client/rest.go index aba689f75b19..93530e450616 100644 --- a/x/auth/client/rest.go +++ b/x/auth/client/rest.go @@ -4,6 +4,8 @@ import ( "log" "net/http" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" @@ -30,7 +32,7 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, cliCtx context.CLIContext if br.Simulate || simAndExec { if gasAdj < 0 { - rest.WriteErrorResponse(w, http.StatusBadRequest, types.ErrorInvalidGasAdjustment.Error()) + rest.WriteErrorResponse(w, http.StatusBadRequest, tx.ErrorInvalidGasAdjustment.Error()) return } diff --git a/x/auth/types/errors.go b/x/auth/types/errors.go index 8e765ceb9891..553f872ba6cc 100644 --- a/x/auth/types/errors.go +++ b/x/auth/types/errors.go @@ -5,6 +5,5 @@ import ( ) var ( - ErrorInvalidSigner = sdkerrors.Register(ModuleName, 2, "tx intended signer does not match the given signer") - ErrorInvalidGasAdjustment = sdkerrors.Register(ModuleName, 3, "invalid gas adjustment") + ErrorInvalidSigner = sdkerrors.Register(ModuleName, 2, "tx intended signer does not match the given signer") ) diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index 786d8ffde979..8fb469147082 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" + clientx "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/multisig" yaml "gopkg.in/yaml.v2" @@ -17,6 +19,9 @@ import ( // MaxGasWanted defines the max gas allowed. const MaxGasWanted = uint64((1 << 63) - 1) +var _ clientx.ClientFee = &StdFee{} +var _ clientx.ClientSignature = &StdSignature{} + // NewStdFee returns a new instance of StdFee func NewStdFee(gas uint64, amount sdk.Coins) StdFee { return StdFee{ @@ -35,6 +40,14 @@ func (fee StdFee) GetAmount() sdk.Coins { return fee.Amount } +func (fee *StdFee) SetGas(gas uint64) { + fee.Gas = gas +} + +func (fee *StdFee) SetAmount(amount sdk.Coins) { + fee.Amount = amount +} + // Bytes returns the encoded bytes of a StdFee. func (fee StdFee) Bytes() []byte { if len(fee.Amount) == 0 { @@ -83,6 +96,14 @@ func (ss StdSignature) GetPubKey() (pk crypto.PubKey) { return pk } +func (ss StdSignature) SetPubKey(crypto.PubKey) error { + panic("implement me") +} + +func (ss StdSignature) SetSignature([]byte) { + panic("implement me") +} + // MarshalYAML returns the YAML representation of the signature. func (ss StdSignature) MarshalYAML() (interface{}, error) { var ( diff --git a/x/auth/types/types.pb.go b/x/auth/types/types.pb.go index 69e8d5a86018..73aa0ebdb64a 100644 --- a/x/auth/types/types.pb.go +++ b/x/auth/types/types.pb.go @@ -5,13 +5,14 @@ package types import ( fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. From 6a0fa18aa85be82db8f83049a8473916053c548e Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 28 Apr 2020 14:21:37 -0400 Subject: [PATCH 04/48] Revert unneeded changes --- client/tx/cmd.go | 21 --------------------- client/tx/tx.go | 7 ------- types/module/client.go | 11 +++++++++++ types/module/client/client.go | 11 ----------- x/auth/client/rest.go | 2 -- x/auth/types/stdtx.go | 28 +++++++++------------------- x/auth/types/types.pb.go | 7 +++---- 7 files changed, 23 insertions(+), 64 deletions(-) delete mode 100644 client/tx/cmd.go create mode 100644 types/module/client.go delete mode 100644 types/module/client/client.go diff --git a/client/tx/cmd.go b/client/tx/cmd.go deleted file mode 100644 index 118b89c99e26..000000000000 --- a/client/tx/cmd.go +++ /dev/null @@ -1,21 +0,0 @@ -package tx - -import ( - "bufio" - - "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/spf13/cobra" -) - -type TxCmdContext struct { - Marshaler codec.JSONMarshaler - AccountRetriever AccountRetriever - TxGenerator Generator -} - -func NewCLIContextFromTxCmd(ctx TxCmdContext, cmd *cobra.Command) context.CLIContext { - inBuf := bufio.NewReader(cmd.InOrStdin()) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(ctx.Marshaler) - return cliCtx -} diff --git a/client/tx/tx.go b/client/tx/tx.go index b85bc6a2651f..7b7de55d7eed 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -8,11 +8,6 @@ import ( "os" "strings" - errors2 "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/gov/types" - - "github.com/tendermint/tendermint/crypto" - "github.com/gogo/protobuf/jsonpb" "github.com/tendermint/tendermint/crypto" @@ -26,8 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/rest" ) -var ErrorInvalidGasAdjustment = errors2.Register(types.ModuleName, 3, "invalid gas adjustment") - type ( // Generator defines an interface a client can utilize to generate an // application-defined concrete transaction type. The type returned must diff --git a/types/module/client.go b/types/module/client.go new file mode 100644 index 000000000000..bbaa5d4a8258 --- /dev/null +++ b/types/module/client.go @@ -0,0 +1,11 @@ +package module + +import ( + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/spf13/cobra" +) + +type ClientModule interface { + NewTxCmd(ctx context.CLIContext) *cobra.Command + NewQueryCmd(ctx context.CLIContext) *cobra.Command +} diff --git a/types/module/client/client.go b/types/module/client/client.go deleted file mode 100644 index bfb173753db4..000000000000 --- a/types/module/client/client.go +++ /dev/null @@ -1,11 +0,0 @@ -package client - -import ( - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/spf13/cobra" -) - -type ClientModule interface { - // cli - NewTxCmd(ctx tx.TxCmdContext) *cobra.Command -} diff --git a/x/auth/client/rest.go b/x/auth/client/rest.go index 75bd249f653b..e451e121b2b9 100644 --- a/x/auth/client/rest.go +++ b/x/auth/client/rest.go @@ -4,8 +4,6 @@ import ( "log" "net/http" - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index f9330564b240..16d7f319408b 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -4,8 +4,6 @@ import ( "encoding/json" "fmt" - clientx "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/multisig" yaml "gopkg.in/yaml.v2" @@ -19,7 +17,15 @@ import ( // MaxGasWanted defines the max gas allowed. const MaxGasWanted = uint64((1 << 63) - 1) -// NewStdFee returns a new instance of StdFee +// Deprecated: StdFee includes the amount of coins paid in fees and the maximum +// gas to be used by the transaction. The ratio yields an effective "gasprice", +// which must be above some miminum to be accepted into the mempool. +type StdFee struct { + Amount sdk.Coins `json:"amount" yaml:"amount"` + Gas uint64 `json:"gas" yaml:"gas"` +} + +// Deprecated: NewStdFee returns a new instance of StdFee func NewStdFee(gas uint64, amount sdk.Coins) StdFee { return StdFee{ Amount: amount, @@ -37,14 +43,6 @@ func (fee StdFee) GetAmount() sdk.Coins { return fee.Amount } -func (fee *StdFee) SetGas(gas uint64) { - fee.Gas = gas -} - -func (fee *StdFee) SetAmount(amount sdk.Coins) { - fee.Amount = amount -} - // Bytes returns the encoded bytes of a StdFee. func (fee StdFee) Bytes() []byte { if len(fee.Amount) == 0 { @@ -94,14 +92,6 @@ func (ss StdSignature) GetPubKey() (pk crypto.PubKey) { return pk } -func (ss StdSignature) SetPubKey(crypto.PubKey) error { - panic("implement me") -} - -func (ss StdSignature) SetSignature([]byte) { - panic("implement me") -} - // MarshalYAML returns the YAML representation of the signature. func (ss StdSignature) MarshalYAML() (interface{}, error) { var ( diff --git a/x/auth/types/types.pb.go b/x/auth/types/types.pb.go index 146a02828f15..ad102a4ce8e7 100644 --- a/x/auth/types/types.pb.go +++ b/x/auth/types/types.pb.go @@ -5,13 +5,12 @@ package types import ( fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. From 026a8eadf7e69f1f20bea46d7cc1ff1e09db88b7 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 28 Apr 2020 14:46:51 -0400 Subject: [PATCH 05/48] Simplify cli tx UX --- client/context/client_tx.go | 62 ++++++++++++++ client/context/context.go | 125 ++++++++++++++++++----------- client/tx/factory.go | 40 ++++----- client/tx/tx.go | 64 +++------------ std/tx.go | 21 ++--- x/bank/client/cli/tx.go | 11 ++- x/bank/client/rest/rest.go | 3 +- x/bank/client/rest/tx.go | 2 +- x/bank/module.go | 10 +++ x/crisis/client/cli/tx.go | 6 +- x/distribution/client/cli/tx.go | 18 ++--- x/distribution/client/rest/rest.go | 3 +- x/distribution/client/rest/tx.go | 12 +-- x/gov/client/cli/tx.go | 18 ++--- x/gov/client/rest/rest.go | 3 +- x/gov/client/rest/tx.go | 8 +- x/params/client/cli/tx.go | 4 +- x/slashing/client/cli/tx.go | 6 +- x/slashing/client/rest/rest.go | 3 +- x/slashing/client/rest/tx.go | 4 +- x/staking/client/cli/tx.go | 22 ++--- x/staking/client/rest/rest.go | 3 +- x/staking/client/rest/tx.go | 8 +- x/upgrade/client/cli/tx.go | 10 +-- x/upgrade/client/rest/tx.go | 6 +- 25 files changed, 263 insertions(+), 209 deletions(-) create mode 100644 client/context/client_tx.go diff --git a/client/context/client_tx.go b/client/context/client_tx.go new file mode 100644 index 000000000000..cd2c0b0cdb5a --- /dev/null +++ b/client/context/client_tx.go @@ -0,0 +1,62 @@ +package context + +import ( + "github.com/tendermint/tendermint/crypto" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/types" +) + +// AccountRetriever defines the interfaces required by transactions to +// ensure an account exists and to be able to query for account fields necessary +// for signing. +type AccountRetriever interface { + EnsureExists(addr types.AccAddress) error + GetAccountNumberSequence(addr types.AccAddress) (uint64, uint64, error) +} + +type ( + // TxGenerator defines an interface a client can utilize to generate an + // application-defined concrete transaction type. The type returned must + // implement ClientTx. + TxGenerator interface { + NewTx() ClientTx + NewFee() ClientFee + NewSignature() ClientSignature + } + + ClientFee interface { + types.Fee + SetGas(uint64) + SetAmount(types.Coins) + } + + ClientSignature interface { + types.Signature + SetPubKey(crypto.PubKey) error + SetSignature([]byte) + } + + // ClientTx defines an interface which an application-defined concrete transaction + // type must implement. Namely, it must be able to set messages, generate + // signatures, and provide canonical bytes to sign over. The transaction must + // also know how to encode itself. + ClientTx interface { + types.Tx + codec.ProtoMarshaler + + SetMsgs(...types.Msg) error + GetSignatures() []types.Signature + SetSignatures(...ClientSignature) error + GetFee() types.Fee + SetFee(ClientFee) error + GetMemo() string + SetMemo(string) + + // CanonicalSignBytes returns the canonical JSON bytes to sign over, given a + // chain ID, along with an account and sequence number. The JSON encoding + // ensures all field names adhere to their proto definition, default values + // are omitted, and follows the JSON Canonical Form. + CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error) + } +) diff --git a/client/context/context.go b/client/context/context.go index 88edd9dfb898..80bc7bf11e1c 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -22,28 +22,30 @@ import ( // CLIContext implements a typical CLI context created in SDK modules for // transaction handling and queries. type CLIContext struct { - FromAddress sdk.AccAddress - Client rpcclient.Client - ChainID string - Marshaler codec.JSONMarshaler - Input io.Reader - Keyring keyring.Keyring - Output io.Writer - OutputFormat string - Height int64 - HomeDir string - NodeURI string - From string - BroadcastMode string - Verifier tmlite.Verifier - FromName string - TrustNode bool - UseLedger bool - Simulate bool - GenerateOnly bool - Offline bool - Indent bool - SkipConfirm bool + FromAddress sdk.AccAddress + Client rpcclient.Client + ChainID string + Marshaler codec.JSONMarshaler + Input io.Reader + Keyring keyring.Keyring + Output io.Writer + OutputFormat string + Height int64 + HomeDir string + NodeURI string + From string + BroadcastMode string + Verifier tmlite.Verifier + FromName string + TrustNode bool + UseLedger bool + Simulate bool + GenerateOnly bool + Offline bool + Indent bool + SkipConfirm bool + TxGenerator TxGenerator + AccountRetriever AccountRetriever // TODO: Deprecated (remove). Codec *codec.Codec @@ -59,29 +61,11 @@ func NewCLIContextWithInputAndFrom(input io.Reader, from string) CLIContext { var nodeURI string var rpc rpcclient.Client - homedir := viper.GetString(flags.FlagHome) - genOnly := viper.GetBool(flags.FlagGenerateOnly) - backend := viper.GetString(flags.FlagKeyringBackend) - if len(backend) == 0 { - backend = keyring.BackendMemory - } - - keyring, err := newKeyringFromFlags(backend, homedir, input, genOnly) - if err != nil { - panic(fmt.Errorf("couldn't acquire keyring: %v", err)) - } - - fromAddress, fromName, err := GetFromFields(keyring, from, genOnly) - if err != nil { - fmt.Printf("failed to get from fields: %v\n", err) - os.Exit(1) - } - offline := viper.GetBool(flags.FlagOffline) if !offline { nodeURI = viper.GetString(flags.FlagNode) if nodeURI != "" { - rpc, err = rpchttp.New(nodeURI, "/websocket") + rpc, err := rpchttp.New(nodeURI, "/websocket") if err != nil { fmt.Printf("failted to get client: %v\n", err) os.Exit(1) @@ -97,22 +81,19 @@ func NewCLIContextWithInputAndFrom(input io.Reader, from string) CLIContext { Output: os.Stdout, NodeURI: nodeURI, From: viper.GetString(flags.FlagFrom), - Keyring: keyring, OutputFormat: viper.GetString(cli.OutputFlag), Height: viper.GetInt64(flags.FlagHeight), - HomeDir: homedir, TrustNode: trustNode, UseLedger: viper.GetBool(flags.FlagUseLedger), BroadcastMode: viper.GetString(flags.FlagBroadcastMode), Simulate: viper.GetBool(flags.FlagDryRun), - GenerateOnly: genOnly, Offline: offline, - FromAddress: fromAddress, - FromName: fromName, Indent: viper.GetBool(flags.FlagIndentResponse), SkipConfirm: viper.GetBool(flags.FlagSkipConfirmation), } + ctx.InitWithInputAndFrom(input, from) + if offline { return ctx } @@ -147,6 +128,46 @@ func NewCLIContextWithInput(input io.Reader) CLIContext { return NewCLIContextWithInputAndFrom(input, viper.GetString(flags.FlagFrom)) } +// InitWithInputAndFrom re-initializes an existing CLI with a new io.Reader and from parameter +func (ctx *CLIContext) InitWithInputAndFrom(input io.Reader, from string) CLIContext { + homedir := viper.GetString(flags.FlagHome) + genOnly := viper.GetBool(flags.FlagGenerateOnly) + backend := viper.GetString(flags.FlagKeyringBackend) + if len(backend) == 0 { + backend = keyring.BackendMemory + } + + keyring, err := newKeyringFromFlags(backend, homedir, input, genOnly) + if err != nil { + panic(fmt.Errorf("couldn't acquire keyring: %v", err)) + } + + fromAddress, fromName, err := GetFromFields(keyring, from, genOnly) + if err != nil { + fmt.Printf("failed to get from fields: %v\n", err) + os.Exit(1) + } + + ctx.HomeDir = homedir + + return ctx. + WithKeyring(keyring). + WithFromAddress(fromAddress). + WithFromName(fromName). + WithGenerateOnly(genOnly) + +} + +// InitWithInputAndFrom re-initializes an existing CLI with a new io.Reader +func (ctx *CLIContext) InitWithInput(input io.Reader) CLIContext { + return ctx.InitWithInputAndFrom(input, viper.GetString(flags.FlagFrom)) +} + +// InitWithInputAndFrom re-initializes an existing CLI with a new from parameter +func (ctx *CLIContext) InitWithFrom(from string) CLIContext { + return ctx.InitWithInputAndFrom(os.Stdin, from) +} + // WithKeyring returns a copy of the context with an updated keyring. func (ctx CLIContext) WithKeyring(k keyring.Keyring) CLIContext { ctx.Keyring = k @@ -265,6 +286,18 @@ func (ctx CLIContext) WithBroadcastMode(mode string) CLIContext { return ctx } +// WithTxGenerator returns the context with an updated TxGenerator +func (ctx CLIContext) WithTxGenerator(generator TxGenerator) CLIContext { + ctx.TxGenerator = generator + return ctx +} + +// WithAccountRetriever returns the context with an updated AccountRetriever +func (ctx CLIContext) WithAccountRetriever(retriever AccountRetriever) CLIContext { + ctx.AccountRetriever = retriever + return ctx +} + // Println outputs toPrint to the ctx.Output based on ctx.OutputFormat which is // either text or json. If text, toPrint will be YAML encoded. Otherwise, toPrint // will be JSON encoded using ctx.Marshaler. An error is returned upon failure. diff --git a/client/tx/factory.go b/client/tx/factory.go index 25cff13d6720..63363f8a004c 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -3,6 +3,8 @@ package tx import ( "io" + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/spf13/viper" "github.com/cosmos/cosmos-sdk/client/flags" @@ -10,20 +12,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// AccountRetriever defines the interfaces required for use by the Factory to -// ensure an account exists and to be able to query for account fields necessary -// for signing. -type AccountRetriever interface { - EnsureExists(addr sdk.AccAddress) error - GetAccountNumberSequence(addr sdk.AccAddress) (uint64, uint64, error) -} - // Factory defines a client transaction factory that facilitates generating and // signing an application-specific transaction. type Factory struct { keybase keyring.Keyring - txGenerator Generator - accountRetriever AccountRetriever + txGenerator context.TxGenerator + accountRetriever context.AccountRetriever accountNumber uint64 sequence uint64 gas uint64 @@ -64,29 +58,29 @@ func NewFactoryFromCLI(input io.Reader) Factory { } // nolint -func (f Factory) AccountNumber() uint64 { return f.accountNumber } -func (f Factory) Sequence() uint64 { return f.sequence } -func (f Factory) Gas() uint64 { return f.gas } -func (f Factory) GasAdjustment() float64 { return f.gasAdjustment } -func (f Factory) Keybase() keyring.Keyring { return f.keybase } -func (f Factory) ChainID() string { return f.chainID } -func (f Factory) Memo() string { return f.memo } -func (f Factory) Fees() sdk.Coins { return f.fees } -func (f Factory) GasPrices() sdk.DecCoins { return f.gasPrices } -func (f Factory) AccountRetriever() AccountRetriever { return f.accountRetriever } +func (f Factory) AccountNumber() uint64 { return f.accountNumber } +func (f Factory) Sequence() uint64 { return f.sequence } +func (f Factory) Gas() uint64 { return f.gas } +func (f Factory) GasAdjustment() float64 { return f.gasAdjustment } +func (f Factory) Keybase() keyring.Keyring { return f.keybase } +func (f Factory) ChainID() string { return f.chainID } +func (f Factory) Memo() string { return f.memo } +func (f Factory) Fees() sdk.Coins { return f.fees } +func (f Factory) GasPrices() sdk.DecCoins { return f.gasPrices } +func (f Factory) AccountRetriever() context.AccountRetriever { return f.accountRetriever } // SimulateAndExecute returns the option to simulate and then execute the transaction // using the gas from the simulation results func (f Factory) SimulateAndExecute() bool { return f.simulateAndExecute } -// WithTxGenerator returns a copy of the Factory with an updated Generator. -func (f Factory) WithTxGenerator(g Generator) Factory { +// WithTxGenerator returns a copy of the Factory with an updated TxGenerator. +func (f Factory) WithTxGenerator(g context.TxGenerator) Factory { f.txGenerator = g return f } // WithAccountRetriever returns a copy of the Factory with an updated AccountRetriever. -func (f Factory) WithAccountRetriever(ar AccountRetriever) Factory { +func (f Factory) WithAccountRetriever(ar context.AccountRetriever) Factory { f.accountRetriever = ar return f } diff --git a/client/tx/tx.go b/client/tx/tx.go index 7b7de55d7eed..ce40a58d645b 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -9,67 +9,26 @@ import ( "strings" "github.com/gogo/protobuf/jsonpb" - "github.com/tendermint/tendermint/crypto" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/input" clientkeys "github.com/cosmos/cosmos-sdk/client/keys" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/rest" ) -type ( - // Generator defines an interface a client can utilize to generate an - // application-defined concrete transaction type. The type returned must - // implement ClientTx. - Generator interface { - NewTx() ClientTx - NewFee() ClientFee - NewSignature() ClientSignature - } - - ClientFee interface { - sdk.Fee - SetGas(uint64) - SetAmount(sdk.Coins) - } - - ClientSignature interface { - sdk.Signature - SetPubKey(crypto.PubKey) error - SetSignature([]byte) - } - - // ClientTx defines an interface which an application-defined concrete transaction - // type must implement. Namely, it must be able to set messages, generate - // signatures, and provide canonical bytes to sign over. The transaction must - // also know how to encode itself. - ClientTx interface { - sdk.Tx - codec.ProtoMarshaler - - SetMsgs(...sdk.Msg) error - GetSignatures() []sdk.Signature - SetSignatures(...ClientSignature) error - GetFee() sdk.Fee - SetFee(ClientFee) error - GetMemo() string - SetMemo(string) - - // CanonicalSignBytes returns the canonical JSON bytes to sign over, given a - // chain ID, along with an account and sequence number. The JSON encoding - // ensures all field names adhere to their proto definition, default values - // are omitted, and follows the JSON Canonical Form. - CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error) - } -) - // GenerateOrBroadcastTx will either generate and print and unsigned transaction // or sign it and broadcast it returning an error upon failure. -func GenerateOrBroadcastTx(ctx context.CLIContext, txf Factory, msgs ...sdk.Msg) error { +func GenerateOrBroadcastTx(ctx context.CLIContext, msgs ...sdk.Msg) error { + txf := NewFactoryFromCLI(ctx.Input).WithTxGenerator(ctx.TxGenerator).WithAccountRetriever(ctx.AccountRetriever) + return GenerateOrBroadcastTxWithFactory(ctx, txf, msgs...) +} + +// GenerateOrBroadcastTxWithFactory will either generate and print and unsigned transaction +// or sign it and broadcast it returning an error upon failure. +func GenerateOrBroadcastTxWithFactory(ctx context.CLIContext, txf Factory, msgs ...sdk.Msg) error { if ctx.GenerateOnly { return GenerateTx(ctx, txf, msgs...) } @@ -166,7 +125,7 @@ func BroadcastTx(ctx context.CLIContext, txf Factory, msgs ...sdk.Msg) error { // provided http.ResponseWriter. It will simulate gas costs if requested by the // BaseReq. Upon any error, the error will be written to the http.ResponseWriter. func WriteGeneratedTxResponse( - ctx context.CLIContext, w http.ResponseWriter, txg Generator, br rest.BaseReq, msgs ...sdk.Msg, + ctx context.CLIContext, w http.ResponseWriter, txg context.TxGenerator, br rest.BaseReq, msgs ...sdk.Msg, ) { gasAdj, ok := rest.ParseFloat64OrReturnBadRequest(w, br.GasAdjustment, flags.DefaultGasAdjustment) @@ -225,7 +184,7 @@ func WriteGeneratedTxResponse( // BuildUnsignedTx builds a transaction to be signed given a set of messages. The // transaction is initially created via the provided factory's generator. Once // created, the fee, memo, and messages are set. -func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (ClientTx, error) { +func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (context.ClientTx, error) { if txf.chainID == "" { return nil, fmt.Errorf("chain ID required but not specified") } @@ -252,6 +211,7 @@ func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (ClientTx, error) { clientFee.SetGas(txf.gas) tx := txf.txGenerator.NewTx() + tx.SetMemo(txf.memo) if err := tx.SetFee(clientFee); err != nil { return nil, err @@ -349,7 +309,7 @@ func PrepareFactory(ctx context.CLIContext, txf Factory) (Factory, error) { // // Note, It is assumed the Factory has the necessary fields set that are required // by the CanonicalSignBytes call. -func Sign(txf Factory, name, passphrase string, tx ClientTx) ([]byte, error) { +func Sign(txf Factory, name, passphrase string, tx context.ClientTx) ([]byte, error) { if txf.keybase == nil { return nil, errors.New("keybase must be set prior to signing a transaction") } diff --git a/std/tx.go b/std/tx.go index 8b922f637938..58dcff3f0cb1 100644 --- a/std/tx.go +++ b/std/tx.go @@ -4,7 +4,8 @@ import ( "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/crypto" - clientx "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/client/context" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth" @@ -12,26 +13,26 @@ import ( var ( _ sdk.Tx = (*Transaction)(nil) - _ clientx.ClientTx = (*Transaction)(nil) - _ clientx.Generator = TxGenerator{} - _ clientx.ClientFee = &StdFee{} - _ clientx.ClientSignature = &StdSignature{} + _ context.ClientTx = (*Transaction)(nil) + _ context.TxGenerator = TxGenerator{} + _ context.ClientFee = &StdFee{} + _ context.ClientSignature = &StdSignature{} ) // TxGenerator defines a transaction generator that allows clients to construct // transactions. type TxGenerator struct{} -func (g TxGenerator) NewFee() clientx.ClientFee { +func (g TxGenerator) NewFee() context.ClientFee { return &StdFee{} } -func (g TxGenerator) NewSignature() clientx.ClientSignature { +func (g TxGenerator) NewSignature() context.ClientSignature { return &StdSignature{} } // NewTx returns a reference to an empty Transaction type. -func (TxGenerator) NewTx() clientx.ClientTx { +func (TxGenerator) NewTx() context.ClientTx { return &Transaction{} } @@ -134,7 +135,7 @@ func (tx Transaction) GetSignatures() []sdk.Signature { // SetSignatures sets the transaction's signatures. It will overwrite any // existing signatures set. -func (tx *Transaction) SetSignatures(sdkSigs ...clientx.ClientSignature) error { +func (tx *Transaction) SetSignatures(sdkSigs ...context.ClientSignature) error { sigs := make([]StdSignature, len(sdkSigs)) for i, sig := range sdkSigs { if sig != nil { @@ -152,7 +153,7 @@ func (tx Transaction) GetFee() sdk.Fee { } // SetFee sets the transaction's fee. It will overwrite any existing fee set. -func (tx *Transaction) SetFee(fee clientx.ClientFee) error { +func (tx *Transaction) SetFee(fee context.ClientFee) error { tx.Fee = NewStdFee(fee.GetGas(), fee.GetAmount()) return nil } diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index 597004519fe8..8c334c4a7166 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -17,7 +17,7 @@ import ( ) // NewTxCmd returns a root CLI command handler for all x/bank transaction commands. -func NewTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewTxCmd(cliCtx context.CLIContext) *cobra.Command { txCmd := &cobra.Command{ Use: types.ModuleName, Short: "Bank transaction subcommands", @@ -26,21 +26,20 @@ func NewTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobr RunE: client.ValidateCmd, } - txCmd.AddCommand(NewSendTxCmd(m, txg, ar)) + txCmd.AddCommand(NewSendTxCmd(cliCtx)) return txCmd } // NewSendTxCmd returns a CLI command handler for creating a MsgSend transaction. -func NewSendTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewSendTxCmd(cliCtx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "send [from_key_or_address] [to_address] [amount]", Short: "Create and/or sign and broadcast a MsgSend transaction", Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) - cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m) - txf := tx.NewFactoryFromCLI(inBuf).WithTxGenerator(txg).WithAccountRetriever(ar) + cliCtx.InitWithInputAndFrom(inBuf, args[0]) toAddr, err := sdk.AccAddressFromBech32(args[1]) if err != nil { @@ -57,7 +56,7 @@ func NewSendTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) * return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } diff --git a/x/bank/client/rest/rest.go b/x/bank/client/rest/rest.go index 439000012ec3..964333863bc5 100644 --- a/x/bank/client/rest/rest.go +++ b/x/bank/client/rest/rest.go @@ -4,13 +4,12 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" ) // RegisterHandlers registers all x/bank transaction and query HTTP REST handlers // on the provided mux router. -func RegisterHandlers(ctx context.CLIContext, m codec.Marshaler, txg tx.Generator, r *mux.Router) { +func RegisterHandlers(ctx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { r.HandleFunc("/bank/accounts/{address}/transfers", NewSendRequestHandlerFn(ctx, m, txg)).Methods("POST") r.HandleFunc("/bank/balances/{address}", QueryBalancesRequestHandlerFn(ctx)).Methods("GET") } diff --git a/x/bank/client/rest/tx.go b/x/bank/client/rest/tx.go index db671b741b4f..6889ef0c2dc0 100644 --- a/x/bank/client/rest/tx.go +++ b/x/bank/client/rest/tx.go @@ -22,7 +22,7 @@ type SendReq struct { // NewSendRequestHandlerFn returns an HTTP REST handler for creating a MsgSend // transaction. -func NewSendRequestHandlerFn(ctx context.CLIContext, m codec.Marshaler, txg tx.Generator) http.HandlerFunc { +func NewSendRequestHandlerFn(ctx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { ctx = ctx.WithMarshaler(m) diff --git a/x/bank/module.go b/x/bank/module.go index 1cc4b7fa4d0e..4c4647115e7b 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -165,3 +165,13 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp simState.AppParams, simState.Cdc, am.accountKeeper, am.keeper, ) } + +var _ module.ClientModule = AppModuleBasic{} + +func (am AppModuleBasic) NewTxCmd(ctx context.CLIContext) *cobra.Command { + return cli.NewTxCmd(ctx) +} + +func (am AppModuleBasic) NewQueryCmd(ctx context.CLIContext) *cobra.Command { + return nil +} diff --git a/x/crisis/client/cli/tx.go b/x/crisis/client/cli/tx.go index 320515123a85..18ea757cbc03 100644 --- a/x/crisis/client/cli/tx.go +++ b/x/crisis/client/cli/tx.go @@ -17,7 +17,7 @@ import ( ) // NewTxCmd returns a root CLI command handler for all x/crisis transaction commands. -func NewTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { txCmd := &cobra.Command{ Use: types.ModuleName, Short: "Crisis transactions subcommands", @@ -33,7 +33,7 @@ func NewTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobr // NewMsgVerifyInvariantTxCmd returns a CLI command handler for creating a // MsgVerifyInvariant transaction. -func NewMsgVerifyInvariantTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewMsgVerifyInvariantTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { cmd := &cobra.Command{ Use: "invariant-broken [module-name] [invariant-route]", Short: "Submit proof that an invariant broken to halt the chain", @@ -51,7 +51,7 @@ func NewMsgVerifyInvariantTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.Accou return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index e6df78fcc06c..2230ea0eef84 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -37,7 +37,7 @@ const ( ) // NewTxCmd returns a root CLI command handler for all x/distribution transaction commands. -func NewTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { distTxCmd := &cobra.Command{ Use: types.ModuleName, Short: "Distribution transactions subcommands", @@ -87,7 +87,7 @@ func newSplitAndApply( return nil } -func NewWithdrawRewardsCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewWithdrawRewardsCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { cmd := &cobra.Command{ Use: "withdraw-rewards [validator-addr]", Short: "Withdraw rewards from a given delegation address, and optionally withdraw validator commission if the delegation address given is a validator operator", @@ -127,14 +127,14 @@ $ %s tx distribution withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx } } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msgs...) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msgs...) }, } cmd.Flags().Bool(flagCommission, false, "also withdraw validator's commission") return flags.PostCommands(cmd)[0] } -func NewWithdrawAllRewardsCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewWithdrawAllRewardsCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { cmd := &cobra.Command{ Use: "withdraw-all-rewards", Short: "withdraw all delegations rewards for a delegator", @@ -169,13 +169,13 @@ $ %s tx distribution withdraw-all-rewards --from mykey } chunkSize := viper.GetInt(flagMaxMessagesPerTx) - return newSplitAndApply(tx.GenerateOrBroadcastTx, cliCtx, txf, msgs, chunkSize) + return newSplitAndApply(tx.GenerateOrBroadcastTxWithFactory, cliCtx, txf, msgs, chunkSize) }, } return flags.PostCommands(cmd)[0] } -func NewSetWithdrawAddrCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewSetWithdrawAddrCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { cmd := &cobra.Command{ Use: "set-withdraw-addr [withdraw-addr]", Short: "change the default withdraw address for rewards associated with an address", @@ -207,13 +207,13 @@ $ %s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75 return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } return flags.PostCommands(cmd)[0] } -func NewFundCommunityPoolCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewFundCommunityPoolCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { cmd := &cobra.Command{ Use: "community-pool-spend [proposal-file]", Args: cobra.ExactArgs(1), @@ -256,7 +256,7 @@ Where proposal.json contains: return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } return flags.PostCommands(cmd)[0] diff --git a/x/distribution/client/rest/rest.go b/x/distribution/client/rest/rest.go index 2e71d77cbdc6..7b0811dfc020 100644 --- a/x/distribution/client/rest/rest.go +++ b/x/distribution/client/rest/rest.go @@ -6,7 +6,6 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" @@ -16,7 +15,7 @@ import ( govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" ) -func RegisterHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Generator, r *mux.Router) { +func RegisterHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { registerQueryRoutes(cliCtx, r) registerTxHandlers(cliCtx, m, txg, r) } diff --git a/x/distribution/client/rest/tx.go b/x/distribution/client/rest/tx.go index d36a0a4eabf1..855cf207a473 100644 --- a/x/distribution/client/rest/tx.go +++ b/x/distribution/client/rest/tx.go @@ -31,7 +31,7 @@ type ( } ) -func registerTxHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Generator, r *mux.Router) { +func registerTxHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { // Withdraw all delegator rewards r.HandleFunc( "/distribution/delegators/{delegatorAddr}/rewards", @@ -63,7 +63,7 @@ func registerTxHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Gen ).Methods("POST") } -func newWithdrawDelegatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Generator) http.HandlerFunc { +func newWithdrawDelegatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithMarshaler(m) var req withdrawRewardsReq @@ -91,7 +91,7 @@ func newWithdrawDelegatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Mar } } -func newWithdrawDelegationRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Generator) http.HandlerFunc { +func newWithdrawDelegationRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithMarshaler(m) var req withdrawRewardsReq @@ -124,7 +124,7 @@ func newWithdrawDelegationRewardsHandlerFn(cliCtx context.CLIContext, m codec.Ma } } -func newSetDelegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Generator) http.HandlerFunc { +func newSetDelegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithMarshaler(m) var req setWithdrawalAddrReq @@ -152,7 +152,7 @@ func newSetDelegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, m codec.M } } -func newWithdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Generator) http.HandlerFunc { +func newWithdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithMarshaler(m) var req withdrawRewardsReq @@ -181,7 +181,7 @@ func newWithdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Mar } } -func newFundCommunityPoolHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Generator) http.HandlerFunc { +func newFundCommunityPoolHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithMarshaler(m) var req fundCommunityPoolReq diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index dc8f0eac5a52..96661068dbf6 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -57,8 +57,8 @@ var ProposalFlags = []string{ // under the governance CLI (eg. parameter change proposals). func NewTxCmd( cdc codec.Marshaler, - txg tx.Generator, - ar tx.AccountRetriever, + txg context.TxGenerator, + ar context.AccountRetriever, newMsgFn func() types.MsgSubmitProposalI, pcmds []*cobra.Command) *cobra.Command { govTxCmd := &cobra.Command{ @@ -86,8 +86,8 @@ func NewTxCmd( // NewCmdSubmitProposal implements submitting a proposal transaction command. func NewCmdSubmitProposal( cdc codec.Marshaler, - txg tx.Generator, - ar tx.AccountRetriever, + txg context.TxGenerator, + ar context.AccountRetriever, newMsgFn func() types.MsgSubmitProposalI) *cobra.Command { cmd := &cobra.Command{ Use: "submit-proposal", @@ -144,7 +144,7 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } @@ -158,7 +158,7 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr } // NewCmdDeposit implements depositing tokens for an active proposal. -func NewCmdDeposit(cdc codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewCmdDeposit(cdc codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { return &cobra.Command{ Use: "deposit [proposal-id] [deposit]", Args: cobra.ExactArgs(2), @@ -199,13 +199,13 @@ $ %s tx gov deposit 1 10stake --from mykey return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } } // NewCmdVote implements creating a new vote command. -func NewCmdVote(cdc codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewCmdVote(cdc codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { return &cobra.Command{ Use: "vote [proposal-id] [option]", Args: cobra.ExactArgs(2), @@ -248,7 +248,7 @@ $ %s tx gov vote 1 yes --from mykey return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } } diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index 0522566dde9a..a9e0a3e62f48 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -3,7 +3,6 @@ package rest import ( "net/http" - "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/gorilla/mux" @@ -33,7 +32,7 @@ type ProposalRESTHandler struct { func RegisterHandlers( cliCtx context.CLIContext, - txg tx.Generator, + txg context.TxGenerator, r *mux.Router, newMsgFn func() types.MsgSubmitProposalI, phs []ProposalRESTHandler) { diff --git a/x/gov/client/rest/tx.go b/x/gov/client/rest/tx.go index 22d6ff924251..bb2fd27c6ebf 100644 --- a/x/gov/client/rest/tx.go +++ b/x/gov/client/rest/tx.go @@ -15,7 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" ) -func registerTxHandlers(cliCtx context.CLIContext, txg tx.Generator, r *mux.Router, newMsgFn func() types.MsgSubmitProposalI, phs []ProposalRESTHandler) { +func registerTxHandlers(cliCtx context.CLIContext, txg context.TxGenerator, r *mux.Router, newMsgFn func() types.MsgSubmitProposalI, phs []ProposalRESTHandler) { propSubRtr := r.PathPrefix("/gov/proposals").Subrouter() for _, ph := range phs { propSubRtr.HandleFunc(fmt.Sprintf("/%s", ph.SubRoute), ph.Handler).Methods("POST") @@ -26,7 +26,7 @@ func registerTxHandlers(cliCtx context.CLIContext, txg tx.Generator, r *mux.Rout r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), newVoteHandlerFn(cliCtx, txg)).Methods("POST") } -func newPostProposalHandlerFn(cliCtx context.CLIContext, txg tx.Generator, newMsgFn func() types.MsgSubmitProposalI) http.HandlerFunc { +func newPostProposalHandlerFn(cliCtx context.CLIContext, txg context.TxGenerator, newMsgFn func() types.MsgSubmitProposalI) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req PostProposalReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { @@ -56,7 +56,7 @@ func newPostProposalHandlerFn(cliCtx context.CLIContext, txg tx.Generator, newMs } } -func newDepositHandlerFn(cliCtx context.CLIContext, txg tx.Generator) http.HandlerFunc { +func newDepositHandlerFn(cliCtx context.CLIContext, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -91,7 +91,7 @@ func newDepositHandlerFn(cliCtx context.CLIContext, txg tx.Generator) http.Handl } } -func newVoteHandlerFn(cliCtx context.CLIContext, txg tx.Generator) http.HandlerFunc { +func newVoteHandlerFn(cliCtx context.CLIContext, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] diff --git a/x/params/client/cli/tx.go b/x/params/client/cli/tx.go index 020854f2a125..1b326081ecba 100644 --- a/x/params/client/cli/tx.go +++ b/x/params/client/cli/tx.go @@ -21,7 +21,7 @@ import ( // NewSubmitParamChangeProposalTxCmd returns a CLI command handler for creating // a parameter change proposal governance transaction. -func NewSubmitParamChangeProposalTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewSubmitParamChangeProposalTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { cmd := &cobra.Command{ Use: "param-change [proposal-file]", Args: cobra.ExactArgs(1), @@ -85,7 +85,7 @@ Where proposal.json contains: return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } diff --git a/x/slashing/client/cli/tx.go b/x/slashing/client/cli/tx.go index 0389cc631610..5811efc6b939 100644 --- a/x/slashing/client/cli/tx.go +++ b/x/slashing/client/cli/tx.go @@ -17,7 +17,7 @@ import ( ) // NewTxCmd returns a root CLI command handler for all x/slashing transaction commands. -func NewTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { slashingTxCmd := &cobra.Command{ Use: types.ModuleName, Short: "Slashing transaction subcommands", @@ -30,7 +30,7 @@ func NewTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobr return slashingTxCmd } -func NewUnjailTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewUnjailTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { cmd := &cobra.Command{ Use: "unjail", Args: cobra.NoArgs, @@ -53,7 +53,7 @@ $ tx slashing unjail --from mykey return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } return flags.PostCommands(cmd)[0] diff --git a/x/slashing/client/rest/rest.go b/x/slashing/client/rest/rest.go index d4c500f84c94..716ac12904a7 100644 --- a/x/slashing/client/rest/rest.go +++ b/x/slashing/client/rest/rest.go @@ -4,11 +4,10 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" ) -func RegisterHandlers(ctx context.CLIContext, m codec.Marshaler, txg tx.Generator, r *mux.Router) { +func RegisterHandlers(ctx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { registerQueryRoutes(ctx, r) registerTxHandlers(ctx, m, txg, r) } diff --git a/x/slashing/client/rest/tx.go b/x/slashing/client/rest/tx.go index dba316db8462..c496615a37aa 100644 --- a/x/slashing/client/rest/tx.go +++ b/x/slashing/client/rest/tx.go @@ -15,7 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/slashing/types" ) -func registerTxHandlers(ctx context.CLIContext, m codec.Marshaler, txg tx.Generator, r *mux.Router) { +func registerTxHandlers(ctx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { r.HandleFunc("/slashing/validators/{validatorAddr}/unjail", NewUnjailRequestHandlerFn(ctx, m, txg)).Methods("POST") } @@ -26,7 +26,7 @@ type UnjailReq struct { // NewUnjailRequestHandlerFn returns an HTTP REST handler for creating a MsgUnjail // transaction. -func NewUnjailRequestHandlerFn(ctx context.CLIContext, m codec.Marshaler, txg tx.Generator) http.HandlerFunc { +func NewUnjailRequestHandlerFn(ctx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { ctx = ctx.WithMarshaler(m) vars := mux.Vars(r) diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index dcec0ca44d32..9e0b9e1d11cb 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -37,7 +37,7 @@ var ( ) // NewTxCmd returns a root CLI command handler for all x/staking transaction commands. -func NewTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { stakingTxCmd := &cobra.Command{ Use: types.ModuleName, Short: "Staking transaction subcommands", @@ -56,7 +56,7 @@ func NewTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobr return stakingTxCmd } -func NewCreateValidatorCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewCreateValidatorCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { cmd := &cobra.Command{ Use: "create-validator", Short: "create new validator initialized with a self-delegation to it", @@ -72,7 +72,7 @@ func NewCreateValidatorCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRet if err != nil { return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } cmd.Flags().AddFlagSet(FsPk) @@ -91,7 +91,7 @@ func NewCreateValidatorCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRet return flags.PostCommands(cmd)[0] } -func NewEditValidatorCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewEditValidatorCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { cmd := &cobra.Command{ Use: "edit-validator", Short: "edit an existing validator account", @@ -142,13 +142,13 @@ func NewEditValidatorCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetri } // build and sign the transaction, then broadcast to Tendermint - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } return flags.PostCommands(cmd)[0] } -func NewDelegateCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewDelegateCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { cmd := &cobra.Command{ Use: "delegate [validator-addr] [amount]", Args: cobra.ExactArgs(2), @@ -186,7 +186,7 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10 return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } cmd.Flags().AddFlagSet(fsDescriptionEdit) @@ -196,7 +196,7 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10 return flags.PostCommands(cmd)[0] } -func NewRedelegateCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewRedelegateCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { cmd := &cobra.Command{ Use: "redelegate [src-validator-addr] [dst-validator-addr] [amount]", Short: "Redelegate illiquid tokens from one validator to another", @@ -238,13 +238,13 @@ $ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } return flags.PostCommands(cmd)[0] } -func NewUnbondCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *cobra.Command { +func NewUnbondCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { cmd := &cobra.Command{ Use: "unbond [validator-addr] [amount]", Short: "Unbond shares from a validator", @@ -282,7 +282,7 @@ $ %s tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100s return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } return flags.PostCommands(cmd)[0] diff --git a/x/staking/client/rest/rest.go b/x/staking/client/rest/rest.go index b43cf152c662..b7e61c1ec6dd 100644 --- a/x/staking/client/rest/rest.go +++ b/x/staking/client/rest/rest.go @@ -4,11 +4,10 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" ) -func RegisterHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Generator, r *mux.Router) { +func RegisterHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { registerQueryRoutes(cliCtx, r) registerTxHandlers(cliCtx, m, txg, r) } diff --git a/x/staking/client/rest/tx.go b/x/staking/client/rest/tx.go index 01328279ea1a..ff0128badbf8 100644 --- a/x/staking/client/rest/tx.go +++ b/x/staking/client/rest/tx.go @@ -15,7 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" ) -func registerTxHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Generator, r *mux.Router) { +func registerTxHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { r.HandleFunc( "/staking/delegators/{delegatorAddr}/delegations", newPostDelegationsHandlerFn(cliCtx, m, txg), @@ -57,7 +57,7 @@ type ( } ) -func newPostDelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Generator) http.HandlerFunc { +func newPostDelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithMarshaler(m) var req DelegateRequest @@ -90,7 +90,7 @@ func newPostDelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, t } } -func newPostRedelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Generator) http.HandlerFunc { +func newPostRedelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithMarshaler(m) var req RedelegateRequest @@ -123,7 +123,7 @@ func newPostRedelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, } } -func newPostUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg tx.Generator) http.HandlerFunc { +func newPostUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithMarshaler(m) var req UndelegateRequest diff --git a/x/upgrade/client/cli/tx.go b/x/upgrade/client/cli/tx.go index 27df5c3ec3ca..0a0127d1cba7 100644 --- a/x/upgrade/client/cli/tx.go +++ b/x/upgrade/client/cli/tx.go @@ -31,7 +31,7 @@ const ( // NewCmdSubmitUpgradeProposal implements a command handler for submitting a software upgrade proposal transaction. func NewCmdSubmitUpgradeProposal( - m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever, + m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever, newMsgFn func() gov.MsgSubmitProposalI, ) *cobra.Command { @@ -75,7 +75,7 @@ func NewCmdSubmitUpgradeProposal( return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } @@ -92,8 +92,8 @@ func NewCmdSubmitUpgradeProposal( // NewCmdSubmitCancelUpgradeProposal implements a command handler for submitting a software upgrade cancel proposal transaction. func NewCmdSubmitCancelUpgradeProposal( m codec.Marshaler, - txg tx.Generator, - ar tx.AccountRetriever, + txg context.TxGenerator, + ar context.AccountRetriever, newMsgFn func() gov.MsgSubmitProposalI) *cobra.Command { cmd := &cobra.Command{ Use: "cancel-software-upgrade [flags]", @@ -140,7 +140,7 @@ func NewCmdSubmitCancelUpgradeProposal( return err } - return tx.GenerateOrBroadcastTx(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) }, } diff --git a/x/upgrade/client/rest/tx.go b/x/upgrade/client/rest/tx.go index f04e4d07ab74..85dd2e157fee 100644 --- a/x/upgrade/client/rest/tx.go +++ b/x/upgrade/client/rest/tx.go @@ -21,7 +21,7 @@ import ( // nolint func newRegisterTxRoutes( cliCtx context.CLIContext, - txg tx.Generator, + txg context.TxGenerator, newMsgFn func() gov.MsgSubmitProposalI, r *mux.Router) { r.HandleFunc("/upgrade/plan", newPostPlanHandler(cliCtx, txg, newMsgFn)).Methods("POST") @@ -61,7 +61,7 @@ func ProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler } // nolint -func newPostPlanHandler(cliCtx context.CLIContext, txg tx.Generator, newMsgFn func() gov.MsgSubmitProposalI) http.HandlerFunc { +func newPostPlanHandler(cliCtx context.CLIContext, txg context.TxGenerator, newMsgFn func() gov.MsgSubmitProposalI) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req PlanRequest @@ -106,7 +106,7 @@ func newPostPlanHandler(cliCtx context.CLIContext, txg tx.Generator, newMsgFn fu } // nolint -func newCancelPlanHandler(cliCtx context.CLIContext, txg tx.Generator, newMsgFn func() gov.MsgSubmitProposalI) http.HandlerFunc { +func newCancelPlanHandler(cliCtx context.CLIContext, txg context.TxGenerator, newMsgFn func() gov.MsgSubmitProposalI) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req CancelRequest From d0cd45add60eca0260def707f5969385b856c7a3 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 28 Apr 2020 14:56:55 -0400 Subject: [PATCH 06/48] Wire up bank tx REST routes --- client/tx/tx.go | 7 +++---- types/module/client.go | 5 ++++- x/bank/client/rest/rest.go | 5 ++--- x/bank/client/rest/tx.go | 7 ++----- x/bank/module.go | 4 ++++ x/distribution/client/rest/tx.go | 10 +++++----- x/gov/client/rest/tx.go | 6 +++--- x/slashing/client/rest/tx.go | 2 +- x/staking/client/rest/tx.go | 6 +++--- x/upgrade/client/rest/tx.go | 4 ++-- 10 files changed, 29 insertions(+), 27 deletions(-) diff --git a/client/tx/tx.go b/client/tx/tx.go index ce40a58d645b..ce45e6bc2bb9 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -124,9 +124,7 @@ func BroadcastTx(ctx context.CLIContext, txf Factory, msgs ...sdk.Msg) error { // WriteGeneratedTxResponse writes a generated unsigned transaction to the // provided http.ResponseWriter. It will simulate gas costs if requested by the // BaseReq. Upon any error, the error will be written to the http.ResponseWriter. -func WriteGeneratedTxResponse( - ctx context.CLIContext, w http.ResponseWriter, txg context.TxGenerator, br rest.BaseReq, msgs ...sdk.Msg, -) { +func WriteGeneratedTxResponse(ctx context.CLIContext, w http.ResponseWriter, br rest.BaseReq, msgs ...sdk.Msg) { gasAdj, ok := rest.ParseFloat64OrReturnBadRequest(w, br.GasAdjustment, flags.DefaultGasAdjustment) if !ok { @@ -145,7 +143,8 @@ func WriteGeneratedTxResponse( WithGasAdjustment(gasAdj). WithMemo(br.Memo). WithChainID(br.ChainID). - WithSimulateAndExecute(br.Simulate) + WithSimulateAndExecute(br.Simulate). + WithTxGenerator(ctx.TxGenerator) if br.Simulate || simAndExec { if gasAdj < 0 { diff --git a/types/module/client.go b/types/module/client.go index bbaa5d4a8258..d39fdb2f9c16 100644 --- a/types/module/client.go +++ b/types/module/client.go @@ -1,11 +1,14 @@ package module import ( - "github.com/cosmos/cosmos-sdk/client/context" + "github.com/gorilla/mux" "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client/context" ) type ClientModule interface { NewTxCmd(ctx context.CLIContext) *cobra.Command NewQueryCmd(ctx context.CLIContext) *cobra.Command + NewRESTRoutes(ctx context.CLIContext, rtr *mux.Router) } diff --git a/x/bank/client/rest/rest.go b/x/bank/client/rest/rest.go index 964333863bc5..f9fec1e38450 100644 --- a/x/bank/client/rest/rest.go +++ b/x/bank/client/rest/rest.go @@ -4,13 +4,12 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/codec" ) // RegisterHandlers registers all x/bank transaction and query HTTP REST handlers // on the provided mux router. -func RegisterHandlers(ctx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { - r.HandleFunc("/bank/accounts/{address}/transfers", NewSendRequestHandlerFn(ctx, m, txg)).Methods("POST") +func RegisterHandlers(ctx context.CLIContext, r *mux.Router) { + r.HandleFunc("/bank/accounts/{address}/transfers", NewSendRequestHandlerFn(ctx)).Methods("POST") r.HandleFunc("/bank/balances/{address}", QueryBalancesRequestHandlerFn(ctx)).Methods("GET") } diff --git a/x/bank/client/rest/tx.go b/x/bank/client/rest/tx.go index 6889ef0c2dc0..bd96552f3568 100644 --- a/x/bank/client/rest/tx.go +++ b/x/bank/client/rest/tx.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" @@ -22,10 +21,8 @@ type SendReq struct { // NewSendRequestHandlerFn returns an HTTP REST handler for creating a MsgSend // transaction. -func NewSendRequestHandlerFn(ctx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { +func NewSendRequestHandlerFn(ctx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - ctx = ctx.WithMarshaler(m) - vars := mux.Vars(r) bech32Addr := vars["address"] @@ -50,7 +47,7 @@ func NewSendRequestHandlerFn(ctx context.CLIContext, m codec.Marshaler, txg cont } msg := types.NewMsgSend(fromAddr, toAddr, req.Amount) - tx.WriteGeneratedTxResponse(ctx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(ctx, w, req.BaseReq, msg) } } diff --git a/x/bank/module.go b/x/bank/module.go index 4c4647115e7b..29fce03e9253 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -175,3 +175,7 @@ func (am AppModuleBasic) NewTxCmd(ctx context.CLIContext) *cobra.Command { func (am AppModuleBasic) NewQueryCmd(ctx context.CLIContext) *cobra.Command { return nil } + +func (am AppModuleBasic) NewRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { + rest.RegisterHandlers(ctx, rtr) +} diff --git a/x/distribution/client/rest/tx.go b/x/distribution/client/rest/tx.go index 855cf207a473..7ffdc39ad4ad 100644 --- a/x/distribution/client/rest/tx.go +++ b/x/distribution/client/rest/tx.go @@ -87,7 +87,7 @@ func newWithdrawDelegatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Mar return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msgs...) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msgs...) } } @@ -120,7 +120,7 @@ func newWithdrawDelegationRewardsHandlerFn(cliCtx context.CLIContext, m codec.Ma return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg) } } @@ -148,7 +148,7 @@ func newSetDelegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, m codec.M return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg) } } @@ -177,7 +177,7 @@ func newWithdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Mar return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msgs...) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msgs...) } } @@ -204,7 +204,7 @@ func newFundCommunityPoolHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg) } } diff --git a/x/gov/client/rest/tx.go b/x/gov/client/rest/tx.go index bb2fd27c6ebf..788692121a80 100644 --- a/x/gov/client/rest/tx.go +++ b/x/gov/client/rest/tx.go @@ -52,7 +52,7 @@ func newPostProposalHandlerFn(cliCtx context.CLIContext, txg context.TxGenerator return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg) } } @@ -87,7 +87,7 @@ func newDepositHandlerFn(cliCtx context.CLIContext, txg context.TxGenerator) htt return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg) } } @@ -127,7 +127,7 @@ func newVoteHandlerFn(cliCtx context.CLIContext, txg context.TxGenerator) http.H return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg) } } diff --git a/x/slashing/client/rest/tx.go b/x/slashing/client/rest/tx.go index c496615a37aa..6641adcb786c 100644 --- a/x/slashing/client/rest/tx.go +++ b/x/slashing/client/rest/tx.go @@ -61,7 +61,7 @@ func NewUnjailRequestHandlerFn(ctx context.CLIContext, m codec.Marshaler, txg co if rest.CheckBadRequestError(w, msg.ValidateBasic()) { return } - tx.WriteGeneratedTxResponse(ctx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(ctx, w, req.BaseReq, msg) } } diff --git a/x/staking/client/rest/tx.go b/x/staking/client/rest/tx.go index ff0128badbf8..f0e0bb6fc93e 100644 --- a/x/staking/client/rest/tx.go +++ b/x/staking/client/rest/tx.go @@ -86,7 +86,7 @@ func newPostDelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, t return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg) } } @@ -119,7 +119,7 @@ func newPostRedelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg) } } @@ -151,7 +151,7 @@ func newPostUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, m codec.Mar return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg) } } diff --git a/x/upgrade/client/rest/tx.go b/x/upgrade/client/rest/tx.go index 85dd2e157fee..c4a9d92941b4 100644 --- a/x/upgrade/client/rest/tx.go +++ b/x/upgrade/client/rest/tx.go @@ -101,7 +101,7 @@ func newPostPlanHandler(cliCtx context.CLIContext, txg context.TxGenerator, newM return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg) } } @@ -137,7 +137,7 @@ func newCancelPlanHandler(cliCtx context.CLIContext, txg context.TxGenerator, ne return } - tx.WriteGeneratedTxResponse(cliCtx, w, txg, req.BaseReq, msg) + tx.WriteGeneratedTxResponse(cliCtx, w, req.BaseReq, msg) } } From 97d3537214021000930f6886dbae97ffd4b0cb73 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 28 Apr 2020 15:49:21 -0400 Subject: [PATCH 07/48] Fix assignment issue --- client/context/context.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/context/context.go b/client/context/context.go index 80bc7bf11e1c..7543d1224046 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -60,12 +60,13 @@ type CLIContext struct { func NewCLIContextWithInputAndFrom(input io.Reader, from string) CLIContext { var nodeURI string var rpc rpcclient.Client + var err error offline := viper.GetBool(flags.FlagOffline) if !offline { nodeURI = viper.GetString(flags.FlagNode) if nodeURI != "" { - rpc, err := rpchttp.New(nodeURI, "/websocket") + rpc, err = rpchttp.New(nodeURI, "/websocket") if err != nil { fmt.Printf("failted to get client: %v\n", err) os.Exit(1) @@ -137,12 +138,12 @@ func (ctx *CLIContext) InitWithInputAndFrom(input io.Reader, from string) CLICon backend = keyring.BackendMemory } - keyring, err := newKeyringFromFlags(backend, homedir, input, genOnly) + kr, err := newKeyringFromFlags(backend, homedir, input, genOnly) if err != nil { panic(fmt.Errorf("couldn't acquire keyring: %v", err)) } - fromAddress, fromName, err := GetFromFields(keyring, from, genOnly) + fromAddress, fromName, err := GetFromFields(kr, from, genOnly) if err != nil { fmt.Printf("failed to get from fields: %v\n", err) os.Exit(1) @@ -151,7 +152,7 @@ func (ctx *CLIContext) InitWithInputAndFrom(input io.Reader, from string) CLICon ctx.HomeDir = homedir return ctx. - WithKeyring(keyring). + WithKeyring(kr). WithFromAddress(fromAddress). WithFromName(fromName). WithGenerateOnly(genOnly) From 77a96a0a7b13a46cb85f5d67b5df8b6ecf71e36d Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Fri, 15 May 2020 14:36:32 -0400 Subject: [PATCH 08/48] Wire up bank NewSendTxCmd --- client/context/client_tx.go | 3 +- client/tx/factory.go | 20 ++++---- client/tx/tx.go | 4 +- simapp/cmd/simcli/main.go | 14 ++++-- std/tx.go | 7 ++- x/auth/types/client_tx.go | 96 +++++++++++++++++++++++++++++++++++++ 6 files changed, 125 insertions(+), 19 deletions(-) create mode 100644 x/auth/types/client_tx.go diff --git a/client/context/client_tx.go b/client/context/client_tx.go index cd2c0b0cdb5a..bbbc13869b94 100644 --- a/client/context/client_tx.go +++ b/client/context/client_tx.go @@ -3,7 +3,6 @@ package context import ( "github.com/tendermint/tendermint/crypto" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types" ) @@ -23,6 +22,7 @@ type ( NewTx() ClientTx NewFee() ClientFee NewSignature() ClientSignature + MarshalTx(tx ClientTx) ([]byte, error) } ClientFee interface { @@ -43,7 +43,6 @@ type ( // also know how to encode itself. ClientTx interface { types.Tx - codec.ProtoMarshaler SetMsgs(...types.Msg) error GetSignatures() []types.Signature diff --git a/client/tx/factory.go b/client/tx/factory.go index 64a3b8ba382a..dc1b2c6dfcb6 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -56,16 +56,16 @@ func NewFactoryFromCLI(input io.Reader) Factory { return f } -func (f Factory) AccountNumber() uint64 { return f.accountNumber } -func (f Factory) Sequence() uint64 { return f.sequence } -func (f Factory) Gas() uint64 { return f.gas } -func (f Factory) GasAdjustment() float64 { return f.gasAdjustment } -func (f Factory) Keybase() keyring.Keyring { return f.keybase } -func (f Factory) ChainID() string { return f.chainID } -func (f Factory) Memo() string { return f.memo } -func (f Factory) Fees() sdk.Coins { return f.fees } -func (f Factory) GasPrices() sdk.DecCoins { return f.gasPrices } -func (f Factory) AccountRetriever() AccountRetriever { return f.accountRetriever } +func (f Factory) AccountNumber() uint64 { return f.accountNumber } +func (f Factory) Sequence() uint64 { return f.sequence } +func (f Factory) Gas() uint64 { return f.gas } +func (f Factory) GasAdjustment() float64 { return f.gasAdjustment } +func (f Factory) Keybase() keyring.Keyring { return f.keybase } +func (f Factory) ChainID() string { return f.chainID } +func (f Factory) Memo() string { return f.memo } +func (f Factory) Fees() sdk.Coins { return f.fees } +func (f Factory) GasPrices() sdk.DecCoins { return f.gasPrices } +func (f Factory) AccountRetriever() context.AccountRetriever { return f.accountRetriever } // SimulateAndExecute returns the option to simulate and then execute the transaction // using the gas from the simulation results diff --git a/client/tx/tx.go b/client/tx/tx.go index 5fd5d1e2931f..fc0b19d6e788 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -248,7 +248,7 @@ func BuildSimTx(txf Factory, msgs ...sdk.Msg) ([]byte, error) { return nil, err } - return tx.Marshal() + return txf.txGenerator.MarshalTx(tx) } // CalculateGas simulates the execution of a transaction and returns the @@ -338,7 +338,7 @@ func Sign(txf Factory, name, passphrase string, tx context.ClientTx) ([]byte, er return nil, err } - return tx.Marshal() + return txf.txGenerator.MarshalTx(tx) } // GasEstimateResponse defines a response definition for tx gas estimation. diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index 337fa166e3f8..18626ec0b2f7 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -5,9 +5,12 @@ import ( "os" "path" + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/client" @@ -81,7 +84,7 @@ func main() { } } -func queryCmd(cdc *amino.Codec) *cobra.Command { +func queryCmd(cdc *codec.Codec) *cobra.Command { queryCmd := &cobra.Command{ Use: "query", Aliases: []string{"q"}, @@ -107,7 +110,7 @@ func queryCmd(cdc *amino.Codec) *cobra.Command { return queryCmd } -func txCmd(cdc *amino.Codec) *cobra.Command { +func txCmd(cdc *codec.Codec) *cobra.Command { txCmd := &cobra.Command{ Use: "tx", Short: "Transactions subcommands", @@ -116,8 +119,11 @@ func txCmd(cdc *amino.Codec) *cobra.Command { RunE: client.ValidateCmd, } + cliCtx := context.NewCLIContext() + cliCtx = cliCtx.WithMarshaler(appCodec).WithTxGenerator(types.StdTxGenerator{cdc}) + txCmd.AddCommand( - bankcmd.SendTxCmd(cdc), + bankcmd.NewSendTxCmd(cliCtx), flags.LineBreak, authcmd.GetSignCommand(cdc), authcmd.GetMultiSignCommand(cdc), diff --git a/std/tx.go b/std/tx.go index 58dcff3f0cb1..a3869f05d4e7 100644 --- a/std/tx.go +++ b/std/tx.go @@ -1,7 +1,7 @@ package std import ( - "github.com/tendermint/go-amino" + amino "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/crypto" "github.com/cosmos/cosmos-sdk/client/context" @@ -23,6 +23,11 @@ var ( // transactions. type TxGenerator struct{} +func (g TxGenerator) MarshalTx(tx context.ClientTx) ([]byte, error) { + stdTx := tx.(*Transaction) + return stdTx.Marshal() +} + func (g TxGenerator) NewFee() context.ClientFee { return &StdFee{} } diff --git a/x/auth/types/client_tx.go b/x/auth/types/client_tx.go new file mode 100644 index 000000000000..316587d8baa3 --- /dev/null +++ b/x/auth/types/client_tx.go @@ -0,0 +1,96 @@ +package types + +import ( + "github.com/tendermint/tendermint/crypto" + + "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +type StdClientTx struct { + StdTx +} + +func (s *StdClientTx) SetMsgs(msgs ...sdk.Msg) error { + s.Msgs = msgs + return nil +} + +func (s StdClientTx) GetSignatures() []sdk.Signature { + res := make([]sdk.Signature, len(s.Signatures)) + for i, sig := range s.Signatures { + res[i] = sig + } + return res +} + +func (s *StdClientTx) SetSignatures(signatures ...context.ClientSignature) error { + sigs := make([]StdSignature, len(s.Signatures)) + for i, sig := range signatures { + sigs[i] = StdSignature{ + PubKey: sig.GetPubKey().Bytes(), + Signature: sig.GetSignature(), + } + } + s.Signatures = sigs + return nil +} + +func (s StdClientTx) GetFee() sdk.Fee { + return s.Fee +} + +func (s *StdClientTx) SetFee(fee context.ClientFee) error { + s.Fee = StdFee{Amount: fee.GetAmount(), Gas: fee.GetGas()} + return nil +} + +func (s *StdClientTx) SetMemo(memo string) { + s.SetMemo(memo) +} + +func (s StdClientTx) CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error) { + return StdSignBytes(cid, num, seq, s.Fee, s.Msgs, s.Memo), nil +} + +var _ context.ClientTx = &StdClientTx{} + +type StdTxGenerator struct { + Cdc *codec.Codec +} + +func (s StdTxGenerator) NewTx() context.ClientTx { + return &StdClientTx{} +} + +func (s StdTxGenerator) NewFee() context.ClientFee { + return &StdFee{} +} + +func (s StdTxGenerator) NewSignature() context.ClientSignature { + return &StdSignature{} +} + +func (s StdTxGenerator) MarshalTx(tx context.ClientTx) ([]byte, error) { + return DefaultTxEncoder(s.Cdc)(tx) +} + +var _ context.TxGenerator = StdTxGenerator{} + +func (fee *StdFee) SetGas(gas uint64) { + fee.Gas = gas +} + +func (fee *StdFee) SetAmount(coins sdk.Coins) { + fee.Amount = coins +} + +func (ss *StdSignature) SetPubKey(key crypto.PubKey) error { + ss.PubKey = key.Bytes() + return nil +} + +func (ss *StdSignature) SetSignature(bytes []byte) { + ss.Signature = bytes +} From 31ba870312d44f62382325e1d0864538bab1d38a Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 18 May 2020 15:53:36 -0400 Subject: [PATCH 09/48] fix lint --- client/keys/parse.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/keys/parse.go b/client/keys/parse.go index 220517913708..3afd773b96a4 100644 --- a/client/keys/parse.go +++ b/client/keys/parse.go @@ -14,10 +14,9 @@ import ( "github.com/tendermint/tendermint/libs/cli" - "github.com/cosmos/cosmos-sdk/types/bech32" - "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/bech32" ) func bech32Prefixes(config *sdk.Config) []string { From 89bc11dec09494644506198de9a8b10d6118c8a8 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 18 May 2020 15:54:43 -0400 Subject: [PATCH 10/48] revert file --- client/keys/parse.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/keys/parse.go b/client/keys/parse.go index 3afd773b96a4..220517913708 100644 --- a/client/keys/parse.go +++ b/client/keys/parse.go @@ -14,9 +14,10 @@ import ( "github.com/tendermint/tendermint/libs/cli" + "github.com/cosmos/cosmos-sdk/types/bech32" + "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/bech32" ) func bech32Prefixes(config *sdk.Config) []string { From a2c9f54a157329b815251115b5e94f87883a700d Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 18 May 2020 15:54:54 -0400 Subject: [PATCH 11/48] revert file --- client/keys/parse.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/keys/parse.go b/client/keys/parse.go index 220517913708..26b109e6714b 100644 --- a/client/keys/parse.go +++ b/client/keys/parse.go @@ -12,9 +12,8 @@ import ( "github.com/spf13/viper" yaml "gopkg.in/yaml.v2" - "github.com/tendermint/tendermint/libs/cli" - "github.com/cosmos/cosmos-sdk/types/bech32" + "github.com/tendermint/tendermint/libs/cli" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" From b7600bd2992fca9ab6333a84d0c04e643b71ae13 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 18 May 2020 16:29:04 -0400 Subject: [PATCH 12/48] fix simcli --- client/context/context.go | 121 +++++++++++++++++++------------------ client/context/verifier.go | 2 +- simapp/cmd/simcli/main.go | 7 ++- x/bank/client/cli/tx.go | 3 +- 4 files changed, 68 insertions(+), 65 deletions(-) diff --git a/client/context/context.go b/client/context/context.go index 7543d1224046..baff455b6fa4 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -1,13 +1,15 @@ package context import ( + "bufio" "fmt" "io" "os" + "github.com/tendermint/tendermint/libs/cli" + "github.com/pkg/errors" "github.com/spf13/viper" - "github.com/tendermint/tendermint/libs/cli" tmlite "github.com/tendermint/tendermint/lite" rpcclient "github.com/tendermint/tendermint/rpc/client" rpchttp "github.com/tendermint/tendermint/rpc/client/http" @@ -58,55 +60,9 @@ type CLIContext struct { // a CLIContext in tests or any non CLI-based environment, the verifier will not be created // and will be set as nil because FlagTrustNode must be set. func NewCLIContextWithInputAndFrom(input io.Reader, from string) CLIContext { - var nodeURI string - var rpc rpcclient.Client - var err error - - offline := viper.GetBool(flags.FlagOffline) - if !offline { - nodeURI = viper.GetString(flags.FlagNode) - if nodeURI != "" { - rpc, err = rpchttp.New(nodeURI, "/websocket") - if err != nil { - fmt.Printf("failted to get client: %v\n", err) - os.Exit(1) - } - } - } - - trustNode := viper.GetBool(flags.FlagTrustNode) - ctx := CLIContext{ - Client: rpc, - ChainID: viper.GetString(flags.FlagChainID), - Input: input, - Output: os.Stdout, - NodeURI: nodeURI, - From: viper.GetString(flags.FlagFrom), - OutputFormat: viper.GetString(cli.OutputFlag), - Height: viper.GetInt64(flags.FlagHeight), - TrustNode: trustNode, - UseLedger: viper.GetBool(flags.FlagUseLedger), - BroadcastMode: viper.GetString(flags.FlagBroadcastMode), - Simulate: viper.GetBool(flags.FlagDryRun), - Offline: offline, - Indent: viper.GetBool(flags.FlagIndentResponse), - SkipConfirm: viper.GetBool(flags.FlagSkipConfirmation), - } - + ctx := CLIContext{} ctx.InitWithInputAndFrom(input, from) - - if offline { - return ctx - } - - // create a verifier for the specific chain ID and RPC client - verifier, err := CreateVerifier(ctx, DefaultVerifierCacheSize) - if err != nil && !trustNode { - fmt.Printf("failed to create verifier: %s\n", err) - os.Exit(1) - } - - return ctx.WithVerifier(verifier) + return ctx } // NewCLIContextWithFrom returns a new initialized CLIContext with parameters from the @@ -130,7 +86,43 @@ func NewCLIContextWithInput(input io.Reader) CLIContext { } // InitWithInputAndFrom re-initializes an existing CLI with a new io.Reader and from parameter -func (ctx *CLIContext) InitWithInputAndFrom(input io.Reader, from string) CLIContext { +func (ctx *CLIContext) InitWithInputAndFrom(input io.Reader, from string) { + input = bufio.NewReader(input) + + var nodeURI string + var rpc rpcclient.Client + var err error + + offline := viper.GetBool(flags.FlagOffline) + if !offline { + nodeURI = viper.GetString(flags.FlagNode) + if nodeURI != "" { + rpc, err = rpchttp.New(nodeURI, "/websocket") + if err != nil { + fmt.Printf("failted to get client: %v\n", err) + os.Exit(1) + } + } + } + + trustNode := viper.GetBool(flags.FlagTrustNode) + + ctx.Client = rpc + ctx.ChainID = viper.GetString(flags.FlagChainID) + ctx.Input = input + ctx.Output = os.Stdout + ctx.NodeURI = nodeURI + ctx.From = viper.GetString(flags.FlagFrom) + ctx.OutputFormat = viper.GetString(cli.OutputFlag) + ctx.Height = viper.GetInt64(flags.FlagHeight) + ctx.TrustNode = trustNode + ctx.UseLedger = viper.GetBool(flags.FlagUseLedger) + ctx.BroadcastMode = viper.GetString(flags.FlagBroadcastMode) + ctx.Simulate = viper.GetBool(flags.FlagDryRun) + ctx.Offline = offline + ctx.Indent = viper.GetBool(flags.FlagIndentResponse) + ctx.SkipConfirm = viper.GetBool(flags.FlagSkipConfirmation) + homedir := viper.GetString(flags.FlagHome) genOnly := viper.GetBool(flags.FlagGenerateOnly) backend := viper.GetString(flags.FlagKeyringBackend) @@ -151,22 +143,33 @@ func (ctx *CLIContext) InitWithInputAndFrom(input io.Reader, from string) CLICon ctx.HomeDir = homedir - return ctx. - WithKeyring(kr). - WithFromAddress(fromAddress). - WithFromName(fromName). - WithGenerateOnly(genOnly) + ctx.Keyring = kr + ctx.FromAddress = fromAddress + ctx.FromName = fromName + ctx.GenerateOnly = genOnly + + if offline { + return + } + + // create a verifier for the specific chain ID and RPC client + verifier, err := CreateVerifier(ctx, DefaultVerifierCacheSize) + if err != nil && !trustNode { + fmt.Printf("failed to create verifier: %s\n", err) + os.Exit(1) + } + ctx.Verifier = verifier } // InitWithInputAndFrom re-initializes an existing CLI with a new io.Reader -func (ctx *CLIContext) InitWithInput(input io.Reader) CLIContext { - return ctx.InitWithInputAndFrom(input, viper.GetString(flags.FlagFrom)) +func (ctx *CLIContext) InitWithInput(input io.Reader) { + ctx.InitWithInputAndFrom(input, viper.GetString(flags.FlagFrom)) } // InitWithInputAndFrom re-initializes an existing CLI with a new from parameter -func (ctx *CLIContext) InitWithFrom(from string) CLIContext { - return ctx.InitWithInputAndFrom(os.Stdin, from) +func (ctx *CLIContext) InitWithFrom(from string) { + ctx.InitWithInputAndFrom(os.Stdin, from) } // WithKeyring returns a copy of the context with an updated keyring. diff --git a/client/context/verifier.go b/client/context/verifier.go index b849d3e397d1..3e4d947545c0 100644 --- a/client/context/verifier.go +++ b/client/context/verifier.go @@ -22,7 +22,7 @@ const ( // or if the verifier could not be created. A CLIContext must at the very least // have the chain ID and home directory set. If the CLIContext has TrustNode // enabled, no verifier will be created. -func CreateVerifier(ctx CLIContext, cacheSize int) (tmlite.Verifier, error) { +func CreateVerifier(ctx *CLIContext, cacheSize int) (tmlite.Verifier, error) { if ctx.TrustNode { return nil, nil } diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index 18626ec0b2f7..02c47e5e4e1e 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -6,13 +6,15 @@ import ( "path" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth/types" + bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/tendermint/tendermint/libs/cli" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/keys" @@ -23,7 +25,6 @@ import ( authclient "github.com/cosmos/cosmos-sdk/x/auth/client" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" - bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" ) var ( @@ -119,7 +120,7 @@ func txCmd(cdc *codec.Codec) *cobra.Command { RunE: client.ValidateCmd, } - cliCtx := context.NewCLIContext() + cliCtx := context.CLIContext{} cliCtx = cliCtx.WithMarshaler(appCodec).WithTxGenerator(types.StdTxGenerator{cdc}) txCmd.AddCommand( diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index 8c334c4a7166..36cd9f9720ff 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -38,8 +38,7 @@ func NewSendTxCmd(cliCtx context.CLIContext) *cobra.Command { Short: "Create and/or sign and broadcast a MsgSend transaction", Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - cliCtx.InitWithInputAndFrom(inBuf, args[0]) + cliCtx.InitWithInputAndFrom(cmd.InOrStdin(), args[0]) toAddr, err := sdk.AccAddressFromBech32(args[1]) if err != nil { From 2f99c3f13421eb2cbb0840e74e3f5621e61fae7b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 19 May 2020 10:40:17 -0400 Subject: [PATCH 13/48] Refactor AccountRetriever --- Makefile | 2 +- client/context/account_retriever.go | 21 ++++++++++ client/context/client_tx.go | 8 ---- client/context/context.go | 28 +++++++------ client/context/verifier.go | 2 +- client/tx/tx.go | 4 +- go.sum | 1 + simapp/cmd/simcli/main.go | 5 ++- tests/mocks/account_retriever.go | 57 +++++++++++++++++++++++++- tests/mocks/tendermint_tm_db_DB.go | 14 +++---- x/auth/alias.go | 1 - x/auth/client/cli/query.go | 4 +- x/auth/client/cli/tx_multisign.go | 2 +- x/auth/client/cli/validate_sigs.go | 2 +- x/auth/client/rest/query.go | 6 +-- x/auth/client/tx.go | 8 ++-- x/auth/types/account_retriever.go | 33 ++++++--------- x/auth/types/account_retriever_test.go | 8 ++-- 18 files changed, 136 insertions(+), 70 deletions(-) create mode 100644 client/context/account_retriever.go diff --git a/Makefile b/Makefile index e32facd4e148..399e60d7cb7e 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ build-sim: go.sum build-sim mocks: $(MOCKS_DIR) - mockgen -source=x/auth/types/account_retriever.go -package mocks -destination tests/mocks/account_retriever.go + mockgen -source=client/context/account_retriever.go -package mocks -destination tests/mocks/account_retriever.go mockgen -package mocks -destination tests/mocks/tendermint_tm_db_DB.go github.com/tendermint/tm-db DB mockgen -source=types/module/module.go -package mocks -destination tests/mocks/types_module_module.go mockgen -source=types/invariant.go -package mocks -destination tests/mocks/types_invariant.go diff --git a/client/context/account_retriever.go b/client/context/account_retriever.go new file mode 100644 index 000000000000..cd002ad4f5bf --- /dev/null +++ b/client/context/account_retriever.go @@ -0,0 +1,21 @@ +package context + +import "github.com/cosmos/cosmos-sdk/types" + +// AccountRetriever defines the interfaces required by transactions to +// ensure an account exists and to be able to query for account fields necessary +// for signing. +type AccountRetriever interface { + EnsureExists(nodeQuerier NodeQuerier, addr types.AccAddress) error + GetAccountNumberSequence(nodeQuerier NodeQuerier, addr types.AccAddress) (uint64, uint64, error) +} + +// NodeQuerier is an interface that is satisfied by types that provide the QueryWithData method +type NodeQuerier interface { + // QueryWithData performs a query to a Tendermint node with the provided path + // and a data payload. It returns the result and height of the query upon success + // or an error if the query fails. + QueryWithData(path string, data []byte) ([]byte, int64, error) +} + +var _ NodeQuerier = CLIContext{} diff --git a/client/context/client_tx.go b/client/context/client_tx.go index bbbc13869b94..eee9711e68d5 100644 --- a/client/context/client_tx.go +++ b/client/context/client_tx.go @@ -6,14 +6,6 @@ import ( "github.com/cosmos/cosmos-sdk/types" ) -// AccountRetriever defines the interfaces required by transactions to -// ensure an account exists and to be able to query for account fields necessary -// for signing. -type AccountRetriever interface { - EnsureExists(addr types.AccAddress) error - GetAccountNumberSequence(addr types.AccAddress) (uint64, uint64, error) -} - type ( // TxGenerator defines an interface a client can utilize to generate an // application-defined concrete transaction type. The type returned must diff --git a/client/context/context.go b/client/context/context.go index baff455b6fa4..2d0b44fdd7a6 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -13,7 +13,6 @@ import ( tmlite "github.com/tendermint/tendermint/lite" rpcclient "github.com/tendermint/tendermint/rpc/client" rpchttp "github.com/tendermint/tendermint/rpc/client/http" - yaml "gopkg.in/yaml.v2" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" @@ -60,9 +59,8 @@ type CLIContext struct { // a CLIContext in tests or any non CLI-based environment, the verifier will not be created // and will be set as nil because FlagTrustNode must be set. func NewCLIContextWithInputAndFrom(input io.Reader, from string) CLIContext { - ctx := CLIContext{} - ctx.InitWithInputAndFrom(input, from) - return ctx + ctx := &CLIContext{} + return ctx.InitWithInputAndFrom(input, from) } // NewCLIContextWithFrom returns a new initialized CLIContext with parameters from the @@ -85,8 +83,9 @@ func NewCLIContextWithInput(input io.Reader) CLIContext { return NewCLIContextWithInputAndFrom(input, viper.GetString(flags.FlagFrom)) } -// InitWithInputAndFrom re-initializes an existing CLI with a new io.Reader and from parameter -func (ctx *CLIContext) InitWithInputAndFrom(input io.Reader, from string) { +// InitWithInputAndFrom returns a new CLIContext re-initialized from an existing +// CLIContext with a new io.Reader and from parameter +func (ctx CLIContext) InitWithInputAndFrom(input io.Reader, from string) CLIContext { input = bufio.NewReader(input) var nodeURI string @@ -149,7 +148,7 @@ func (ctx *CLIContext) InitWithInputAndFrom(input io.Reader, from string) { ctx.GenerateOnly = genOnly if offline { - return + return ctx } // create a verifier for the specific chain ID and RPC client @@ -160,16 +159,19 @@ func (ctx *CLIContext) InitWithInputAndFrom(input io.Reader, from string) { } ctx.Verifier = verifier + return ctx } -// InitWithInputAndFrom re-initializes an existing CLI with a new io.Reader -func (ctx *CLIContext) InitWithInput(input io.Reader) { - ctx.InitWithInputAndFrom(input, viper.GetString(flags.FlagFrom)) +// InitWithInput returns a new CLIContext re-initialized from an existing +// CLIContext with a new io.Reader and from parameter +func (ctx CLIContext) InitWithInput(input io.Reader) CLIContext { + return ctx.InitWithInputAndFrom(input, viper.GetString(flags.FlagFrom)) } -// InitWithInputAndFrom re-initializes an existing CLI with a new from parameter -func (ctx *CLIContext) InitWithFrom(from string) { - ctx.InitWithInputAndFrom(os.Stdin, from) +// InitWithInput returns a new CLIContext re-initialized from an existing +// CLIContext with a new from parameter +func (ctx CLIContext) InitWithFrom(from string) CLIContext { + return ctx.InitWithInputAndFrom(os.Stdin, from) } // WithKeyring returns a copy of the context with an updated keyring. diff --git a/client/context/verifier.go b/client/context/verifier.go index 3e4d947545c0..b849d3e397d1 100644 --- a/client/context/verifier.go +++ b/client/context/verifier.go @@ -22,7 +22,7 @@ const ( // or if the verifier could not be created. A CLIContext must at the very least // have the chain ID and home directory set. If the CLIContext has TrustNode // enabled, no verifier will be created. -func CreateVerifier(ctx *CLIContext, cacheSize int) (tmlite.Verifier, error) { +func CreateVerifier(ctx CLIContext, cacheSize int) (tmlite.Verifier, error) { if ctx.TrustNode { return nil, nil } diff --git a/client/tx/tx.go b/client/tx/tx.go index fc0b19d6e788..26f777ea6fa0 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -281,13 +281,13 @@ func CalculateGas( func PrepareFactory(ctx context.CLIContext, txf Factory) (Factory, error) { from := ctx.GetFromAddress() - if err := txf.accountRetriever.EnsureExists(from); err != nil { + if err := txf.accountRetriever.EnsureExists(ctx, from); err != nil { return txf, err } initNum, initSeq := txf.accountNumber, txf.sequence if initNum == 0 || initSeq == 0 { - num, seq, err := txf.accountRetriever.GetAccountNumberSequence(from) + num, seq, err := txf.accountRetriever.GetAccountNumberSequence(ctx, from) if err != nil { return txf, err } diff --git a/go.sum b/go.sum index fb321d359ba5..a8ae328a8b6d 100644 --- a/go.sum +++ b/go.sum @@ -629,6 +629,7 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2 h1:V9r/14uGBqLgNlHRYWdVqjMdWkcOHnE2KG8DwVqQSEc= golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index 02c47e5e4e1e..47aeb3228a1c 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -121,7 +121,10 @@ func txCmd(cdc *codec.Codec) *cobra.Command { } cliCtx := context.CLIContext{} - cliCtx = cliCtx.WithMarshaler(appCodec).WithTxGenerator(types.StdTxGenerator{cdc}) + cliCtx = cliCtx. + WithMarshaler(appCodec). + WithTxGenerator(types.StdTxGenerator{cdc}). + WithAccountRetriever(types.NewAccountRetriever(appCodec)) txCmd.AddCommand( bankcmd.NewSendTxCmd(cliCtx), diff --git a/tests/mocks/account_retriever.go b/tests/mocks/account_retriever.go index a3086c77bdca..f0e089f2881a 100644 --- a/tests/mocks/account_retriever.go +++ b/tests/mocks/account_retriever.go @@ -1,14 +1,69 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: x/auth/types/account_retriever.go +// Source: client/context/account_retriever.go // Package mocks is a generated GoMock package. package mocks import ( + context "github.com/cosmos/cosmos-sdk/client/context" + types "github.com/cosmos/cosmos-sdk/types" gomock "github.com/golang/mock/gomock" reflect "reflect" ) +// MockAccountRetriever is a mock of AccountRetriever interface +type MockAccountRetriever struct { + ctrl *gomock.Controller + recorder *MockAccountRetrieverMockRecorder +} + +// MockAccountRetrieverMockRecorder is the mock recorder for MockAccountRetriever +type MockAccountRetrieverMockRecorder struct { + mock *MockAccountRetriever +} + +// NewMockAccountRetriever creates a new mock instance +func NewMockAccountRetriever(ctrl *gomock.Controller) *MockAccountRetriever { + mock := &MockAccountRetriever{ctrl: ctrl} + mock.recorder = &MockAccountRetrieverMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockAccountRetriever) EXPECT() *MockAccountRetrieverMockRecorder { + return m.recorder +} + +// EnsureExists mocks base method +func (m *MockAccountRetriever) EnsureExists(nodeQuerier context.NodeQuerier, addr types.AccAddress) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EnsureExists", nodeQuerier, addr) + ret0, _ := ret[0].(error) + return ret0 +} + +// EnsureExists indicates an expected call of EnsureExists +func (mr *MockAccountRetrieverMockRecorder) EnsureExists(nodeQuerier, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnsureExists", reflect.TypeOf((*MockAccountRetriever)(nil).EnsureExists), nodeQuerier, addr) +} + +// GetAccountNumberSequence mocks base method +func (m *MockAccountRetriever) GetAccountNumberSequence(nodeQuerier context.NodeQuerier, addr types.AccAddress) (uint64, uint64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccountNumberSequence", nodeQuerier, addr) + ret0, _ := ret[0].(uint64) + ret1, _ := ret[1].(uint64) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetAccountNumberSequence indicates an expected call of GetAccountNumberSequence +func (mr *MockAccountRetrieverMockRecorder) GetAccountNumberSequence(nodeQuerier, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccountNumberSequence", reflect.TypeOf((*MockAccountRetriever)(nil).GetAccountNumberSequence), nodeQuerier, addr) +} + // MockNodeQuerier is a mock of NodeQuerier interface type MockNodeQuerier struct { ctrl *gomock.Controller diff --git a/tests/mocks/tendermint_tm_db_DB.go b/tests/mocks/tendermint_tm_db_DB.go index bed59a498d03..cdf5e5ab0a27 100644 --- a/tests/mocks/tendermint_tm_db_DB.go +++ b/tests/mocks/tendermint_tm_db_DB.go @@ -6,7 +6,7 @@ package mocks import ( gomock "github.com/golang/mock/gomock" - tm_db "github.com/tendermint/tm-db" + db "github.com/tendermint/tm-db" reflect "reflect" ) @@ -106,10 +106,10 @@ func (mr *MockDBMockRecorder) Has(arg0 interface{}) *gomock.Call { } // Iterator mocks base method -func (m *MockDB) Iterator(arg0, arg1 []byte) (tm_db.Iterator, error) { +func (m *MockDB) Iterator(arg0, arg1 []byte) (db.Iterator, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Iterator", arg0, arg1) - ret0, _ := ret[0].(tm_db.Iterator) + ret0, _ := ret[0].(db.Iterator) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -121,10 +121,10 @@ func (mr *MockDBMockRecorder) Iterator(arg0, arg1 interface{}) *gomock.Call { } // NewBatch mocks base method -func (m *MockDB) NewBatch() tm_db.Batch { +func (m *MockDB) NewBatch() db.Batch { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "NewBatch") - ret0, _ := ret[0].(tm_db.Batch) + ret0, _ := ret[0].(db.Batch) return ret0 } @@ -149,10 +149,10 @@ func (mr *MockDBMockRecorder) Print() *gomock.Call { } // ReverseIterator mocks base method -func (m *MockDB) ReverseIterator(arg0, arg1 []byte) (tm_db.Iterator, error) { +func (m *MockDB) ReverseIterator(arg0, arg1 []byte) (db.Iterator, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ReverseIterator", arg0, arg1) - ret0, _ := ret[0].(tm_db.Iterator) + ret0, _ := ret[0].(db.Iterator) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/x/auth/alias.go b/x/auth/alias.go index 01392a61d277..c5c464fc0ba0 100644 --- a/x/auth/alias.go +++ b/x/auth/alias.go @@ -81,7 +81,6 @@ type ( SignatureVerificationGasConsumer = ante.SignatureVerificationGasConsumer AccountKeeper = keeper.AccountKeeper BaseAccount = types.BaseAccount - NodeQuerier = types.NodeQuerier AccountRetriever = types.AccountRetriever GenesisState = types.GenesisState Params = types.Params diff --git a/x/auth/client/cli/query.go b/x/auth/client/cli/query.go index ccff833b3c7c..2e428e1e543e 100644 --- a/x/auth/client/cli/query.go +++ b/x/auth/client/cli/query.go @@ -83,14 +83,14 @@ func GetAccountCmd(cdc *codec.Codec) *cobra.Command { Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) - accGetter := types.NewAccountRetriever(authclient.Codec, cliCtx) + accGetter := types.NewAccountRetriever(authclient.Codec) key, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } - acc, err := accGetter.GetAccount(key) + acc, err := accGetter.GetAccount(cliCtx, key) if err != nil { return err } diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 71375da72e05..42b4daada567 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -85,7 +85,7 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) txBldr := types.NewTxBuilderFromCLI(inBuf) if !cliCtx.Offline { - accnum, seq, err := types.NewAccountRetriever(client.Codec, cliCtx).GetAccountNumberSequence(multisigInfo.GetAddress()) + accnum, seq, err := types.NewAccountRetriever(client.Codec).GetAccountNumberSequence(cliCtx, multisigInfo.GetAddress()) if err != nil { return err } diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index a7b87d387818..07846fc6e76c 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -89,7 +89,7 @@ func printAndValidateSigs( // Validate the actual signature over the transaction bytes since we can // reach out to a full node to query accounts. if !offline && success { - acc, err := types.NewAccountRetriever(client.Codec, cliCtx).GetAccount(sigAddr) + acc, err := types.NewAccountRetriever(client.Codec).GetAccount(cliCtx, sigAddr) if err != nil { cmd.Printf("failed to get account: %s\n", sigAddr) return false diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index a350bed55543..1107fd92a817 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -32,13 +32,13 @@ func QueryAccountRequestHandlerFn(storeName string, cliCtx context.CLIContext) h return } - accGetter := types.NewAccountRetriever(client.Codec, cliCtx) + accGetter := types.NewAccountRetriever(client.Codec) - account, height, err := accGetter.GetAccountWithHeight(addr) + account, height, err := accGetter.GetAccountWithHeight(cliCtx, addr) if err != nil { // TODO: Handle more appropriately based on the error type. // Ref: https://github.com/cosmos/cosmos-sdk/issues/4923 - if err := accGetter.EnsureExists(addr); err != nil { + if err := accGetter.EnsureExists(cliCtx, addr); err != nil { cliCtx = cliCtx.WithHeight(height) rest.PostProcessResponse(w, cliCtx, types.BaseAccount{}) return diff --git a/x/auth/client/tx.go b/x/auth/client/tx.go index c06acf7367a1..707cdc2f7262 100644 --- a/x/auth/client/tx.go +++ b/x/auth/client/tx.go @@ -255,7 +255,7 @@ func populateAccountFromState( txBldr authtypes.TxBuilder, cliCtx context.CLIContext, addr sdk.AccAddress, ) (authtypes.TxBuilder, error) { - num, seq, err := authtypes.NewAccountRetriever(Codec, cliCtx).GetAccountNumberSequence(addr) + num, seq, err := authtypes.NewAccountRetriever(Codec).GetAccountNumberSequence(cliCtx, addr) if err != nil { return txBldr, err } @@ -302,8 +302,8 @@ func parseQueryResponse(bz []byte) (sdk.SimulationResponse, error) { func PrepareTxBuilder(txBldr authtypes.TxBuilder, cliCtx context.CLIContext) (authtypes.TxBuilder, error) { from := cliCtx.GetFromAddress() - accGetter := authtypes.NewAccountRetriever(Codec, cliCtx) - if err := accGetter.EnsureExists(from); err != nil { + accGetter := authtypes.NewAccountRetriever(Codec) + if err := accGetter.EnsureExists(cliCtx, from); err != nil { return txBldr, err } @@ -311,7 +311,7 @@ func PrepareTxBuilder(txBldr authtypes.TxBuilder, cliCtx context.CLIContext) (au // TODO: (ref #1903) Allow for user supplied account number without // automatically doing a manual lookup. if txbldrAccNum == 0 || txbldrAccSeq == 0 { - num, seq, err := authtypes.NewAccountRetriever(Codec, cliCtx).GetAccountNumberSequence(from) + num, seq, err := authtypes.NewAccountRetriever(Codec).GetAccountNumberSequence(cliCtx, from) if err != nil { return txBldr, err } diff --git a/x/auth/types/account_retriever.go b/x/auth/types/account_retriever.go index bc24b4a9c480..8a8fe89e1cdb 100644 --- a/x/auth/types/account_retriever.go +++ b/x/auth/types/account_retriever.go @@ -3,47 +3,40 @@ package types import ( "fmt" + "github.com/cosmos/cosmos-sdk/client/context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/exported" ) -// NodeQuerier is an interface that is satisfied by types that provide the QueryWithData method -type NodeQuerier interface { - // QueryWithData performs a query to a Tendermint node with the provided path - // and a data payload. It returns the result and height of the query upon success - // or an error if the query fails. - QueryWithData(path string, data []byte) ([]byte, int64, error) -} - // AccountRetriever defines the properties of a type that can be used to // retrieve accounts. type AccountRetriever struct { - codec Codec - querier NodeQuerier + codec Codec } // NewAccountRetriever initialises a new AccountRetriever instance. -func NewAccountRetriever(codec Codec, querier NodeQuerier) AccountRetriever { - return AccountRetriever{codec: codec, querier: querier} +func NewAccountRetriever(codec Codec) AccountRetriever { + return AccountRetriever{codec: codec} } // GetAccount queries for an account given an address and a block height. An // error is returned if the query or decoding fails. -func (ar AccountRetriever) GetAccount(addr sdk.AccAddress) (exported.Account, error) { - account, _, err := ar.GetAccountWithHeight(addr) +func (ar AccountRetriever) GetAccount(querier context.NodeQuerier, addr sdk.AccAddress) (exported.Account, error) { + account, _, err := ar.GetAccountWithHeight(querier, addr) return account, err } // GetAccountWithHeight queries for an account given an address. Returns the // height of the query with the account. An error is returned if the query // or decoding fails. -func (ar AccountRetriever) GetAccountWithHeight(addr sdk.AccAddress) (exported.Account, int64, error) { +func (ar AccountRetriever) GetAccountWithHeight(querier context.NodeQuerier, addr sdk.AccAddress) (exported.Account, int64, error) { bs, err := ar.codec.MarshalJSON(NewQueryAccountParams(addr)) if err != nil { return nil, 0, err } - bz, height, err := ar.querier.QueryWithData(fmt.Sprintf("custom/%s/%s", QuerierRoute, QueryAccount), bs) + bz, height, err := querier.QueryWithData(fmt.Sprintf("custom/%s/%s", QuerierRoute, QueryAccount), bs) if err != nil { return nil, height, err } @@ -57,8 +50,8 @@ func (ar AccountRetriever) GetAccountWithHeight(addr sdk.AccAddress) (exported.A } // EnsureExists returns an error if no account exists for the given address else nil. -func (ar AccountRetriever) EnsureExists(addr sdk.AccAddress) error { - if _, err := ar.GetAccount(addr); err != nil { +func (ar AccountRetriever) EnsureExists(querier context.NodeQuerier, addr sdk.AccAddress) error { + if _, err := ar.GetAccount(querier, addr); err != nil { return err } return nil @@ -66,8 +59,8 @@ func (ar AccountRetriever) EnsureExists(addr sdk.AccAddress) error { // GetAccountNumberSequence returns sequence and account number for the given address. // It returns an error if the account couldn't be retrieved from the state. -func (ar AccountRetriever) GetAccountNumberSequence(addr sdk.AccAddress) (uint64, uint64, error) { - acc, err := ar.GetAccount(addr) +func (ar AccountRetriever) GetAccountNumberSequence(nodeQuerier context.NodeQuerier, addr sdk.AccAddress) (uint64, uint64, error) { + acc, err := ar.GetAccount(nodeQuerier, addr) if err != nil { return 0, 0, err } diff --git a/x/auth/types/account_retriever_test.go b/x/auth/types/account_retriever_test.go index 99310d1170ff..effddd194305 100644 --- a/x/auth/types/account_retriever_test.go +++ b/x/auth/types/account_retriever_test.go @@ -19,7 +19,7 @@ func TestAccountRetriever(t *testing.T) { defer mockCtrl.Finish() mockNodeQuerier := mocks.NewMockNodeQuerier(mockCtrl) - accRetr := types.NewAccountRetriever(appCodec, mockNodeQuerier) + accRetr := types.NewAccountRetriever(appCodec) addr := []byte("test") bs, err := appCodec.MarshalJSON(types.NewQueryAccountParams(addr)) require.NoError(t, err) @@ -28,17 +28,17 @@ func TestAccountRetriever(t *testing.T) { mockNodeQuerier.EXPECT().QueryWithData(gomock.Eq(route), gomock.Eq(bs)).Return(nil, int64(0), errFoo).Times(1) - _, err = accRetr.GetAccount(addr) + _, err = accRetr.GetAccount(nil, addr) require.Error(t, err) mockNodeQuerier.EXPECT().QueryWithData(gomock.Eq(route), gomock.Eq(bs)).Return(nil, int64(0), errFoo).Times(1) - n, s, err := accRetr.GetAccountNumberSequence(addr) + n, s, err := accRetr.GetAccountNumberSequence(mockNodeQuerier, addr) require.Error(t, err) require.Equal(t, uint64(0), n) require.Equal(t, uint64(0), s) mockNodeQuerier.EXPECT().QueryWithData(gomock.Eq(route), gomock.Eq(bs)).Return(nil, int64(0), errFoo).Times(1) - require.Error(t, accRetr.EnsureExists(addr)) + require.Error(t, accRetr.EnsureExists(mockNodeQuerier, addr)) } From cab64cdeb0b4fe57cbd63cbf7d4e0be4fcc0c88a Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 19 May 2020 10:46:17 -0400 Subject: [PATCH 14/48] Fix build From 6af906d56ec02880bd694cb0f85b2cf4b5229db1 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 19 May 2020 12:05:31 -0400 Subject: [PATCH 15/48] Fix build From 457a612b61efe254ccefb41707a04e30cbe10d25 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 19 May 2020 12:05:50 -0400 Subject: [PATCH 16/48] Fix build --- client/context/context.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/context/context.go b/client/context/context.go index 2d0b44fdd7a6..de4b3772b5e6 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -6,6 +6,8 @@ import ( "io" "os" + yaml "gopkg.in/yaml.v2" + "github.com/tendermint/tendermint/libs/cli" "github.com/pkg/errors" From d7021373cafa3323b8debcfd0ffb6e0b3e14206d Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 19 May 2020 13:54:47 -0400 Subject: [PATCH 17/48] Fix integration tests --- .../context/{client_tx.go => tx_generator.go} | 12 +++++----- client/tx/tx.go | 10 ++++---- std/tx.go | 10 +++++--- x/auth/types/client_tx.go | 23 +++++++++++++------ x/bank/client/cli/cli_test.go | 4 ++-- x/bank/client/cli/tx.go | 2 +- 6 files changed, 37 insertions(+), 24 deletions(-) rename client/context/{client_tx.go => tx_generator.go} (85%) diff --git a/client/context/client_tx.go b/client/context/tx_generator.go similarity index 85% rename from client/context/client_tx.go rename to client/context/tx_generator.go index eee9711e68d5..8dd2392bb986 100644 --- a/client/context/client_tx.go +++ b/client/context/tx_generator.go @@ -9,12 +9,12 @@ import ( type ( // TxGenerator defines an interface a client can utilize to generate an // application-defined concrete transaction type. The type returned must - // implement ClientTx. + // implement TxBuilder. TxGenerator interface { - NewTx() ClientTx + NewTx() TxBuilder NewFee() ClientFee NewSignature() ClientSignature - MarshalTx(tx ClientTx) ([]byte, error) + MarshalTx(tx types.Tx) ([]byte, error) } ClientFee interface { @@ -29,12 +29,12 @@ type ( SetSignature([]byte) } - // ClientTx defines an interface which an application-defined concrete transaction + // TxBuilder defines an interface which an application-defined concrete transaction // type must implement. Namely, it must be able to set messages, generate // signatures, and provide canonical bytes to sign over. The transaction must // also know how to encode itself. - ClientTx interface { - types.Tx + TxBuilder interface { + GetTx() types.Tx SetMsgs(...types.Msg) error GetSignatures() []types.Signature diff --git a/client/tx/tx.go b/client/tx/tx.go index 26f777ea6fa0..37d08e4ec1ea 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -60,7 +60,7 @@ func GenerateTx(ctx context.CLIContext, txf Factory, msgs ...sdk.Msg) error { return err } - return ctx.Println(tx) + return ctx.Println(tx.GetTx()) } // BroadcastTx attempts to generate, sign and broadcast a transaction with the @@ -185,7 +185,7 @@ func WriteGeneratedTxResponse( // BuildUnsignedTx builds a transaction to be signed given a set of messages. The // transaction is initially created via the provided factory's generator. Once // created, the fee, memo, and messages are set. -func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (context.ClientTx, error) { +func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (context.TxBuilder, error) { if txf.chainID == "" { return nil, fmt.Errorf("chain ID required but not specified") } @@ -248,7 +248,7 @@ func BuildSimTx(txf Factory, msgs ...sdk.Msg) ([]byte, error) { return nil, err } - return txf.txGenerator.MarshalTx(tx) + return txf.txGenerator.MarshalTx(tx.GetTx()) } // CalculateGas simulates the execution of a transaction and returns the @@ -312,7 +312,7 @@ func PrepareFactory(ctx context.CLIContext, txf Factory) (Factory, error) { // // Note, It is assumed the Factory has the necessary fields set that are required // by the CanonicalSignBytes call. -func Sign(txf Factory, name, passphrase string, tx context.ClientTx) ([]byte, error) { +func Sign(txf Factory, name, passphrase string, tx context.TxBuilder) ([]byte, error) { if txf.keybase == nil { return nil, errors.New("keybase must be set prior to signing a transaction") } @@ -338,7 +338,7 @@ func Sign(txf Factory, name, passphrase string, tx context.ClientTx) ([]byte, er return nil, err } - return txf.txGenerator.MarshalTx(tx) + return txf.txGenerator.MarshalTx(tx.GetTx()) } // GasEstimateResponse defines a response definition for tx gas estimation. diff --git a/std/tx.go b/std/tx.go index a3869f05d4e7..561344a7c4bd 100644 --- a/std/tx.go +++ b/std/tx.go @@ -13,7 +13,7 @@ import ( var ( _ sdk.Tx = (*Transaction)(nil) - _ context.ClientTx = (*Transaction)(nil) + _ context.TxBuilder = (*Transaction)(nil) _ context.TxGenerator = TxGenerator{} _ context.ClientFee = &StdFee{} _ context.ClientSignature = &StdSignature{} @@ -23,7 +23,7 @@ var ( // transactions. type TxGenerator struct{} -func (g TxGenerator) MarshalTx(tx context.ClientTx) ([]byte, error) { +func (g TxGenerator) MarshalTx(tx sdk.Tx) ([]byte, error) { stdTx := tx.(*Transaction) return stdTx.Marshal() } @@ -37,7 +37,7 @@ func (g TxGenerator) NewSignature() context.ClientSignature { } // NewTx returns a reference to an empty Transaction type. -func (TxGenerator) NewTx() context.ClientTx { +func (TxGenerator) NewTx() context.TxBuilder { return &Transaction{} } @@ -173,6 +173,10 @@ func (tx *Transaction) SetMemo(memo string) { tx.Memo = memo } +func (tx *Transaction) GetTx() sdk.Tx { + return tx +} + // CanonicalSignBytes returns the canonical JSON bytes to sign over for the // Transaction given a chain ID, account sequence and account number. The JSON // encoding ensures all field names adhere to their proto definition, default diff --git a/x/auth/types/client_tx.go b/x/auth/types/client_tx.go index 316587d8baa3..1e41a00ecbaf 100644 --- a/x/auth/types/client_tx.go +++ b/x/auth/types/client_tx.go @@ -12,6 +12,12 @@ type StdClientTx struct { StdTx } +var _ context.TxBuilder = &StdClientTx{} + +func (s *StdClientTx) GetTx() sdk.Tx { + return s.StdTx +} + func (s *StdClientTx) SetMsgs(msgs ...sdk.Msg) error { s.Msgs = msgs return nil @@ -26,10 +32,15 @@ func (s StdClientTx) GetSignatures() []sdk.Signature { } func (s *StdClientTx) SetSignatures(signatures ...context.ClientSignature) error { - sigs := make([]StdSignature, len(s.Signatures)) + sigs := make([]StdSignature, len(signatures)) for i, sig := range signatures { + pubKey := sig.GetPubKey() + var pubKeyBz []byte + if pubKey != nil { + pubKeyBz = pubKey.Bytes() + } sigs[i] = StdSignature{ - PubKey: sig.GetPubKey().Bytes(), + PubKey: pubKeyBz, Signature: sig.GetSignature(), } } @@ -47,20 +58,18 @@ func (s *StdClientTx) SetFee(fee context.ClientFee) error { } func (s *StdClientTx) SetMemo(memo string) { - s.SetMemo(memo) + s.Memo = memo } func (s StdClientTx) CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error) { return StdSignBytes(cid, num, seq, s.Fee, s.Msgs, s.Memo), nil } -var _ context.ClientTx = &StdClientTx{} - type StdTxGenerator struct { Cdc *codec.Codec } -func (s StdTxGenerator) NewTx() context.ClientTx { +func (s StdTxGenerator) NewTx() context.TxBuilder { return &StdClientTx{} } @@ -72,7 +81,7 @@ func (s StdTxGenerator) NewSignature() context.ClientSignature { return &StdSignature{} } -func (s StdTxGenerator) MarshalTx(tx context.ClientTx) ([]byte, error) { +func (s StdTxGenerator) MarshalTx(tx sdk.Tx) ([]byte, error) { return DefaultTxEncoder(s.Cdc)(tx) } diff --git a/x/bank/client/cli/cli_test.go b/x/bank/client/cli/cli_test.go index fa35b5b6f09b..743d348731ad 100644 --- a/x/bank/client/cli/cli_test.go +++ b/x/bank/client/cli/cli_test.go @@ -42,8 +42,8 @@ func TestCLISend(t *testing.T) { tests.WaitForNextNBlocksTM(1, f.Port) // Ensure account balances match expected - require.Equal(t, sendTokens, testutil.QueryBalances(f, barAddr).AmountOf(cli.Denom)) - require.Equal(t, startTokens.Sub(sendTokens), testutil.QueryBalances(f, fooAddr).AmountOf(cli.Denom)) + require.Equal(t, sendTokens.String(), testutil.QueryBalances(f, barAddr).AmountOf(cli.Denom).String()) + require.Equal(t, startTokens.Sub(sendTokens).String(), testutil.QueryBalances(f, fooAddr).AmountOf(cli.Denom).String()) // Test --dry-run success, _, _ = testutil.TxSend(f, cli.KeyFoo, barAddr, sdk.NewCoin(cli.Denom, sendTokens), "--dry-run") diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index 36cd9f9720ff..19fb9e2d7bdb 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -38,7 +38,7 @@ func NewSendTxCmd(cliCtx context.CLIContext) *cobra.Command { Short: "Create and/or sign and broadcast a MsgSend transaction", Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { - cliCtx.InitWithInputAndFrom(cmd.InOrStdin(), args[0]) + cliCtx = cliCtx.InitWithInputAndFrom(cmd.InOrStdin(), args[0]) toAddr, err := sdk.AccAddressFromBech32(args[1]) if err != nil { From 72036522409b4ec882927613fae051ec755f6c21 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 19 May 2020 14:41:01 -0400 Subject: [PATCH 18/48] Fix tests --- x/auth/types/account_retriever_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/types/account_retriever_test.go b/x/auth/types/account_retriever_test.go index effddd194305..ad61a41e6645 100644 --- a/x/auth/types/account_retriever_test.go +++ b/x/auth/types/account_retriever_test.go @@ -28,7 +28,7 @@ func TestAccountRetriever(t *testing.T) { mockNodeQuerier.EXPECT().QueryWithData(gomock.Eq(route), gomock.Eq(bs)).Return(nil, int64(0), errFoo).Times(1) - _, err = accRetr.GetAccount(nil, addr) + _, err = accRetr.GetAccount(mockNodeQuerier, addr) require.Error(t, err) mockNodeQuerier.EXPECT().QueryWithData(gomock.Eq(route), From fc0b01a60cdf47dc0fbb91f09ec1070b4e14b787 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 19 May 2020 14:50:56 -0400 Subject: [PATCH 19/48] Docs, linting --- simapp/cmd/simcli/main.go | 10 ++++----- x/auth/types/client_tx.go | 46 +++++++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index 47aeb3228a1c..c5938a7dd4ae 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -5,26 +5,24 @@ import ( "os" "path" - "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/x/auth/types" - bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" - "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/tendermint/tendermint/libs/cli" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/lcd" "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" + "github.com/cosmos/cosmos-sdk/x/auth/types" + bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" ) var ( diff --git a/x/auth/types/client_tx.go b/x/auth/types/client_tx.go index 1e41a00ecbaf..ccc0618f064c 100644 --- a/x/auth/types/client_tx.go +++ b/x/auth/types/client_tx.go @@ -8,22 +8,26 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -type StdClientTx struct { +// StdTxBuilder wraps StdTx to implement to the context.TxBuilder interface +type StdTxBuilder struct { StdTx } -var _ context.TxBuilder = &StdClientTx{} +var _ context.TxBuilder = &StdTxBuilder{} -func (s *StdClientTx) GetTx() sdk.Tx { +// GetTx implements TxBuilder.GetTx +func (s *StdTxBuilder) GetTx() sdk.Tx { return s.StdTx } -func (s *StdClientTx) SetMsgs(msgs ...sdk.Msg) error { +// SetMsgs implements TxBuilder.SetMsgs +func (s *StdTxBuilder) SetMsgs(msgs ...sdk.Msg) error { s.Msgs = msgs return nil } -func (s StdClientTx) GetSignatures() []sdk.Signature { +// GetSignatures implements TxBuilder.GetSignatures +func (s StdTxBuilder) GetSignatures() []sdk.Signature { res := make([]sdk.Signature, len(s.Signatures)) for i, sig := range s.Signatures { res[i] = sig @@ -31,7 +35,8 @@ func (s StdClientTx) GetSignatures() []sdk.Signature { return res } -func (s *StdClientTx) SetSignatures(signatures ...context.ClientSignature) error { +// SetSignatures implements TxBuilder.SetSignatures +func (s *StdTxBuilder) SetSignatures(signatures ...context.ClientSignature) error { sigs := make([]StdSignature, len(signatures)) for i, sig := range signatures { pubKey := sig.GetPubKey() @@ -48,58 +53,75 @@ func (s *StdClientTx) SetSignatures(signatures ...context.ClientSignature) error return nil } -func (s StdClientTx) GetFee() sdk.Fee { +// GetFee implements TxBuilder.GetFee +func (s StdTxBuilder) GetFee() sdk.Fee { return s.Fee } -func (s *StdClientTx) SetFee(fee context.ClientFee) error { +// SetFee implements TxBuilder.SetFee +func (s *StdTxBuilder) SetFee(fee context.ClientFee) error { s.Fee = StdFee{Amount: fee.GetAmount(), Gas: fee.GetGas()} return nil } -func (s *StdClientTx) SetMemo(memo string) { +// SetMemo implements TxBuilder.SetMemo +func (s *StdTxBuilder) SetMemo(memo string) { s.Memo = memo } -func (s StdClientTx) CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error) { +// CanonicalSignBytes implements TxBuilder.CanonicalSignBytes +func (s StdTxBuilder) CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error) { return StdSignBytes(cid, num, seq, s.Fee, s.Msgs, s.Memo), nil } +// StdTxGenerator is a context.TxGenerator for StdTx type StdTxGenerator struct { Cdc *codec.Codec } +var _ context.TxGenerator = StdTxGenerator{} + +// NewTx implements TxGenerator.NewTx func (s StdTxGenerator) NewTx() context.TxBuilder { - return &StdClientTx{} + return &StdTxBuilder{} } +// NewFee implements TxGenerator.NewFee func (s StdTxGenerator) NewFee() context.ClientFee { return &StdFee{} } +// NewSignature implements TxGenerator.NewSignature func (s StdTxGenerator) NewSignature() context.ClientSignature { return &StdSignature{} } +// MarshalTx implements TxGenerator.MarshalTx func (s StdTxGenerator) MarshalTx(tx sdk.Tx) ([]byte, error) { return DefaultTxEncoder(s.Cdc)(tx) } -var _ context.TxGenerator = StdTxGenerator{} +var _ context.ClientFee = &StdFee{} +// SetGas implements ClientFee.SetGas func (fee *StdFee) SetGas(gas uint64) { fee.Gas = gas } +// SetAmount implements ClientFee.SetAmount func (fee *StdFee) SetAmount(coins sdk.Coins) { fee.Amount = coins } +var _ context.ClientSignature = &StdSignature{} + +// SetPubKey implements ClientSignature.SetPubKey func (ss *StdSignature) SetPubKey(key crypto.PubKey) error { ss.PubKey = key.Bytes() return nil } +// SetSignature implements ClientSignature.SetSignature func (ss *StdSignature) SetSignature(bytes []byte) { ss.Signature = bytes } From aacd246f2aba3fd4b6ae2e401976ddfe71c4d227 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 19 May 2020 14:58:42 -0400 Subject: [PATCH 20/48] Linting --- client/context/context.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/context/context.go b/client/context/context.go index de4b3772b5e6..a7c0e56a01a1 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -6,12 +6,11 @@ import ( "io" "os" + "github.com/pkg/errors" + "github.com/spf13/viper" yaml "gopkg.in/yaml.v2" "github.com/tendermint/tendermint/libs/cli" - - "github.com/pkg/errors" - "github.com/spf13/viper" tmlite "github.com/tendermint/tendermint/lite" rpcclient "github.com/tendermint/tendermint/rpc/client" rpchttp "github.com/tendermint/tendermint/rpc/client/http" @@ -61,7 +60,7 @@ type CLIContext struct { // a CLIContext in tests or any non CLI-based environment, the verifier will not be created // and will be set as nil because FlagTrustNode must be set. func NewCLIContextWithInputAndFrom(input io.Reader, from string) CLIContext { - ctx := &CLIContext{} + ctx := CLIContext{} return ctx.InitWithInputAndFrom(input, from) } From 8ef786133a8c4b4bd3394c1ed0f5498100487dc4 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 19 May 2020 15:50:08 -0400 Subject: [PATCH 21/48] WIP on all modules --- x/bank/module.go | 3 +- x/crisis/client/cli/tx.go | 12 +++---- x/crisis/module.go | 9 +++++ x/distribution/client/cli/tx.go | 57 +++++++++++--------------------- x/distribution/module.go | 9 +++++ x/gov/client/cli/tx.go | 50 +++++++++------------------- x/gov/client/proposal_handler.go | 2 +- x/gov/module.go | 20 +++++++---- x/params/client/cli/tx.go | 8 ++--- x/slashing/client/cli/tx.go | 15 +++------ x/staking/client/cli/tx.go | 44 +++++++++--------------- 11 files changed, 97 insertions(+), 132 deletions(-) diff --git a/x/bank/module.go b/x/bank/module.go index 02d4c34f7fb0..2afad16f428b 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -27,6 +27,7 @@ var ( _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} _ module.InterfaceModule = AppModuleBasic{} + _ module.ClientModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the bank module. @@ -173,8 +174,6 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp ) } -var _ module.ClientModule = AppModuleBasic{} - func (am AppModuleBasic) NewTxCmd(ctx context.CLIContext) *cobra.Command { return cli.NewTxCmd(ctx) } diff --git a/x/crisis/client/cli/tx.go b/x/crisis/client/cli/tx.go index 18ea757cbc03..c728602f1d1d 100644 --- a/x/crisis/client/cli/tx.go +++ b/x/crisis/client/cli/tx.go @@ -17,7 +17,7 @@ import ( ) // NewTxCmd returns a root CLI command handler for all x/crisis transaction commands. -func NewTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewTxCmd(ctx context.CLIContext) *cobra.Command { txCmd := &cobra.Command{ Use: types.ModuleName, Short: "Crisis transactions subcommands", @@ -26,22 +26,20 @@ func NewTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetr RunE: client.ValidateCmd, } - txCmd.AddCommand(NewMsgVerifyInvariantTxCmd(m, txg, ar)) + txCmd.AddCommand(NewMsgVerifyInvariantTxCmd(ctx)) return txCmd } // NewMsgVerifyInvariantTxCmd returns a CLI command handler for creating a // MsgVerifyInvariant transaction. -func NewMsgVerifyInvariantTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewMsgVerifyInvariantTxCmd(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "invariant-broken [module-name] [invariant-route]", Short: "Submit proof that an invariant broken to halt the chain", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) - txf := tx.NewFactoryFromCLI(inBuf).WithTxGenerator(txg).WithAccountRetriever(ar) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) senderAddr := cliCtx.GetFromAddress() moduleName, route := args[0], args[1] @@ -51,7 +49,7 @@ func NewMsgVerifyInvariantTxCmd(m codec.Marshaler, txg context.TxGenerator, ar c return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } diff --git a/x/crisis/module.go b/x/crisis/module.go index 93d30ee360e8..9b569f2a1bd8 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -21,6 +21,7 @@ import ( var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} + _ module.ClientModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the crisis module. @@ -63,6 +64,14 @@ func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { // GetQueryCmd returns no root query command for the crisis module. func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil } +func (b AppModuleBasic) NewTxCmd(ctx context.CLIContext) *cobra.Command { + return cli.NewTxCmd(ctx) +} + +func (b AppModuleBasic) NewQueryCmd(ctx context.CLIContext) *cobra.Command { return nil } + +func (b AppModuleBasic) NewRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {} + //____________________________________________________________________________ // AppModule implements an application module for the crisis module. diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 2230ea0eef84..a4f2df5e1780 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -37,7 +37,7 @@ const ( ) // NewTxCmd returns a root CLI command handler for all x/distribution transaction commands. -func NewTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewTxCmd(ctx context.CLIContext) *cobra.Command { distTxCmd := &cobra.Command{ Use: types.ModuleName, Short: "Distribution transactions subcommands", @@ -47,26 +47,25 @@ func NewTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetr } distTxCmd.AddCommand(flags.PostCommands( - NewWithdrawRewardsCmd(m, txg, ar), - NewWithdrawAllRewardsCmd(m, txg, ar), - NewSetWithdrawAddrCmd(m, txg, ar), - NewFundCommunityPoolCmd(m, txg, ar), + NewWithdrawRewardsCmd(ctx), + NewWithdrawAllRewardsCmd(ctx), + NewSetWithdrawAddrCmd(ctx), + NewFundCommunityPoolCmd(ctx), )...) return distTxCmd } -type newGenerateOrBroadcastFunc func(ctx context.CLIContext, txf tx.Factory, msgs ...sdk.Msg) error +type newGenerateOrBroadcastFunc func(ctx context.CLIContext, msgs ...sdk.Msg) error func newSplitAndApply( newGenerateOrBroadcast newGenerateOrBroadcastFunc, cliCtx context.CLIContext, - txBldr tx.Factory, msgs []sdk.Msg, chunkSize int, ) error { if chunkSize == 0 { - return newGenerateOrBroadcast(cliCtx, txBldr, msgs...) + return newGenerateOrBroadcast(cliCtx, msgs...) } // split messages into slices of length chunkSize @@ -79,7 +78,7 @@ func newSplitAndApply( } msgChunk := msgs[i:sliceEnd] - if err := newGenerateOrBroadcast(cliCtx, txBldr, msgChunk...); err != nil { + if err := newGenerateOrBroadcast(cliCtx, msgChunk...); err != nil { return err } } @@ -87,7 +86,7 @@ func newSplitAndApply( return nil } -func NewWithdrawRewardsCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewWithdrawRewardsCmd(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "withdraw-rewards [validator-addr]", Short: "Withdraw rewards from a given delegation address, and optionally withdraw validator commission if the delegation address given is a validator operator", @@ -104,11 +103,7 @@ $ %s tx distribution withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txf := tx.NewFactoryFromCLI(inBuf). - WithTxGenerator(txg). - WithAccountRetriever(ar) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) delAddr := cliCtx.GetFromAddress() valAddr, err := sdk.ValAddressFromBech32(args[0]) @@ -127,14 +122,14 @@ $ %s tx distribution withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx } } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msgs...) + return tx.GenerateOrBroadcastTx(cliCtx, msgs...) }, } cmd.Flags().Bool(flagCommission, false, "also withdraw validator's commission") return flags.PostCommands(cmd)[0] } -func NewWithdrawAllRewardsCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewWithdrawAllRewardsCmd(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "withdraw-all-rewards", Short: "withdraw all delegations rewards for a delegator", @@ -149,11 +144,7 @@ $ %s tx distribution withdraw-all-rewards --from mykey ), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txf := tx.NewFactoryFromCLI(inBuf). - WithTxGenerator(txg). - WithAccountRetriever(ar) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) delAddr := cliCtx.GetFromAddress() @@ -169,13 +160,13 @@ $ %s tx distribution withdraw-all-rewards --from mykey } chunkSize := viper.GetInt(flagMaxMessagesPerTx) - return newSplitAndApply(tx.GenerateOrBroadcastTxWithFactory, cliCtx, txf, msgs, chunkSize) + return newSplitAndApply(tx.GenerateOrBroadcastTx, cliCtx, msgs, chunkSize) }, } return flags.PostCommands(cmd)[0] } -func NewSetWithdrawAddrCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewSetWithdrawAddrCmd(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "set-withdraw-addr [withdraw-addr]", Short: "change the default withdraw address for rewards associated with an address", @@ -190,11 +181,7 @@ $ %s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75 ), Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txf := tx.NewFactoryFromCLI(inBuf). - WithTxGenerator(txg). - WithAccountRetriever(ar) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) delAddr := cliCtx.GetFromAddress() withdrawAddr, err := sdk.AccAddressFromBech32(args[0]) @@ -207,13 +194,13 @@ $ %s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75 return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } return flags.PostCommands(cmd)[0] } -func NewFundCommunityPoolCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewFundCommunityPoolCmd(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "community-pool-spend [proposal-file]", Args: cobra.ExactArgs(1), @@ -239,11 +226,7 @@ Where proposal.json contains: ), ), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txf := tx.NewFactoryFromCLI(inBuf). - WithTxGenerator(txg). - WithAccountRetriever(ar) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) depositorAddr := cliCtx.GetFromAddress() amount, err := sdk.ParseCoins(args[0]) @@ -256,7 +239,7 @@ Where proposal.json contains: return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } return flags.PostCommands(cmd)[0] diff --git a/x/distribution/module.go b/x/distribution/module.go index ee32db9231a8..fc9b7966e73e 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -25,6 +25,7 @@ var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} + _ module.ClientModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the distribution module. @@ -73,6 +74,14 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { return cli.GetQueryCmd(StoreKey, cdc) } +func (b AppModuleBasic) NewTxCmd(ctx context.CLIContext) *cobra.Command { + return cli.NewTxCmd(ctx) +} + +func (b AppModuleBasic) NewQueryCmd(ctx context.CLIContext) *cobra.Command { return nil } + +func (b AppModuleBasic) NewRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {} + //____________________________________________________________________________ // AppModule implements an application module for the distribution module. diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 96661068dbf6..1e023dfd1454 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -56,11 +56,9 @@ var ProposalFlags = []string{ // to proposal type handlers that are implemented in other modules but are mounted // under the governance CLI (eg. parameter change proposals). func NewTxCmd( - cdc codec.Marshaler, - txg context.TxGenerator, - ar context.AccountRetriever, - newMsgFn func() types.MsgSubmitProposalI, - pcmds []*cobra.Command) *cobra.Command { + ctx context.CLIContext, + pcmds []*cobra.Command, +) *cobra.Command { govTxCmd := &cobra.Command{ Use: types.ModuleName, Short: "Governance transactions subcommands", @@ -69,14 +67,14 @@ func NewTxCmd( RunE: client.ValidateCmd, } - cmdSubmitProp := NewCmdSubmitProposal(cdc, txg, ar, newMsgFn) + cmdSubmitProp := NewCmdSubmitProposal(ctx) for _, pcmd := range pcmds { cmdSubmitProp.AddCommand(flags.PostCommands(pcmd)[0]) } govTxCmd.AddCommand(flags.PostCommands( - NewCmdDeposit(cdc, txg, ar), - NewCmdVote(cdc, txg, ar), + NewCmdDeposit(ctx), + NewCmdVote(ctx), cmdSubmitProp, )...) @@ -84,11 +82,7 @@ func NewTxCmd( } // NewCmdSubmitProposal implements submitting a proposal transaction command. -func NewCmdSubmitProposal( - cdc codec.Marshaler, - txg context.TxGenerator, - ar context.AccountRetriever, - newMsgFn func() types.MsgSubmitProposalI) *cobra.Command { +func NewCmdSubmitProposal(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "submit-proposal", Short: "Submit a proposal along with an initial deposit", @@ -116,9 +110,7 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr ), ), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(cdc) - txf := tx.NewFactoryFromCLI(inBuf).WithTxGenerator(txg).WithAccountRetriever(ar) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) proposal, err := parseSubmitProposalFlags() if err != nil { @@ -132,19 +124,13 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr content := types.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type) - msg := newMsgFn() - err = msg.SetContent(content) - if err != nil { - return err - } - msg.SetInitialDeposit(amount) - msg.SetProposer(cliCtx.FromAddress) + msg := types.NewMsgSubmitProposal(content, amount, cliCtx.FromAddress) if err = msg.ValidateBasic(); err != nil { return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } @@ -158,7 +144,7 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr } // NewCmdDeposit implements depositing tokens for an active proposal. -func NewCmdDeposit(cdc codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewCmdDeposit(ctx context.CLIContext) *cobra.Command { return &cobra.Command{ Use: "deposit [proposal-id] [deposit]", Args: cobra.ExactArgs(2), @@ -174,9 +160,7 @@ $ %s tx gov deposit 1 10stake --from mykey ), ), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(cdc) - txf := tx.NewFactoryFromCLI(inBuf).WithTxGenerator(txg).WithAccountRetriever(ar) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) // validate that the proposal id is a uint proposalID, err := strconv.ParseUint(args[0], 10, 64) @@ -199,13 +183,13 @@ $ %s tx gov deposit 1 10stake --from mykey return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } } // NewCmdVote implements creating a new vote command. -func NewCmdVote(cdc codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewCmdVote(ctx context.CLIContext) *cobra.Command { return &cobra.Command{ Use: "vote [proposal-id] [option]", Args: cobra.ExactArgs(2), @@ -222,9 +206,7 @@ $ %s tx gov vote 1 yes --from mykey ), ), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(cdc) - txf := tx.NewFactoryFromCLI(inBuf).WithTxGenerator(txg).WithAccountRetriever(ar) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) // Get voting address from := cliCtx.GetFromAddress() @@ -248,7 +230,7 @@ $ %s tx gov vote 1 yes --from mykey return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } } diff --git a/x/gov/client/proposal_handler.go b/x/gov/client/proposal_handler.go index cdfc0115e094..3143aec4151c 100644 --- a/x/gov/client/proposal_handler.go +++ b/x/gov/client/proposal_handler.go @@ -12,7 +12,7 @@ import ( type RESTHandlerFn func(context.CLIContext) rest.ProposalRESTHandler // function to create the cli handler -type CLIHandlerFn func(*codec.Codec) *cobra.Command +type CLIHandlerFn func(marshaler codec.Marshaler) *cobra.Command // The combined type for a proposal handler for both cli and rest type ProposalHandler struct { diff --git a/x/gov/module.go b/x/gov/module.go index 63fecf1440ce..eec752aa32bf 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -28,6 +28,7 @@ var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} + _ module.ClientModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the gov module. @@ -80,20 +81,25 @@ func (a AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Rout } // GetTxCmd returns the root tx command for the gov module. -func (a AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { +func (a AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { return nil } +// GetQueryCmd returns the root query command for the gov module. +func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { + return cli.GetQueryCmd(StoreKey, cdc) +} + +func (a AppModuleBasic) NewTxCmd(ctx context.CLIContext) *cobra.Command { proposalCLIHandlers := make([]*cobra.Command, 0, len(a.proposalHandlers)) for _, proposalHandler := range a.proposalHandlers { - proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler(cdc)) + proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler(a.cdc)) } - return cli.GetTxCmd(StoreKey, cdc, proposalCLIHandlers) + return cli.NewTxCmd(ctx, proposalCLIHandlers) } -// GetQueryCmd returns the root query command for the gov module. -func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetQueryCmd(StoreKey, cdc) -} +func (a AppModuleBasic) NewQueryCmd(ctx context.CLIContext) *cobra.Command { return nil } + +func (a AppModuleBasic) NewRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {} //____________________________________________________________________________ diff --git a/x/params/client/cli/tx.go b/x/params/client/cli/tx.go index 1b326081ecba..c133f006bf89 100644 --- a/x/params/client/cli/tx.go +++ b/x/params/client/cli/tx.go @@ -21,7 +21,7 @@ import ( // NewSubmitParamChangeProposalTxCmd returns a CLI command handler for creating // a parameter change proposal governance transaction. -func NewSubmitParamChangeProposalTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewSubmitParamChangeProposalTxCmd(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "param-change [proposal-file]", Args: cobra.ExactArgs(1), @@ -61,9 +61,7 @@ Where proposal.json contains: ), ), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) - txf := tx.NewFactoryFromCLI(inBuf).WithTxGenerator(txg).WithAccountRetriever(ar) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) proposal, err := paramscutils.ParseParamChangeProposalJSON(m, args[0]) if err != nil { @@ -85,7 +83,7 @@ Where proposal.json contains: return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } diff --git a/x/slashing/client/cli/tx.go b/x/slashing/client/cli/tx.go index 5811efc6b939..1f0d7aa9f2d6 100644 --- a/x/slashing/client/cli/tx.go +++ b/x/slashing/client/cli/tx.go @@ -17,7 +17,7 @@ import ( ) // NewTxCmd returns a root CLI command handler for all x/slashing transaction commands. -func NewTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewTxCmd(ctx context.CLIContext) *cobra.Command { slashingTxCmd := &cobra.Command{ Use: types.ModuleName, Short: "Slashing transaction subcommands", @@ -26,11 +26,11 @@ func NewTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetr RunE: client.ValidateCmd, } - slashingTxCmd.AddCommand(NewUnjailTxCmd(m, txg, ar)) + slashingTxCmd.AddCommand(NewUnjailTxCmd(ctx)) return slashingTxCmd } -func NewUnjailTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewUnjailTxCmd(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "unjail", Args: cobra.NoArgs, @@ -40,12 +40,7 @@ func NewUnjailTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.Accou $ tx slashing unjail --from mykey `, RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txf := tx.NewFactoryFromCLI(inBuf). - WithTxGenerator(txg). - WithAccountRetriever(ar) - - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) valAddr := cliCtx.GetFromAddress() msg := types.NewMsgUnjail(sdk.ValAddress(valAddr)) @@ -53,7 +48,7 @@ $ tx slashing unjail --from mykey return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } return flags.PostCommands(cmd)[0] diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index 196c41ee48b2..388c4897f060 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -37,7 +37,7 @@ var ( ) // NewTxCmd returns a root CLI command handler for all x/staking transaction commands. -func NewTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewTxCmd(ctx context.CLIContext) *cobra.Command { stakingTxCmd := &cobra.Command{ Use: types.ModuleName, Short: "Staking transaction subcommands", @@ -47,27 +47,23 @@ func NewTxCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetr } stakingTxCmd.AddCommand(flags.PostCommands( - NewCreateValidatorCmd(m, txg, ar), - NewEditValidatorCmd(m, txg, ar), - NewDelegateCmd(m, txg, ar), - NewRedelegateCmd(m, txg, ar), - NewUnbondCmd(m, txg, ar), + NewCreateValidatorCmd(ctx), + NewEditValidatorCmd(ctx), + NewDelegateCmd(ctx), + NewRedelegateCmd(ctx), + NewUnbondCmd(ctx), )...) return stakingTxCmd } -func NewCreateValidatorCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewCreateValidatorCmd(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "create-validator", Short: "create new validator initialized with a self-delegation to it", RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txf := tx.NewFactoryFromCLI(inBuf). - WithTxGenerator(txg). - WithAccountRetriever(ar) - - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) + txf := tx.NewFactoryFromCLI(ctx.Input).WithTxGenerator(ctx.TxGenerator).WithAccountRetriever(ctx.AccountRetriever) txf, msg, err := NewBuildCreateValidatorMsg(cliCtx, txf) if err != nil { @@ -93,17 +89,12 @@ func NewCreateValidatorCmd(m codec.Marshaler, txg context.TxGenerator, ar contex return flags.PostCommands(cmd)[0] } -func NewEditValidatorCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewEditValidatorCmd(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "edit-validator", Short: "edit an existing validator account", RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txf := tx.NewFactoryFromCLI(inBuf). - WithTxGenerator(txg). - WithAccountRetriever(ar) - - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) valAddr := cliCtx.GetFromAddress() description := types.NewDescription( @@ -144,14 +135,14 @@ func NewEditValidatorCmd(m codec.Marshaler, txg context.TxGenerator, ar context. } // build and sign the transaction, then broadcast to Tendermint - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } return flags.PostCommands(cmd)[0] } -func NewDelegateCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewDelegateCmd(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "delegate [validator-addr] [amount]", Args: cobra.ExactArgs(2), @@ -166,12 +157,7 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10 ), ), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txf := tx.NewFactoryFromCLI(inBuf). - WithTxGenerator(txg). - WithAccountRetriever(ar) - - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) amount, err := sdk.ParseCoin(args[1]) if err != nil { @@ -189,7 +175,7 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10 return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } cmd.Flags().AddFlagSet(fsDescriptionEdit) From b6918f67c1b9590d5ddcbb33bdcb0d769c8c2c45 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 19 May 2020 17:25:19 -0400 Subject: [PATCH 22/48] Implement other module new tx cmd's --- simapp/cmd/simcli/main.go | 4 +- types/module/module.go | 12 +++ x/distribution/client/cli/tx.go | 10 +-- x/distribution/client/cli/utils.go | 2 +- x/gov/client/cli/tx.go | 5 +- x/gov/client/proposal_handler.go | 3 +- x/gov/module.go | 2 +- x/params/client/cli/tx.go | 89 +------------------ x/params/client/proposal_handler.go | 2 +- x/staking/client/cli/tx.go | 21 ++--- x/upgrade/client/cli/tx.go | 123 +-------------------------- x/upgrade/client/proposal_handler.go | 2 +- 12 files changed, 37 insertions(+), 238 deletions(-) diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index f753b75baebc..a1c59440c0c5 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -5,8 +5,6 @@ import ( "os" "path" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/tendermint/tendermint/libs/cli" @@ -140,7 +138,7 @@ func txCmd(cdc *codec.Codec) *cobra.Command { ) // add modules' tx commands - simapp.ModuleBasics.AddTxCommands(txCmd, cdc) + simapp.ModuleBasics.AddNewTxCommands(txCmd, cliCtx) return txCmd } diff --git a/types/module/module.go b/types/module/module.go index 4a3447230878..202fead621ae 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -112,6 +112,18 @@ func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command, cdc *codec.Codec) } } +// AddTxCommands adds all tx commands to the rootTxCmd +func (bm BasicManager) AddNewTxCommands(rootTxCmd *cobra.Command, ctx context.CLIContext) { + for _, b := range bm { + cm, ok := b.(ClientModule) + if ok { + if cmd := cm.NewTxCmd(ctx); cmd != nil { + rootTxCmd.AddCommand(cmd) + } + } + } +} + // AddQueryCommands adds all query commands to the rootQueryCmd func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, cdc *codec.Codec) { for _, b := range bm { diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 041766f76b80..64a1deeea21c 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -417,7 +417,7 @@ $ %s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75 } // GetCmdSubmitProposal implements the command to submit a community-pool-spend proposal -func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command { +func GetCmdSubmitProposal(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "community-pool-spend [proposal-file]", Args: cobra.ExactArgs(1), @@ -443,11 +443,9 @@ Where proposal.json contains: ), ), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) - proposal, err := ParseCommunityPoolSpendProposalJSON(cdc, args[0]) + proposal, err := ParseCommunityPoolSpendProposalJSON(ctx.Marshaler, args[0]) if err != nil { return err } @@ -472,7 +470,7 @@ Where proposal.json contains: return err } - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } diff --git a/x/distribution/client/cli/utils.go b/x/distribution/client/cli/utils.go index 4d4169a7fad0..c5310f6469ca 100644 --- a/x/distribution/client/cli/utils.go +++ b/x/distribution/client/cli/utils.go @@ -19,7 +19,7 @@ type ( ) // ParseCommunityPoolSpendProposalJSON reads and parses a CommunityPoolSpendProposalJSON from a file. -func ParseCommunityPoolSpendProposalJSON(cdc *codec.Codec, proposalFile string) (CommunityPoolSpendProposalJSON, error) { +func ParseCommunityPoolSpendProposalJSON(cdc codec.JSONMarshaler, proposalFile string) (CommunityPoolSpendProposalJSON, error) { proposal := CommunityPoolSpendProposalJSON{} contents, err := ioutil.ReadFile(proposalFile) diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index c8c7b0f4f201..88fff9cb1566 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -126,7 +126,10 @@ $ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome pr content := types.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type) - msg := types.NewMsgSubmitProposal(content, amount, cliCtx.FromAddress) + msg, err := types.NewMsgSubmitProposal(content, amount, cliCtx.FromAddress) + if err != nil { + return err + } if err = msg.ValidateBasic(); err != nil { return err diff --git a/x/gov/client/proposal_handler.go b/x/gov/client/proposal_handler.go index 3143aec4151c..10de527db6c3 100644 --- a/x/gov/client/proposal_handler.go +++ b/x/gov/client/proposal_handler.go @@ -4,7 +4,6 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/gov/client/rest" ) @@ -12,7 +11,7 @@ import ( type RESTHandlerFn func(context.CLIContext) rest.ProposalRESTHandler // function to create the cli handler -type CLIHandlerFn func(marshaler codec.Marshaler) *cobra.Command +type CLIHandlerFn func(context.CLIContext) *cobra.Command // The combined type for a proposal handler for both cli and rest type ProposalHandler struct { diff --git a/x/gov/module.go b/x/gov/module.go index 622938293a00..ec57f53a6e57 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -98,7 +98,7 @@ func (a AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegi func (a AppModuleBasic) NewTxCmd(ctx context.CLIContext) *cobra.Command { proposalCLIHandlers := make([]*cobra.Command, 0, len(a.proposalHandlers)) for _, proposalHandler := range a.proposalHandlers { - proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler(a.cdc)) + proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler(ctx)) } return cli.NewTxCmd(ctx, proposalCLIHandlers) diff --git a/x/params/client/cli/tx.go b/x/params/client/cli/tx.go index 1f68389b7c12..b14df343efe0 100644 --- a/x/params/client/cli/tx.go +++ b/x/params/client/cli/tx.go @@ -1,7 +1,6 @@ package cli import ( - "bufio" "fmt" "strings" @@ -9,11 +8,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/auth" - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils" paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" @@ -63,7 +59,7 @@ Where proposal.json contains: RunE: func(cmd *cobra.Command, args []string) error { cliCtx := ctx.InitWithInput(cmd.InOrStdin()) - proposal, err := paramscutils.ParseParamChangeProposalJSON(m, args[0]) + proposal, err := paramscutils.ParseParamChangeProposalJSON(ctx.Marshaler, args[0]) if err != nil { return err } @@ -92,86 +88,3 @@ Where proposal.json contains: return cmd } - -// --------------------------------------------------------------------------- -// Deprecated -// -// TODO: Remove once client-side Protobuf migration has been completed. -// --------------------------------------------------------------------------- - -// GetCmdSubmitProposal implements a command handler for submitting a parameter -// change proposal transaction. -// -// TODO: Remove once client-side Protobuf migration has been completed. -// ref: https://github.com/cosmos/cosmos-sdk/issues/5864 -func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "param-change [proposal-file]", - Args: cobra.ExactArgs(1), - Short: "Submit a parameter change proposal", - Long: strings.TrimSpace( - fmt.Sprintf(`Submit a parameter proposal along with an initial deposit. -The proposal details must be supplied via a JSON file. For values that contains -objects, only non-empty fields will be updated. - -IMPORTANT: Currently parameter changes are evaluated but not validated, so it is -very important that any "value" change is valid (ie. correct type and within bounds) -for its respective parameter, eg. "MaxValidators" should be an integer and not a decimal. - -Proper vetting of a parameter change proposal should prevent this from happening -(no deposits should occur during the governance process), but it should be noted -regardless. - -Example: -$ %s tx gov submit-proposal param-change --from= - -Where proposal.json contains: - -{ - "title": "Staking Param Change", - "description": "Update max validators", - "changes": [ - { - "subspace": "staking", - "key": "MaxValidators", - "value": 105 - } - ], - "deposit": "1000stake" -} -`, - version.ClientName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - proposal, err := paramscutils.ParseParamChangeProposalJSON(cdc, args[0]) - if err != nil { - return err - } - - from := cliCtx.GetFromAddress() - content := paramproposal.NewParameterChangeProposal(proposal.Title, proposal.Description, proposal.Changes.ToParamChanges()) - - deposit, err := sdk.ParseCoins(proposal.Deposit) - if err != nil { - return err - } - - msg, err := govtypes.NewMsgSubmitProposal(content, deposit, from) - if err != nil { - return err - } - if err := msg.ValidateBasic(); err != nil { - return err - } - - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } - - return cmd -} diff --git a/x/params/client/proposal_handler.go b/x/params/client/proposal_handler.go index dd93e9bdd27b..77a672d89c4e 100644 --- a/x/params/client/proposal_handler.go +++ b/x/params/client/proposal_handler.go @@ -7,4 +7,4 @@ import ( ) // ProposalHandler is the param change proposal handler. -var ProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitProposal, rest.ProposalRESTHandler) +var ProposalHandler = govclient.NewProposalHandler(cli.NewSubmitParamChangeProposalTxCmd, rest.ProposalRESTHandler) diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index 388c4897f060..3f4ff21893c2 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -185,7 +185,7 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10 return flags.PostCommands(cmd)[0] } -func NewRedelegateCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewRedelegateCmd(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "redelegate [src-validator-addr] [dst-validator-addr] [amount]", Short: "Redelegate illiquid tokens from one validator to another", @@ -200,12 +200,8 @@ $ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj ), ), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txf := tx.NewFactoryFromCLI(inBuf). - WithTxGenerator(txg). - WithAccountRetriever(ar) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) delAddr := cliCtx.GetFromAddress() valSrcAddr, err := sdk.ValAddressFromBech32(args[0]) if err != nil { @@ -227,14 +223,14 @@ $ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } return flags.PostCommands(cmd)[0] } -func NewUnbondCmd(m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever) *cobra.Command { +func NewUnbondCmd(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "unbond [validator-addr] [amount]", Short: "Unbond shares from a validator", @@ -249,12 +245,7 @@ $ %s tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100s ), ), RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txf := tx.NewFactoryFromCLI(inBuf). - WithTxGenerator(txg). - WithAccountRetriever(ar) - - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) delAddr := cliCtx.GetFromAddress() valAddr, err := sdk.ValAddressFromBech32(args[0]) @@ -272,7 +263,7 @@ $ %s tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100s return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } diff --git a/x/upgrade/client/cli/tx.go b/x/upgrade/client/cli/tx.go index 108990a39684..5f0da3ce84f7 100644 --- a/x/upgrade/client/cli/tx.go +++ b/x/upgrade/client/cli/tx.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" gov "github.com/cosmos/cosmos-sdk/x/gov/types" - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/gov/client/cli" "github.com/spf13/cobra" @@ -16,7 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -30,10 +28,7 @@ const ( ) // NewCmdSubmitUpgradeProposal implements a command handler for submitting a software upgrade proposal transaction. -func NewCmdSubmitUpgradeProposal( - m codec.Marshaler, txg context.TxGenerator, ar context.AccountRetriever, - newMsgFn func() gov.MsgSubmitProposalI, -) *cobra.Command { +func NewCmdSubmitUpgradeProposal(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "software-upgrade [name] (--upgrade-height [height] | --upgrade-time [time]) (--upgrade-info [info]) [flags]", @@ -49,9 +44,7 @@ func NewCmdSubmitUpgradeProposal( return err } - inBuf := bufio.NewReader(cmd.InOrStdin()) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) - txf := tx.NewFactoryFromCLI(inBuf).WithTxGenerator(txg).WithAccountRetriever(ar) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) from := cliCtx.GetFromAddress() depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) @@ -63,19 +56,16 @@ func NewCmdSubmitUpgradeProposal( return err } - msg := newMsgFn() - err = msg.SetContent(content) + msg, err := gov.NewMsgSubmitProposal(content, deposit, from) if err != nil { return err } - msg.SetInitialDeposit(deposit) - msg.SetProposer(from) if err = msg.ValidateBasic(); err != nil { return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } @@ -193,108 +183,3 @@ func parseArgsToContent(cmd *cobra.Command, name string) (gov.Content, error) { content := types.NewSoftwareUpgradeProposal(title, description, plan) return content, nil } - -// GetCmdSubmitUpgradeProposal implements a command handler for submitting a software upgrade proposal transaction. -func GetCmdSubmitUpgradeProposal(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "software-upgrade [name] (--upgrade-height [height] | --upgrade-time [time]) (--upgrade-info [info]) [flags]", - Args: cobra.ExactArgs(1), - Short: "Submit a software upgrade proposal", - Long: "Submit a software upgrade along with an initial deposit.\n" + - "Please specify a unique name and height OR time for the upgrade to take effect.\n" + - "You may include info to reference a binary download link, in a format compatible with: https://github.com/regen-network/cosmosd", - RunE: func(cmd *cobra.Command, args []string) error { - name := args[0] - content, err := parseArgsToContent(cmd, name) - if err != nil { - return err - } - - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - from := cliCtx.GetFromAddress() - - depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) - if err != nil { - return err - } - deposit, err := sdk.ParseCoins(depositStr) - if err != nil { - return err - } - - msg, err := gov.NewMsgSubmitProposal(content, deposit, from) - if err != nil { - return err - } - if err := msg.ValidateBasic(); err != nil { - return err - } - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } - - cmd.Flags().String(cli.FlagTitle, "", "title of proposal") - cmd.Flags().String(cli.FlagDescription, "", "description of proposal") - cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") - cmd.Flags().Int64(FlagUpgradeHeight, 0, "The height at which the upgrade must happen (not to be used together with --upgrade-time)") - cmd.Flags().String(FlagUpgradeTime, "", fmt.Sprintf("The time at which the upgrade must happen (ex. %s) (not to be used together with --upgrade-height)", TimeFormat)) - cmd.Flags().String(FlagUpgradeInfo, "", "Optional info for the planned upgrade such as commit hash, etc.") - - return cmd -} - -// GetCmdSubmitCancelUpgradeProposal implements a command handler for submitting a software upgrade cancel proposal transaction. -func GetCmdSubmitCancelUpgradeProposal(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "cancel-software-upgrade [flags]", - Args: cobra.ExactArgs(0), - Short: "Submit a software upgrade proposal", - Long: "Cancel a software upgrade along with an initial deposit.", - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - from := cliCtx.GetFromAddress() - - depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) - if err != nil { - return err - } - - deposit, err := sdk.ParseCoins(depositStr) - if err != nil { - return err - } - - title, err := cmd.Flags().GetString(cli.FlagTitle) - if err != nil { - return err - } - - description, err := cmd.Flags().GetString(cli.FlagDescription) - if err != nil { - return err - } - - content := types.NewCancelSoftwareUpgradeProposal(title, description) - - msg, err := gov.NewMsgSubmitProposal(content, deposit, from) - if err != nil { - return err - } - if err := msg.ValidateBasic(); err != nil { - return err - } - - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } - - cmd.Flags().String(cli.FlagTitle, "", "title of proposal") - cmd.Flags().String(cli.FlagDescription, "", "description of proposal") - cmd.Flags().String(cli.FlagDeposit, "", "deposit of proposal") - - return cmd -} diff --git a/x/upgrade/client/proposal_handler.go b/x/upgrade/client/proposal_handler.go index 314c8ac587a5..7cf0f9d778d2 100644 --- a/x/upgrade/client/proposal_handler.go +++ b/x/upgrade/client/proposal_handler.go @@ -6,4 +6,4 @@ import ( "github.com/cosmos/cosmos-sdk/x/upgrade/client/rest" ) -var ProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitUpgradeProposal, rest.ProposalRESTHandler) +var ProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitUpgradeProposal, rest.ProposalRESTHandler) From ed494ceea9c32538d97563158ad79bbecfd8d20c Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 19 May 2020 17:36:28 -0400 Subject: [PATCH 23/48] Fix cmd's --- x/distribution/client/cli/tx.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 64a1deeea21c..7bcbba09f7d2 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -126,7 +126,7 @@ $ %s tx distribution withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx }, } cmd.Flags().Bool(flagCommission, false, "also withdraw validator's commission") - return flags.PostCommands(cmd)[0] + return cmd } func NewWithdrawAllRewardsCmd(ctx context.CLIContext) *cobra.Command { @@ -163,7 +163,7 @@ $ %s tx distribution withdraw-all-rewards --from mykey return newSplitAndApply(tx.GenerateOrBroadcastTx, cliCtx, msgs, chunkSize) }, } - return flags.PostCommands(cmd)[0] + return cmd } func NewSetWithdrawAddrCmd(ctx context.CLIContext) *cobra.Command { @@ -197,7 +197,7 @@ $ %s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75 return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } - return flags.PostCommands(cmd)[0] + return cmd } func NewFundCommunityPoolCmd(ctx context.CLIContext) *cobra.Command { @@ -242,7 +242,7 @@ Where proposal.json contains: return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } - return flags.PostCommands(cmd)[0] + return cmd } // --------------------------------------------------------------------------- From c51730b98ee2ee7c8a0039e5ff82c733a2877e9e Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 19 May 2020 17:51:36 -0400 Subject: [PATCH 24/48] Refactor existing GetTxCmd --- simapp/cmd/simcli/main.go | 5 +++-- types/module/client.go | 14 -------------- types/module/module.go | 18 +++--------------- x/auth/module.go | 4 ++-- x/bank/module.go | 5 ++--- x/capability/module.go | 2 +- x/crisis/module.go | 9 ++------- x/distribution/module.go | 7 +++---- x/evidence/client/cli/tx.go | 8 ++++---- x/evidence/client/evidence_handler.go | 3 +-- x/evidence/module.go | 6 +++--- x/genutil/module.go | 2 +- x/gov/module.go | 19 ++++++++----------- x/ibc-transfer/module.go | 4 ++-- x/ibc/module.go | 4 ++-- x/mint/module.go | 2 +- x/params/module.go | 2 +- x/slashing/module.go | 4 ++-- x/staking/module.go | 4 ++-- x/upgrade/module.go | 2 +- 20 files changed, 44 insertions(+), 80 deletions(-) delete mode 100644 types/module/client.go diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index a1c59440c0c5..1a4f8439dae2 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -122,7 +122,8 @@ func txCmd(cdc *codec.Codec) *cobra.Command { cliCtx = cliCtx. WithMarshaler(appCodec). WithTxGenerator(types.StdTxGenerator{cdc}). - WithAccountRetriever(types.NewAccountRetriever(appCodec)) + WithAccountRetriever(types.NewAccountRetriever(appCodec)). + WithCodec(cdc) txCmd.AddCommand( bankcmd.NewSendTxCmd(cliCtx), @@ -138,7 +139,7 @@ func txCmd(cdc *codec.Codec) *cobra.Command { ) // add modules' tx commands - simapp.ModuleBasics.AddNewTxCommands(txCmd, cliCtx) + simapp.ModuleBasics.AddTxCommands(txCmd, cliCtx) return txCmd } diff --git a/types/module/client.go b/types/module/client.go deleted file mode 100644 index d39fdb2f9c16..000000000000 --- a/types/module/client.go +++ /dev/null @@ -1,14 +0,0 @@ -package module - -import ( - "github.com/gorilla/mux" - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client/context" -) - -type ClientModule interface { - NewTxCmd(ctx context.CLIContext) *cobra.Command - NewQueryCmd(ctx context.CLIContext) *cobra.Command - NewRESTRoutes(ctx context.CLIContext, rtr *mux.Router) -} diff --git a/types/module/module.go b/types/module/module.go index 202fead621ae..d3bdd2155c81 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -52,7 +52,7 @@ type AppModuleBasic interface { // client functionality RegisterRESTRoutes(context.CLIContext, *mux.Router) - GetTxCmd(*codec.Codec) *cobra.Command + GetTxCmd(context.CLIContext) *cobra.Command GetQueryCmd(*codec.Codec) *cobra.Command } @@ -104,26 +104,14 @@ func (bm BasicManager) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Route } // AddTxCommands adds all tx commands to the rootTxCmd -func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command, cdc *codec.Codec) { +func (bm BasicManager) AddTxCommands(rootTxCmd *cobra.Command, ctx context.CLIContext) { for _, b := range bm { - if cmd := b.GetTxCmd(cdc); cmd != nil { + if cmd := b.GetTxCmd(ctx); cmd != nil { rootTxCmd.AddCommand(cmd) } } } -// AddTxCommands adds all tx commands to the rootTxCmd -func (bm BasicManager) AddNewTxCommands(rootTxCmd *cobra.Command, ctx context.CLIContext) { - for _, b := range bm { - cm, ok := b.(ClientModule) - if ok { - if cmd := cm.NewTxCmd(ctx); cmd != nil { - rootTxCmd.AddCommand(cmd) - } - } - } -} - // AddQueryCommands adds all query commands to the rootQueryCmd func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command, cdc *codec.Codec) { for _, b := range bm { diff --git a/x/auth/module.go b/x/auth/module.go index 2f425d645956..2f1834f4117e 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -63,8 +63,8 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router } // GetTxCmd returns the root tx command for the auth module. -func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetTxCmd(cdc) +func (AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { + return cli.GetTxCmd(ctx.Codec) } // GetQueryCmd returns the root query command for the auth module. diff --git a/x/bank/module.go b/x/bank/module.go index 2afad16f428b..2994bd4ed106 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -27,7 +27,6 @@ var ( _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} _ module.InterfaceModule = AppModuleBasic{} - _ module.ClientModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the bank module. @@ -63,8 +62,8 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router } // GetTxCmd returns the root tx command for the bank module. -func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetTxCmd(cdc) +func (AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { + return cli.NewTxCmd(ctx) } // GetQueryCmd returns no root query command for the bank module. diff --git a/x/capability/module.go b/x/capability/module.go index a7b285bdd3d1..911d6921cee5 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -65,7 +65,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessag func (a AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {} // GetTxCmd returns the capability module's root tx command. -func (a AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil } +func (a AppModuleBasic) GetTxCmd(_ context.CLIContext) *cobra.Command { return nil } // GetQueryCmd returns the capability module's root query command. func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil } diff --git a/x/crisis/module.go b/x/crisis/module.go index 9b569f2a1bd8..47b23dff9dcb 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -21,7 +21,6 @@ import ( var ( _ module.AppModule = AppModule{} _ module.AppModuleBasic = AppModuleBasic{} - _ module.ClientModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the crisis module. @@ -57,17 +56,13 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessag func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {} // GetTxCmd returns the root tx command for the crisis module. -func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetTxCmd(cdc) +func (b AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { + return cli.NewTxCmd(ctx) } // GetQueryCmd returns no root query command for the crisis module. func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil } -func (b AppModuleBasic) NewTxCmd(ctx context.CLIContext) *cobra.Command { - return cli.NewTxCmd(ctx) -} - func (b AppModuleBasic) NewQueryCmd(ctx context.CLIContext) *cobra.Command { return nil } func (b AppModuleBasic) NewRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {} diff --git a/x/distribution/module.go b/x/distribution/module.go index 0be76565461e..d990fd98903c 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -9,9 +9,9 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -27,7 +27,6 @@ var ( _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} _ module.InterfaceModule = AppModuleBasic{} - _ module.ClientModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the distribution module. @@ -67,8 +66,8 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router } // GetTxCmd returns the root tx command for the distribution module. -func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetTxCmd(StoreKey, cdc) +func (AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { + return cli.NewTxCmd(ctx) } // GetQueryCmd returns the root query command for the distribution module. diff --git a/x/evidence/client/cli/tx.go b/x/evidence/client/cli/tx.go index c14c3d5d0555..2912d0897db2 100644 --- a/x/evidence/client/cli/tx.go +++ b/x/evidence/client/cli/tx.go @@ -2,8 +2,8 @@ package cli import ( "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/spf13/cobra" @@ -14,7 +14,7 @@ import ( // modules, under a sub-command. This allows external modules to implement custom // Evidence types and Handlers while having the ability to create and sign txs // containing them all from a single root command. -func GetTxCmd(storeKey string, cdc *codec.Codec, childCmds []*cobra.Command) *cobra.Command { +func GetTxCmd(storeKey string, ctx context.CLIContext, childCmds []*cobra.Command) *cobra.Command { cmd := &cobra.Command{ Use: types.ModuleName, Short: "Evidence transaction subcommands", @@ -23,7 +23,7 @@ func GetTxCmd(storeKey string, cdc *codec.Codec, childCmds []*cobra.Command) *co RunE: client.ValidateCmd, } - submitEvidenceCmd := SubmitEvidenceCmd(cdc) + submitEvidenceCmd := SubmitEvidenceCmd(ctx) for _, childCmd := range childCmds { submitEvidenceCmd.AddCommand(flags.PostCommands(childCmd)[0]) } @@ -36,7 +36,7 @@ func GetTxCmd(storeKey string, cdc *codec.Codec, childCmds []*cobra.Command) *co // SubmitEvidenceCmd returns the top-level evidence submission command handler. // All concrete evidence submission child command handlers should be registered // under this command. -func SubmitEvidenceCmd(cdc *codec.Codec) *cobra.Command { +func SubmitEvidenceCmd(_ context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "submit", Short: "Submit arbitrary evidence of misbehavior", diff --git a/x/evidence/client/evidence_handler.go b/x/evidence/client/evidence_handler.go index 0b56b4c4cbf1..335894a567c0 100644 --- a/x/evidence/client/evidence_handler.go +++ b/x/evidence/client/evidence_handler.go @@ -4,7 +4,6 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/evidence/client/rest" ) @@ -13,7 +12,7 @@ type ( RESTHandlerFn func(context.CLIContext) rest.EvidenceRESTHandler // CLIHandlerFn defines a CLI command handler for evidence submission - CLIHandlerFn func(*codec.Codec) *cobra.Command + CLIHandlerFn func(context.CLIContext) *cobra.Command // EvidenceHandler defines a type that exposes REST and CLI client handlers for // evidence submission. diff --git a/x/evidence/module.go b/x/evidence/module.go index 99a2174c4f81..3a289f466a30 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -82,14 +82,14 @@ func (a AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Rout } // GetTxCmd returns the evidence module's root tx command. -func (a AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { +func (a AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { evidenceCLIHandlers := make([]*cobra.Command, len(a.evidenceHandlers)) for i, evidenceHandler := range a.evidenceHandlers { - evidenceCLIHandlers[i] = evidenceHandler.CLIHandler(cdc) + evidenceCLIHandlers[i] = evidenceHandler.CLIHandler(ctx) } - return cli.GetTxCmd(StoreKey, cdc, evidenceCLIHandlers) + return cli.GetTxCmd(StoreKey, ctx, evidenceCLIHandlers) } // GetTxCmd returns the evidence module's root query command. diff --git a/x/genutil/module.go b/x/genutil/module.go index 5853274f3bf2..11fd49381b4d 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -52,7 +52,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessag func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {} // GetTxCmd returns no root tx command for the genutil module. -func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil } +func (AppModuleBasic) GetTxCmd(_ context.CLIContext) *cobra.Command { return nil } // GetQueryCmd returns no root query command for the genutil module. func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil } diff --git a/x/gov/module.go b/x/gov/module.go index ec57f53a6e57..1b52ff4848b4 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -30,7 +30,6 @@ var ( _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModuleSimulation = AppModule{} _ module.InterfaceModule = AppModuleBasic{} - _ module.ClientModule = AppModuleBasic{} ) // AppModuleBasic defines the basic application module used by the gov module. @@ -83,7 +82,14 @@ func (a AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Rout } // GetTxCmd returns the root tx command for the gov module. -func (a AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { return nil } +func (a AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { + proposalCLIHandlers := make([]*cobra.Command, 0, len(a.proposalHandlers)) + for _, proposalHandler := range a.proposalHandlers { + proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler(ctx)) + } + + return cli.NewTxCmd(ctx, proposalCLIHandlers) +} // GetQueryCmd returns the root query command for the gov module. func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { @@ -95,15 +101,6 @@ func (a AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegi types.RegisterInterfaces(registry) } -func (a AppModuleBasic) NewTxCmd(ctx context.CLIContext) *cobra.Command { - proposalCLIHandlers := make([]*cobra.Command, 0, len(a.proposalHandlers)) - for _, proposalHandler := range a.proposalHandlers { - proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler(ctx)) - } - - return cli.NewTxCmd(ctx, proposalCLIHandlers) -} - func (a AppModuleBasic) NewQueryCmd(ctx context.CLIContext) *cobra.Command { return nil } func (a AppModuleBasic) NewRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {} diff --git a/x/ibc-transfer/module.go b/x/ibc-transfer/module.go index cca17d18d033..2aa0b7dd6072 100644 --- a/x/ibc-transfer/module.go +++ b/x/ibc-transfer/module.go @@ -70,8 +70,8 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router } // GetTxCmd implements AppModuleBasic interface -func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetTxCmd(cdc) +func (AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { + return cli.GetTxCmd(ctx.Codec) } // GetQueryCmd implements AppModuleBasic interface diff --git a/x/ibc/module.go b/x/ibc/module.go index 84bea0207ba2..bac0447cae63 100644 --- a/x/ibc/module.go +++ b/x/ibc/module.go @@ -66,8 +66,8 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router } // GetTxCmd returns the root tx command for the ibc module. -func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetTxCmd(StoreKey, cdc) +func (AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { + return cli.GetTxCmd(StoreKey, ctx.Codec) } // GetQueryCmd returns no root query command for the ibc module. diff --git a/x/mint/module.go b/x/mint/module.go index 34a75f991a6c..1c8f1765b74d 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -63,7 +63,7 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router } // GetTxCmd returns no root tx command for the mint module. -func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil } +func (AppModuleBasic) GetTxCmd(_ context.CLIContext) *cobra.Command { return nil } // GetQueryCmd returns the root query command for the mint module. func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { diff --git a/x/params/module.go b/x/params/module.go index 628b1c8365d4..9dab3b572fc6 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -50,7 +50,7 @@ func (AppModuleBasic) ValidateGenesis(_ codec.JSONMarshaler, _ json.RawMessage) func (AppModuleBasic) RegisterRESTRoutes(_ context.CLIContext, _ *mux.Router) {} // GetTxCmd returns no root tx command for the params module. -func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil } +func (AppModuleBasic) GetTxCmd(_ context.CLIContext) *cobra.Command { return nil } // GetQueryCmd returns no root query command for the params module. func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil } diff --git a/x/slashing/module.go b/x/slashing/module.go index 79730152e54a..4cdf540016f5 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -67,8 +67,8 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router } // GetTxCmd returns the root tx command for the slashing module. -func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetTxCmd(cdc) +func (AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { + return cli.NewTxCmd(ctx) } // GetQueryCmd returns no root query command for the slashing module. diff --git a/x/staking/module.go b/x/staking/module.go index 721e66bdd0ca..174575181ecc 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -70,8 +70,8 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router } // GetTxCmd returns the root tx command for the staking module. -func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { - return cli.GetTxCmd(StoreKey, cdc) +func (AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { + return cli.NewTxCmd(ctx) } // GetQueryCmd returns no root query command for the staking module. diff --git a/x/upgrade/module.go b/x/upgrade/module.go index f2c94d762780..d0a8ee51975c 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -65,7 +65,7 @@ func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { } // GetTxCmd returns the transaction commands for this module -func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { +func (AppModuleBasic) GetTxCmd(_ context.CLIContext) *cobra.Command { txCmd := &cobra.Command{ Use: "upgrade", Short: "Upgrade transaction subcommands", From 0c624ce70a9c8f7511daf095412bd8799f7652b0 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 10:35:49 -0400 Subject: [PATCH 25/48] Fix cmd --- x/staking/client/cli/tx.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index 3f4ff21893c2..6d40dc96173b 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -86,7 +86,7 @@ func NewCreateValidatorCmd(ctx context.CLIContext) *cobra.Command { _ = cmd.MarkFlagRequired(FlagPubKey) _ = cmd.MarkFlagRequired(FlagMoniker) - return flags.PostCommands(cmd)[0] + return cmd } func NewEditValidatorCmd(ctx context.CLIContext) *cobra.Command { @@ -139,7 +139,7 @@ func NewEditValidatorCmd(ctx context.CLIContext) *cobra.Command { }, } - return flags.PostCommands(cmd)[0] + return cmd } func NewDelegateCmd(ctx context.CLIContext) *cobra.Command { @@ -182,7 +182,7 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10 cmd.Flags().AddFlagSet(fsCommissionUpdate) cmd.Flags().AddFlagSet(FsMinSelfDelegation) - return flags.PostCommands(cmd)[0] + return cmd } func NewRedelegateCmd(ctx context.CLIContext) *cobra.Command { @@ -227,7 +227,7 @@ $ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj }, } - return flags.PostCommands(cmd)[0] + return cmd } func NewUnbondCmd(ctx context.CLIContext) *cobra.Command { @@ -267,7 +267,7 @@ $ %s tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100s }, } - return flags.PostCommands(cmd)[0] + return cmd } func NewBuildCreateValidatorMsg(cliCtx context.CLIContext, txf tx.Factory) (tx.Factory, sdk.Msg, error) { From 414ef2c82f00cfef9a7b1df724358a8e87151ade Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 11:01:09 -0400 Subject: [PATCH 26/48] Removing deprecated code --- client/context/context.go | 14 +- client/tx/tx.go | 6 +- simapp/cmd/simcli/main.go | 2 +- types/rest/rest.go | 8 +- x/bank/client/cli/tx.go | 65 -------- x/bank/client/rest/query.go | 4 +- x/bank/client/rest/tx.go | 2 +- x/bank/module.go | 12 -- x/crisis/client/cli/tx.go | 49 ------ x/crisis/module.go | 4 - x/distribution/client/cli/tx.go | 220 +-------------------------- x/distribution/client/rest/tx.go | 10 +- x/distribution/module.go | 8 - x/evidence/client/cli/tx.go | 2 +- x/evidence/module.go | 2 +- x/gov/client/cli/tx.go | 196 ------------------------ x/gov/module.go | 4 - x/params/client/cli/query.go | 2 +- x/params/client/cli/tx.go | 2 +- x/slashing/client/cli/tx.go | 57 ------- x/slashing/client/rest/rest.go | 2 +- x/slashing/client/rest/tx.go | 8 +- x/staking/client/cli/tx.go | 247 +------------------------------ x/staking/client/rest/rest.go | 2 +- x/staking/client/rest/tx.go | 14 +- x/upgrade/client/cli/tx.go | 19 +-- 26 files changed, 49 insertions(+), 912 deletions(-) diff --git a/client/context/context.go b/client/context/context.go index a7c0e56a01a1..87cd1a7154de 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -27,7 +27,7 @@ type CLIContext struct { FromAddress sdk.AccAddress Client rpcclient.Client ChainID string - Marshaler codec.JSONMarshaler + JSONMarshaler codec.JSONMarshaler Input io.Reader Keyring keyring.Keyring Output io.Writer @@ -187,9 +187,9 @@ func (ctx CLIContext) WithInput(r io.Reader) CLIContext { return ctx } -// WithMarshaler returns a copy of the CLIContext with an updated JSONMarshaler. -func (ctx CLIContext) WithMarshaler(m codec.JSONMarshaler) CLIContext { - ctx.Marshaler = m +// WithJSONMarshaler returns a copy of the CLIContext with an updated JSONMarshaler. +func (ctx CLIContext) WithJSONMarshaler(m codec.JSONMarshaler) CLIContext { + ctx.JSONMarshaler = m return ctx } @@ -307,7 +307,7 @@ func (ctx CLIContext) WithAccountRetriever(retriever AccountRetriever) CLIContex // Println outputs toPrint to the ctx.Output based on ctx.OutputFormat which is // either text or json. If text, toPrint will be YAML encoded. Otherwise, toPrint -// will be JSON encoded using ctx.Marshaler. An error is returned upon failure. +// will be JSON encoded using ctx.JSONMarshaler. An error is returned upon failure. func (ctx CLIContext) Println(toPrint interface{}) error { var ( out []byte @@ -319,11 +319,11 @@ func (ctx CLIContext) Println(toPrint interface{}) error { out, err = yaml.Marshal(&toPrint) case "json": - out, err = ctx.Marshaler.MarshalJSON(toPrint) + out, err = ctx.JSONMarshaler.MarshalJSON(toPrint) // To JSON indent, we re-encode the already encoded JSON given there is no // error. The re-encoded JSON uses the standard library as the initial encoded - // JSON should have the correct output produced by ctx.Marshaler. + // JSON should have the correct output produced by ctx.JSONMarshaler. if ctx.Indent && err == nil { out, err = codec.MarshalIndentFromJSON(out) } diff --git a/client/tx/tx.go b/client/tx/tx.go index 37d08e4ec1ea..b7548cda1058 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -92,7 +92,7 @@ func BroadcastTx(ctx context.CLIContext, txf Factory, msgs ...sdk.Msg) error { } if !ctx.SkipConfirm { - out, err := ctx.Marshaler.MarshalJSON(tx) + out, err := ctx.JSONMarshaler.MarshalJSON(tx) if err != nil { return err } @@ -162,7 +162,7 @@ func WriteGeneratedTxResponse( txf = txf.WithGas(adjusted) if br.Simulate { - rest.WriteSimulationResponse(w, ctx.Marshaler, txf.Gas()) + rest.WriteSimulationResponse(w, ctx.JSONMarshaler, txf.Gas()) return } } @@ -172,7 +172,7 @@ func WriteGeneratedTxResponse( return } - output, err := ctx.Marshaler.MarshalJSON(tx) + output, err := ctx.JSONMarshaler.MarshalJSON(tx) if rest.CheckInternalServerError(w, err) { return } diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index 1a4f8439dae2..a81c768d7e2a 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -120,7 +120,7 @@ func txCmd(cdc *codec.Codec) *cobra.Command { cliCtx := context.CLIContext{} cliCtx = cliCtx. - WithMarshaler(appCodec). + WithJSONMarshaler(appCodec). WithTxGenerator(types.StdTxGenerator{cdc}). WithAccountRetriever(types.NewAccountRetriever(appCodec)). WithCodec(cdc) diff --git a/types/rest/rest.go b/types/rest/rest.go index b730676a4471..8395c983c32e 100644 --- a/types/rest/rest.go +++ b/types/rest/rest.go @@ -264,8 +264,8 @@ func PostProcessResponseBare(w http.ResponseWriter, ctx context.CLIContext, body // ref: https://github.com/cosmos/cosmos-sdk/issues/5864 var marshaler codec.JSONMarshaler - if ctx.Marshaler != nil { - marshaler = ctx.Marshaler + if ctx.JSONMarshaler != nil { + marshaler = ctx.JSONMarshaler } else { marshaler = ctx.Codec } @@ -308,8 +308,8 @@ func PostProcessResponse(w http.ResponseWriter, ctx context.CLIContext, resp int // ref: https://github.com/cosmos/cosmos-sdk/issues/5864 var marshaler codec.JSONMarshaler - if ctx.Marshaler != nil { - marshaler = ctx.Marshaler + if ctx.JSONMarshaler != nil { + marshaler = ctx.JSONMarshaler } else { marshaler = ctx.Codec } diff --git a/x/bank/client/cli/tx.go b/x/bank/client/cli/tx.go index 19fb9e2d7bdb..f0ddf275e033 100644 --- a/x/bank/client/cli/tx.go +++ b/x/bank/client/cli/tx.go @@ -1,18 +1,13 @@ package cli import ( - "bufio" - "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth" - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/bank/types" ) @@ -61,63 +56,3 @@ func NewSendTxCmd(cliCtx context.CLIContext) *cobra.Command { return flags.PostCommands(cmd)[0] } - -// --------------------------------------------------------------------------- -// Deprecated -// -// TODO: Remove once client-side Protobuf migration has been completed. -// --------------------------------------------------------------------------- - -// GetTxCmd returns the transaction commands for this module -// -// TODO: Remove once client-side Protobuf migration has been completed. -// ref: https://github.com/cosmos/cosmos-sdk/issues/5864 -func GetTxCmd(cdc *codec.Codec) *cobra.Command { - txCmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Bank transaction subcommands", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - txCmd.AddCommand( - SendTxCmd(cdc), - ) - return txCmd -} - -// SendTxCmd will create a send tx and sign it with the given key. -// -// TODO: Remove once client-side Protobuf migration has been completed. -// ref: https://github.com/cosmos/cosmos-sdk/issues/5864 -func SendTxCmd(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "send [from_key_or_address] [to_address] [amount]", - Short: "Create and sign a send tx", - Args: cobra.ExactArgs(3), - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithCodec(cdc) - - to, err := sdk.AccAddressFromBech32(args[1]) - if err != nil { - return err - } - - // parse coins trying to be sent - coins, err := sdk.ParseCoins(args[2]) - if err != nil { - return err - } - - // build and sign the transaction, then broadcast to Tendermint - msg := types.NewMsgSend(cliCtx.GetFromAddress(), to, coins) - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } - - cmd = flags.PostCommands(cmd)[0] - - return cmd -} diff --git a/x/bank/client/rest/query.go b/x/bank/client/rest/query.go index ec6b39ad88b0..aec6ed7be528 100644 --- a/x/bank/client/rest/query.go +++ b/x/bank/client/rest/query.go @@ -41,8 +41,8 @@ func QueryBalancesRequestHandlerFn(ctx context.CLIContext) http.HandlerFunc { // ref: https://github.com/cosmos/cosmos-sdk/issues/5864 var marshaler codec.JSONMarshaler - if ctx.Marshaler != nil { - marshaler = ctx.Marshaler + if ctx.JSONMarshaler != nil { + marshaler = ctx.JSONMarshaler } else { marshaler = ctx.Codec } diff --git a/x/bank/client/rest/tx.go b/x/bank/client/rest/tx.go index bd96552f3568..60202c9aa4ab 100644 --- a/x/bank/client/rest/tx.go +++ b/x/bank/client/rest/tx.go @@ -32,7 +32,7 @@ func NewSendRequestHandlerFn(ctx context.CLIContext) http.HandlerFunc { } var req SendReq - if !rest.ReadRESTReq(w, r, ctx.Marshaler, &req) { + if !rest.ReadRESTReq(w, r, ctx.JSONMarshaler, &req) { return } diff --git a/x/bank/module.go b/x/bank/module.go index 2994bd4ed106..3aeec566e689 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -172,15 +172,3 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp simState.AppParams, simState.Cdc, am.accountKeeper, am.keeper, ) } - -func (am AppModuleBasic) NewTxCmd(ctx context.CLIContext) *cobra.Command { - return cli.NewTxCmd(ctx) -} - -func (am AppModuleBasic) NewQueryCmd(ctx context.CLIContext) *cobra.Command { - return nil -} - -func (am AppModuleBasic) NewRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { - rest.RegisterHandlers(ctx, rtr) -} diff --git a/x/crisis/client/cli/tx.go b/x/crisis/client/cli/tx.go index c728602f1d1d..2d6780a7cf21 100644 --- a/x/crisis/client/cli/tx.go +++ b/x/crisis/client/cli/tx.go @@ -1,18 +1,12 @@ package cli import ( - "bufio" - "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth" - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/crisis/types" ) @@ -55,46 +49,3 @@ func NewMsgVerifyInvariantTxCmd(ctx context.CLIContext) *cobra.Command { return flags.PostCommands(cmd)[0] } - -// --------------------------------------------------------------------------- -// Deprecated -// -// TODO: Remove once client-side Protobuf migration has been completed. -// --------------------------------------------------------------------------- - -// GetTxCmd returns the transaction commands for this module -func GetTxCmd(cdc *codec.Codec) *cobra.Command { - txCmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Crisis transactions subcommands", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - txCmd.AddCommand(flags.PostCommands( - GetCmdInvariantBroken(cdc), - )...) - return txCmd -} - -// command to replace a delegator's withdrawal address -func GetCmdInvariantBroken(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "invariant-broken [module-name] [invariant-route]", - Short: "submit proof that an invariant broken to halt the chain", - Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - senderAddr := cliCtx.GetFromAddress() - moduleName, route := args[0], args[1] - msg := types.NewMsgVerifyInvariant(senderAddr, moduleName, route) - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } - return cmd -} diff --git a/x/crisis/module.go b/x/crisis/module.go index 47b23dff9dcb..52393973faae 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -63,10 +63,6 @@ func (b AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { // GetQueryCmd returns no root query command for the crisis module. func (AppModuleBasic) GetQueryCmd(_ *codec.Codec) *cobra.Command { return nil } -func (b AppModuleBasic) NewQueryCmd(ctx context.CLIContext) *cobra.Command { return nil } - -func (b AppModuleBasic) NewRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {} - //____________________________________________________________________________ // AppModule implements an application module for the crisis module. diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 7bcbba09f7d2..b0e328d661ab 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -2,27 +2,21 @@ package cli import ( - "bufio" "fmt" "strings" - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/auth" - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" - "github.com/cosmos/cosmos-sdk/x/gov" - "github.com/cosmos/cosmos-sdk/x/distribution/client/common" "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/gov" ) var ( @@ -245,177 +239,6 @@ Where proposal.json contains: return cmd } -// --------------------------------------------------------------------------- -// Deprecated -// -// TODO: Remove once client-side Protobuf migration has been completed. -// --------------------------------------------------------------------------- -// GetTxCmd returns the transaction commands for this module -func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command { - distTxCmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Distribution transactions subcommands", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - distTxCmd.AddCommand(flags.PostCommands( - GetCmdWithdrawRewards(cdc), - GetCmdSetWithdrawAddr(cdc), - GetCmdWithdrawAllRewards(cdc, storeKey), - GetCmdFundCommunityPool(cdc), - )...) - - return distTxCmd -} - -type generateOrBroadcastFunc func(context.CLIContext, auth.TxBuilder, []sdk.Msg) error - -func splitAndApply( - generateOrBroadcast generateOrBroadcastFunc, - cliCtx context.CLIContext, - txBldr auth.TxBuilder, - msgs []sdk.Msg, - chunkSize int, -) error { - - if chunkSize == 0 { - return generateOrBroadcast(cliCtx, txBldr, msgs) - } - - // split messages into slices of length chunkSize - totalMessages := len(msgs) - for i := 0; i < len(msgs); i += chunkSize { - - sliceEnd := i + chunkSize - if sliceEnd > totalMessages { - sliceEnd = totalMessages - } - - msgChunk := msgs[i:sliceEnd] - if err := generateOrBroadcast(cliCtx, txBldr, msgChunk); err != nil { - return err - } - } - - return nil -} - -// command to withdraw rewards -func GetCmdWithdrawRewards(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "withdraw-rewards [validator-addr]", - Short: "Withdraw rewards from a given delegation address, and optionally withdraw validator commission if the delegation address given is a validator operator", - Long: strings.TrimSpace( - fmt.Sprintf(`Withdraw rewards from a given delegation address, -and optionally withdraw validator commission if the delegation address given is a validator operator. - -Example: -$ %s tx distribution withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj --from mykey -$ %s tx distribution withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj --from mykey --commission -`, - version.ClientName, version.ClientName, - ), - ), - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - delAddr := cliCtx.GetFromAddress() - valAddr, err := sdk.ValAddressFromBech32(args[0]) - if err != nil { - return err - } - - msgs := []sdk.Msg{types.NewMsgWithdrawDelegatorReward(delAddr, valAddr)} - if viper.GetBool(flagCommission) { - msgs = append(msgs, types.NewMsgWithdrawValidatorCommission(valAddr)) - } - - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, msgs) - }, - } - cmd.Flags().Bool(flagCommission, false, "also withdraw validator's commission") - return cmd -} - -// command to withdraw all rewards -func GetCmdWithdrawAllRewards(cdc *codec.Codec, queryRoute string) *cobra.Command { - cmd := &cobra.Command{ - Use: "withdraw-all-rewards", - Short: "withdraw all delegations rewards for a delegator", - Long: strings.TrimSpace( - fmt.Sprintf(`Withdraw all rewards for a single delegator. - -Example: -$ %s tx distribution withdraw-all-rewards --from mykey -`, - version.ClientName, - ), - ), - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - delAddr := cliCtx.GetFromAddress() - - // The transaction cannot be generated offline since it requires a query - // to get all the validators. - if cliCtx.Offline { - return fmt.Errorf("cannot generate tx in offline mode") - } - - msgs, err := common.WithdrawAllDelegatorRewards(cliCtx, queryRoute, delAddr) - if err != nil { - return err - } - - chunkSize := viper.GetInt(flagMaxMessagesPerTx) - return splitAndApply(authclient.GenerateOrBroadcastMsgs, cliCtx, txBldr, msgs, chunkSize) - }, - } - - cmd.Flags().Int(flagMaxMessagesPerTx, MaxMessagesPerTxDefault, "Limit the number of messages per tx (0 for unlimited)") - return cmd -} - -// command to replace a delegator's withdrawal address -func GetCmdSetWithdrawAddr(cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ - Use: "set-withdraw-addr [withdraw-addr]", - Short: "change the default withdraw address for rewards associated with an address", - Long: strings.TrimSpace( - fmt.Sprintf(`Set the withdraw address for rewards associated with a delegator address. - -Example: -$ %s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p --from mykey -`, - version.ClientName, - ), - ), - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - delAddr := cliCtx.GetFromAddress() - withdrawAddr, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - - msg := types.NewMsgSetWithdrawAddress(delAddr, withdrawAddr) - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } -} - // GetCmdSubmitProposal implements the command to submit a community-pool-spend proposal func GetCmdSubmitProposal(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ @@ -445,7 +268,7 @@ Where proposal.json contains: RunE: func(cmd *cobra.Command, args []string) error { cliCtx := ctx.InitWithInput(cmd.InOrStdin()) - proposal, err := ParseCommunityPoolSpendProposalJSON(ctx.Marshaler, args[0]) + proposal, err := ParseCommunityPoolSpendProposalJSON(ctx.JSONMarshaler, args[0]) if err != nil { return err } @@ -476,40 +299,3 @@ Where proposal.json contains: return cmd } - -// GetCmdFundCommunityPool returns a command implementation that supports directly -// funding the community pool. -func GetCmdFundCommunityPool(cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ - Use: "fund-community-pool [amount]", - Args: cobra.ExactArgs(1), - Short: "Funds the community pool with the specified amount", - Long: strings.TrimSpace( - fmt.Sprintf(`Funds the community pool with the specified amount - -Example: -$ %s tx distribution fund-community-pool 100uatom --from mykey -`, - version.ClientName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - depositorAddr := cliCtx.GetFromAddress() - amount, err := sdk.ParseCoins(args[0]) - if err != nil { - return err - } - - msg := types.NewMsgFundCommunityPool(amount, depositorAddr) - if err := msg.ValidateBasic(); err != nil { - return err - } - - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } -} diff --git a/x/distribution/client/rest/tx.go b/x/distribution/client/rest/tx.go index 7ffdc39ad4ad..0e67e92e3a94 100644 --- a/x/distribution/client/rest/tx.go +++ b/x/distribution/client/rest/tx.go @@ -65,7 +65,7 @@ func registerTxHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg contex func newWithdrawDelegatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithMarshaler(m) + cliCtx = cliCtx.WithJSONMarshaler(m) var req withdrawRewardsReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return @@ -93,7 +93,7 @@ func newWithdrawDelegatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Mar func newWithdrawDelegationRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithMarshaler(m) + cliCtx = cliCtx.WithJSONMarshaler(m) var req withdrawRewardsReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return @@ -126,7 +126,7 @@ func newWithdrawDelegationRewardsHandlerFn(cliCtx context.CLIContext, m codec.Ma func newSetDelegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithMarshaler(m) + cliCtx = cliCtx.WithJSONMarshaler(m) var req setWithdrawalAddrReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return @@ -154,7 +154,7 @@ func newSetDelegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, m codec.M func newWithdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithMarshaler(m) + cliCtx = cliCtx.WithJSONMarshaler(m) var req withdrawRewardsReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return @@ -183,7 +183,7 @@ func newWithdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Mar func newFundCommunityPoolHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithMarshaler(m) + cliCtx = cliCtx.WithJSONMarshaler(m) var req fundCommunityPoolReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return diff --git a/x/distribution/module.go b/x/distribution/module.go index d990fd98903c..aac9577c71ad 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -80,14 +80,6 @@ func (b AppModuleBasic) RegisterInterfaceTypes(registry cdctypes.InterfaceRegist types.RegisterInterfaces(registry) } -func (b AppModuleBasic) NewTxCmd(ctx context.CLIContext) *cobra.Command { - return cli.NewTxCmd(ctx) -} - -func (b AppModuleBasic) NewQueryCmd(ctx context.CLIContext) *cobra.Command { return nil } - -func (b AppModuleBasic) NewRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {} - //____________________________________________________________________________ // AppModule implements an application module for the distribution module. diff --git a/x/evidence/client/cli/tx.go b/x/evidence/client/cli/tx.go index 2912d0897db2..3ee0dcd963fd 100644 --- a/x/evidence/client/cli/tx.go +++ b/x/evidence/client/cli/tx.go @@ -14,7 +14,7 @@ import ( // modules, under a sub-command. This allows external modules to implement custom // Evidence types and Handlers while having the ability to create and sign txs // containing them all from a single root command. -func GetTxCmd(storeKey string, ctx context.CLIContext, childCmds []*cobra.Command) *cobra.Command { +func GetTxCmd(ctx context.CLIContext, childCmds []*cobra.Command) *cobra.Command { cmd := &cobra.Command{ Use: types.ModuleName, Short: "Evidence transaction subcommands", diff --git a/x/evidence/module.go b/x/evidence/module.go index 3a289f466a30..6e1380985c90 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -89,7 +89,7 @@ func (a AppModuleBasic) GetTxCmd(ctx context.CLIContext) *cobra.Command { evidenceCLIHandlers[i] = evidenceHandler.CLIHandler(ctx) } - return cli.GetTxCmd(StoreKey, ctx, evidenceCLIHandlers) + return cli.GetTxCmd(ctx, evidenceCLIHandlers) } // GetTxCmd returns the evidence module's root query command. diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 88fff9cb1566..d36fbff83922 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -1,24 +1,18 @@ package cli import ( - "bufio" "fmt" "strconv" "strings" - "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/auth" - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" govutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils" "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -240,194 +234,4 @@ $ %s tx gov vote 1 yes --from mykey } } -// GetTxCmd returns the transaction commands for this module -// governance ModuleClient is slightly different from other ModuleClients in that -// it contains a slice of "proposal" child commands. These commands are respective -// to proposal type handlers that are implemented in other modules but are mounted -// under the governance CLI (eg. parameter change proposals). -func GetTxCmd(storeKey string, cdc *codec.Codec, pcmds []*cobra.Command) *cobra.Command { - govTxCmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Governance transactions subcommands", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmdSubmitProp := GetCmdSubmitProposal(cdc) - for _, pcmd := range pcmds { - cmdSubmitProp.AddCommand(flags.PostCommands(pcmd)[0]) - } - - govTxCmd.AddCommand(flags.PostCommands( - GetCmdDeposit(cdc), - GetCmdVote(cdc), - cmdSubmitProp, - )...) - - return govTxCmd -} - -// GetCmdSubmitProposal implements submitting a proposal transaction command. -func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "submit-proposal", - Short: "Submit a proposal along with an initial deposit", - Long: strings.TrimSpace( - fmt.Sprintf(`Submit a proposal along with an initial deposit. -Proposal title, description, type and deposit can be given directly or through a proposal JSON file. - -Example: -$ %s tx gov submit-proposal --proposal="path/to/proposal.json" --from mykey - -Where proposal.json contains: - -{ - "title": "Test Proposal", - "description": "My awesome proposal", - "type": "Text", - "deposit": "10test" -} - -Which is equivalent to: - -$ %s tx gov submit-proposal --title="Test Proposal" --description="My awesome proposal" --type="Text" --deposit="10test" --from mykey -`, - version.ClientName, version.ClientName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - proposal, err := parseSubmitProposalFlags() - if err != nil { - return err - } - - amount, err := sdk.ParseCoins(proposal.Deposit) - if err != nil { - return err - } - - content := types.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type) - - msg, err := types.NewMsgSubmitProposal(content, amount, cliCtx.GetFromAddress()) - if err != nil { - return errors.Wrap(err, "can't create new MsgSubmitProposal") - } - if err := msg.ValidateBasic(); err != nil { - return err - } - - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } - - cmd.Flags().String(FlagTitle, "", "title of proposal") - cmd.Flags().String(FlagDescription, "", "description of proposal") - cmd.Flags().String(flagProposalType, "", "proposalType of proposal, types: text/parameter_change/software_upgrade") - cmd.Flags().String(FlagDeposit, "", "deposit of proposal") - cmd.Flags().String(FlagProposal, "", "proposal file path (if this path is given, other proposal flags are ignored)") - - return cmd -} - -// GetCmdDeposit implements depositing tokens for an active proposal. -func GetCmdDeposit(cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ - Use: "deposit [proposal-id] [deposit]", - Args: cobra.ExactArgs(2), - Short: "Deposit tokens for an active proposal", - Long: strings.TrimSpace( - fmt.Sprintf(`Submit a deposit for an active proposal. You can -find the proposal-id by running "%s query gov proposals". - -Example: -$ %s tx gov deposit 1 10stake --from mykey -`, - version.ClientName, version.ClientName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - // validate that the proposal id is a uint - proposalID, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return fmt.Errorf("proposal-id %s not a valid uint, please input a valid proposal-id", args[0]) - } - - // Get depositor address - from := cliCtx.GetFromAddress() - - // Get amount of coins - amount, err := sdk.ParseCoins(args[1]) - if err != nil { - return err - } - - msg := types.NewMsgDeposit(from, proposalID, amount) - err = msg.ValidateBasic() - if err != nil { - return err - } - - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } -} - -// GetCmdVote implements creating a new vote command. -func GetCmdVote(cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ - Use: "vote [proposal-id] [option]", - Args: cobra.ExactArgs(2), - Short: "Vote for an active proposal, options: yes/no/no_with_veto/abstain", - Long: strings.TrimSpace( - fmt.Sprintf(`Submit a vote for an active proposal. You can -find the proposal-id by running "%s query gov proposals". - - -Example: -$ %s tx gov vote 1 yes --from mykey -`, - version.ClientName, version.ClientName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - // Get voting address - from := cliCtx.GetFromAddress() - - // validate that the proposal id is a uint - proposalID, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return fmt.Errorf("proposal-id %s not a valid int, please input a valid proposal-id", args[0]) - } - - // Find out which vote option user chose - byteVoteOption, err := types.VoteOptionFromString(govutils.NormalizeVoteOption(args[1])) - if err != nil { - return err - } - - // Build vote message and run basic validation - msg := types.NewMsgVote(from, proposalID, byteVoteOption) - err = msg.ValidateBasic() - if err != nil { - return err - } - - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } -} - // DONTCOVER diff --git a/x/gov/module.go b/x/gov/module.go index 1b52ff4848b4..27b667b76c63 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -101,10 +101,6 @@ func (a AppModuleBasic) RegisterInterfaceTypes(registry codectypes.InterfaceRegi types.RegisterInterfaces(registry) } -func (a AppModuleBasic) NewQueryCmd(ctx context.CLIContext) *cobra.Command { return nil } - -func (a AppModuleBasic) NewRESTRoutes(ctx context.CLIContext, rtr *mux.Router) {} - //____________________________________________________________________________ // AppModule implements an application module for the gov module. diff --git a/x/params/client/cli/query.go b/x/params/client/cli/query.go index 39a7390d04dc..2c98f8638761 100644 --- a/x/params/client/cli/query.go +++ b/x/params/client/cli/query.go @@ -35,7 +35,7 @@ func NewQuerySubspaceParamsCmd(m codec.Marshaler) *cobra.Command { Short: "Query for raw parameters by subspace and key", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - cliCtx := context.NewCLIContext().WithMarshaler(m) + cliCtx := context.NewCLIContext().WithJSONMarshaler(m) params := types.NewQuerySubspaceParams(args[0], args[1]) route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParams) diff --git a/x/params/client/cli/tx.go b/x/params/client/cli/tx.go index b14df343efe0..a02ca0b3162b 100644 --- a/x/params/client/cli/tx.go +++ b/x/params/client/cli/tx.go @@ -59,7 +59,7 @@ Where proposal.json contains: RunE: func(cmd *cobra.Command, args []string) error { cliCtx := ctx.InitWithInput(cmd.InOrStdin()) - proposal, err := paramscutils.ParseParamChangeProposalJSON(ctx.Marshaler, args[0]) + proposal, err := paramscutils.ParseParamChangeProposalJSON(ctx.JSONMarshaler, args[0]) if err != nil { return err } diff --git a/x/slashing/client/cli/tx.go b/x/slashing/client/cli/tx.go index 1f0d7aa9f2d6..3cae546e0907 100644 --- a/x/slashing/client/cli/tx.go +++ b/x/slashing/client/cli/tx.go @@ -1,18 +1,13 @@ package cli import ( - "bufio" - "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth" - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/slashing/types" ) @@ -53,55 +48,3 @@ $ tx slashing unjail --from mykey } return flags.PostCommands(cmd)[0] } - -// --------------------------------------------------------------------------- -// Deprecated -// -// TODO: Remove once client-side Protobuf migration has been completed. -// --------------------------------------------------------------------------- - -// GetTxCmd returns the transaction commands for this module -// -// TODO: Remove once client-side Protobuf migration has been completed. -// ref: https://github.com/cosmos/cosmos-sdk/issues/5864 -func GetTxCmd(cdc *codec.Codec) *cobra.Command { - slashingTxCmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Slashing transactions subcommands", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - slashingTxCmd.AddCommand(flags.PostCommands( - GetCmdUnjail(cdc), - )...) - - return slashingTxCmd -} - -// GetCmdUnjail implements the create unjail validator command. -// -// TODO: Remove once client-side Protobuf migration has been completed. -// ref: https://github.com/cosmos/cosmos-sdk/issues/5864 -func GetCmdUnjail(cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ - Use: "unjail", - Args: cobra.NoArgs, - Short: "unjail validator previously jailed for downtime", - Long: `unjail a jailed validator: - -$ tx slashing unjail --from mykey -`, - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - valAddr := cliCtx.GetFromAddress() - - msg := types.NewMsgUnjail(sdk.ValAddress(valAddr)) - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } -} diff --git a/x/slashing/client/rest/rest.go b/x/slashing/client/rest/rest.go index 716ac12904a7..fc09a013b813 100644 --- a/x/slashing/client/rest/rest.go +++ b/x/slashing/client/rest/rest.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) -func RegisterHandlers(ctx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { +func RegisterHandlers(ctx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator, r *mux.Router) { registerQueryRoutes(ctx, r) registerTxHandlers(ctx, m, txg, r) } diff --git a/x/slashing/client/rest/tx.go b/x/slashing/client/rest/tx.go index 6641adcb786c..d5146eec3175 100644 --- a/x/slashing/client/rest/tx.go +++ b/x/slashing/client/rest/tx.go @@ -15,7 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/slashing/types" ) -func registerTxHandlers(ctx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { +func registerTxHandlers(ctx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator, r *mux.Router) { r.HandleFunc("/slashing/validators/{validatorAddr}/unjail", NewUnjailRequestHandlerFn(ctx, m, txg)).Methods("POST") } @@ -26,14 +26,14 @@ type UnjailReq struct { // NewUnjailRequestHandlerFn returns an HTTP REST handler for creating a MsgUnjail // transaction. -func NewUnjailRequestHandlerFn(ctx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { +func NewUnjailRequestHandlerFn(ctx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - ctx = ctx.WithMarshaler(m) + ctx = ctx.WithJSONMarshaler(m) vars := mux.Vars(r) bech32Validator := vars["validatorAddr"] var req UnjailReq - if !rest.ReadRESTReq(w, r, ctx.Marshaler, &req) { + if !rest.ReadRESTReq(w, r, ctx.JSONMarshaler, &req) { return } diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index 6d40dc96173b..c3c9c4b6e5e1 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -1,11 +1,12 @@ package cli import ( - "bufio" "fmt" "os" "strings" + "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/spf13/cobra" flag "github.com/spf13/pflag" "github.com/spf13/viper" @@ -17,11 +18,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/auth" - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -409,247 +407,6 @@ func PrepareFlagsForTxCreateValidator( } } -// --------------------------------------------------------------------------- -// Deprecated -// -// TODO: Remove once client-side Protobuf migration has been completed. -// --------------------------------------------------------------------------- - -// GetTxCmd returns the transaction commands for this module -// -// TODO: Remove once client-side Protobuf migration has been completed. -// ref: https://github.com/cosmos/cosmos-sdk/issues/5864 -// GetTxCmd returns the transaction commands for this module -func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command { - stakingTxCmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Staking transaction subcommands", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - stakingTxCmd.AddCommand(flags.PostCommands( - GetCmdCreateValidator(cdc), - GetCmdEditValidator(cdc), - GetCmdDelegate(cdc), - GetCmdRedelegate(storeKey, cdc), - GetCmdUnbond(storeKey, cdc), - )...) - - return stakingTxCmd -} - -// GetCmdCreateValidator implements the create validator command handler. -func GetCmdCreateValidator(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "create-validator", - Short: "create new validator initialized with a self-delegation to it", - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - txBldr, msg, err := BuildCreateValidatorMsg(cliCtx, txBldr) - if err != nil { - return err - } - - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } - - cmd.Flags().AddFlagSet(FsPk) - cmd.Flags().AddFlagSet(FsAmount) - cmd.Flags().AddFlagSet(fsDescriptionCreate) - cmd.Flags().AddFlagSet(FsCommissionCreate) - cmd.Flags().AddFlagSet(FsMinSelfDelegation) - - cmd.Flags().String(FlagIP, "", fmt.Sprintf("The node's public IP. It takes effect only when used in combination with --%s", flags.FlagGenerateOnly)) - cmd.Flags().String(FlagNodeID, "", "The node's ID") - - _ = cmd.MarkFlagRequired(flags.FlagFrom) - _ = cmd.MarkFlagRequired(FlagAmount) - _ = cmd.MarkFlagRequired(FlagPubKey) - _ = cmd.MarkFlagRequired(FlagMoniker) - - return cmd -} - -// GetCmdEditValidator implements the create edit validator command. -// TODO: add full description -func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "edit-validator", - Short: "edit an existing validator account", - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(auth.DefaultTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - valAddr := cliCtx.GetFromAddress() - description := types.NewDescription( - viper.GetString(FlagMoniker), - viper.GetString(FlagIdentity), - viper.GetString(FlagWebsite), - viper.GetString(FlagSecurityContact), - viper.GetString(FlagDetails), - ) - - var newRate *sdk.Dec - - commissionRate := viper.GetString(FlagCommissionRate) - if commissionRate != "" { - rate, err := sdk.NewDecFromStr(commissionRate) - if err != nil { - return fmt.Errorf("invalid new commission rate: %v", err) - } - - newRate = &rate - } - - var newMinSelfDelegation *sdk.Int - - minSelfDelegationString := viper.GetString(FlagMinSelfDelegation) - if minSelfDelegationString != "" { - msb, ok := sdk.NewIntFromString(minSelfDelegationString) - if !ok { - return types.ErrMinSelfDelegationInvalid - } - - newMinSelfDelegation = &msb - } - - msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description, newRate, newMinSelfDelegation) - - // build and sign the transaction, then broadcast to Tendermint - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } - - cmd.Flags().AddFlagSet(fsDescriptionEdit) - cmd.Flags().AddFlagSet(fsCommissionUpdate) - cmd.Flags().AddFlagSet(FsMinSelfDelegation) - - return cmd -} - -// GetCmdDelegate implements the delegate command. -func GetCmdDelegate(cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ - Use: "delegate [validator-addr] [amount]", - Args: cobra.ExactArgs(2), - Short: "Delegate liquid tokens to a validator", - Long: strings.TrimSpace( - fmt.Sprintf(`Delegate an amount of liquid coins to a validator from your wallet. - -Example: -$ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 1000stake --from mykey -`, - version.ClientName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(auth.DefaultTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - amount, err := sdk.ParseCoin(args[1]) - if err != nil { - return err - } - - delAddr := cliCtx.GetFromAddress() - valAddr, err := sdk.ValAddressFromBech32(args[0]) - if err != nil { - return err - } - - msg := types.NewMsgDelegate(delAddr, valAddr, amount) - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } -} - -// GetCmdRedelegate the begin redelegation command. -func GetCmdRedelegate(storeName string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ - Use: "redelegate [src-validator-addr] [dst-validator-addr] [amount]", - Short: "Redelegate illiquid tokens from one validator to another", - Args: cobra.ExactArgs(3), - Long: strings.TrimSpace( - fmt.Sprintf(`Redelegate an amount of illiquid staking tokens from one validator to another. - -Example: -$ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 100stake --from mykey -`, - version.ClientName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(auth.DefaultTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - delAddr := cliCtx.GetFromAddress() - valSrcAddr, err := sdk.ValAddressFromBech32(args[0]) - if err != nil { - return err - } - - valDstAddr, err := sdk.ValAddressFromBech32(args[1]) - if err != nil { - return err - } - - amount, err := sdk.ParseCoin(args[2]) - if err != nil { - return err - } - - msg := types.NewMsgBeginRedelegate(delAddr, valSrcAddr, valDstAddr, amount) - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } -} - -// GetCmdUnbond implements the unbond validator command. -func GetCmdUnbond(storeName string, cdc *codec.Codec) *cobra.Command { - return &cobra.Command{ - Use: "unbond [validator-addr] [amount]", - Short: "Unbond shares from a validator", - Args: cobra.ExactArgs(2), - Long: strings.TrimSpace( - fmt.Sprintf(`Unbond an amount of bonded shares from a validator. - -Example: -$ %s tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100stake --from mykey -`, - version.ClientName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(auth.DefaultTxEncoder(cdc)) - cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc) - - delAddr := cliCtx.GetFromAddress() - valAddr, err := sdk.ValAddressFromBech32(args[0]) - if err != nil { - return err - } - - amount, err := sdk.ParseCoin(args[1]) - if err != nil { - return err - } - - msg := types.NewMsgUndelegate(delAddr, valAddr, amount) - return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) - }, - } -} - // BuildCreateValidatorMsg makes a new MsgCreateValidator. func BuildCreateValidatorMsg(cliCtx context.CLIContext, txBldr auth.TxBuilder) (auth.TxBuilder, sdk.Msg, error) { amounstStr := viper.GetString(FlagAmount) diff --git a/x/staking/client/rest/rest.go b/x/staking/client/rest/rest.go index b7e61c1ec6dd..f58ed0d9626d 100644 --- a/x/staking/client/rest/rest.go +++ b/x/staking/client/rest/rest.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) -func RegisterHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { +func RegisterHandlers(cliCtx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator, r *mux.Router) { registerQueryRoutes(cliCtx, r) registerTxHandlers(cliCtx, m, txg, r) } diff --git a/x/staking/client/rest/tx.go b/x/staking/client/rest/tx.go index c540eb7f2141..6eda2925410c 100644 --- a/x/staking/client/rest/tx.go +++ b/x/staking/client/rest/tx.go @@ -15,7 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" ) -func registerTxHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { +func registerTxHandlers(cliCtx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator, r *mux.Router) { r.HandleFunc( "/staking/delegators/{delegatorAddr}/delegations", newPostDelegationsHandlerFn(cliCtx, m, txg), @@ -57,9 +57,9 @@ type ( } ) -func newPostDelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { +func newPostDelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithMarshaler(m) + cliCtx = cliCtx.WithJSONMarshaler(m) var req DelegateRequest if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { @@ -90,9 +90,9 @@ func newPostDelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, t } } -func newPostRedelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { +func newPostRedelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithMarshaler(m) + cliCtx = cliCtx.WithJSONMarshaler(m) var req RedelegateRequest if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { @@ -123,9 +123,9 @@ func newPostRedelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, } } -func newPostUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { +func newPostUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithMarshaler(m) + cliCtx = cliCtx.WithJSONMarshaler(m) var req UndelegateRequest if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { diff --git a/x/upgrade/client/cli/tx.go b/x/upgrade/client/cli/tx.go index 5f0da3ce84f7..218399ce8bdc 100644 --- a/x/upgrade/client/cli/tx.go +++ b/x/upgrade/client/cli/tx.go @@ -1,7 +1,6 @@ package cli import ( - "bufio" "fmt" "time" @@ -13,7 +12,6 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -80,20 +78,14 @@ func NewCmdSubmitUpgradeProposal(ctx context.CLIContext) *cobra.Command { } // NewCmdSubmitCancelUpgradeProposal implements a command handler for submitting a software upgrade cancel proposal transaction. -func NewCmdSubmitCancelUpgradeProposal( - m codec.Marshaler, - txg context.TxGenerator, - ar context.AccountRetriever, - newMsgFn func() gov.MsgSubmitProposalI) *cobra.Command { +func NewCmdSubmitCancelUpgradeProposal(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "cancel-software-upgrade [flags]", Args: cobra.ExactArgs(0), Short: "Submit a software upgrade proposal", Long: "Cancel a software upgrade along with an initial deposit.", RunE: func(cmd *cobra.Command, args []string) error { - inBuf := bufio.NewReader(cmd.InOrStdin()) - cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m) - txf := tx.NewFactoryFromCLI(inBuf).WithTxGenerator(txg).WithAccountRetriever(ar) + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) from := cliCtx.GetFromAddress() depositStr, err := cmd.Flags().GetString(cli.FlagDeposit) @@ -118,19 +110,16 @@ func NewCmdSubmitCancelUpgradeProposal( content := types.NewCancelSoftwareUpgradeProposal(title, description) - msg := newMsgFn() - err = msg.SetContent(content) + msg, err := gov.NewMsgSubmitProposal(content, deposit, from) if err != nil { return err } - msg.SetInitialDeposit(deposit) - msg.SetProposer(from) if err = msg.ValidateBasic(); err != nil { return err } - return tx.GenerateOrBroadcastTxWithFactory(cliCtx, txf, msg) + return tx.GenerateOrBroadcastTx(cliCtx, msg) }, } From 50c1044062a36ffe2d8e9ad871e02c3b8b03d714 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 11:22:00 -0400 Subject: [PATCH 27/48] Update ADR 020 & CHANGELOG --- CHANGELOG.md | 1 + client/context/context.go | 16 +++++--- .../adr-020-protobuf-transaction-encoding.md | 41 ++++++++++++++----- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6384005aca8a..b8d615e6b3ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,7 @@ ALL legacy code should use `*codec.Codec` instead of `*amino.Codec` directly * (x/gov) [\#6147](https://github.com/cosmos/cosmos-sdk/pull/6147) The `Content` field on `Proposal` and `MsgSubmitProposal` is now `Any` in concordance with [ADR 019](docs/architecture/adr-019-protobuf-state-encoding.md) and `GetContent` should now be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposal` constructor now may return an `error` +* (x/auth) `AccountRetriever` methods now takes `NodeQuerier` as a parameter instead of as a struct member ### Features diff --git a/client/context/context.go b/client/context/context.go index 87cd1a7154de..8a7d7bbf7f56 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -163,18 +163,22 @@ func (ctx CLIContext) InitWithInputAndFrom(input io.Reader, from string) CLICont return ctx } +// InitWithFrom returns a new CLIContext re-initialized from an existing +// CLIContext with a new from parameter +func (ctx CLIContext) InitWithFrom(from string) CLIContext { + return ctx.InitWithInputAndFrom(os.Stdin, from) +} + +// Init returns a new CLIContext re-initialized from an existing +// CLIContext with parameters from the command line using Viper. +func (ctx CLIContext) Init() CLIContext { return ctx.InitWithFrom(viper.GetString(flags.FlagFrom)) } + // InitWithInput returns a new CLIContext re-initialized from an existing // CLIContext with a new io.Reader and from parameter func (ctx CLIContext) InitWithInput(input io.Reader) CLIContext { return ctx.InitWithInputAndFrom(input, viper.GetString(flags.FlagFrom)) } -// InitWithInput returns a new CLIContext re-initialized from an existing -// CLIContext with a new from parameter -func (ctx CLIContext) InitWithFrom(from string) CLIContext { - return ctx.InitWithInputAndFrom(os.Stdin, from) -} - // WithKeyring returns a copy of the context with an updated keyring. func (ctx CLIContext) WithKeyring(k keyring.Keyring) CLIContext { ctx.Keyring = k diff --git a/docs/architecture/adr-020-protobuf-transaction-encoding.md b/docs/architecture/adr-020-protobuf-transaction-encoding.md index 98670b02693c..e844fc0a74b2 100644 --- a/docs/architecture/adr-020-protobuf-transaction-encoding.md +++ b/docs/architecture/adr-020-protobuf-transaction-encoding.md @@ -297,17 +297,19 @@ and messages. ```go type AccountRetriever interface { - EnsureExists(addr sdk.AccAddress) error - GetAccountNumberSequence(addr sdk.AccAddress) (uint64, uint64, error) + EnsureExists(querier NodeQuerier, addr sdk.AccAddress) error + GetAccountNumberSequence(querier NodeQuerier, addr sdk.AccAddress) (uint64, uint64, error) } type Generator interface { - NewTx() ClientTx + NewTx() TxBuilder + NewFee() ClientFee + NewSignature() ClientSignature + MarshalTx(tx types.Tx) ([]byte, error) } -type ClientTx interface { - sdk.Tx - codec.ProtoMarshaler +type TxBuilder interface { + GetTx() sdk.Tx SetMsgs(...sdk.Msg) error GetSignatures() []sdk.Signature @@ -321,11 +323,30 @@ type ClientTx interface { } ``` -We then update `CLIContext` to have a new field: `Marshaler`. +We then update `CLIContext` to have new fields: `JSONMarshaler`, `TxGenerator`, +and `AccountRetriever`, and we update `AppModuleBasic.GetTxCmd` to take +a `CLIContext` which should have all of these fields pre-populated. -Then, each module's client handler will at the minimum accept a `Marshaler` instead -of a concrete Amino codec and a `Generator` along with an `AccountRetriever` so -that account fields can be retrieved for signing. +Each client method should then use one of the `Init` methods to re-initialize +the pre-populated `CLIContext`. `tx.GenerateOrBroadcastTx` can then be used to +generate or broadcast a transaction. For example: + +```go +import "github.com/spf13/cobra" +import "github.com/cosmos/cosmos-sdk/client/tx" +import "github.com/cosmos/cosmos-sdk/client/context" + +func NewCmdDoSomething(ctx context.CLIContext) *cobra.Command { + return &cobra.Command{ + ... + RunE: func(cmd *cobra.Command, args []string) error { + cliCtx := ctx.InitWithInput(cmd.InOrStdin()) + ... + return tx.GenerateOrBroadcastTx(cliCtx, msg) + }, + } +} +``` ## Future Improvements From b47fdc1e70767181787403752999d08e52cda8c1 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 11:24:38 -0400 Subject: [PATCH 28/48] Lint --- docs/architecture/adr-020-protobuf-transaction-encoding.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/architecture/adr-020-protobuf-transaction-encoding.md b/docs/architecture/adr-020-protobuf-transaction-encoding.md index e844fc0a74b2..a50dce281937 100644 --- a/docs/architecture/adr-020-protobuf-transaction-encoding.md +++ b/docs/architecture/adr-020-protobuf-transaction-encoding.md @@ -334,7 +334,7 @@ generate or broadcast a transaction. For example: ```go import "github.com/spf13/cobra" import "github.com/cosmos/cosmos-sdk/client/tx" -import "github.com/cosmos/cosmos-sdk/client/context" +import "github.com/cosmos/cosmos-sdk/client/context" func NewCmdDoSomething(ctx context.CLIContext) *cobra.Command { return &cobra.Command{ From aa16184dde9a978d7f6699880bdc44791bd875ec Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 11:24:51 -0400 Subject: [PATCH 29/48] Lint --- docs/architecture/adr-020-protobuf-transaction-encoding.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/architecture/adr-020-protobuf-transaction-encoding.md b/docs/architecture/adr-020-protobuf-transaction-encoding.md index a50dce281937..4841d5609616 100644 --- a/docs/architecture/adr-020-protobuf-transaction-encoding.md +++ b/docs/architecture/adr-020-protobuf-transaction-encoding.md @@ -328,7 +328,7 @@ and `AccountRetriever`, and we update `AppModuleBasic.GetTxCmd` to take a `CLIContext` which should have all of these fields pre-populated. Each client method should then use one of the `Init` methods to re-initialize -the pre-populated `CLIContext`. `tx.GenerateOrBroadcastTx` can then be used to +the pre-populated `CLIContext`. `tx.GenerateOrBroadcastTx` can be used to generate or broadcast a transaction. For example: ```go From 3d24b15eae7a681887b334760490f1594199793a Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 11:26:09 -0400 Subject: [PATCH 30/48] Lint --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8d615e6b3ec..6b582419f2ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,7 +102,7 @@ ALL legacy code should use `*codec.Codec` instead of `*amino.Codec` directly * (x/gov) [\#6147](https://github.com/cosmos/cosmos-sdk/pull/6147) The `Content` field on `Proposal` and `MsgSubmitProposal` is now `Any` in concordance with [ADR 019](docs/architecture/adr-019-protobuf-state-encoding.md) and `GetContent` should now be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposal` constructor now may return an `error` -* (x/auth) `AccountRetriever` methods now takes `NodeQuerier` as a parameter instead of as a struct member +* (x/auth) All `AccountRetriever` methods now take `NodeQuerier` as a parameter instead of as a struct member ### Features From 865bcd08ac4fd4515d88a155db60e3a667cfe71b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 11:27:02 -0400 Subject: [PATCH 31/48] Lint --- docs/architecture/adr-020-protobuf-transaction-encoding.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/architecture/adr-020-protobuf-transaction-encoding.md b/docs/architecture/adr-020-protobuf-transaction-encoding.md index 4841d5609616..ebb9e8435e3f 100644 --- a/docs/architecture/adr-020-protobuf-transaction-encoding.md +++ b/docs/architecture/adr-020-protobuf-transaction-encoding.md @@ -338,7 +338,6 @@ import "github.com/cosmos/cosmos-sdk/client/context" func NewCmdDoSomething(ctx context.CLIContext) *cobra.Command { return &cobra.Command{ - ... RunE: func(cmd *cobra.Command, args []string) error { cliCtx := ctx.InitWithInput(cmd.InOrStdin()) ... From b3f030da78833fdd9521cc4330d058b65f94c1de Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 11:28:24 -0400 Subject: [PATCH 32/48] Lint --- docs/architecture/adr-020-protobuf-transaction-encoding.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/architecture/adr-020-protobuf-transaction-encoding.md b/docs/architecture/adr-020-protobuf-transaction-encoding.md index ebb9e8435e3f..b33beefa863b 100644 --- a/docs/architecture/adr-020-protobuf-transaction-encoding.md +++ b/docs/architecture/adr-020-protobuf-transaction-encoding.md @@ -339,9 +339,9 @@ import "github.com/cosmos/cosmos-sdk/client/context" func NewCmdDoSomething(ctx context.CLIContext) *cobra.Command { return &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { - cliCtx := ctx.InitWithInput(cmd.InOrStdin()) - ... - return tx.GenerateOrBroadcastTx(cliCtx, msg) + ctx := ctx.InitWithInput(cmd.InOrStdin()) + // command logic... + tx.GenerateOrBroadcastTx(cliCtx, msg) }, } } From f952ed3aa57422234d2fbec92b08fe43a8b8e146 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 11:29:51 -0400 Subject: [PATCH 33/48] Lint --- docs/architecture/adr-020-protobuf-transaction-encoding.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/architecture/adr-020-protobuf-transaction-encoding.md b/docs/architecture/adr-020-protobuf-transaction-encoding.md index b33beefa863b..f6c7a22ebe0b 100644 --- a/docs/architecture/adr-020-protobuf-transaction-encoding.md +++ b/docs/architecture/adr-020-protobuf-transaction-encoding.md @@ -340,7 +340,7 @@ func NewCmdDoSomething(ctx context.CLIContext) *cobra.Command { return &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { ctx := ctx.InitWithInput(cmd.InOrStdin()) - // command logic... + msg := NewSomeMsg{...} tx.GenerateOrBroadcastTx(cliCtx, msg) }, } From 7dc136b7761a28f1f8b1a8de8dff5a5d9f13e494 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 11:32:07 -0400 Subject: [PATCH 34/48] Lint --- docs/architecture/adr-020-protobuf-transaction-encoding.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/architecture/adr-020-protobuf-transaction-encoding.md b/docs/architecture/adr-020-protobuf-transaction-encoding.md index f6c7a22ebe0b..811f557039de 100644 --- a/docs/architecture/adr-020-protobuf-transaction-encoding.md +++ b/docs/architecture/adr-020-protobuf-transaction-encoding.md @@ -340,8 +340,8 @@ func NewCmdDoSomething(ctx context.CLIContext) *cobra.Command { return &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { ctx := ctx.InitWithInput(cmd.InOrStdin()) - msg := NewSomeMsg{...} - tx.GenerateOrBroadcastTx(cliCtx, msg) + msg := NewSomeMsg{...} + tx.GenerateOrBroadcastTx(cliCtx, msg) }, } } From c19ba5bf0fb2b8a64f3c203b249c4f695c53fd41 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 11:52:06 -0400 Subject: [PATCH 35/48] Fix client/tx tests --- client/tx/tx_test.go | 19 +- std/codec.pb.go | 3721 ++++-------------------------------------- std/codec.proto | 8 - 3 files changed, 297 insertions(+), 3451 deletions(-) diff --git a/client/tx/tx_test.go b/client/tx/tx_test.go index ec9830a609c3..85f6973679ef 100644 --- a/client/tx/tx_test.go +++ b/client/tx/tx_test.go @@ -6,13 +6,20 @@ import ( "github.com/stretchr/testify/require" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/std" + "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/bank" ) +func NewTestTxGenerator() context.TxGenerator { + _, cdc := simapp.MakeCodecs() + return types.StdTxGenerator{Cdc: cdc} +} + func TestCalculateGas(t *testing.T) { makeQueryFunc := func(gasUsed uint64, wantErr bool) func(string, []byte) ([]byte, int64, error) { return func(string, []byte) ([]byte, int64, error) { @@ -52,7 +59,7 @@ func TestCalculateGas(t *testing.T) { for _, tc := range testCases { stc := tc - txf := tx.Factory{}.WithChainID("test-chain").WithTxGenerator(std.TxGenerator{}) + txf := tx.Factory{}.WithChainID("test-chain").WithTxGenerator(NewTestTxGenerator()) t.Run(stc.name, func(t *testing.T) { queryFunc := makeQueryFunc(stc.args.queryFuncGasUsed, stc.args.queryFuncWantErr) @@ -72,7 +79,7 @@ func TestCalculateGas(t *testing.T) { func TestBuildSimTx(t *testing.T) { txf := tx.Factory{}. - WithTxGenerator(std.TxGenerator{}). + WithTxGenerator(NewTestTxGenerator()). WithAccountNumber(50). WithSequence(23). WithFees("50stake"). @@ -83,15 +90,11 @@ func TestBuildSimTx(t *testing.T) { bz, err := tx.BuildSimTx(txf, msg) require.NoError(t, err) require.NotNil(t, bz) - - tx := &std.Transaction{} - require.NoError(t, tx.Unmarshal(bz)) - require.Equal(t, []sdk.Signature{sdk.Signature(std.StdSignature{})}, tx.GetSignatures()) } func TestBuildUnsignedTx(t *testing.T) { txf := tx.Factory{}. - WithTxGenerator(std.TxGenerator{}). + WithTxGenerator(NewTestTxGenerator()). WithAccountNumber(50). WithSequence(23). WithFees("50stake"). diff --git a/std/codec.pb.go b/std/codec.pb.go index 4b5f1c09329f..9c43d734d305 100644 --- a/std/codec.pb.go +++ b/std/codec.pb.go @@ -5,18 +5,9 @@ package std import ( fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - types8 "github.com/cosmos/cosmos-sdk/types" github_com_cosmos_cosmos_sdk_x_auth_exported "github.com/cosmos/cosmos-sdk/x/auth/exported" types "github.com/cosmos/cosmos-sdk/x/auth/types" types1 "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" - types2 "github.com/cosmos/cosmos-sdk/x/bank/types" - types3 "github.com/cosmos/cosmos-sdk/x/crisis/types" - types4 "github.com/cosmos/cosmos-sdk/x/distribution/types" - types5 "github.com/cosmos/cosmos-sdk/x/gov/types" - types6 "github.com/cosmos/cosmos-sdk/x/slashing/types" - types7 "github.com/cosmos/cosmos-sdk/x/staking/types" - _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" _ "github.com/regen-network/cosmos-proto" io "io" @@ -162,3340 +153,312 @@ func (*Account) XXX_OneofWrappers() []interface{} { } } -// Transaction defines the application-level transaction that can be signed and -// processed by the state-machine. It contains a base of common fields and -// repeated set of Message types. -type Transaction struct { - StdTxBase `protobuf:"bytes,1,opt,name=base,proto3,embedded=base" json:""` - Msgs []Message `protobuf:"bytes,2,rep,name=msgs,proto3" json:"msgs"` -} - -func (m *Transaction) Reset() { *m = Transaction{} } -func (m *Transaction) String() string { return proto.CompactTextString(m) } -func (*Transaction) ProtoMessage() {} -func (*Transaction) Descriptor() ([]byte, []int) { - return fileDescriptor_ff851c3a98ef46f7, []int{1} -} -func (m *Transaction) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Transaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Transaction.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Transaction) XXX_Merge(src proto.Message) { - xxx_messageInfo_Transaction.Merge(m, src) -} -func (m *Transaction) XXX_Size() int { - return m.Size() -} -func (m *Transaction) XXX_DiscardUnknown() { - xxx_messageInfo_Transaction.DiscardUnknown(m) -} - -var xxx_messageInfo_Transaction proto.InternalMessageInfo - -// Message defines the set of valid concrete message types that can be used to -// construct a transaction. -type Message struct { - // sum defines the set of all allowed valid messages defined in modules. - // - // Types that are valid to be assigned to Sum: - // *Message_MsgSend - // *Message_MsgMultiSend - // *Message_MsgVerifyInvariant - // *Message_MsgSetWithdrawAddress - // *Message_MsgWithdrawDelegatorReward - // *Message_MsgWithdrawValidatorCommission - // *Message_MsgFundCommunityPool - // *Message_MsgVote - // *Message_MsgDeposit - // *Message_MsgUnjail - // *Message_MsgCreateValidator - // *Message_MsgEditValidator - // *Message_MsgDelegate - // *Message_MsgBeginRedelegate - // *Message_MsgUndelegate - Sum isMessage_Sum `protobuf_oneof:"sum"` -} - -func (m *Message) Reset() { *m = Message{} } -func (m *Message) String() string { return proto.CompactTextString(m) } -func (*Message) ProtoMessage() {} -func (*Message) Descriptor() ([]byte, []int) { - return fileDescriptor_ff851c3a98ef46f7, []int{2} -} -func (m *Message) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Message.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Message) XXX_Merge(src proto.Message) { - xxx_messageInfo_Message.Merge(m, src) -} -func (m *Message) XXX_Size() int { - return m.Size() -} -func (m *Message) XXX_DiscardUnknown() { - xxx_messageInfo_Message.DiscardUnknown(m) -} - -var xxx_messageInfo_Message proto.InternalMessageInfo - -type isMessage_Sum interface { - isMessage_Sum() - MarshalTo([]byte) (int, error) - Size() int -} - -type Message_MsgSend struct { - MsgSend *types2.MsgSend `protobuf:"bytes,1,opt,name=msg_send,json=msgSend,proto3,oneof" json:"msg_send,omitempty"` -} -type Message_MsgMultiSend struct { - MsgMultiSend *types2.MsgMultiSend `protobuf:"bytes,2,opt,name=msg_multi_send,json=msgMultiSend,proto3,oneof" json:"msg_multi_send,omitempty"` -} -type Message_MsgVerifyInvariant struct { - MsgVerifyInvariant *types3.MsgVerifyInvariant `protobuf:"bytes,3,opt,name=msg_verify_invariant,json=msgVerifyInvariant,proto3,oneof" json:"msg_verify_invariant,omitempty"` -} -type Message_MsgSetWithdrawAddress struct { - MsgSetWithdrawAddress *types4.MsgSetWithdrawAddress `protobuf:"bytes,4,opt,name=msg_set_withdraw_address,json=msgSetWithdrawAddress,proto3,oneof" json:"msg_set_withdraw_address,omitempty"` -} -type Message_MsgWithdrawDelegatorReward struct { - MsgWithdrawDelegatorReward *types4.MsgWithdrawDelegatorReward `protobuf:"bytes,5,opt,name=msg_withdraw_delegator_reward,json=msgWithdrawDelegatorReward,proto3,oneof" json:"msg_withdraw_delegator_reward,omitempty"` -} -type Message_MsgWithdrawValidatorCommission struct { - MsgWithdrawValidatorCommission *types4.MsgWithdrawValidatorCommission `protobuf:"bytes,6,opt,name=msg_withdraw_validator_commission,json=msgWithdrawValidatorCommission,proto3,oneof" json:"msg_withdraw_validator_commission,omitempty"` -} -type Message_MsgFundCommunityPool struct { - MsgFundCommunityPool *types4.MsgFundCommunityPool `protobuf:"bytes,7,opt,name=msg_fund_community_pool,json=msgFundCommunityPool,proto3,oneof" json:"msg_fund_community_pool,omitempty"` -} -type Message_MsgVote struct { - MsgVote *types5.MsgVote `protobuf:"bytes,10,opt,name=msg_vote,json=msgVote,proto3,oneof" json:"msg_vote,omitempty"` -} -type Message_MsgDeposit struct { - MsgDeposit *types5.MsgDeposit `protobuf:"bytes,11,opt,name=msg_deposit,json=msgDeposit,proto3,oneof" json:"msg_deposit,omitempty"` -} -type Message_MsgUnjail struct { - MsgUnjail *types6.MsgUnjail `protobuf:"bytes,12,opt,name=msg_unjail,json=msgUnjail,proto3,oneof" json:"msg_unjail,omitempty"` -} -type Message_MsgCreateValidator struct { - MsgCreateValidator *types7.MsgCreateValidator `protobuf:"bytes,13,opt,name=msg_create_validator,json=msgCreateValidator,proto3,oneof" json:"msg_create_validator,omitempty"` -} -type Message_MsgEditValidator struct { - MsgEditValidator *types7.MsgEditValidator `protobuf:"bytes,14,opt,name=msg_edit_validator,json=msgEditValidator,proto3,oneof" json:"msg_edit_validator,omitempty"` -} -type Message_MsgDelegate struct { - MsgDelegate *types7.MsgDelegate `protobuf:"bytes,15,opt,name=msg_delegate,json=msgDelegate,proto3,oneof" json:"msg_delegate,omitempty"` -} -type Message_MsgBeginRedelegate struct { - MsgBeginRedelegate *types7.MsgBeginRedelegate `protobuf:"bytes,16,opt,name=msg_begin_redelegate,json=msgBeginRedelegate,proto3,oneof" json:"msg_begin_redelegate,omitempty"` -} -type Message_MsgUndelegate struct { - MsgUndelegate *types7.MsgUndelegate `protobuf:"bytes,17,opt,name=msg_undelegate,json=msgUndelegate,proto3,oneof" json:"msg_undelegate,omitempty"` -} - -func (*Message_MsgSend) isMessage_Sum() {} -func (*Message_MsgMultiSend) isMessage_Sum() {} -func (*Message_MsgVerifyInvariant) isMessage_Sum() {} -func (*Message_MsgSetWithdrawAddress) isMessage_Sum() {} -func (*Message_MsgWithdrawDelegatorReward) isMessage_Sum() {} -func (*Message_MsgWithdrawValidatorCommission) isMessage_Sum() {} -func (*Message_MsgFundCommunityPool) isMessage_Sum() {} -func (*Message_MsgVote) isMessage_Sum() {} -func (*Message_MsgDeposit) isMessage_Sum() {} -func (*Message_MsgUnjail) isMessage_Sum() {} -func (*Message_MsgCreateValidator) isMessage_Sum() {} -func (*Message_MsgEditValidator) isMessage_Sum() {} -func (*Message_MsgDelegate) isMessage_Sum() {} -func (*Message_MsgBeginRedelegate) isMessage_Sum() {} -func (*Message_MsgUndelegate) isMessage_Sum() {} - -func (m *Message) GetSum() isMessage_Sum { - if m != nil { - return m.Sum - } - return nil -} - -func (m *Message) GetMsgSend() *types2.MsgSend { - if x, ok := m.GetSum().(*Message_MsgSend); ok { - return x.MsgSend - } - return nil -} - -func (m *Message) GetMsgMultiSend() *types2.MsgMultiSend { - if x, ok := m.GetSum().(*Message_MsgMultiSend); ok { - return x.MsgMultiSend - } - return nil -} - -func (m *Message) GetMsgVerifyInvariant() *types3.MsgVerifyInvariant { - if x, ok := m.GetSum().(*Message_MsgVerifyInvariant); ok { - return x.MsgVerifyInvariant - } - return nil -} - -func (m *Message) GetMsgSetWithdrawAddress() *types4.MsgSetWithdrawAddress { - if x, ok := m.GetSum().(*Message_MsgSetWithdrawAddress); ok { - return x.MsgSetWithdrawAddress - } - return nil +func init() { + proto.RegisterType((*Account)(nil), "cosmos_sdk.std.v1.Account") } -func (m *Message) GetMsgWithdrawDelegatorReward() *types4.MsgWithdrawDelegatorReward { - if x, ok := m.GetSum().(*Message_MsgWithdrawDelegatorReward); ok { - return x.MsgWithdrawDelegatorReward - } - return nil -} +func init() { proto.RegisterFile("std/codec.proto", fileDescriptor_ff851c3a98ef46f7) } -func (m *Message) GetMsgWithdrawValidatorCommission() *types4.MsgWithdrawValidatorCommission { - if x, ok := m.GetSum().(*Message_MsgWithdrawValidatorCommission); ok { - return x.MsgWithdrawValidatorCommission - } - return nil +var fileDescriptor_ff851c3a98ef46f7 = []byte{ + // 379 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xcd, 0x4a, 0xeb, 0x40, + 0x14, 0xc7, 0x93, 0xdb, 0xf6, 0x5e, 0x98, 0xde, 0x7b, 0xc5, 0x80, 0x1a, 0xba, 0x08, 0x55, 0x37, + 0xa2, 0x74, 0x42, 0xad, 0x0a, 0x76, 0x67, 0x15, 0x71, 0xa1, 0x20, 0x2e, 0x5c, 0xb8, 0x09, 0xc9, + 0xcc, 0xd0, 0x86, 0x36, 0x99, 0x90, 0x99, 0x09, 0xed, 0x5b, 0xf8, 0x30, 0xae, 0x7c, 0x02, 0x71, + 0xd5, 0xa5, 0x4b, 0x69, 0x5f, 0x44, 0x3a, 0x33, 0x36, 0x85, 0xc4, 0x6e, 0x02, 0x67, 0xfe, 0x1f, + 0xbf, 0xc0, 0x39, 0x60, 0x83, 0x71, 0xec, 0x22, 0x8a, 0x09, 0x82, 0x49, 0x4a, 0x39, 0xb5, 0x36, + 0x11, 0x65, 0x11, 0x65, 0x1e, 0xc3, 0x43, 0xc8, 0x38, 0x86, 0x59, 0xbb, 0x71, 0xc4, 0x07, 0x61, + 0x8a, 0xbd, 0xc4, 0x4f, 0xf9, 0xc4, 0x95, 0x2e, 0x57, 0x99, 0x5a, 0xab, 0x83, 0xca, 0x37, 0xec, + 0xb1, 0xeb, 0x0b, 0x3e, 0x70, 0xf9, 0x24, 0x21, 0x4c, 0x7d, 0xb5, 0xd2, 0xd4, 0x4a, 0x46, 0x18, + 0x0f, 0xe3, 0x7e, 0xd1, 0xb1, 0xf7, 0x5a, 0x05, 0x7f, 0x2e, 0x10, 0xa2, 0x22, 0xe6, 0xd6, 0x35, + 0xf8, 0x1b, 0xf8, 0x8c, 0x78, 0xbe, 0x9a, 0x6d, 0xb3, 0x69, 0x1e, 0xd4, 0x8f, 0x77, 0xe1, 0xca, + 0xef, 0x8d, 0xe1, 0xa2, 0x0f, 0x66, 0x6d, 0xd8, 0xf3, 0x19, 0xd1, 0xc1, 0x1b, 0xe3, 0xa1, 0x1e, + 0xe4, 0xa3, 0x95, 0x81, 0x06, 0xa2, 0x31, 0x0f, 0x63, 0x41, 0x05, 0xf3, 0x34, 0x7b, 0xd9, 0xfa, + 0x4b, 0xb6, 0x9e, 0x95, 0xb5, 0x2a, 0xe7, 0xa2, 0xfd, 0x72, 0x99, 0x7f, 0x54, 0x8f, 0x39, 0xca, + 0x46, 0x3f, 0x68, 0x56, 0x04, 0x76, 0x30, 0x19, 0xf9, 0x13, 0x82, 0x0b, 0xd0, 0x8a, 0x84, 0x76, + 0xd6, 0x43, 0xaf, 0x54, 0xb8, 0x40, 0xdc, 0xc2, 0x65, 0x82, 0x95, 0x00, 0x3b, 0x21, 0x69, 0x48, + 0x71, 0x88, 0x0a, 0xbc, 0xaa, 0xe4, 0x9d, 0xac, 0xe7, 0xdd, 0xeb, 0x74, 0x01, 0xb8, 0x9d, 0x94, + 0x2a, 0xd6, 0x2d, 0xf8, 0x1f, 0x51, 0x2c, 0x46, 0xf9, 0x8a, 0x6a, 0x92, 0xb3, 0x5f, 0xbe, 0xa2, + 0x3b, 0xe9, 0xcd, 0x6b, 0xff, 0x45, 0xab, 0x0f, 0xdd, 0xf3, 0xf7, 0x97, 0xd6, 0xe9, 0x61, 0x3f, + 0xe4, 0x03, 0x11, 0x40, 0x44, 0x23, 0x7d, 0x54, 0xdf, 0x87, 0xc6, 0xf0, 0xd0, 0xd5, 0xe7, 0x43, + 0xc6, 0x09, 0x4d, 0x39, 0xc1, 0x50, 0x47, 0x7b, 0x35, 0x50, 0x61, 0x22, 0xea, 0x75, 0xdf, 0x66, + 0x8e, 0x39, 0x9d, 0x39, 0xe6, 0xe7, 0xcc, 0x31, 0x9f, 0xe7, 0x8e, 0x31, 0x9d, 0x3b, 0xc6, 0xc7, + 0xdc, 0x31, 0x9e, 0x9a, 0x6b, 0x6b, 0x19, 0xc7, 0xc1, 0x6f, 0x79, 0x7f, 0x9d, 0xaf, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x7f, 0xbc, 0x05, 0x1d, 0x0e, 0x03, 0x00, 0x00, } -func (m *Message) GetMsgFundCommunityPool() *types4.MsgFundCommunityPool { - if x, ok := m.GetSum().(*Message_MsgFundCommunityPool); ok { - return x.MsgFundCommunityPool +func (this *Account) GetAccount() github_com_cosmos_cosmos_sdk_x_auth_exported.Account { + if x := this.GetBaseAccount(); x != nil { + return x } - return nil -} - -func (m *Message) GetMsgVote() *types5.MsgVote { - if x, ok := m.GetSum().(*Message_MsgVote); ok { - return x.MsgVote + if x := this.GetContinuousVestingAccount(); x != nil { + return x } - return nil -} - -func (m *Message) GetMsgDeposit() *types5.MsgDeposit { - if x, ok := m.GetSum().(*Message_MsgDeposit); ok { - return x.MsgDeposit + if x := this.GetDelayedVestingAccount(); x != nil { + return x } - return nil -} - -func (m *Message) GetMsgUnjail() *types6.MsgUnjail { - if x, ok := m.GetSum().(*Message_MsgUnjail); ok { - return x.MsgUnjail + if x := this.GetPeriodicVestingAccount(); x != nil { + return x } - return nil -} - -func (m *Message) GetMsgCreateValidator() *types7.MsgCreateValidator { - if x, ok := m.GetSum().(*Message_MsgCreateValidator); ok { - return x.MsgCreateValidator + if x := this.GetModuleAccount(); x != nil { + return x } return nil } -func (m *Message) GetMsgEditValidator() *types7.MsgEditValidator { - if x, ok := m.GetSum().(*Message_MsgEditValidator); ok { - return x.MsgEditValidator +func (this *Account) SetAccount(value github_com_cosmos_cosmos_sdk_x_auth_exported.Account) error { + if value == nil { + this.Sum = nil + return nil } - return nil -} - -func (m *Message) GetMsgDelegate() *types7.MsgDelegate { - if x, ok := m.GetSum().(*Message_MsgDelegate); ok { - return x.MsgDelegate + switch vt := value.(type) { + case *types.BaseAccount: + this.Sum = &Account_BaseAccount{vt} + return nil + case *types1.ContinuousVestingAccount: + this.Sum = &Account_ContinuousVestingAccount{vt} + return nil + case *types1.DelayedVestingAccount: + this.Sum = &Account_DelayedVestingAccount{vt} + return nil + case *types1.PeriodicVestingAccount: + this.Sum = &Account_PeriodicVestingAccount{vt} + return nil + case *types.ModuleAccount: + this.Sum = &Account_ModuleAccount{vt} + return nil } - return nil + return fmt.Errorf("can't encode value of type %T as message Account", value) } -func (m *Message) GetMsgBeginRedelegate() *types7.MsgBeginRedelegate { - if x, ok := m.GetSum().(*Message_MsgBeginRedelegate); ok { - return x.MsgBeginRedelegate +func (m *Account) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err } - return nil + return dAtA[:n], nil } -func (m *Message) GetMsgUndelegate() *types7.MsgUndelegate { - if x, ok := m.GetSum().(*Message_MsgUndelegate); ok { - return x.MsgUndelegate - } - return nil +func (m *Account) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -// XXX_OneofWrappers is for the internal use of the proto package. -func (*Message) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*Message_MsgSend)(nil), - (*Message_MsgMultiSend)(nil), - (*Message_MsgVerifyInvariant)(nil), - (*Message_MsgSetWithdrawAddress)(nil), - (*Message_MsgWithdrawDelegatorReward)(nil), - (*Message_MsgWithdrawValidatorCommission)(nil), - (*Message_MsgFundCommunityPool)(nil), - (*Message_MsgVote)(nil), - (*Message_MsgDeposit)(nil), - (*Message_MsgUnjail)(nil), - (*Message_MsgCreateValidator)(nil), - (*Message_MsgEditValidator)(nil), - (*Message_MsgDelegate)(nil), - (*Message_MsgBeginRedelegate)(nil), - (*Message_MsgUndelegate)(nil), +func (m *Account) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Sum != nil { + { + size := m.Sum.Size() + i -= size + if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } } + return len(dAtA) - i, nil } -// SignDoc defines a standard application-level signing document to compose -// signatures for a Transaction. -type SignDoc struct { - StdSignDocBase `protobuf:"bytes,1,opt,name=base,proto3,embedded=base" json:""` - Msgs []Message `protobuf:"bytes,2,rep,name=msgs,proto3" json:"msgs"` +func (m *Account_BaseAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *SignDoc) Reset() { *m = SignDoc{} } -func (m *SignDoc) String() string { return proto.CompactTextString(m) } -func (*SignDoc) ProtoMessage() {} -func (*SignDoc) Descriptor() ([]byte, []int) { - return fileDescriptor_ff851c3a98ef46f7, []int{3} -} -func (m *SignDoc) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *SignDoc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_SignDoc.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err +func (m *Account_BaseAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.BaseAccount != nil { + { + size, err := m.BaseAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) } - return b[:n], nil + i-- + dAtA[i] = 0xa } + return len(dAtA) - i, nil } -func (m *SignDoc) XXX_Merge(src proto.Message) { - xxx_messageInfo_SignDoc.Merge(m, src) -} -func (m *SignDoc) XXX_Size() int { - return m.Size() -} -func (m *SignDoc) XXX_DiscardUnknown() { - xxx_messageInfo_SignDoc.DiscardUnknown(m) +func (m *Account_ContinuousVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -var xxx_messageInfo_SignDoc proto.InternalMessageInfo - -func (m *SignDoc) GetMsgs() []Message { - if m != nil { - return m.Msgs +func (m *Account_ContinuousVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.ContinuousVestingAccount != nil { + { + size, err := m.ContinuousVestingAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 } - return nil + return len(dAtA) - i, nil } - -// StdFee includes the amount of coins paid in fees and the maximum -// gas to be used by the transaction. The ratio yields an effective "gasprice", -// which must be above some miminum to be accepted into the mempool. -type StdFee struct { - Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` - Gas uint64 `protobuf:"varint,2,opt,name=gas,proto3" json:"gas,omitempty"` +func (m *Account_DelayedVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *StdFee) Reset() { *m = StdFee{} } -func (m *StdFee) String() string { return proto.CompactTextString(m) } -func (*StdFee) ProtoMessage() {} -func (*StdFee) Descriptor() ([]byte, []int) { - return fileDescriptor_ff851c3a98ef46f7, []int{4} -} -func (m *StdFee) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *StdFee) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_StdFee.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err +func (m *Account_DelayedVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.DelayedVestingAccount != nil { + { + size, err := m.DelayedVestingAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) } - return b[:n], nil + i-- + dAtA[i] = 0x1a } + return len(dAtA) - i, nil } -func (m *StdFee) XXX_Merge(src proto.Message) { - xxx_messageInfo_StdFee.Merge(m, src) -} -func (m *StdFee) XXX_Size() int { - return m.Size() -} -func (m *StdFee) XXX_DiscardUnknown() { - xxx_messageInfo_StdFee.DiscardUnknown(m) -} - -var xxx_messageInfo_StdFee proto.InternalMessageInfo - -// StdSignature defines a signature structure that contains the signature of a -// transaction and an optional public key. -type StdSignature struct { - PubKey []byte `protobuf:"bytes,1,opt,name=pub_key,json=pubKey,proto3" json:"public_key,omitempty" yaml:"public_key"` - Signature []byte `protobuf:"bytes,2,opt,name=signature,proto3" json:"signature,omitempty"` +func (m *Account_PeriodicVestingAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *StdSignature) Reset() { *m = StdSignature{} } -func (m *StdSignature) String() string { return proto.CompactTextString(m) } -func (*StdSignature) ProtoMessage() {} -func (*StdSignature) Descriptor() ([]byte, []int) { - return fileDescriptor_ff851c3a98ef46f7, []int{5} -} -func (m *StdSignature) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *StdSignature) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_StdSignature.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *StdSignature) XXX_Merge(src proto.Message) { - xxx_messageInfo_StdSignature.Merge(m, src) -} -func (m *StdSignature) XXX_Size() int { - return m.Size() -} -func (m *StdSignature) XXX_DiscardUnknown() { - xxx_messageInfo_StdSignature.DiscardUnknown(m) -} - -var xxx_messageInfo_StdSignature proto.InternalMessageInfo - -// StdTxBase defines a transaction base which application-level concrete transaction -// types can extend. -type StdTxBase struct { - Fee StdFee `protobuf:"bytes,1,opt,name=fee,proto3" json:"fee"` - Signatures []StdSignature `protobuf:"bytes,2,rep,name=signatures,proto3" json:"signatures"` - Memo string `protobuf:"bytes,3,opt,name=memo,proto3" json:"memo,omitempty"` -} - -func (m *StdTxBase) Reset() { *m = StdTxBase{} } -func (m *StdTxBase) String() string { return proto.CompactTextString(m) } -func (*StdTxBase) ProtoMessage() {} -func (*StdTxBase) Descriptor() ([]byte, []int) { - return fileDescriptor_ff851c3a98ef46f7, []int{6} -} -func (m *StdTxBase) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *StdTxBase) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_StdTxBase.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *StdTxBase) XXX_Merge(src proto.Message) { - xxx_messageInfo_StdTxBase.Merge(m, src) -} -func (m *StdTxBase) XXX_Size() int { - return m.Size() -} -func (m *StdTxBase) XXX_DiscardUnknown() { - xxx_messageInfo_StdTxBase.DiscardUnknown(m) -} - -var xxx_messageInfo_StdTxBase proto.InternalMessageInfo - -func (m *StdTxBase) GetFee() StdFee { - if m != nil { - return m.Fee - } - return StdFee{} -} - -func (m *StdTxBase) GetSignatures() []StdSignature { - if m != nil { - return m.Signatures - } - return nil -} - -func (m *StdTxBase) GetMemo() string { - if m != nil { - return m.Memo - } - return "" -} - -// StdSignDocBase defines the base structure for which applications can extend -// to define the concrete structure that signers sign over. -type StdSignDocBase struct { - ChainID string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty" yaml:"chain_id"` - AccountNumber uint64 `protobuf:"varint,2,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty" yaml:"account_number"` - Sequence uint64 `protobuf:"varint,3,opt,name=sequence,proto3" json:"sequence,omitempty"` - Memo string `protobuf:"bytes,4,opt,name=memo,proto3" json:"memo,omitempty"` - Fee StdFee `protobuf:"bytes,5,opt,name=fee,proto3" json:"fee"` -} - -func (m *StdSignDocBase) Reset() { *m = StdSignDocBase{} } -func (m *StdSignDocBase) String() string { return proto.CompactTextString(m) } -func (*StdSignDocBase) ProtoMessage() {} -func (*StdSignDocBase) Descriptor() ([]byte, []int) { - return fileDescriptor_ff851c3a98ef46f7, []int{7} -} -func (m *StdSignDocBase) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *StdSignDocBase) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_StdSignDocBase.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *StdSignDocBase) XXX_Merge(src proto.Message) { - xxx_messageInfo_StdSignDocBase.Merge(m, src) -} -func (m *StdSignDocBase) XXX_Size() int { - return m.Size() -} -func (m *StdSignDocBase) XXX_DiscardUnknown() { - xxx_messageInfo_StdSignDocBase.DiscardUnknown(m) -} - -var xxx_messageInfo_StdSignDocBase proto.InternalMessageInfo - -func (m *StdSignDocBase) GetChainID() string { - if m != nil { - return m.ChainID - } - return "" -} - -func (m *StdSignDocBase) GetAccountNumber() uint64 { - if m != nil { - return m.AccountNumber - } - return 0 -} - -func (m *StdSignDocBase) GetSequence() uint64 { - if m != nil { - return m.Sequence - } - return 0 -} - -func (m *StdSignDocBase) GetMemo() string { - if m != nil { - return m.Memo - } - return "" -} - -func (m *StdSignDocBase) GetFee() StdFee { - if m != nil { - return m.Fee - } - return StdFee{} -} - -func init() { - proto.RegisterType((*Account)(nil), "cosmos_sdk.std.v1.Account") - proto.RegisterType((*Transaction)(nil), "cosmos_sdk.std.v1.Transaction") - proto.RegisterType((*Message)(nil), "cosmos_sdk.std.v1.Message") - proto.RegisterType((*SignDoc)(nil), "cosmos_sdk.std.v1.SignDoc") - proto.RegisterType((*StdFee)(nil), "cosmos_sdk.std.v1.StdFee") - proto.RegisterType((*StdSignature)(nil), "cosmos_sdk.std.v1.StdSignature") - proto.RegisterType((*StdTxBase)(nil), "cosmos_sdk.std.v1.StdTxBase") - proto.RegisterType((*StdSignDocBase)(nil), "cosmos_sdk.std.v1.StdSignDocBase") -} - -func init() { proto.RegisterFile("std/codec.proto", fileDescriptor_ff851c3a98ef46f7) } - -var fileDescriptor_ff851c3a98ef46f7 = []byte{ - // 1317 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xcf, 0x6f, 0x1b, 0xc5, - 0x17, 0x5f, 0x37, 0x6e, 0xdc, 0x8c, 0x9d, 0xb4, 0x99, 0x6f, 0xfb, 0xad, 0x6b, 0x5a, 0x3b, 0x35, - 0xa8, 0x2a, 0x2d, 0xb1, 0xe9, 0x0f, 0x10, 0xb5, 0x10, 0xa2, 0x4e, 0x1a, 0x39, 0x40, 0xa1, 0xda, - 0xb4, 0x45, 0x20, 0xc1, 0x6a, 0xbc, 0x33, 0xdd, 0x0c, 0xf1, 0xec, 0x2c, 0x3b, 0xb3, 0xae, 0x8d, - 0xc4, 0x09, 0x0e, 0x94, 0x13, 0x57, 0x6e, 0x3d, 0x73, 0xee, 0x89, 0xbf, 0xa0, 0xea, 0xa9, 0x47, - 0x4e, 0x06, 0xa5, 0x17, 0xd4, 0x13, 0xea, 0x5f, 0x80, 0x66, 0x76, 0x76, 0xed, 0xc4, 0x1b, 0xb7, - 0x07, 0x2e, 0xab, 0x79, 0x3f, 0x3e, 0x9f, 0xf7, 0xf6, 0xbd, 0x37, 0xfb, 0x16, 0x1c, 0x15, 0x12, - 0x37, 0x5d, 0x8e, 0x89, 0xdb, 0x08, 0x42, 0x2e, 0x39, 0x5c, 0x76, 0xb9, 0x60, 0x5c, 0x38, 0x02, - 0xef, 0x34, 0x84, 0xc4, 0x8d, 0xfe, 0xa5, 0xca, 0x45, 0xb9, 0x4d, 0x43, 0xec, 0x04, 0x28, 0x94, - 0xc3, 0xa6, 0xf6, 0x6a, 0xc6, 0x4e, 0xab, 0x93, 0x42, 0x8c, 0xaf, 0x9c, 0x9b, 0x76, 0xf6, 0xb8, - 0xc7, 0xc7, 0x27, 0xe3, 0xb7, 0x2c, 0x87, 0x01, 0x11, 0x4d, 0xfd, 0x34, 0xaa, 0xf2, 0xa0, 0x89, - 0x22, 0xb9, 0xdd, 0x9c, 0xb6, 0xac, 0x18, 0x4b, 0x9f, 0x08, 0x49, 0x7d, 0xaf, 0x99, 0x89, 0xed, - 0x22, 0x7f, 0x27, 0xc3, 0x52, 0x19, 0x34, 0xdd, 0x90, 0x0a, 0x2a, 0xb2, 0x79, 0x31, 0x15, 0x32, - 0xa4, 0xdd, 0x48, 0x52, 0xee, 0x67, 0x78, 0x9c, 0x1c, 0x34, 0x3d, 0xde, 0xcf, 0x30, 0x9c, 0x1e, - 0x34, 0x45, 0x0f, 0x89, 0xed, 0xec, 0x74, 0x5e, 0x1b, 0x34, 0x85, 0x44, 0x3b, 0x99, 0xc6, 0xfa, - 0xef, 0x79, 0x50, 0xb8, 0xee, 0xba, 0x3c, 0xf2, 0x25, 0xdc, 0x00, 0xa5, 0x2e, 0x12, 0xc4, 0x41, - 0xb1, 0x5c, 0xce, 0xad, 0xe4, 0xce, 0x17, 0x2f, 0x9f, 0x6d, 0x4c, 0x74, 0x61, 0xd0, 0x50, 0xef, - 0xde, 0xe8, 0x5f, 0x6a, 0xb4, 0x91, 0x20, 0x06, 0xd8, 0xb1, 0xec, 0x62, 0x77, 0x2c, 0xc2, 0x3e, - 0xa8, 0xb8, 0xdc, 0x97, 0xd4, 0x8f, 0x78, 0x24, 0x1c, 0x53, 0xa7, 0x94, 0xf5, 0x90, 0x66, 0x7d, - 0x37, 0x8b, 0x35, 0xf6, 0x54, 0xec, 0x6b, 0x29, 0xfe, 0x6e, 0xac, 0x1c, 0x87, 0x2a, 0xbb, 0x07, - 0xd8, 0x20, 0x03, 0x27, 0x31, 0xe9, 0xa1, 0x21, 0xc1, 0x53, 0x41, 0xe7, 0x74, 0xd0, 0x2b, 0xb3, - 0x83, 0xae, 0xc7, 0xe0, 0xa9, 0x88, 0x27, 0x70, 0x96, 0x01, 0x06, 0xa0, 0x1c, 0x90, 0x90, 0x72, - 0x4c, 0xdd, 0xa9, 0x78, 0x79, 0x1d, 0xef, 0xea, 0xec, 0x78, 0xb7, 0x0c, 0x7a, 0x2a, 0xe0, 0xff, - 0x83, 0x4c, 0x0b, 0xfc, 0x04, 0x2c, 0x31, 0x8e, 0xa3, 0xde, 0xb8, 0x45, 0x87, 0x75, 0x9c, 0xd7, - 0xb3, 0x5b, 0x74, 0x53, 0xfb, 0x8e, 0x69, 0x17, 0xd9, 0xa4, 0xa2, 0x75, 0xed, 0xc9, 0xa3, 0xd5, - 0x77, 0x2e, 0x78, 0x54, 0x6e, 0x47, 0xdd, 0x86, 0xcb, 0x99, 0xb9, 0x3b, 0xc9, 0x7d, 0x12, 0x78, - 0xa7, 0x69, 0x46, 0x9d, 0x0c, 0x02, 0x1e, 0x4a, 0x82, 0x1b, 0x06, 0xda, 0x3e, 0x0c, 0xe6, 0x44, - 0xc4, 0xea, 0x0f, 0x72, 0xa0, 0x78, 0x3b, 0x44, 0xbe, 0x40, 0xae, 0x1a, 0x59, 0xf8, 0x01, 0xc8, - 0xab, 0x39, 0x30, 0x83, 0x73, 0xba, 0x31, 0x75, 0x7d, 0x1b, 0x5b, 0x12, 0xdf, 0x1e, 0xa8, 0xd1, - 0x69, 0x97, 0x1e, 0x8f, 0x6a, 0xd6, 0xd3, 0x51, 0x2d, 0xf7, 0x7c, 0x54, 0xb3, 0x6c, 0x8d, 0x83, - 0x57, 0x41, 0x9e, 0x09, 0x4f, 0x94, 0x0f, 0xad, 0xcc, 0x9d, 0x2f, 0x5e, 0xae, 0x64, 0xe0, 0x6f, - 0x12, 0x21, 0x90, 0x47, 0xda, 0xf9, 0xc7, 0x1a, 0xa5, 0xbc, 0x5b, 0xf9, 0x9f, 0x1e, 0xd6, 0xac, - 0xfa, 0xcf, 0x45, 0x50, 0x30, 0x56, 0xd8, 0x02, 0x47, 0x98, 0xf0, 0x1c, 0x41, 0x7c, 0x6c, 0x72, - 0x39, 0xb3, 0xb7, 0x42, 0xea, 0x7a, 0x6a, 0x3a, 0xe1, 0x6d, 0x11, 0x1f, 0x77, 0x2c, 0xbb, 0xc0, - 0xe2, 0x23, 0xfc, 0x08, 0x2c, 0x29, 0x2c, 0x8b, 0x7a, 0x92, 0xc6, 0x0c, 0xf1, 0xc0, 0xd6, 0x0f, - 0x64, 0xb8, 0xa9, 0x5c, 0x0d, 0x4d, 0x89, 0x4d, 0xc8, 0xf0, 0x6b, 0x70, 0x5c, 0x71, 0xf5, 0x49, - 0x48, 0xef, 0x0d, 0x1d, 0xea, 0xf7, 0x51, 0x48, 0x51, 0x3a, 0x8d, 0x17, 0xf6, 0x32, 0xc6, 0x1f, - 0x06, 0xc3, 0x79, 0x57, 0x43, 0x36, 0x13, 0x44, 0xc7, 0xb2, 0x21, 0x9b, 0xd2, 0x42, 0x1f, 0x94, - 0xe3, 0xf7, 0x94, 0xce, 0x7d, 0x2a, 0xb7, 0x71, 0x88, 0xee, 0x3b, 0x08, 0xe3, 0x90, 0x08, 0x61, - 0x26, 0x70, 0xdf, 0xc4, 0x4f, 0x7e, 0x60, 0xd2, 0xf7, 0x97, 0x9f, 0x1b, 0xec, 0xf5, 0x18, 0xaa, - 0x26, 0x9e, 0x65, 0x19, 0xe0, 0xf7, 0xe0, 0x8c, 0x8a, 0x97, 0xc6, 0xc2, 0xa4, 0x47, 0x3c, 0x24, - 0x79, 0xe8, 0x84, 0xe4, 0x3e, 0x0a, 0xb1, 0x19, 0xc7, 0xf7, 0x5e, 0x1a, 0x34, 0x21, 0x5e, 0x4f, - 0x08, 0x6c, 0x8d, 0xef, 0x58, 0x76, 0x85, 0x1d, 0x68, 0x85, 0x0f, 0x72, 0xe0, 0xec, 0x9e, 0xf8, - 0x7d, 0xd4, 0xa3, 0x58, 0xc7, 0x77, 0x39, 0x63, 0x54, 0x08, 0xca, 0xfd, 0xf2, 0xbc, 0xce, 0xe1, - 0xfd, 0x57, 0xce, 0xe1, 0x6e, 0x42, 0xb2, 0x96, 0x72, 0x74, 0x2c, 0xbb, 0xca, 0x66, 0x7a, 0xc0, - 0x1d, 0x70, 0x52, 0xa5, 0x72, 0x2f, 0xf2, 0xb1, 0x0e, 0x1e, 0xf9, 0x54, 0x0e, 0x9d, 0x80, 0xf3, - 0x5e, 0xb9, 0xa0, 0x13, 0xb8, 0xfc, 0xd2, 0x04, 0x36, 0x22, 0x1f, 0xaf, 0x25, 0xd0, 0x5b, 0x9c, - 0xf7, 0x3a, 0x96, 0xad, 0xe6, 0x65, 0x4a, 0x0f, 0xaf, 0xc5, 0xf3, 0xdc, 0xe7, 0x92, 0x94, 0xc1, - 0xf4, 0xdd, 0x1a, 0x34, 0x3c, 0xde, 0x4f, 0x06, 0x87, 0x4b, 0x62, 0xc6, 0x59, 0x1d, 0x61, 0x1b, - 0x14, 0x15, 0x14, 0x93, 0x80, 0x0b, 0x2a, 0xcb, 0x45, 0x8d, 0xae, 0x1d, 0x84, 0x5e, 0x8f, 0xdd, - 0x3a, 0x96, 0x0d, 0x58, 0x2a, 0xc1, 0x75, 0xa0, 0x24, 0x27, 0xf2, 0xbf, 0x41, 0xb4, 0x57, 0x2e, - 0x65, 0x7d, 0x72, 0x92, 0xf5, 0x63, 0x78, 0xee, 0x68, 0xd7, 0x8e, 0x65, 0x2f, 0xb0, 0x44, 0x80, - 0x4e, 0x7c, 0x19, 0xdc, 0x90, 0x20, 0x49, 0xc6, 0xad, 0x2b, 0x2f, 0x6a, 0xbe, 0x8b, 0xfb, 0xf8, - 0xe2, 0x85, 0x65, 0xe8, 0xd6, 0x34, 0x26, 0x6d, 0x83, 0xb9, 0x0d, 0xfb, 0xb4, 0xf0, 0x0b, 0xa0, - 0xb4, 0x0e, 0xc1, 0x54, 0x4e, 0xd0, 0x2f, 0x69, 0xfa, 0x37, 0x67, 0xd1, 0xdf, 0xc0, 0x54, 0x4e, - 0x92, 0x1f, 0x63, 0xfb, 0x74, 0x70, 0x13, 0x94, 0xe2, 0x2a, 0xea, 0x81, 0x24, 0xe5, 0xa3, 0x9a, - 0xf4, 0x8d, 0x59, 0xa4, 0x66, 0x78, 0x55, 0x33, 0x8a, 0x6c, 0x2c, 0x26, 0x65, 0xe8, 0x12, 0x8f, - 0xfa, 0x4e, 0x48, 0x52, 0xca, 0x63, 0x2f, 0x2f, 0x43, 0x5b, 0x61, 0xec, 0x14, 0x62, 0xca, 0xb0, - 0x4f, 0x0b, 0x3f, 0x8b, 0x3f, 0x60, 0x91, 0x9f, 0x52, 0x2f, 0x6b, 0xea, 0x73, 0xb3, 0xa8, 0xef, - 0xf8, 0x13, 0xac, 0x8b, 0x6c, 0x52, 0xd1, 0xba, 0xf0, 0xe4, 0xd1, 0xea, 0xb9, 0x99, 0x6b, 0x22, - 0xfe, 0xa1, 0x50, 0x19, 0x9a, 0xc5, 0xf0, 0x63, 0x0e, 0x14, 0xb6, 0xa8, 0xe7, 0xaf, 0x73, 0x17, - 0xae, 0xed, 0x59, 0x0a, 0x67, 0xb3, 0x97, 0x82, 0x71, 0xfe, 0x6f, 0x37, 0x43, 0xfd, 0x87, 0x1c, - 0x98, 0xdf, 0x92, 0x78, 0x83, 0x10, 0xf8, 0x15, 0x98, 0x47, 0xcc, 0xfc, 0xd5, 0x28, 0x8a, 0xff, - 0x4d, 0x52, 0xe8, 0x1f, 0x0e, 0xea, 0xb7, 0xdf, 0x56, 0xd8, 0xdf, 0xfe, 0xac, 0x9d, 0x7f, 0x85, - 0xb7, 0x55, 0x00, 0x61, 0x1b, 0x52, 0x78, 0x0c, 0xcc, 0x79, 0x48, 0xe8, 0x55, 0x91, 0xb7, 0xd5, - 0xb1, 0x75, 0x44, 0x6d, 0xa5, 0xbf, 0x1f, 0xd6, 0x72, 0xf5, 0xef, 0x40, 0xc9, 0xbc, 0x21, 0x92, - 0x51, 0x48, 0xe0, 0x06, 0x28, 0x04, 0x51, 0xd7, 0xd9, 0x21, 0x43, 0x5d, 0x93, 0x52, 0x7b, 0xf5, - 0xf9, 0xa8, 0x76, 0x3c, 0x88, 0xba, 0x3d, 0xea, 0x2a, 0xed, 0x5b, 0x9c, 0x51, 0x49, 0x58, 0x20, - 0x87, 0x2f, 0x46, 0xb5, 0xe5, 0x21, 0x62, 0xbd, 0x56, 0x7d, 0x6c, 0xad, 0xdb, 0xf3, 0x41, 0xd4, - 0xfd, 0x98, 0x0c, 0xe1, 0x69, 0xb0, 0x20, 0x12, 0x52, 0x1d, 0xb9, 0x64, 0x8f, 0x15, 0x66, 0x2b, - 0xfe, 0x9a, 0x03, 0x0b, 0xe9, 0xce, 0x85, 0x97, 0xc0, 0xdc, 0x3d, 0x92, 0x74, 0xe2, 0x54, 0x76, - 0x27, 0x36, 0x48, 0x52, 0x43, 0xe5, 0x0b, 0x6f, 0x00, 0x90, 0x72, 0x26, 0xe5, 0xaf, 0x1d, 0xdc, - 0x43, 0xed, 0x67, 0xf0, 0x13, 0x40, 0x08, 0x41, 0x9e, 0x11, 0xc6, 0xf5, 0xe6, 0x5b, 0xb0, 0xf5, - 0xb9, 0xfe, 0x4f, 0x0e, 0x2c, 0xed, 0x6d, 0xbd, 0xfa, 0xd0, 0xb9, 0xdb, 0x88, 0xfa, 0x0e, 0x8d, - 0x17, 0xf7, 0x42, 0xbb, 0xba, 0x3b, 0xaa, 0x15, 0xd6, 0x94, 0x6e, 0x73, 0xfd, 0xc5, 0xa8, 0x76, - 0x34, 0x2e, 0x47, 0xe2, 0x54, 0xb7, 0x0b, 0xfa, 0xb8, 0x89, 0xe1, 0x87, 0x60, 0xc9, 0xfc, 0x14, - 0x39, 0x7e, 0xc4, 0xba, 0x24, 0x8c, 0x9b, 0xd1, 0x3e, 0xf5, 0x62, 0x54, 0x3b, 0x11, 0xa3, 0xf6, - 0xda, 0xeb, 0xf6, 0xa2, 0x51, 0x7c, 0xaa, 0x65, 0x58, 0x01, 0x47, 0x04, 0xf9, 0x36, 0x22, 0xbe, - 0x4b, 0x74, 0x9e, 0x79, 0x3b, 0x95, 0xd3, 0xfc, 0xf3, 0xe3, 0xfc, 0x93, 0x6a, 0x1e, 0x7e, 0xf5, - 0x6a, 0xb6, 0x5b, 0x8f, 0x77, 0xab, 0xb9, 0xa7, 0xbb, 0xd5, 0xdc, 0x5f, 0xbb, 0xd5, 0xdc, 0x2f, - 0xcf, 0xaa, 0xd6, 0xd3, 0x67, 0x55, 0xeb, 0x8f, 0x67, 0x55, 0xeb, 0xcb, 0x95, 0x99, 0x23, 0x27, - 0x24, 0xee, 0xce, 0xeb, 0x1f, 0xf6, 0x2b, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0x5e, 0x75, 0x49, - 0x67, 0x26, 0x0d, 0x00, 0x00, -} - -func (this *StdFee) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*StdFee) - if !ok { - that2, ok := that.(StdFee) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.Amount) != len(that1.Amount) { - return false - } - for i := range this.Amount { - if !this.Amount[i].Equal(&that1.Amount[i]) { - return false - } - } - if this.Gas != that1.Gas { - return false - } - return true -} -func (this *Account) GetAccount() github_com_cosmos_cosmos_sdk_x_auth_exported.Account { - if x := this.GetBaseAccount(); x != nil { - return x - } - if x := this.GetContinuousVestingAccount(); x != nil { - return x - } - if x := this.GetDelayedVestingAccount(); x != nil { - return x - } - if x := this.GetPeriodicVestingAccount(); x != nil { - return x - } - if x := this.GetModuleAccount(); x != nil { - return x - } - return nil -} - -func (this *Account) SetAccount(value github_com_cosmos_cosmos_sdk_x_auth_exported.Account) error { - if value == nil { - this.Sum = nil - return nil - } - switch vt := value.(type) { - case *types.BaseAccount: - this.Sum = &Account_BaseAccount{vt} - return nil - case *types1.ContinuousVestingAccount: - this.Sum = &Account_ContinuousVestingAccount{vt} - return nil - case *types1.DelayedVestingAccount: - this.Sum = &Account_DelayedVestingAccount{vt} - return nil - case *types1.PeriodicVestingAccount: - this.Sum = &Account_PeriodicVestingAccount{vt} - return nil - case *types.ModuleAccount: - this.Sum = &Account_ModuleAccount{vt} - return nil - } - return fmt.Errorf("can't encode value of type %T as message Account", value) -} - -func (this *Message) GetMsg() github_com_cosmos_cosmos_sdk_types.Msg { - if x := this.GetMsgSend(); x != nil { - return x - } - if x := this.GetMsgMultiSend(); x != nil { - return x - } - if x := this.GetMsgVerifyInvariant(); x != nil { - return x - } - if x := this.GetMsgSetWithdrawAddress(); x != nil { - return x - } - if x := this.GetMsgWithdrawDelegatorReward(); x != nil { - return x - } - if x := this.GetMsgWithdrawValidatorCommission(); x != nil { - return x - } - if x := this.GetMsgFundCommunityPool(); x != nil { - return x - } - if x := this.GetMsgVote(); x != nil { - return x - } - if x := this.GetMsgDeposit(); x != nil { - return x - } - if x := this.GetMsgUnjail(); x != nil { - return x - } - if x := this.GetMsgCreateValidator(); x != nil { - return x - } - if x := this.GetMsgEditValidator(); x != nil { - return x - } - if x := this.GetMsgDelegate(); x != nil { - return x - } - if x := this.GetMsgBeginRedelegate(); x != nil { - return x - } - if x := this.GetMsgUndelegate(); x != nil { - return x - } - return nil -} - -func (this *Message) SetMsg(value github_com_cosmos_cosmos_sdk_types.Msg) error { - if value == nil { - this.Sum = nil - return nil - } - switch vt := value.(type) { - case *types2.MsgSend: - this.Sum = &Message_MsgSend{vt} - return nil - case types2.MsgSend: - this.Sum = &Message_MsgSend{&vt} - return nil - case *types2.MsgMultiSend: - this.Sum = &Message_MsgMultiSend{vt} - return nil - case types2.MsgMultiSend: - this.Sum = &Message_MsgMultiSend{&vt} - return nil - case *types3.MsgVerifyInvariant: - this.Sum = &Message_MsgVerifyInvariant{vt} - return nil - case types3.MsgVerifyInvariant: - this.Sum = &Message_MsgVerifyInvariant{&vt} - return nil - case *types4.MsgSetWithdrawAddress: - this.Sum = &Message_MsgSetWithdrawAddress{vt} - return nil - case types4.MsgSetWithdrawAddress: - this.Sum = &Message_MsgSetWithdrawAddress{&vt} - return nil - case *types4.MsgWithdrawDelegatorReward: - this.Sum = &Message_MsgWithdrawDelegatorReward{vt} - return nil - case types4.MsgWithdrawDelegatorReward: - this.Sum = &Message_MsgWithdrawDelegatorReward{&vt} - return nil - case *types4.MsgWithdrawValidatorCommission: - this.Sum = &Message_MsgWithdrawValidatorCommission{vt} - return nil - case types4.MsgWithdrawValidatorCommission: - this.Sum = &Message_MsgWithdrawValidatorCommission{&vt} - return nil - case *types4.MsgFundCommunityPool: - this.Sum = &Message_MsgFundCommunityPool{vt} - return nil - case types4.MsgFundCommunityPool: - this.Sum = &Message_MsgFundCommunityPool{&vt} - return nil - case *types5.MsgVote: - this.Sum = &Message_MsgVote{vt} - return nil - case types5.MsgVote: - this.Sum = &Message_MsgVote{&vt} - return nil - case *types5.MsgDeposit: - this.Sum = &Message_MsgDeposit{vt} - return nil - case types5.MsgDeposit: - this.Sum = &Message_MsgDeposit{&vt} - return nil - case *types6.MsgUnjail: - this.Sum = &Message_MsgUnjail{vt} - return nil - case types6.MsgUnjail: - this.Sum = &Message_MsgUnjail{&vt} - return nil - case *types7.MsgCreateValidator: - this.Sum = &Message_MsgCreateValidator{vt} - return nil - case types7.MsgCreateValidator: - this.Sum = &Message_MsgCreateValidator{&vt} - return nil - case *types7.MsgEditValidator: - this.Sum = &Message_MsgEditValidator{vt} - return nil - case types7.MsgEditValidator: - this.Sum = &Message_MsgEditValidator{&vt} - return nil - case *types7.MsgDelegate: - this.Sum = &Message_MsgDelegate{vt} - return nil - case types7.MsgDelegate: - this.Sum = &Message_MsgDelegate{&vt} - return nil - case *types7.MsgBeginRedelegate: - this.Sum = &Message_MsgBeginRedelegate{vt} - return nil - case types7.MsgBeginRedelegate: - this.Sum = &Message_MsgBeginRedelegate{&vt} - return nil - case *types7.MsgUndelegate: - this.Sum = &Message_MsgUndelegate{vt} - return nil - case types7.MsgUndelegate: - this.Sum = &Message_MsgUndelegate{&vt} - return nil - } - return fmt.Errorf("can't encode value of type %T as message Message", value) -} - -func (m *Account) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Account) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Account) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *Account_PeriodicVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) - _ = i - var l int - _ = l - if m.Sum != nil { - { - size := m.Sum.Size() - i -= size - if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - } - } - return len(dAtA) - i, nil -} - -func (m *Account_BaseAccount) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Account_BaseAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.BaseAccount != nil { - { - size, err := m.BaseAccount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} -func (m *Account_ContinuousVestingAccount) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Account_ContinuousVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.ContinuousVestingAccount != nil { - { - size, err := m.ContinuousVestingAccount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - return len(dAtA) - i, nil -} -func (m *Account_DelayedVestingAccount) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Account_DelayedVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.DelayedVestingAccount != nil { - { - size, err := m.DelayedVestingAccount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - return len(dAtA) - i, nil -} -func (m *Account_PeriodicVestingAccount) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Account_PeriodicVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.PeriodicVestingAccount != nil { + if m.PeriodicVestingAccount != nil { { size, err := m.PeriodicVestingAccount.MarshalToSizedBuffer(dAtA[:i]) if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - return len(dAtA) - i, nil -} -func (m *Account_ModuleAccount) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Account_ModuleAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.ModuleAccount != nil { - { - size, err := m.ModuleAccount.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - } - return len(dAtA) - i, nil -} -func (m *Transaction) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Transaction) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Transaction) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Msgs) > 0 { - for iNdEx := len(m.Msgs) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Msgs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - } - { - size, err := m.StdTxBase.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *Message) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Message) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Sum != nil { - { - size := m.Sum.Size() - i -= size - if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - } - } - return len(dAtA) - i, nil -} - -func (m *Message_MsgSend) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgSend) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgSend != nil { - { - size, err := m.MsgSend.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} -func (m *Message_MsgMultiSend) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgMultiSend) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgMultiSend != nil { - { - size, err := m.MsgMultiSend.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - return len(dAtA) - i, nil -} -func (m *Message_MsgVerifyInvariant) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgVerifyInvariant) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgVerifyInvariant != nil { - { - size, err := m.MsgVerifyInvariant.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1a - } - return len(dAtA) - i, nil -} -func (m *Message_MsgSetWithdrawAddress) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgSetWithdrawAddress) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgSetWithdrawAddress != nil { - { - size, err := m.MsgSetWithdrawAddress.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x22 - } - return len(dAtA) - i, nil -} -func (m *Message_MsgWithdrawDelegatorReward) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgWithdrawDelegatorReward) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgWithdrawDelegatorReward != nil { - { - size, err := m.MsgWithdrawDelegatorReward.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - } - return len(dAtA) - i, nil -} -func (m *Message_MsgWithdrawValidatorCommission) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgWithdrawValidatorCommission) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgWithdrawValidatorCommission != nil { - { - size, err := m.MsgWithdrawValidatorCommission.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x32 - } - return len(dAtA) - i, nil -} -func (m *Message_MsgFundCommunityPool) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgFundCommunityPool) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgFundCommunityPool != nil { - { - size, err := m.MsgFundCommunityPool.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x3a - } - return len(dAtA) - i, nil -} -func (m *Message_MsgVote) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgVote) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgVote != nil { - { - size, err := m.MsgVote.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x52 - } - return len(dAtA) - i, nil -} -func (m *Message_MsgDeposit) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgDeposit) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgDeposit != nil { - { - size, err := m.MsgDeposit.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x5a - } - return len(dAtA) - i, nil -} -func (m *Message_MsgUnjail) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgUnjail) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgUnjail != nil { - { - size, err := m.MsgUnjail.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x62 - } - return len(dAtA) - i, nil -} -func (m *Message_MsgCreateValidator) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgCreateValidator) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgCreateValidator != nil { - { - size, err := m.MsgCreateValidator.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x6a - } - return len(dAtA) - i, nil -} -func (m *Message_MsgEditValidator) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgEditValidator) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgEditValidator != nil { - { - size, err := m.MsgEditValidator.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x72 - } - return len(dAtA) - i, nil -} -func (m *Message_MsgDelegate) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgDelegate) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgDelegate != nil { - { - size, err := m.MsgDelegate.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x7a - } - return len(dAtA) - i, nil -} -func (m *Message_MsgBeginRedelegate) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgBeginRedelegate) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgBeginRedelegate != nil { - { - size, err := m.MsgBeginRedelegate.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x82 - } - return len(dAtA) - i, nil -} -func (m *Message_MsgUndelegate) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Message_MsgUndelegate) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.MsgUndelegate != nil { - { - size, err := m.MsgUndelegate.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x8a - } - return len(dAtA) - i, nil -} -func (m *SignDoc) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *SignDoc) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *SignDoc) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Msgs) > 0 { - for iNdEx := len(m.Msgs) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Msgs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - } - { - size, err := m.StdSignDocBase.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *StdFee) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *StdFee) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *StdFee) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Gas != 0 { - i = encodeVarintCodec(dAtA, i, uint64(m.Gas)) - i-- - dAtA[i] = 0x10 - } - if len(m.Amount) > 0 { - for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *StdSignature) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *StdSignature) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *StdSignature) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Signature) > 0 { - i -= len(m.Signature) - copy(dAtA[i:], m.Signature) - i = encodeVarintCodec(dAtA, i, uint64(len(m.Signature))) - i-- - dAtA[i] = 0x12 - } - if len(m.PubKey) > 0 { - i -= len(m.PubKey) - copy(dAtA[i:], m.PubKey) - i = encodeVarintCodec(dAtA, i, uint64(len(m.PubKey))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *StdTxBase) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *StdTxBase) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *StdTxBase) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Memo) > 0 { - i -= len(m.Memo) - copy(dAtA[i:], m.Memo) - i = encodeVarintCodec(dAtA, i, uint64(len(m.Memo))) - i-- - dAtA[i] = 0x1a - } - if len(m.Signatures) > 0 { - for iNdEx := len(m.Signatures) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Signatures[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - } - } - { - size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *StdSignDocBase) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *StdSignDocBase) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *StdSignDocBase) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.Fee.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintCodec(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - if len(m.Memo) > 0 { - i -= len(m.Memo) - copy(dAtA[i:], m.Memo) - i = encodeVarintCodec(dAtA, i, uint64(len(m.Memo))) - i-- - dAtA[i] = 0x22 - } - if m.Sequence != 0 { - i = encodeVarintCodec(dAtA, i, uint64(m.Sequence)) - i-- - dAtA[i] = 0x18 - } - if m.AccountNumber != 0 { - i = encodeVarintCodec(dAtA, i, uint64(m.AccountNumber)) - i-- - dAtA[i] = 0x10 - } - if len(m.ChainID) > 0 { - i -= len(m.ChainID) - copy(dAtA[i:], m.ChainID) - i = encodeVarintCodec(dAtA, i, uint64(len(m.ChainID))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintCodec(dAtA []byte, offset int, v uint64) int { - offset -= sovCodec(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Account) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Sum != nil { - n += m.Sum.Size() - } - return n -} - -func (m *Account_BaseAccount) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.BaseAccount != nil { - l = m.BaseAccount.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Account_ContinuousVestingAccount) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ContinuousVestingAccount != nil { - l = m.ContinuousVestingAccount.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Account_DelayedVestingAccount) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.DelayedVestingAccount != nil { - l = m.DelayedVestingAccount.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Account_PeriodicVestingAccount) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.PeriodicVestingAccount != nil { - l = m.PeriodicVestingAccount.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Account_ModuleAccount) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.ModuleAccount != nil { - l = m.ModuleAccount.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Transaction) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.StdTxBase.Size() - n += 1 + l + sovCodec(uint64(l)) - if len(m.Msgs) > 0 { - for _, e := range m.Msgs { - l = e.Size() - n += 1 + l + sovCodec(uint64(l)) - } - } - return n -} - -func (m *Message) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Sum != nil { - n += m.Sum.Size() - } - return n -} - -func (m *Message_MsgSend) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgSend != nil { - l = m.MsgSend.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgMultiSend) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgMultiSend != nil { - l = m.MsgMultiSend.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgVerifyInvariant) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgVerifyInvariant != nil { - l = m.MsgVerifyInvariant.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgSetWithdrawAddress) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgSetWithdrawAddress != nil { - l = m.MsgSetWithdrawAddress.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgWithdrawDelegatorReward) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgWithdrawDelegatorReward != nil { - l = m.MsgWithdrawDelegatorReward.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgWithdrawValidatorCommission) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgWithdrawValidatorCommission != nil { - l = m.MsgWithdrawValidatorCommission.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgFundCommunityPool) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgFundCommunityPool != nil { - l = m.MsgFundCommunityPool.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgVote) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgVote != nil { - l = m.MsgVote.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgDeposit) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgDeposit != nil { - l = m.MsgDeposit.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgUnjail) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgUnjail != nil { - l = m.MsgUnjail.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgCreateValidator) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgCreateValidator != nil { - l = m.MsgCreateValidator.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgEditValidator) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgEditValidator != nil { - l = m.MsgEditValidator.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgDelegate) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgDelegate != nil { - l = m.MsgDelegate.Size() - n += 1 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgBeginRedelegate) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgBeginRedelegate != nil { - l = m.MsgBeginRedelegate.Size() - n += 2 + l + sovCodec(uint64(l)) - } - return n -} -func (m *Message_MsgUndelegate) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MsgUndelegate != nil { - l = m.MsgUndelegate.Size() - n += 2 + l + sovCodec(uint64(l)) - } - return n -} -func (m *SignDoc) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.StdSignDocBase.Size() - n += 1 + l + sovCodec(uint64(l)) - if len(m.Msgs) > 0 { - for _, e := range m.Msgs { - l = e.Size() - n += 1 + l + sovCodec(uint64(l)) - } - } - return n -} - -func (m *StdFee) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Amount) > 0 { - for _, e := range m.Amount { - l = e.Size() - n += 1 + l + sovCodec(uint64(l)) - } - } - if m.Gas != 0 { - n += 1 + sovCodec(uint64(m.Gas)) - } - return n -} - -func (m *StdSignature) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.PubKey) - if l > 0 { - n += 1 + l + sovCodec(uint64(l)) - } - l = len(m.Signature) - if l > 0 { - n += 1 + l + sovCodec(uint64(l)) - } - return n -} - -func (m *StdTxBase) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.Fee.Size() - n += 1 + l + sovCodec(uint64(l)) - if len(m.Signatures) > 0 { - for _, e := range m.Signatures { - l = e.Size() - n += 1 + l + sovCodec(uint64(l)) - } - } - l = len(m.Memo) - if l > 0 { - n += 1 + l + sovCodec(uint64(l)) - } - return n -} - -func (m *StdSignDocBase) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.ChainID) - if l > 0 { - n += 1 + l + sovCodec(uint64(l)) - } - if m.AccountNumber != 0 { - n += 1 + sovCodec(uint64(m.AccountNumber)) - } - if m.Sequence != 0 { - n += 1 + sovCodec(uint64(m.Sequence)) - } - l = len(m.Memo) - if l > 0 { - n += 1 + l + sovCodec(uint64(l)) - } - l = m.Fee.Size() - n += 1 + l + sovCodec(uint64(l)) - return n -} - -func sovCodec(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozCodec(x uint64) (n int) { - return sovCodec(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Account) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Account: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Account: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types.BaseAccount{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Account_BaseAccount{v} - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ContinuousVestingAccount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types1.ContinuousVestingAccount{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Account_ContinuousVestingAccount{v} - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field DelayedVestingAccount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types1.DelayedVestingAccount{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Account_DelayedVestingAccount{v} - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PeriodicVestingAccount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types1.PeriodicVestingAccount{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Account_PeriodicVestingAccount{v} - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ModuleAccount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types.ModuleAccount{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Account_ModuleAccount{v} - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipCodec(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Transaction) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Transaction: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Transaction: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StdTxBase", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.StdTxBase.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Msgs", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Msgs = append(m.Msgs, Message{}) - if err := m.Msgs[len(m.Msgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipCodec(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Message) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Message: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Message: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgSend", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types2.MsgSend{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgSend{v} - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgMultiSend", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types2.MsgMultiSend{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgMultiSend{v} - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgVerifyInvariant", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types3.MsgVerifyInvariant{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgVerifyInvariant{v} - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgSetWithdrawAddress", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types4.MsgSetWithdrawAddress{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgSetWithdrawAddress{v} - iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgWithdrawDelegatorReward", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types4.MsgWithdrawDelegatorReward{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgWithdrawDelegatorReward{v} - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgWithdrawValidatorCommission", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types4.MsgWithdrawValidatorCommission{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgWithdrawValidatorCommission{v} - iNdEx = postIndex - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgFundCommunityPool", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types4.MsgFundCommunityPool{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgFundCommunityPool{v} - iNdEx = postIndex - case 10: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgVote", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types5.MsgVote{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgVote{v} - iNdEx = postIndex - case 11: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgDeposit", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types5.MsgDeposit{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgDeposit{v} - iNdEx = postIndex - case 12: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgUnjail", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types6.MsgUnjail{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgUnjail{v} - iNdEx = postIndex - case 13: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgCreateValidator", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types7.MsgCreateValidator{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgCreateValidator{v} - iNdEx = postIndex - case 14: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgEditValidator", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types7.MsgEditValidator{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgEditValidator{v} - iNdEx = postIndex - case 15: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgDelegate", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types7.MsgDelegate{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgDelegate{v} - iNdEx = postIndex - case 16: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgBeginRedelegate", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types7.MsgBeginRedelegate{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgBeginRedelegate{v} - iNdEx = postIndex - case 17: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MsgUndelegate", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &types7.MsgUndelegate{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Sum = &Message_MsgUndelegate{v} - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipCodec(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *SignDoc) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: SignDoc: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: SignDoc: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StdSignDocBase", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.StdSignDocBase.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Msgs", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Msgs = append(m.Msgs, Message{}) - if err := m.Msgs[len(m.Msgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipCodec(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *StdFee) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: StdFee: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: StdFee: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Amount = append(m.Amount, types8.Coin{}) - if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Gas", wireType) - } - m.Gas = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Gas |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipCodec(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *StdSignature) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: StdSignature: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: StdSignature: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PubKey = append(m.PubKey[:0], dAtA[iNdEx:postIndex]...) - if m.PubKey == nil { - m.PubKey = []byte{} - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Signature = append(m.Signature[:0], dAtA[iNdEx:postIndex]...) - if m.Signature == nil { - m.Signature = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipCodec(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthCodec + return 0, err } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + return len(dAtA) - i, nil +} +func (m *Account_ModuleAccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Account_ModuleAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.ModuleAccount != nil { + { + size, err := m.ModuleAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - iNdEx += skippy + i -= size + i = encodeVarintCodec(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0x2a + } + return len(dAtA) - i, nil +} +func encodeVarintCodec(dAtA []byte, offset int, v uint64) int { + offset -= sovCodec(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Account) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sum != nil { + n += m.Sum.Size() } + return n +} - if iNdEx > l { - return io.ErrUnexpectedEOF +func (m *Account_BaseAccount) Size() (n int) { + if m == nil { + return 0 } - return nil + var l int + _ = l + if m.BaseAccount != nil { + l = m.BaseAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Account_ContinuousVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ContinuousVestingAccount != nil { + l = m.ContinuousVestingAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Account_DelayedVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.DelayedVestingAccount != nil { + l = m.DelayedVestingAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Account_PeriodicVestingAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.PeriodicVestingAccount != nil { + l = m.PeriodicVestingAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} +func (m *Account_ModuleAccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ModuleAccount != nil { + l = m.ModuleAccount.Size() + n += 1 + l + sovCodec(uint64(l)) + } + return n +} + +func sovCodec(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCodec(x uint64) (n int) { + return sovCodec(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *StdTxBase) Unmarshal(dAtA []byte) error { +func (m *Account) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -3518,15 +481,15 @@ func (m *StdTxBase) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: StdTxBase: wiretype end group for non-group") + return fmt.Errorf("proto: Account: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: StdTxBase: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Account: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -3553,13 +516,15 @@ func (m *StdTxBase) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Fee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + v := &types.BaseAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } + m.Sum = &Account_BaseAccount{v} iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Signatures", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ContinuousVestingAccount", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -3586,16 +551,17 @@ func (m *StdTxBase) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Signatures = append(m.Signatures, StdSignature{}) - if err := m.Signatures[len(m.Signatures)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + v := &types1.ContinuousVestingAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } + m.Sum = &Account_ContinuousVestingAccount{v} iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Memo", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field DelayedVestingAccount", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowCodec @@ -3605,152 +571,32 @@ func (m *StdTxBase) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthCodec } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthCodec } if postIndex > l { return io.ErrUnexpectedEOF } - m.Memo = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipCodec(dAtA[iNdEx:]) - if err != nil { + v := &types1.DelayedVestingAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthCodec - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *StdSignDocBase) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: StdSignDocBase: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: StdSignDocBase: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ChainID", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthCodec - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthCodec - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ChainID = string(dAtA[iNdEx:postIndex]) + m.Sum = &Account_DelayedVestingAccount{v} iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field AccountNumber", wireType) - } - m.AccountNumber = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.AccountNumber |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Sequence", wireType) - } - m.Sequence = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCodec - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Sequence |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Memo", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field PeriodicVestingAccount", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowCodec @@ -3760,27 +606,30 @@ func (m *StdSignDocBase) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthCodec } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthCodec } if postIndex > l { return io.ErrUnexpectedEOF } - m.Memo = string(dAtA[iNdEx:postIndex]) + v := &types1.PeriodicVestingAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &Account_PeriodicVestingAccount{v} iNdEx = postIndex case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ModuleAccount", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -3807,9 +656,11 @@ func (m *StdSignDocBase) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Fee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + v := &types.ModuleAccount{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } + m.Sum = &Account_ModuleAccount{v} iNdEx = postIndex default: iNdEx = preIndex diff --git a/std/codec.proto b/std/codec.proto index ca0cf869a7db..2a232237ebb4 100644 --- a/std/codec.proto +++ b/std/codec.proto @@ -2,16 +2,8 @@ syntax = "proto3"; package cosmos_sdk.std.v1; import "third_party/proto/cosmos-proto/cosmos.proto"; -import "third_party/proto/gogoproto/gogo.proto"; -import "types/types.proto"; import "x/auth/types/types.proto"; import "x/auth/vesting/types/types.proto"; -import "x/bank/types/types.proto"; -import "x/crisis/types/types.proto"; -import "x/distribution/types/types.proto"; -import "x/gov/types/types.proto"; -import "x/slashing/types/types.proto"; -import "x/staking/types/types.proto"; option go_package = "github.com/cosmos/cosmos-sdk/std"; From e6d1ff30432d981acb905943cf117fc2679d33f9 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 12:37:39 -0400 Subject: [PATCH 36/48] Fix mocks --- tests/mocks/types_module_module.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go index 274ac5c0636b..0d52cde999c6 100644 --- a/tests/mocks/types_module_module.go +++ b/tests/mocks/types_module_module.go @@ -106,7 +106,7 @@ func (mr *MockAppModuleBasicMockRecorder) RegisterRESTRoutes(arg0, arg1 interfac } // GetTxCmd mocks base method -func (m *MockAppModuleBasic) GetTxCmd(arg0 *codec.Codec) *cobra.Command { +func (m *MockAppModuleBasic) GetTxCmd(arg0 context.CLIContext) *cobra.Command { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetTxCmd", arg0) ret0, _ := ret[0].(*cobra.Command) @@ -223,7 +223,7 @@ func (mr *MockAppModuleGenesisMockRecorder) RegisterRESTRoutes(arg0, arg1 interf } // GetTxCmd mocks base method -func (m *MockAppModuleGenesis) GetTxCmd(arg0 *codec.Codec) *cobra.Command { +func (m *MockAppModuleGenesis) GetTxCmd(arg0 context.CLIContext) *cobra.Command { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetTxCmd", arg0) ret0, _ := ret[0].(*cobra.Command) @@ -368,7 +368,7 @@ func (mr *MockAppModuleMockRecorder) RegisterRESTRoutes(arg0, arg1 interface{}) } // GetTxCmd mocks base method -func (m *MockAppModule) GetTxCmd(arg0 *codec.Codec) *cobra.Command { +func (m *MockAppModule) GetTxCmd(arg0 context.CLIContext) *cobra.Command { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetTxCmd", arg0) ret0, _ := ret[0].(*cobra.Command) From 06ceb4264a2f2992cecf75901fd91c2cfabbeaa6 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 13:50:54 -0400 Subject: [PATCH 37/48] Fix tests --- x/distribution/client/cli/tx.go | 31 ++++++++++++++++++++++++++++ x/distribution/client/cli/tx_test.go | 27 +++--------------------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index b0e328d661ab..d050387cef85 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -299,3 +299,34 @@ Where proposal.json contains: return cmd } + +type generateOrBroadcastFunc func(context.CLIContext, []sdk.Msg) error + +func splitAndApply( + generateOrBroadcast generateOrBroadcastFunc, + cliCtx context.CLIContext, + msgs []sdk.Msg, + chunkSize int, +) error { + + if chunkSize == 0 { + return generateOrBroadcast(cliCtx, msgs) + } + + // split messages into slices of length chunkSize + totalMessages := len(msgs) + for i := 0; i < len(msgs); i += chunkSize { + + sliceEnd := i + chunkSize + if sliceEnd > totalMessages { + sliceEnd = totalMessages + } + + msgChunk := msgs[i:sliceEnd] + if err := generateOrBroadcast(cliCtx, msgChunk); err != nil { + return err + } + } + + return nil +} diff --git a/x/distribution/client/cli/tx_test.go b/x/distribution/client/cli/tx_test.go index d75f44836773..f07478a54662 100644 --- a/x/distribution/client/cli/tx_test.go +++ b/x/distribution/client/cli/tx_test.go @@ -12,37 +12,17 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth" - authclient "github.com/cosmos/cosmos-sdk/x/auth/client" ) -func createFakeTxBuilder() auth.TxBuilder { - cdc := codec.New() - return auth.NewTxBuilder( - authclient.GetTxEncoder(cdc), - 123, - 9876, - 0, - 1.2, - false, - "test_chain", - "hello", - sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1))), - sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDecWithPrec(10000, sdk.Precision))}, - ) -} - func Test_splitAndCall_NoMessages(t *testing.T) { ctx := context.CLIContext{} - txBldr := createFakeTxBuilder() - err := splitAndApply(nil, ctx, txBldr, nil, 10) + err := splitAndApply(nil, ctx, nil, 10) assert.NoError(t, err, "") } func Test_splitAndCall_Splitting(t *testing.T) { ctx := context.CLIContext{} - txBldr := createFakeTxBuilder() addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) @@ -60,11 +40,10 @@ func Test_splitAndCall_Splitting(t *testing.T) { callCount := 0 err := splitAndApply( - func(ctx context.CLIContext, txBldr auth.TxBuilder, msgs []sdk.Msg) error { + func(ctx context.CLIContext, msgs []sdk.Msg) error { callCount++ assert.NotNil(t, ctx) - assert.NotNil(t, txBldr) assert.NotNil(t, msgs) if callCount < 3 { @@ -75,7 +54,7 @@ func Test_splitAndCall_Splitting(t *testing.T) { return nil }, - ctx, txBldr, msgs, chunkSize) + ctx, msgs, chunkSize) assert.NoError(t, err, "") assert.Equal(t, 3, callCount) From 0632d70fac17520363a50ac78753d1ed734b28be Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 13:56:05 -0400 Subject: [PATCH 38/48] Lint fixes --- x/distribution/client/rest/rest.go | 2 +- x/distribution/client/rest/tx.go | 25 +++++++++++-------------- x/gov/client/rest/rest.go | 2 +- x/gov/client/rest/tx.go | 14 +++++++------- x/staking/client/rest/rest.go | 2 +- x/staking/client/rest/tx.go | 14 +++++++------- 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/x/distribution/client/rest/rest.go b/x/distribution/client/rest/rest.go index bfba66c24ea7..d0cea36279c7 100644 --- a/x/distribution/client/rest/rest.go +++ b/x/distribution/client/rest/rest.go @@ -17,7 +17,7 @@ import ( func RegisterHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { registerQueryRoutes(cliCtx, r) - registerTxHandlers(cliCtx, m, txg, r) + registerTxHandlers(cliCtx, m, r) } // RegisterRoutes register distribution REST routes. diff --git a/x/distribution/client/rest/tx.go b/x/distribution/client/rest/tx.go index 0e67e92e3a94..bdb3880565ef 100644 --- a/x/distribution/client/rest/tx.go +++ b/x/distribution/client/rest/tx.go @@ -31,41 +31,40 @@ type ( } ) -func registerTxHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { +func registerTxHandlers(cliCtx context.CLIContext, m codec.Marshaler, r *mux.Router) { // Withdraw all delegator rewards r.HandleFunc( "/distribution/delegators/{delegatorAddr}/rewards", - newWithdrawDelegatorRewardsHandlerFn(cliCtx, m, txg), + newWithdrawDelegatorRewardsHandlerFn(cliCtx), ).Methods("POST") // Withdraw delegation rewards r.HandleFunc( "/distribution/delegators/{delegatorAddr}/rewards/{validatorAddr}", - newWithdrawDelegationRewardsHandlerFn(cliCtx, m, txg), + newWithdrawDelegationRewardsHandlerFn(cliCtx), ).Methods("POST") // Replace the rewards withdrawal address r.HandleFunc( "/distribution/delegators/{delegatorAddr}/withdraw_address", - newSetDelegatorWithdrawalAddrHandlerFn(cliCtx, m, txg), + newSetDelegatorWithdrawalAddrHandlerFn(cliCtx), ).Methods("POST") // Withdraw validator rewards and commission r.HandleFunc( "/distribution/validators/{validatorAddr}/rewards", - newWithdrawValidatorRewardsHandlerFn(cliCtx, m, txg), + newWithdrawValidatorRewardsHandlerFn(cliCtx, m), ).Methods("POST") // Fund the community pool r.HandleFunc( "/distribution/community_pool", - newFundCommunityPoolHandlerFn(cliCtx, m, txg), + newFundCommunityPoolHandlerFn(cliCtx, m), ).Methods("POST") } -func newWithdrawDelegatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { +func newWithdrawDelegatorRewardsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithJSONMarshaler(m) var req withdrawRewardsReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return @@ -91,9 +90,8 @@ func newWithdrawDelegatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Mar } } -func newWithdrawDelegationRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { +func newWithdrawDelegationRewardsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithJSONMarshaler(m) var req withdrawRewardsReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return @@ -124,9 +122,8 @@ func newWithdrawDelegationRewardsHandlerFn(cliCtx context.CLIContext, m codec.Ma } } -func newSetDelegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { +func newSetDelegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithJSONMarshaler(m) var req setWithdrawalAddrReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return @@ -152,7 +149,7 @@ func newSetDelegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, m codec.M } } -func newWithdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { +func newWithdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithJSONMarshaler(m) var req withdrawRewardsReq @@ -181,7 +178,7 @@ func newWithdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Mar } } -func newFundCommunityPoolHandlerFn(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator) http.HandlerFunc { +func newFundCommunityPoolHandlerFn(cliCtx context.CLIContext, m codec.Marshaler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithJSONMarshaler(m) var req fundCommunityPoolReq diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index a9e0a3e62f48..983d5f2af870 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -37,7 +37,7 @@ func RegisterHandlers( newMsgFn func() types.MsgSubmitProposalI, phs []ProposalRESTHandler) { registerQueryRoutes(cliCtx, r) - registerTxHandlers(cliCtx, txg, r, newMsgFn, phs) + registerTxHandlers(cliCtx, r, newMsgFn, phs) } // RegisterRoutes - Central function to define routes that get registered by the main application diff --git a/x/gov/client/rest/tx.go b/x/gov/client/rest/tx.go index 7ff526703468..1d2d1133edd4 100644 --- a/x/gov/client/rest/tx.go +++ b/x/gov/client/rest/tx.go @@ -15,18 +15,18 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" ) -func registerTxHandlers(cliCtx context.CLIContext, txg context.TxGenerator, r *mux.Router, newMsgFn func() types.MsgSubmitProposalI, phs []ProposalRESTHandler) { +func registerTxHandlers(cliCtx context.CLIContext, r *mux.Router, newMsgFn func() types.MsgSubmitProposalI, phs []ProposalRESTHandler) { propSubRtr := r.PathPrefix("/gov/proposals").Subrouter() for _, ph := range phs { propSubRtr.HandleFunc(fmt.Sprintf("/%s", ph.SubRoute), ph.Handler).Methods("POST") } - r.HandleFunc("/gov/proposals", newPostProposalHandlerFn(cliCtx, txg, newMsgFn)).Methods("POST") - r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), newDepositHandlerFn(cliCtx, txg)).Methods("POST") - r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), newVoteHandlerFn(cliCtx, txg)).Methods("POST") + r.HandleFunc("/gov/proposals", newPostProposalHandlerFn(cliCtx, newMsgFn)).Methods("POST") + r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), newDepositHandlerFn(cliCtx)).Methods("POST") + r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), newVoteHandlerFn(cliCtx)).Methods("POST") } -func newPostProposalHandlerFn(cliCtx context.CLIContext, txg context.TxGenerator, newMsgFn func() types.MsgSubmitProposalI) http.HandlerFunc { +func newPostProposalHandlerFn(cliCtx context.CLIContext, newMsgFn func() types.MsgSubmitProposalI) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req PostProposalReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { @@ -56,7 +56,7 @@ func newPostProposalHandlerFn(cliCtx context.CLIContext, txg context.TxGenerator } } -func newDepositHandlerFn(cliCtx context.CLIContext, txg context.TxGenerator) http.HandlerFunc { +func newDepositHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] @@ -91,7 +91,7 @@ func newDepositHandlerFn(cliCtx context.CLIContext, txg context.TxGenerator) htt } } -func newVoteHandlerFn(cliCtx context.CLIContext, txg context.TxGenerator) http.HandlerFunc { +func newVoteHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) strProposalID := vars[RestProposalID] diff --git a/x/staking/client/rest/rest.go b/x/staking/client/rest/rest.go index f58ed0d9626d..fad78a752e5d 100644 --- a/x/staking/client/rest/rest.go +++ b/x/staking/client/rest/rest.go @@ -9,7 +9,7 @@ import ( func RegisterHandlers(cliCtx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator, r *mux.Router) { registerQueryRoutes(cliCtx, r) - registerTxHandlers(cliCtx, m, txg, r) + registerTxHandlers(cliCtx, m, r) } // RegisterRoutes registers staking-related REST handlers to a router diff --git a/x/staking/client/rest/tx.go b/x/staking/client/rest/tx.go index 6eda2925410c..2aa792fe3a3a 100644 --- a/x/staking/client/rest/tx.go +++ b/x/staking/client/rest/tx.go @@ -15,18 +15,18 @@ import ( "github.com/cosmos/cosmos-sdk/x/staking/types" ) -func registerTxHandlers(cliCtx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator, r *mux.Router) { +func registerTxHandlers(cliCtx context.CLIContext, m codec.JSONMarshaler, r *mux.Router) { r.HandleFunc( "/staking/delegators/{delegatorAddr}/delegations", - newPostDelegationsHandlerFn(cliCtx, m, txg), + newPostDelegationsHandlerFn(cliCtx, m), ).Methods("POST") r.HandleFunc( "/staking/delegators/{delegatorAddr}/unbonding_delegations", - newPostUnbondingDelegationsHandlerFn(cliCtx, m, txg), + newPostUnbondingDelegationsHandlerFn(cliCtx, m), ).Methods("POST") r.HandleFunc( "/staking/delegators/{delegatorAddr}/redelegations", - newPostRedelegationsHandlerFn(cliCtx, m, txg), + newPostRedelegationsHandlerFn(cliCtx, m), ).Methods("POST") } @@ -57,7 +57,7 @@ type ( } ) -func newPostDelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator) http.HandlerFunc { +func newPostDelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshaler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithJSONMarshaler(m) @@ -90,7 +90,7 @@ func newPostDelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshale } } -func newPostRedelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator) http.HandlerFunc { +func newPostRedelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshaler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithJSONMarshaler(m) @@ -123,7 +123,7 @@ func newPostRedelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarsha } } -func newPostUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator) http.HandlerFunc { +func newPostUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshaler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { cliCtx = cliCtx.WithJSONMarshaler(m) From 0eb278c93874e20504a7b066b126348f08ecb3b1 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 14:03:43 -0400 Subject: [PATCH 39/48] REST tx migration --- x/bank/client/rest/rest.go | 2 ++ x/bank/module.go | 2 +- x/distribution/client/rest/rest.go | 5 ++--- x/distribution/client/rest/tx.go | 13 +++++-------- x/distribution/module.go | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/x/bank/client/rest/rest.go b/x/bank/client/rest/rest.go index f9fec1e38450..28bdec6907b6 100644 --- a/x/bank/client/rest/rest.go +++ b/x/bank/client/rest/rest.go @@ -11,6 +11,8 @@ import ( func RegisterHandlers(ctx context.CLIContext, r *mux.Router) { r.HandleFunc("/bank/accounts/{address}/transfers", NewSendRequestHandlerFn(ctx)).Methods("POST") r.HandleFunc("/bank/balances/{address}", QueryBalancesRequestHandlerFn(ctx)).Methods("GET") + r.HandleFunc("/bank/total", totalSupplyHandlerFn(ctx)).Methods("GET") + r.HandleFunc("/bank/total/{denom}", supplyOfHandlerFn(ctx)).Methods("GET") } // --------------------------------------------------------------------------- diff --git a/x/bank/module.go b/x/bank/module.go index 3aeec566e689..71721fb65800 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -58,7 +58,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessag // RegisterRESTRoutes registers the REST routes for the bank module. func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { - rest.RegisterRoutes(ctx, rtr) + rest.RegisterHandlers(ctx, rtr) } // GetTxCmd returns the root tx command for the bank module. diff --git a/x/distribution/client/rest/rest.go b/x/distribution/client/rest/rest.go index d0cea36279c7..a1db89d41dd1 100644 --- a/x/distribution/client/rest/rest.go +++ b/x/distribution/client/rest/rest.go @@ -6,7 +6,6 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" @@ -15,9 +14,9 @@ import ( govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" ) -func RegisterHandlers(cliCtx context.CLIContext, m codec.Marshaler, txg context.TxGenerator, r *mux.Router) { +func RegisterHandlers(cliCtx context.CLIContext, r *mux.Router) { registerQueryRoutes(cliCtx, r) - registerTxHandlers(cliCtx, m, r) + registerTxHandlers(cliCtx, r) } // RegisterRoutes register distribution REST routes. diff --git a/x/distribution/client/rest/tx.go b/x/distribution/client/rest/tx.go index bdb3880565ef..86d6d0d4b2be 100644 --- a/x/distribution/client/rest/tx.go +++ b/x/distribution/client/rest/tx.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" @@ -31,7 +30,7 @@ type ( } ) -func registerTxHandlers(cliCtx context.CLIContext, m codec.Marshaler, r *mux.Router) { +func registerTxHandlers(cliCtx context.CLIContext, r *mux.Router) { // Withdraw all delegator rewards r.HandleFunc( "/distribution/delegators/{delegatorAddr}/rewards", @@ -53,13 +52,13 @@ func registerTxHandlers(cliCtx context.CLIContext, m codec.Marshaler, r *mux.Rou // Withdraw validator rewards and commission r.HandleFunc( "/distribution/validators/{validatorAddr}/rewards", - newWithdrawValidatorRewardsHandlerFn(cliCtx, m), + newWithdrawValidatorRewardsHandlerFn(cliCtx), ).Methods("POST") // Fund the community pool r.HandleFunc( "/distribution/community_pool", - newFundCommunityPoolHandlerFn(cliCtx, m), + newFundCommunityPoolHandlerFn(cliCtx), ).Methods("POST") } @@ -149,9 +148,8 @@ func newSetDelegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext) http.Hand } } -func newWithdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Marshaler) http.HandlerFunc { +func newWithdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithJSONMarshaler(m) var req withdrawRewardsReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return @@ -178,9 +176,8 @@ func newWithdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext, m codec.Mar } } -func newFundCommunityPoolHandlerFn(cliCtx context.CLIContext, m codec.Marshaler) http.HandlerFunc { +func newFundCommunityPoolHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithJSONMarshaler(m) var req fundCommunityPoolReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return diff --git a/x/distribution/module.go b/x/distribution/module.go index aac9577c71ad..1a7206ce1b7c 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -62,7 +62,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessag // RegisterRESTRoutes registers the REST routes for the distribution module. func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { - rest.RegisterRoutes(ctx, rtr, StoreKey) + rest.RegisterHandlers(ctx, rtr) } // GetTxCmd returns the root tx command for the distribution module. From 4d9c9783f1c4ac94b8548904db1a7e5938c21969 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 14:11:02 -0400 Subject: [PATCH 40/48] Wire up REST --- simapp/cmd/simcli/main.go | 2 +- x/gov/client/rest/rest.go | 11 ++--------- x/gov/client/rest/tx.go | 11 ++++------- x/gov/module.go | 2 +- x/slashing/client/rest/rest.go | 5 ++--- x/slashing/client/rest/tx.go | 8 +++----- x/slashing/module.go | 2 +- x/staking/client/rest/rest.go | 5 ++--- x/staking/client/rest/tx.go | 21 +++++++-------------- x/staking/module.go | 2 +- 10 files changed, 24 insertions(+), 45 deletions(-) diff --git a/simapp/cmd/simcli/main.go b/simapp/cmd/simcli/main.go index a81c768d7e2a..0ae3f1c5dc5b 100644 --- a/simapp/cmd/simcli/main.go +++ b/simapp/cmd/simcli/main.go @@ -121,7 +121,7 @@ func txCmd(cdc *codec.Codec) *cobra.Command { cliCtx := context.CLIContext{} cliCtx = cliCtx. WithJSONMarshaler(appCodec). - WithTxGenerator(types.StdTxGenerator{cdc}). + WithTxGenerator(types.StdTxGenerator{Cdc: cdc}). WithAccountRetriever(types.NewAccountRetriever(appCodec)). WithCodec(cdc) diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index 983d5f2af870..f56222da7641 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -3,8 +3,6 @@ package rest import ( "net/http" - "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" @@ -30,14 +28,9 @@ type ProposalRESTHandler struct { Handler func(http.ResponseWriter, *http.Request) } -func RegisterHandlers( - cliCtx context.CLIContext, - txg context.TxGenerator, - r *mux.Router, - newMsgFn func() types.MsgSubmitProposalI, - phs []ProposalRESTHandler) { +func RegisterHandlers(cliCtx context.CLIContext, r *mux.Router, phs []ProposalRESTHandler) { registerQueryRoutes(cliCtx, r) - registerTxHandlers(cliCtx, r, newMsgFn, phs) + registerTxHandlers(cliCtx, r, phs) } // RegisterRoutes - Central function to define routes that get registered by the main application diff --git a/x/gov/client/rest/tx.go b/x/gov/client/rest/tx.go index 1d2d1133edd4..e40f107cf8fe 100644 --- a/x/gov/client/rest/tx.go +++ b/x/gov/client/rest/tx.go @@ -15,18 +15,18 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" ) -func registerTxHandlers(cliCtx context.CLIContext, r *mux.Router, newMsgFn func() types.MsgSubmitProposalI, phs []ProposalRESTHandler) { +func registerTxHandlers(cliCtx context.CLIContext, r *mux.Router, phs []ProposalRESTHandler) { propSubRtr := r.PathPrefix("/gov/proposals").Subrouter() for _, ph := range phs { propSubRtr.HandleFunc(fmt.Sprintf("/%s", ph.SubRoute), ph.Handler).Methods("POST") } - r.HandleFunc("/gov/proposals", newPostProposalHandlerFn(cliCtx, newMsgFn)).Methods("POST") + r.HandleFunc("/gov/proposals", newPostProposalHandlerFn(cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), newDepositHandlerFn(cliCtx)).Methods("POST") r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), newVoteHandlerFn(cliCtx)).Methods("POST") } -func newPostProposalHandlerFn(cliCtx context.CLIContext, newMsgFn func() types.MsgSubmitProposalI) http.HandlerFunc { +func newPostProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req PostProposalReq if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { @@ -41,13 +41,10 @@ func newPostProposalHandlerFn(cliCtx context.CLIContext, newMsgFn func() types.M proposalType := gcutils.NormalizeProposalType(req.ProposalType) content := types.ContentFromProposalType(req.Title, req.Description, proposalType) - msg := newMsgFn() - err := msg.SetContent(content) + msg, err := types.NewMsgSubmitProposal(content, req.InitialDeposit, req.Proposer) if rest.CheckBadRequestError(w, err) { return } - msg.SetInitialDeposit(req.InitialDeposit) - msg.SetProposer(req.Proposer) if rest.CheckBadRequestError(w, msg.ValidateBasic()) { return } diff --git a/x/gov/module.go b/x/gov/module.go index 27b667b76c63..9a47a3c9cc17 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -78,7 +78,7 @@ func (a AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Rout proposalRESTHandlers = append(proposalRESTHandlers, proposalHandler.RESTHandler(ctx)) } - rest.RegisterRoutes(ctx, rtr, proposalRESTHandlers) + rest.RegisterHandlers(ctx, rtr, proposalRESTHandlers) } // GetTxCmd returns the root tx command for the gov module. diff --git a/x/slashing/client/rest/rest.go b/x/slashing/client/rest/rest.go index fc09a013b813..32515fbe4fbd 100644 --- a/x/slashing/client/rest/rest.go +++ b/x/slashing/client/rest/rest.go @@ -4,12 +4,11 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/codec" ) -func RegisterHandlers(ctx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator, r *mux.Router) { +func RegisterHandlers(ctx context.CLIContext, r *mux.Router) { registerQueryRoutes(ctx, r) - registerTxHandlers(ctx, m, txg, r) + registerTxHandlers(ctx, r) } // RegisterRoutes registers staking-related REST handlers to a router diff --git a/x/slashing/client/rest/tx.go b/x/slashing/client/rest/tx.go index d5146eec3175..e01536b3e39a 100644 --- a/x/slashing/client/rest/tx.go +++ b/x/slashing/client/rest/tx.go @@ -8,15 +8,14 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/slashing/types" ) -func registerTxHandlers(ctx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator, r *mux.Router) { - r.HandleFunc("/slashing/validators/{validatorAddr}/unjail", NewUnjailRequestHandlerFn(ctx, m, txg)).Methods("POST") +func registerTxHandlers(ctx context.CLIContext, r *mux.Router) { + r.HandleFunc("/slashing/validators/{validatorAddr}/unjail", NewUnjailRequestHandlerFn(ctx)).Methods("POST") } // Unjail TX body @@ -26,9 +25,8 @@ type UnjailReq struct { // NewUnjailRequestHandlerFn returns an HTTP REST handler for creating a MsgUnjail // transaction. -func NewUnjailRequestHandlerFn(ctx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator) http.HandlerFunc { +func NewUnjailRequestHandlerFn(ctx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - ctx = ctx.WithJSONMarshaler(m) vars := mux.Vars(r) bech32Validator := vars["validatorAddr"] diff --git a/x/slashing/module.go b/x/slashing/module.go index 4cdf540016f5..0bc65c296c1d 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -63,7 +63,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessag // RegisterRESTRoutes registers the REST routes for the slashing module. func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { - rest.RegisterRoutes(ctx, rtr) + rest.RegisterHandlers(ctx, rtr) } // GetTxCmd returns the root tx command for the slashing module. diff --git a/x/staking/client/rest/rest.go b/x/staking/client/rest/rest.go index fad78a752e5d..e112341e9f84 100644 --- a/x/staking/client/rest/rest.go +++ b/x/staking/client/rest/rest.go @@ -4,12 +4,11 @@ import ( "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/codec" ) -func RegisterHandlers(cliCtx context.CLIContext, m codec.JSONMarshaler, txg context.TxGenerator, r *mux.Router) { +func RegisterHandlers(cliCtx context.CLIContext, r *mux.Router) { registerQueryRoutes(cliCtx, r) - registerTxHandlers(cliCtx, m, r) + registerTxHandlers(cliCtx, r) } // RegisterRoutes registers staking-related REST handlers to a router diff --git a/x/staking/client/rest/tx.go b/x/staking/client/rest/tx.go index 2aa792fe3a3a..965cf3da470b 100644 --- a/x/staking/client/rest/tx.go +++ b/x/staking/client/rest/tx.go @@ -8,25 +8,24 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/cosmos/cosmos-sdk/x/staking/types" ) -func registerTxHandlers(cliCtx context.CLIContext, m codec.JSONMarshaler, r *mux.Router) { +func registerTxHandlers(cliCtx context.CLIContext, r *mux.Router) { r.HandleFunc( "/staking/delegators/{delegatorAddr}/delegations", - newPostDelegationsHandlerFn(cliCtx, m), + newPostDelegationsHandlerFn(cliCtx), ).Methods("POST") r.HandleFunc( "/staking/delegators/{delegatorAddr}/unbonding_delegations", - newPostUnbondingDelegationsHandlerFn(cliCtx, m), + newPostUnbondingDelegationsHandlerFn(cliCtx), ).Methods("POST") r.HandleFunc( "/staking/delegators/{delegatorAddr}/redelegations", - newPostRedelegationsHandlerFn(cliCtx, m), + newPostRedelegationsHandlerFn(cliCtx), ).Methods("POST") } @@ -57,10 +56,8 @@ type ( } ) -func newPostDelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshaler) http.HandlerFunc { +func newPostDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithJSONMarshaler(m) - var req DelegateRequest if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return @@ -90,10 +87,8 @@ func newPostDelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshale } } -func newPostRedelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshaler) http.HandlerFunc { +func newPostRedelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithJSONMarshaler(m) - var req RedelegateRequest if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return @@ -123,10 +118,8 @@ func newPostRedelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarsha } } -func newPostUnbondingDelegationsHandlerFn(cliCtx context.CLIContext, m codec.JSONMarshaler) http.HandlerFunc { +func newPostUnbondingDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - cliCtx = cliCtx.WithJSONMarshaler(m) - var req UndelegateRequest if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) { return diff --git a/x/staking/module.go b/x/staking/module.go index 174575181ecc..4d6c9fc6f81f 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -66,7 +66,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, bz json.RawMessag // RegisterRESTRoutes registers the REST routes for the staking module. func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { - rest.RegisterRoutes(ctx, rtr) + rest.RegisterHandlers(ctx, rtr) } // GetTxCmd returns the root tx command for the staking module. From 4ac82f04622d6c959b9181504e8dc78ceeeab92d Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 14:14:36 -0400 Subject: [PATCH 41/48] Linting --- x/params/client/cli/query.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/params/client/cli/query.go b/x/params/client/cli/query.go index 2c98f8638761..2db58147287f 100644 --- a/x/params/client/cli/query.go +++ b/x/params/client/cli/query.go @@ -13,7 +13,7 @@ import ( ) // NewQueryCmd returns a root CLI command handler for all x/params query commands. -func NewQueryCmd(m codec.Marshaler) *cobra.Command { +func NewQueryCmd(m codec.JSONMarshaler) *cobra.Command { cmd := &cobra.Command{ Use: types.ModuleName, Short: "Querying commands for the params module", @@ -29,7 +29,7 @@ func NewQueryCmd(m codec.Marshaler) *cobra.Command { // NewQuerySubspaceParamsCmd returns a CLI command handler for querying subspace // parameters managed by the x/params module. -func NewQuerySubspaceParamsCmd(m codec.Marshaler) *cobra.Command { +func NewQuerySubspaceParamsCmd(m codec.JSONMarshaler) *cobra.Command { cmd := &cobra.Command{ Use: "subspace [subspace] [key]", Short: "Query for raw parameters by subspace and key", From 753b792a2a34720058801d2a3749441552287d80 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 14:27:14 -0400 Subject: [PATCH 42/48] Update CHANGELOG, docs --- CHANGELOG.md | 3 ++- docs/building-modules/module-interfaces.md | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b582419f2ac..7505439f31b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,7 +102,8 @@ ALL legacy code should use `*codec.Codec` instead of `*amino.Codec` directly * (x/gov) [\#6147](https://github.com/cosmos/cosmos-sdk/pull/6147) The `Content` field on `Proposal` and `MsgSubmitProposal` is now `Any` in concordance with [ADR 019](docs/architecture/adr-019-protobuf-state-encoding.md) and `GetContent` should now be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposal` constructor now may return an `error` -* (x/auth) All `AccountRetriever` methods now take `NodeQuerier` as a parameter instead of as a struct member +* (modules) [\#5989](https://github.com/cosmos/cosmos-sdk/pull/5989) `AppModuleBasic.GetTxCmd` now takes a single `CLIContext` parameter +* (x/auth) [\#5989](https://github.com/cosmos/cosmos-sdk/pull/5989) All `AccountRetriever` methods now take `NodeQuerier` as a parameter instead of as a struct member ### Features diff --git a/docs/building-modules/module-interfaces.md b/docs/building-modules/module-interfaces.md index 442777b3a9d1..23bc49d32841 100644 --- a/docs/building-modules/module-interfaces.md +++ b/docs/building-modules/module-interfaces.md @@ -30,11 +30,11 @@ This getter function creates the command for the Buy Name transaction. It does t + **Short and Long:** A description for the function is provided here. A `Short` description is expected, and `Long` can be used to provide a more detailed description when a user uses the `--help` flag to ask for more information. + **RunE:** Defines a function that can return an error, called when the command is executed. Using `Run` would do the same thing, but would not allow for errors to be returned. - **`RunE` Function Body:** The function should be specified as a `RunE` to allow for errors to be returned. This function encapsulates all of the logic to create a new transaction that is ready to be relayed to nodes. - + The function should first initialize a [`TxBuilder`](../core/transactions.md#txbuilder) with the application `codec`'s `TxEncoder`, as well as a new [`CLIContext`](../interfaces/query-lifecycle.md#clicontext) with the `codec` and `AccountDecoder`. These contexts contain all the information provided by the user and will be used to transfer this user-specific information between processes. To learn more about how contexts are used in a transaction, click [here](../core/transactions.md#transaction-generation). + + The function should first re-initialize the `CLIContext` that was passed in using one of the `CLIContext.InitXXX` methods. + If applicable, the command's arguments are parsed. Here, the `amount` given by the user is parsed into a denomination of `coins`. + If applicable, the `CLIContext` is used to retrieve any parameters such as the transaction originator's address to be used in the transaction. Here, the `from` address is retrieved by calling `cliCtx.getFromAddress()`. + A [message](./messages-and-queries.md) is created using all parameters parsed from the command arguments and `CLIContext`. The constructor function of the specific message type is called directly. It is good practice to call `ValidateBasic()` on the newly created message to run a sanity check and check for invalid arguments. - + Depending on what the user wants, the transaction is either generated offline or signed and broadcasted to the preconfigured node using `GenerateOrBroadcastMsgs()`. + + Depending on what the user wants, the transaction is either generated offline or signed and broadcasted to the preconfigured node using `GenerateOrBroadcastTx()`. - **Flags.** Add any [flags](#flags) to the command. No flags were specified here, but all transaction commands have flags to provide additional information from the user (e.g. amount of fees they are willing to pay). These *persistent* [transaction flags](../interfaces/cli.md#flags) can be added to a higher-level command so that they apply to all transaction commands. Finally, the module needs to have a `GetTxCmd()`, which aggregates all of the transaction commands of the module. Often, each command getter function has its own file in the module's `cli` folder, and a separate `tx.go` file contains `GetTxCmd()`. Application developers wishing to include the module's transactions will call this function to add them as subcommands in their CLI. Here is the `auth` `GetTxCmd()` function, which adds the `Sign` and `MultiSign` commands. From 4ffd783d2d19eead965f8318da92b71e54552b93 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 14:55:04 -0400 Subject: [PATCH 43/48] Fix tests --- docs/building-modules/module-interfaces.md | 4 ++-- types/module/module_test.go | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/building-modules/module-interfaces.md b/docs/building-modules/module-interfaces.md index 23bc49d32841..442777b3a9d1 100644 --- a/docs/building-modules/module-interfaces.md +++ b/docs/building-modules/module-interfaces.md @@ -30,11 +30,11 @@ This getter function creates the command for the Buy Name transaction. It does t + **Short and Long:** A description for the function is provided here. A `Short` description is expected, and `Long` can be used to provide a more detailed description when a user uses the `--help` flag to ask for more information. + **RunE:** Defines a function that can return an error, called when the command is executed. Using `Run` would do the same thing, but would not allow for errors to be returned. - **`RunE` Function Body:** The function should be specified as a `RunE` to allow for errors to be returned. This function encapsulates all of the logic to create a new transaction that is ready to be relayed to nodes. - + The function should first re-initialize the `CLIContext` that was passed in using one of the `CLIContext.InitXXX` methods. + + The function should first initialize a [`TxBuilder`](../core/transactions.md#txbuilder) with the application `codec`'s `TxEncoder`, as well as a new [`CLIContext`](../interfaces/query-lifecycle.md#clicontext) with the `codec` and `AccountDecoder`. These contexts contain all the information provided by the user and will be used to transfer this user-specific information between processes. To learn more about how contexts are used in a transaction, click [here](../core/transactions.md#transaction-generation). + If applicable, the command's arguments are parsed. Here, the `amount` given by the user is parsed into a denomination of `coins`. + If applicable, the `CLIContext` is used to retrieve any parameters such as the transaction originator's address to be used in the transaction. Here, the `from` address is retrieved by calling `cliCtx.getFromAddress()`. + A [message](./messages-and-queries.md) is created using all parameters parsed from the command arguments and `CLIContext`. The constructor function of the specific message type is called directly. It is good practice to call `ValidateBasic()` on the newly created message to run a sanity check and check for invalid arguments. - + Depending on what the user wants, the transaction is either generated offline or signed and broadcasted to the preconfigured node using `GenerateOrBroadcastTx()`. + + Depending on what the user wants, the transaction is either generated offline or signed and broadcasted to the preconfigured node using `GenerateOrBroadcastMsgs()`. - **Flags.** Add any [flags](#flags) to the command. No flags were specified here, but all transaction commands have flags to provide additional information from the user (e.g. amount of fees they are willing to pay). These *persistent* [transaction flags](../interfaces/cli.md#flags) can be added to a higher-level command so that they apply to all transaction commands. Finally, the module needs to have a `GetTxCmd()`, which aggregates all of the transaction commands of the module. Often, each command getter function has its own file in the module's `cli` folder, and a separate `tx.go` file contains `GetTxCmd()`. Application developers wishing to include the module's transactions will call this function to add them as subcommands in their CLI. Here is the `auth` `GetTxCmd()` function, which adds the `Sign` and `MultiSign` commands. diff --git a/types/module/module_test.go b/types/module/module_test.go index fa5b17ab35e0..1f5e1f247bb0 100644 --- a/types/module/module_test.go +++ b/types/module/module_test.go @@ -24,6 +24,8 @@ func TestBasicManager(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) cdc := codec.New() + ctx := context.CLIContext{} + ctx = ctx.WithCodec(cdc) wantDefaultGenesis := map[string]json.RawMessage{"mockAppModuleBasic1": json.RawMessage(``)} mockAppModuleBasic1 := mocks.NewMockAppModuleBasic(mockCtrl) @@ -33,7 +35,7 @@ func TestBasicManager(t *testing.T) { mockAppModuleBasic1.EXPECT().ValidateGenesis(gomock.Eq(cdc), gomock.Eq(wantDefaultGenesis["mockAppModuleBasic1"])).Times(1).Return(errFoo) mockAppModuleBasic1.EXPECT().RegisterRESTRoutes(gomock.Eq(context.CLIContext{}), gomock.Eq(&mux.Router{})).Times(1) mockAppModuleBasic1.EXPECT().RegisterCodec(gomock.Eq(cdc)).Times(1) - mockAppModuleBasic1.EXPECT().GetTxCmd(cdc).Times(1).Return(nil) + mockAppModuleBasic1.EXPECT().GetTxCmd(ctx).Times(1).Return(nil) mockAppModuleBasic1.EXPECT().GetQueryCmd(cdc).Times(1).Return(nil) mm := module.NewBasicManager(mockAppModuleBasic1) @@ -51,7 +53,7 @@ func TestBasicManager(t *testing.T) { mm.RegisterRESTRoutes(context.CLIContext{}, &mux.Router{}) mockCmd := &cobra.Command{Use: "root"} - mm.AddTxCommands(mockCmd, cdc) + mm.AddTxCommands(mockCmd, ctx) mm.AddQueryCommands(mockCmd, cdc) From b5460b540788d07c048a9fa5520dd85c7936074e Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 20 May 2020 15:30:58 -0400 Subject: [PATCH 44/48] lint --- x/auth/types/account_retriever.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/auth/types/account_retriever.go b/x/auth/types/account_retriever.go index 87cb7254ef5f..90884b0a6017 100644 --- a/x/auth/types/account_retriever.go +++ b/x/auth/types/account_retriever.go @@ -3,15 +3,15 @@ package types import ( "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" ) // AccountRetriever defines the properties of a type that can be used to // retrieve accounts. type AccountRetriever struct { - codec codec.Marshaler + codec codec.Marshaler } // NewAccountRetriever initialises a new AccountRetriever instance. From 01f7f55c67ad192d8222d31c92b226e4795e7c32 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 15:11:25 -0400 Subject: [PATCH 45/48] Address review feedback --- client/context/account_retriever.go | 2 +- client/context/tx_generator.go | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/client/context/account_retriever.go b/client/context/account_retriever.go index cd002ad4f5bf..595eadde91b5 100644 --- a/client/context/account_retriever.go +++ b/client/context/account_retriever.go @@ -7,7 +7,7 @@ import "github.com/cosmos/cosmos-sdk/types" // for signing. type AccountRetriever interface { EnsureExists(nodeQuerier NodeQuerier, addr types.AccAddress) error - GetAccountNumberSequence(nodeQuerier NodeQuerier, addr types.AccAddress) (uint64, uint64, error) + GetAccountNumberSequence(nodeQuerier NodeQuerier, addr types.AccAddress) (accNum uint64, accSeq uint64, err error) } // NodeQuerier is an interface that is satisfied by types that provide the QueryWithData method diff --git a/client/context/tx_generator.go b/client/context/tx_generator.go index 8dd2392bb986..ff023fcec06f 100644 --- a/client/context/tx_generator.go +++ b/client/context/tx_generator.go @@ -44,10 +44,8 @@ type ( GetMemo() string SetMemo(string) - // CanonicalSignBytes returns the canonical JSON bytes to sign over, given a - // chain ID, along with an account and sequence number. The JSON encoding - // ensures all field names adhere to their proto definition, default values - // are omitted, and follows the JSON Canonical Form. + // CanonicalSignBytes returns the canonical sign bytes to sign over, given a + // chain ID, along with an account and sequence number. CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error) } ) From 30b0c06b697be2fa6b083cecc27f45768a298ed1 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 17:03:57 -0400 Subject: [PATCH 46/48] Update CHANGELOG.md Co-authored-by: Alexander Bezobchuk --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf72196cb560..3f40110371c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,7 +103,7 @@ ALL legacy code should use `*codec.Codec` instead of `*amino.Codec` directly is now `Any` in concordance with [ADR 019](docs/architecture/adr-019-protobuf-state-encoding.md) and `GetContent` should now be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposal` constructor now may return an `error` * (modules) [\#5989](https://github.com/cosmos/cosmos-sdk/pull/5989) `AppModuleBasic.GetTxCmd` now takes a single `CLIContext` parameter -* (x/auth) [\#5989](https://github.com/cosmos/cosmos-sdk/pull/5989) All `AccountRetriever` methods now take `NodeQuerier` as a parameter instead of as a struct member +* (x/auth) [\#5989](https://github.com/cosmos/cosmos-sdk/pull/5989) All `AccountRetriever` methods now take `NodeQuerier` as a parameter instead of as a struct member. ### Features From 22f3b928f20814c701bfed4aa31b58a8ef065eec Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 17:04:13 -0400 Subject: [PATCH 47/48] Update CHANGELOG.md Co-authored-by: Alexander Bezobchuk --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f40110371c3..21fdc8bcf8c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,7 +102,7 @@ ALL legacy code should use `*codec.Codec` instead of `*amino.Codec` directly * (x/gov) [\#6147](https://github.com/cosmos/cosmos-sdk/pull/6147) The `Content` field on `Proposal` and `MsgSubmitProposal` is now `Any` in concordance with [ADR 019](docs/architecture/adr-019-protobuf-state-encoding.md) and `GetContent` should now be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposal` constructor now may return an `error` -* (modules) [\#5989](https://github.com/cosmos/cosmos-sdk/pull/5989) `AppModuleBasic.GetTxCmd` now takes a single `CLIContext` parameter +* (modules) [\#5989](https://github.com/cosmos/cosmos-sdk/pull/5989) `AppModuleBasic.GetTxCmd` now takes a single `CLIContext` parameter. * (x/auth) [\#5989](https://github.com/cosmos/cosmos-sdk/pull/5989) All `AccountRetriever` methods now take `NodeQuerier` as a parameter instead of as a struct member. ### Features From dd99d83e9cf658c612db8031b9792c752dcaef3e Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 21 May 2020 17:06:48 -0400 Subject: [PATCH 48/48] group vars --- client/context/context.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client/context/context.go b/client/context/context.go index 8a7d7bbf7f56..6ea912c84359 100644 --- a/client/context/context.go +++ b/client/context/context.go @@ -89,9 +89,11 @@ func NewCLIContextWithInput(input io.Reader) CLIContext { func (ctx CLIContext) InitWithInputAndFrom(input io.Reader, from string) CLIContext { input = bufio.NewReader(input) - var nodeURI string - var rpc rpcclient.Client - var err error + var ( + nodeURI string + rpc rpcclient.Client + err error + ) offline := viper.GetBool(flags.FlagOffline) if !offline {