From 962ed4b03791a90da91c7a27e06151ef7681f8f3 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 5 Nov 2024 11:19:51 +0100 Subject: [PATCH 01/52] add: printer --- client/v2/autocli/app.go | 18 ++++--- client/v2/autocli/builder.go | 3 ++ client/v2/autocli/common.go | 38 +++------------ client/v2/autocli/flag/address.go | 1 + client/v2/autocli/keyring/keyring.go | 5 +- client/v2/autocli/msg.go | 2 +- client/v2/autocli/print/printer.go | 72 ++++++++++++++++++++++++++++ client/v2/tx/tx.go | 37 +++++++------- 8 files changed, 119 insertions(+), 57 deletions(-) create mode 100644 client/v2/autocli/print/printer.go diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index ec793eee67fa..614966aab74d 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -7,11 +7,13 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli/flag" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" "github.com/cosmos/cosmos-sdk/client" sdkflags "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec/types" ) // AppOptions are autocli options for an app. These options can be built via depinject based on an app config. Ex: @@ -34,8 +36,10 @@ type AppOptions struct { // module or need to be improved. ModuleOptions map[string]*autocliv1.ModuleOptions `optional:"true"` - // ClientCtx contains the necessary information needed to execute the commands. - ClientCtx client.Context + InterfaceRegistry types.InterfaceRegistry + AddressCodec address.Codec + ValidatorAddressCodec address.Codec + ConsensusAddressCodec address.Codec } // EnhanceRootCommand enhances the provided root command with autocli AppOptions, @@ -57,13 +61,13 @@ func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error { builder := &Builder{ Builder: flag.Builder{ TypeResolver: protoregistry.GlobalTypes, - FileResolver: appOptions.ClientCtx.InterfaceRegistry, - AddressCodec: appOptions.ClientCtx.AddressCodec, - ValidatorAddressCodec: appOptions.ClientCtx.ValidatorAddressCodec, - ConsensusAddressCodec: appOptions.ClientCtx.ConsensusAddressCodec, + FileResolver: appOptions.InterfaceRegistry, + AddressCodec: appOptions.AddressCodec, + ValidatorAddressCodec: appOptions.ValidatorAddressCodec, + ConsensusAddressCodec: appOptions.ConsensusAddressCodec, }, GetClientConn: func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { - return client.GetClientQueryContext(cmd) + return client.GetClientQueryContext(cmd) // TODO: implement client/v2/grpcconn }, AddQueryConnFlags: sdkflags.AddQueryFlagsToCmd, AddTxConnFlags: sdkflags.AddTxFlagsToCmd, diff --git a/client/v2/autocli/builder.go b/client/v2/autocli/builder.go index 81604f0d810b..17db87da6615 100644 --- a/client/v2/autocli/builder.go +++ b/client/v2/autocli/builder.go @@ -1,6 +1,7 @@ package autocli import ( + "github.com/cosmos/cosmos-sdk/codec" "github.com/spf13/cobra" "google.golang.org/grpc" @@ -19,6 +20,8 @@ type Builder struct { // AddQueryConnFlags and AddTxConnFlags are functions that add flags to query and transaction commands AddQueryConnFlags func(*cobra.Command) AddTxConnFlags func(*cobra.Command) + + JSONCodec codec.JSONCodec } // ValidateAndComplete the builder fields. diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 5c32f16ca32a..4835c5136022 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -1,18 +1,13 @@ package autocli import ( - "fmt" - "strings" - - "github.com/spf13/cobra" - "google.golang.org/protobuf/reflect/protoreflect" - "sigs.k8s.io/yaml" - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" - - "github.com/cosmos/cosmos-sdk/client" + "fmt" + "github.com/spf13/cobra" + "google.golang.org/protobuf/reflect/protoreflect" ) type cmdType int @@ -228,27 +223,6 @@ func enhanceCustomCmd(builder *Builder, cmd *cobra.Command, cmdType cmdType, mod // outOrStdoutFormat formats the output based on the output flag and writes it to the command's output stream. func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error { - clientCtx := client.Context{} - if v := cmd.Context().Value(client.ClientContextKey); v != nil { - clientCtx = *(v.(*client.Context)) - } - flagSet := cmd.Flags() - if clientCtx.OutputFormat == "" || flagSet.Changed(flags.FlagOutput) { - output, _ := flagSet.GetString(flags.FlagOutput) - clientCtx = clientCtx.WithOutputFormat(output) - } - - var err error - outputType := clientCtx.OutputFormat - // if the output type is text, convert the json to yaml - // if output type is json or nil, default to json - if outputType == flags.OutputFormatText { - out, err = yaml.JSONToYAML(out) - if err != nil { - return err - } - } - - cmd.Println(strings.TrimSpace(string(out))) - return nil + output, _ := cmd.Flags().GetString(flags.FlagOutput) + return print.NewPrinter(output, cmd.OutOrStdout()).PrintBytes(out) } diff --git a/client/v2/autocli/flag/address.go b/client/v2/autocli/flag/address.go index 454c30a317dd..2e7133d4bd9a 100644 --- a/client/v2/autocli/flag/address.go +++ b/client/v2/autocli/flag/address.go @@ -147,6 +147,7 @@ func (a *consensusAddressValue) Set(s string) error { return nil } +// TODO: this should be deleted. Keyring should be obtain from flags func getKeyringFromCtx(ctx *context.Context) keyring.Keyring { dctx := *ctx if dctx != nil { diff --git a/client/v2/autocli/keyring/keyring.go b/client/v2/autocli/keyring/keyring.go index f5dce25efceb..9e9bdcc975ea 100644 --- a/client/v2/autocli/keyring/keyring.go +++ b/client/v2/autocli/keyring/keyring.go @@ -2,7 +2,6 @@ package keyring import ( "context" - signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "github.com/cosmos/cosmos-sdk/crypto/types" @@ -25,6 +24,10 @@ func NewKeyringInContext(ctx context.Context, k Keyring) context.Context { return context.WithValue(ctx, KeyringContextKey, NewKeyringImpl(k)) } +//func NewKeyringFromFlags(ctx context.Context, flagSet *pflag.FlagSet) (Keyring, error) { +// k := keyring.New(sdk.KeyringServiceName(), ) +//} + func NewKeyringImpl(k Keyring) *KeyringImpl { return &KeyringImpl{k: k} } diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index 9eb4f0444bba..fa9b665e1d76 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -194,7 +194,7 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor func (b *Builder) handleGovProposal( cmd *cobra.Command, input protoreflect.Message, - clientCtx client.Context, + clientCtx client.Context, // TODO: this could be just the address addressCodec addresscodec.Codec, fd protoreflect.FieldDescriptor, ) error { diff --git a/client/v2/autocli/print/printer.go b/client/v2/autocli/print/printer.go new file mode 100644 index 000000000000..eb570b27a31d --- /dev/null +++ b/client/v2/autocli/print/printer.go @@ -0,0 +1,72 @@ +package print + +import ( + "encoding/json" + "io" + "os" + + "sigs.k8s.io/yaml" +) + +const ( + jsonOutput = "json" + textOutput = "text" +) + +// Printer handles formatted output of different types of data +type Printer struct { + Output io.Writer + OutputFormat string +} + +// NewPrinter creates a new Printer instance with default stdout +func NewPrinter(format string, out io.Writer) *Printer { + if format == "" { + format = jsonOutput + } + + return &Printer{ + Output: out, + OutputFormat: format, + } +} + +// PrintString prints the raw string +func (p *Printer) PrintString(str string) error { + return p.PrintBytes([]byte(str)) +} + +// PrintRaw prints raw JSON message without marshaling +func (p *Printer) PrintRaw(toPrint json.RawMessage) error { + return p.PrintBytes(toPrint) +} + +// PrintBytes prints and formats bytes +func (p *Printer) PrintBytes(out []byte) error { + var err error + if p.OutputFormat == textOutput { + out, err = yaml.JSONToYAML(out) + if err != nil { + return err + } + } + + writer := p.Output + if writer == nil { + writer = os.Stdout + } + + _, err = writer.Write(out) + if err != nil { + return err + } + + if p.OutputFormat != textOutput { + _, err = writer.Write([]byte("\n")) + if err != nil { + return err + } + } + + return nil +} diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index ab82c813ac20..adbc81695bdb 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/pflag" apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/broadcast" "cosmossdk.io/client/v2/broadcast/comet" "cosmossdk.io/client/v2/internal/account" @@ -18,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/input" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" ) @@ -33,23 +35,27 @@ func GenerateOrBroadcastTxCLIWithBroadcaster(ctx client.Context, flagSet *pflag. return err } + output, _ := flagSet.GetString("output") + printer := print.NewPrinter(output, os.Stdout) + genOnly, _ := flagSet.GetBool(flagGenerateOnly) if genOnly { - return generateOnly(ctx, txf, msgs...) + return generateOnly(printer, txf, msgs...) } isDryRun, _ := flagSet.GetBool(flagDryRun) if isDryRun { - return dryRun(txf, msgs...) + return dryRun(printer, txf, msgs...) } - return BroadcastTx(ctx, txf, broadcaster, msgs...) + skipConfirm, _ := flagSet.GetBool("yes") + return BroadcastTx(printer, txf, broadcaster, skipConfirm, msgs...) } // GenerateOrBroadcastTxCLI will either generate and print an unsigned transaction // or sign it and broadcast it using default CometBFT broadcaster, returning an error upon failure. func GenerateOrBroadcastTxCLI(ctx client.Context, flagSet *pflag.FlagSet, msgs ...transaction.Msg) error { - cometBroadcaster, err := getCometBroadcaster(ctx, flagSet) + cometBroadcaster, err := getCometBroadcaster(ctx.Codec, flagSet) if err != nil { return err } @@ -58,10 +64,10 @@ func GenerateOrBroadcastTxCLI(ctx client.Context, flagSet *pflag.FlagSet, msgs . } // getCometBroadcaster returns a new CometBFT broadcaster based on the provided context and flag set. -func getCometBroadcaster(ctx client.Context, flagSet *pflag.FlagSet) (broadcast.Broadcaster, error) { +func getCometBroadcaster(cdc codec.JSONCodec, flagSet *pflag.FlagSet) (broadcast.Broadcaster, error) { url, _ := flagSet.GetString("node") mode, _ := flagSet.GetString("broadcast-mode") - return comet.NewCometBFTBroadcaster(url, mode, ctx.Codec) + return comet.NewCometBFTBroadcaster(url, mode, cdc) } // newFactory creates a new transaction Factory based on the provided context and flag set. @@ -115,25 +121,24 @@ func validateMessages(msgs ...transaction.Msg) error { // generateOnly prepares the transaction and prints the unsigned transaction string. // It first calls Prepare on the transaction factory to set up any necessary pre-conditions. // If preparation is successful, it generates an unsigned transaction string using the provided messages. -func generateOnly(ctx client.Context, txf Factory, msgs ...transaction.Msg) error { +func generateOnly(printer *print.Printer, txf Factory, msgs ...transaction.Msg) error { uTx, err := txf.UnsignedTxString(msgs...) if err != nil { return err } - return ctx.PrintString(uTx) + return printer.PrintString(uTx) } // dryRun performs a dry run of the transaction to estimate the gas required. // It prepares the transaction factory and simulates the transaction with the provided messages. -func dryRun(txf Factory, msgs ...transaction.Msg) error { +func dryRun(printer *print.Printer, txf Factory, msgs ...transaction.Msg) error { _, gas, err := txf.Simulate(msgs...) if err != nil { return err } - _, err = fmt.Fprintf(os.Stderr, "%s\n", GasEstimateResponse{GasEstimate: gas}) - return err + return printer.PrintString(fmt.Sprintf("%s\n", GasEstimateResponse{GasEstimate: gas})) } // SimulateTx simulates a tx and returns the simulation response obtained by the query. @@ -150,7 +155,7 @@ func SimulateTx(ctx client.Context, flagSet *pflag.FlagSet, msgs ...transaction. // BroadcastTx attempts to generate, sign and broadcast a transaction with the // given set of messages. It will also simulate gas requirements if necessary. // It will return an error upon failure. -func BroadcastTx(clientCtx client.Context, txf Factory, broadcaster broadcast.Broadcaster, msgs ...transaction.Msg) error { +func BroadcastTx(printer *print.Printer, txf Factory, broadcaster broadcast.Broadcaster, skipConfirm bool, msgs ...transaction.Msg) error { if txf.simulateAndExecute() { err := txf.calculateGas(msgs...) if err != nil { @@ -163,7 +168,7 @@ func BroadcastTx(clientCtx client.Context, txf Factory, broadcaster broadcast.Br return err } - if !clientCtx.SkipConfirm { + if !skipConfirm { encoder := txf.txConfig.TxJSONEncoder() if encoder == nil { return errors.New("failed to encode transaction: tx json encoder is nil") @@ -178,7 +183,7 @@ func BroadcastTx(clientCtx client.Context, txf Factory, broadcaster broadcast.Br return fmt.Errorf("failed to encode transaction: %w", err) } - if err := clientCtx.PrintRaw(txBytes); err != nil { + if err := printer.PrintRaw(txBytes); err != nil { _, _ = fmt.Fprintf(os.Stderr, "error: %v\n%s\n", err, txBytes) } @@ -194,7 +199,7 @@ func BroadcastTx(clientCtx client.Context, txf Factory, broadcaster broadcast.Br } } - signedTx, err := txf.sign(clientCtx.CmdContext, true) + signedTx, err := txf.sign(context.Background(), true) // TODO: pass ctx from upper call if err != nil { return err } @@ -209,7 +214,7 @@ func BroadcastTx(clientCtx client.Context, txf Factory, broadcaster broadcast.Br return err } - return clientCtx.PrintString(string(res)) + return printer.PrintBytes(res) } // countDirectSigners counts the number of DIRECT signers in a signature data. From 528af7ce8c43d38e8361dc3936681d615d841361 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 5 Nov 2024 14:45:04 +0100 Subject: [PATCH 02/52] add: config --- client/config/config.go | 81 +++-------------- client/v2/autocli/builder.go | 3 - client/v2/autocli/common.go | 47 ++++++++++ client/v2/autocli/config/config.go | 117 +++++++++++++++++++++++++ client/{ => v2/autocli}/config/toml.go | 0 client/v2/autocli/msg.go | 2 + go.mod | 4 +- go.sum | 4 +- 8 files changed, 184 insertions(+), 74 deletions(-) create mode 100644 client/v2/autocli/config/config.go rename client/{ => v2/autocli}/config/toml.go (100%) diff --git a/client/config/config.go b/client/config/config.go index 246ed98c7b9a..b1688f7d7e7e 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -2,17 +2,14 @@ package config import ( "crypto/tls" - "errors" "fmt" - "os" - "path/filepath" - "google.golang.org/grpc" "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" + "cosmossdk.io/client/v2/autocli/config" + "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" ) // DefaultConfig returns default config for the client.toml @@ -27,25 +24,17 @@ func DefaultConfig() *Config { } } -// ClientConfig is an alias for Config for backward compatibility -// Deprecated: use Config instead which avoid name stuttering -type ClientConfig Config - -type Config struct { - ChainID string `mapstructure:"chain-id" json:"chain-id"` - KeyringBackend string `mapstructure:"keyring-backend" json:"keyring-backend"` - KeyringDefaultKeyName string `mapstructure:"keyring-default-keyname" json:"keyring-default-keyname"` - Output string `mapstructure:"output" json:"output"` - Node string `mapstructure:"node" json:"node"` - BroadcastMode string `mapstructure:"broadcast-mode" json:"broadcast-mode"` - GRPC GRPCConfig `mapstructure:",squash"` -} +type ( + // ClientConfig is an alias for Config for backward compatibility + // Deprecated: use Config instead which avoid name stuttering + ClientConfig config.Config -// GRPCConfig holds the gRPC client configuration. -type GRPCConfig struct { - Address string `mapstructure:"grpc-address" json:"grpc-address"` - Insecure bool `mapstructure:"grpc-insecure" json:"grpc-insecure"` -} + Config = config.Config + + GRPCConfig = config.GRPCConfig +) + +var DefaultClientConfigTemplate = config.DefaultClientConfigTemplate // ReadFromClientConfig reads values from client.toml file and updates them in client.Context // It uses CreateClientConfig internally with no custom template and custom config. @@ -59,51 +48,7 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) { // It takes a customClientTemplate and customConfig as input that can be used to overwrite the default config and enhance the client.toml file. // The custom template/config must be both provided or be "" and nil. func CreateClientConfig(ctx client.Context, customClientTemplate string, customConfig interface{}) (client.Context, error) { - configPath := filepath.Join(ctx.HomeDir, "config") - configFilePath := filepath.Join(configPath, "client.toml") - - // when client.toml does not exist create and init with default values - if _, err := os.Stat(configFilePath); os.IsNotExist(err) { - if err := os.MkdirAll(configPath, os.ModePerm); err != nil { - return ctx, fmt.Errorf("couldn't make client config: %w", err) - } - - if (customClientTemplate != "" && customConfig == nil) || (customClientTemplate == "" && customConfig != nil) { - return ctx, errors.New("customClientTemplate and customConfig should be both nil or not nil") - } - - if customClientTemplate != "" { - if err := setConfigTemplate(customClientTemplate); err != nil { - return ctx, fmt.Errorf("couldn't set client config template: %w", err) - } - - if ctx.ChainID != "" { - // chain-id will be written to the client.toml while initiating the chain. - ctx.Viper.Set(flags.FlagChainID, ctx.ChainID) - } - - if err = ctx.Viper.Unmarshal(&customConfig); err != nil { - return ctx, fmt.Errorf("failed to parse custom client config: %w", err) - } - - if err := writeConfigFile(configFilePath, customConfig); err != nil { - return ctx, fmt.Errorf("could not write client config to the file: %w", err) - } - - } else { - conf := DefaultConfig() - if ctx.ChainID != "" { - // chain-id will be written to the client.toml while initiating the chain. - conf.ChainID = ctx.ChainID - } - - if err := writeConfigFile(configFilePath, conf); err != nil { - return ctx, fmt.Errorf("could not write client config to the file: %w", err) - } - } - } - - conf, err := getClientConfig(configPath, ctx.Viper) + conf, err := config.CreateClientConfig(ctx.HomeDir, ctx.ChainID, ctx.Viper, customClientTemplate, customConfig) if err != nil { return ctx, fmt.Errorf("couldn't get client config: %w", err) } diff --git a/client/v2/autocli/builder.go b/client/v2/autocli/builder.go index 17db87da6615..81604f0d810b 100644 --- a/client/v2/autocli/builder.go +++ b/client/v2/autocli/builder.go @@ -1,7 +1,6 @@ package autocli import ( - "github.com/cosmos/cosmos-sdk/codec" "github.com/spf13/cobra" "google.golang.org/grpc" @@ -20,8 +19,6 @@ type Builder struct { // AddQueryConnFlags and AddTxConnFlags are functions that add flags to query and transaction commands AddQueryConnFlags func(*cobra.Command) AddTxConnFlags func(*cobra.Command) - - JSONCodec codec.JSONCodec } // ValidateAndComplete the builder fields. diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 4835c5136022..93e0060bb334 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -2,12 +2,14 @@ package autocli import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "cosmossdk.io/client/v2/autocli/config" "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" "fmt" "github.com/spf13/cobra" "google.golang.org/protobuf/reflect/protoreflect" + "strconv" ) type cmdType int @@ -57,6 +59,10 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip } cmd.Args = binder.CobraArgs + cmd.PreRunE = func(cmd *cobra.Command, args []string) error { + return b.setFlagsFromConfig(cmd, args) + } + cmd.RunE = func(cmd *cobra.Command, args []string) error { ctx = cmd.Context() @@ -226,3 +232,44 @@ func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error { output, _ := cmd.Flags().GetString(flags.FlagOutput) return print.NewPrinter(output, cmd.OutOrStdout()).PrintBytes(out) } + +func (b *Builder) setFlagsFromConfig(cmd *cobra.Command, args []string) error { + conf, err := config.CreateClientConfigFromFlags(cmd.Flags()) + if err != nil { + return err + } + + if cmd.Flags().Lookup("chain-id") != nil && !cmd.Flags().Changed("chain-id") { + cmd.Flags().Set("chain-id", conf.ChainID) + } + + if cmd.Flags().Lookup("keyring-backend") != nil && !cmd.Flags().Changed("keyring-backend") { + cmd.Flags().Set("keyring-backend", conf.KeyringBackend) + } + + if cmd.Flags().Lookup("from") != nil && !cmd.Flags().Changed("from") { + cmd.Flags().Set("from", conf.KeyringDefaultKeyName) + } + + if cmd.Flags().Lookup("output") != nil && !cmd.Flags().Changed("output") { + cmd.Flags().Set("output", conf.Output) + } + + if cmd.Flags().Lookup("node") != nil && !cmd.Flags().Changed("node") { + cmd.Flags().Set("node", conf.Node) + } + + if cmd.Flags().Lookup("broadcast-mode") != nil && !cmd.Flags().Changed("broadcast-mode") { + cmd.Flags().Set("broadcast-mode", conf.BroadcastMode) + } + + if cmd.Flags().Lookup("grpc-addr") != nil && !cmd.Flags().Changed("grpc-addr") { + cmd.Flags().Set("grpc-addr", conf.GRPC.Address) + } + + if cmd.Flags().Lookup("grpc-insecure") != nil && !cmd.Flags().Changed("grpc-insecure") { + cmd.Flags().Set("grpc-insecure", strconv.FormatBool(conf.GRPC.Insecure)) + } + + return nil +} diff --git a/client/v2/autocli/config/config.go b/client/v2/autocli/config/config.go new file mode 100644 index 000000000000..b69d4bcba2ea --- /dev/null +++ b/client/v2/autocli/config/config.go @@ -0,0 +1,117 @@ +package config + +import ( + "errors" + "fmt" + "os" + "path" + "path/filepath" + "strings" + + "github.com/spf13/pflag" + "github.com/spf13/viper" +) + +type Config struct { + ChainID string `mapstructure:"chain-id" json:"chain-id"` + KeyringBackend string `mapstructure:"keyring-backend" json:"keyring-backend"` + KeyringDefaultKeyName string `mapstructure:"keyring-default-keyname" json:"keyring-default-keyname"` + Output string `mapstructure:"output" json:"output"` + Node string `mapstructure:"node" json:"node"` + BroadcastMode string `mapstructure:"broadcast-mode" json:"broadcast-mode"` + GRPC GRPCConfig `mapstructure:",squash"` +} + +// GRPCConfig holds the gRPC client configuration. +type GRPCConfig struct { + Address string `mapstructure:"grpc-address" json:"grpc-address"` + Insecure bool `mapstructure:"grpc-insecure" json:"grpc-insecure"` +} + +func DefaultConfig() *Config { + return &Config{ + ChainID: "", + KeyringBackend: "os", + KeyringDefaultKeyName: "", + Output: "text", + Node: "tcp://localhost:26657", + BroadcastMode: "sync", + } +} + +func CreateClientConfig(homeDir, chainID string, v *viper.Viper, customClientTemplate string, customConfig interface{}) (*Config, error) { + if homeDir == "" { + return nil, errors.New("home dir can't be empty") + } + + configPath := filepath.Join(homeDir, "config") + configFilePath := filepath.Join(configPath, "client.toml") + + // when client.toml does not exist create and init with default values + if _, err := os.Stat(configFilePath); os.IsNotExist(err) { + if err := os.MkdirAll(configPath, os.ModePerm); err != nil { + return nil, fmt.Errorf("couldn't make client config: %w", err) + } + + if (customClientTemplate != "" && customConfig == nil) || (customClientTemplate == "" && customConfig != nil) { + return nil, errors.New("customClientTemplate and customConfig should be both nil or not nil") + } + + if customClientTemplate != "" { + if err := setConfigTemplate(customClientTemplate); err != nil { + return nil, fmt.Errorf("couldn't set client config template: %w", err) + } + + if chainID != "" { + // chain-id will be written to the client.toml while initiating the chain. + v.Set("chain-id", chainID) // TODO: use FlagChainId + } + + if err = v.Unmarshal(&customConfig); err != nil { + return nil, fmt.Errorf("failed to parse custom client config: %w", err) + } + + if err := writeConfigFile(configFilePath, customConfig); err != nil { + return nil, fmt.Errorf("could not write client config to the file: %w", err) + } + + } else { + conf := DefaultConfig() + if chainID != "" { + // chain-id will be written to the client.toml while initiating the chain. + conf.ChainID = chainID + } + + if err := writeConfigFile(configFilePath, conf); err != nil { + return nil, fmt.Errorf("could not write client config to the file: %w", err) + } + } + } + + conf, err := getClientConfig(configPath, v) + if err != nil { + return nil, fmt.Errorf("couldn't get client config: %w", err) + } + + return conf, nil +} + +func CreateClientConfigFromFlags(set *pflag.FlagSet) (*Config, error) { + homeDir, _ := set.GetString("home") + if homeDir == "" { + return DefaultConfig(), nil + } + chainID, _ := set.GetString("chain-id") + + v := viper.New() + executableName, err := os.Executable() + if err != nil { + return nil, err + } + + v.SetEnvPrefix(path.Base(executableName)) + v.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) + v.AutomaticEnv() + + return CreateClientConfig(homeDir, chainID, v, "", nil) +} diff --git a/client/config/toml.go b/client/v2/autocli/config/toml.go similarity index 100% rename from client/config/toml.go rename to client/v2/autocli/config/toml.go diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index fa9b665e1d76..200963a86be2 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -2,6 +2,7 @@ package autocli import ( "context" + "cosmossdk.io/client/v2/tx" "fmt" gogoproto "github.com/cosmos/gogoproto/proto" @@ -166,6 +167,7 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor msg := dynamicpb.NewMessage(input.Descriptor()) proto.Merge(msg, input.Interface()) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) } diff --git a/go.mod b/go.mod index daeab6e96816..ac2f869b12cd 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ module github.com/cosmos/cosmos-sdk require ( cosmossdk.io/api v0.7.6 + cosmossdk.io/client/v2 v2.0.0-00010101000000-000000000000 cosmossdk.io/collections v0.4.0 cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 @@ -11,7 +12,7 @@ require ( cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.4.1 cosmossdk.io/math v1.3.0 - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 @@ -183,6 +184,7 @@ require ( // TODO remove after all modules have their own go.mods replace ( cosmossdk.io/api => ./api + cosmossdk.io/client/v2 => ./client/v2 cosmossdk.io/collections => ./collections cosmossdk.io/store => ./store cosmossdk.io/x/bank => ./x/bank diff --git a/go.sum b/go.sum index ca8c3fd1f0ec..bc9a7686328a 100644 --- a/go.sum +++ b/go.sum @@ -16,8 +16,8 @@ cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM= cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= From 73d8d8595dead7b7197256ab80bdc94860aeab82 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 5 Nov 2024 17:48:34 +0100 Subject: [PATCH 03/52] update: keyring --- client/v2/autocli/app.go | 4 +++ client/v2/autocli/builder.go | 3 +++ client/v2/autocli/common.go | 11 +++++++- client/v2/autocli/flag/address.go | 38 ++++++++-------------------- client/v2/autocli/flag/builder.go | 13 ++++++++++ client/v2/autocli/keyring/keyring.go | 33 +++++++++++++++++++++--- 6 files changed, 70 insertions(+), 32 deletions(-) diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index 614966aab74d..8a730ac2cf3f 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -1,6 +1,7 @@ package autocli import ( + "github.com/cosmos/cosmos-sdk/codec" "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/protobuf/reflect/protoregistry" @@ -40,6 +41,8 @@ type AppOptions struct { AddressCodec address.Codec ValidatorAddressCodec address.Codec ConsensusAddressCodec address.Codec + + Cdc codec.Codec } // EnhanceRootCommand enhances the provided root command with autocli AppOptions, @@ -71,6 +74,7 @@ func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error { }, AddQueryConnFlags: sdkflags.AddQueryFlagsToCmd, AddTxConnFlags: sdkflags.AddTxFlagsToCmd, + Cdc: appOptions.Cdc, } return appOptions.EnhanceRootCommandWithBuilder(rootCmd, builder) diff --git a/client/v2/autocli/builder.go b/client/v2/autocli/builder.go index 81604f0d810b..d85341b68c75 100644 --- a/client/v2/autocli/builder.go +++ b/client/v2/autocli/builder.go @@ -5,6 +5,7 @@ import ( "google.golang.org/grpc" "cosmossdk.io/client/v2/autocli/flag" + "github.com/cosmos/cosmos-sdk/codec" ) // Builder manages options for building CLI commands. @@ -19,6 +20,8 @@ type Builder struct { // AddQueryConnFlags and AddTxConnFlags are functions that add flags to query and transaction commands AddQueryConnFlags func(*cobra.Command) AddTxConnFlags func(*cobra.Command) + + Cdc codec.Codec } // ValidateAndComplete the builder fields. diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 93e0060bb334..b5391c16872c 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -3,6 +3,7 @@ package autocli import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli/config" + "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" @@ -60,7 +61,15 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip cmd.Args = binder.CobraArgs cmd.PreRunE = func(cmd *cobra.Command, args []string) error { - return b.setFlagsFromConfig(cmd, args) + err := b.setFlagsFromConfig(cmd, args) + if err != nil { + return err + } + + k, err := keyring.NewKeyringFromFlags(cmd.Context(), cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) + b.SetKeyring(k) // global flag keyring must be set on PreRunE. + + return err } cmd.RunE = func(cmd *cobra.Command, args []string) error { diff --git a/client/v2/autocli/flag/address.go b/client/v2/autocli/flag/address.go index 2e7133d4bd9a..f7784e400bf3 100644 --- a/client/v2/autocli/flag/address.go +++ b/client/v2/autocli/flag/address.go @@ -6,14 +6,11 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" - "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/core/address" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) @@ -54,9 +51,11 @@ func (a addressValue) String() string { // Set implements the flag.Value interface for addressValue. func (a *addressValue) Set(s string) error { - // we get the keyring on set, as in NewValue the context is the parent context (before RunE) - keyring := getKeyringFromCtx(a.ctx) - addr, err := keyring.LookupAddressByKeyName(s) + if keybase == nil { + return fmt.Errorf("keybase is nil") + } + + addr, err := keybase.LookupAddressByKeyName(s) if err == nil { addrStr, err := a.addressCodec.BytesToString(addr) if err != nil { @@ -109,9 +108,11 @@ func (a consensusAddressValue) String() string { } func (a *consensusAddressValue) Set(s string) error { - // we get the keyring on set, as in NewValue the context is the parent context (before RunE) - keyring := getKeyringFromCtx(a.ctx) - addr, err := keyring.LookupAddressByKeyName(s) + if keybase == nil { + return fmt.Errorf("keybase is nil") + } + + addr, err := keybase.LookupAddressByKeyName(s) if err == nil { addrStr, err := a.addressCodec.BytesToString(addr) if err != nil { @@ -146,22 +147,3 @@ func (a *consensusAddressValue) Set(s string) error { return nil } - -// TODO: this should be deleted. Keyring should be obtain from flags -func getKeyringFromCtx(ctx *context.Context) keyring.Keyring { - dctx := *ctx - if dctx != nil { - if clientCtx := dctx.Value(client.ClientContextKey); clientCtx != nil { - k, err := sdkkeyring.NewAutoCLIKeyring(clientCtx.(*client.Context).Keyring, clientCtx.(*client.Context).AddressCodec) - if err != nil { - panic(fmt.Errorf("failed to create keyring: %w", err)) - } - - return k - } else if k := dctx.Value(keyring.KeyringContextKey); k != nil { - return k.(*keyring.KeyringImpl) - } - } - - return keyring.NoKeyring{} -} diff --git a/client/v2/autocli/flag/builder.go b/client/v2/autocli/flag/builder.go index bdd42634dd35..2c2c35bba158 100644 --- a/client/v2/autocli/flag/builder.go +++ b/client/v2/autocli/flag/builder.go @@ -16,6 +16,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" msgv1 "cosmossdk.io/api/cosmos/msg/v1" + "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" "cosmossdk.io/core/address" @@ -29,6 +30,12 @@ const ( DecScalarType = "cosmos.Dec" ) +// keybase is a global variable that holds the keyring instance used for key management +// and signing operations across the autocli flag package. It must be set in PreRunE +// of the root command. +// TODO: this is super hacky :/ +var keybase keyring.Keyring + // Builder manages options for building pflag flags for protobuf messages. type Builder struct { // TypeResolver specifies how protobuf types will be resolved. If it is @@ -54,6 +61,12 @@ type Builder struct { ConsensusAddressCodec address.ConsensusAddressCodec } +// SetKeyring sets the global keyring instance used for key management and signing operations. +// The keyring must be set in PreRunE of the root command. +func (b *Builder) SetKeyring(k keyring.Keyring) { + keybase = k +} + func (b *Builder) init() { if b.messageFlagTypes == nil { b.messageFlagTypes = map[protoreflect.FullName]Type{} diff --git a/client/v2/autocli/keyring/keyring.go b/client/v2/autocli/keyring/keyring.go index 9e9bdcc975ea..715337feffff 100644 --- a/client/v2/autocli/keyring/keyring.go +++ b/client/v2/autocli/keyring/keyring.go @@ -2,8 +2,17 @@ package keyring import ( "context" + "io" + + "github.com/cosmos/cosmos-sdk/codec" + + "github.com/spf13/pflag" + signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/address" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/types" ) @@ -24,9 +33,27 @@ func NewKeyringInContext(ctx context.Context, k Keyring) context.Context { return context.WithValue(ctx, KeyringContextKey, NewKeyringImpl(k)) } -//func NewKeyringFromFlags(ctx context.Context, flagSet *pflag.FlagSet) (Keyring, error) { -// k := keyring.New(sdk.KeyringServiceName(), ) -//} +func NewKeyringFromFlags(ctx context.Context, flagSet *pflag.FlagSet, ac address.Codec, input io.Reader, cdc codec.Codec) (Keyring, error) { + backEnd, err := flagSet.GetString("keyring-backend") + if err != nil { + return nil, err + } + + keyringDir, err := flagSet.GetString("keyring-dir") + if err != nil { + return nil, err + } + if keyringDir == "" { + keyringDir, _ = flagSet.GetString("home") + } + + k, err := keyring.New(sdk.KeyringServiceName(), backEnd, keyringDir, input, cdc) + if err != nil { + return nil, err + } + + return keyring.NewAutoCLIKeyring(k, ac) +} func NewKeyringImpl(k Keyring) *KeyringImpl { return &KeyringImpl{k: k} From 004d071d2af9dc50bd6d23d5d887824301ac3264 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 6 Nov 2024 10:50:50 +0100 Subject: [PATCH 04/52] add: ConfigOptions to AppOptions --- client/v2/autocli/app.go | 5 +++-- go.mod | 1 - x/accounts/defaults/base/go.mod | 2 +- x/accounts/defaults/base/go.sum | 1 + x/accounts/defaults/lockup/go.mod | 2 +- x/accounts/defaults/lockup/go.sum | 1 + x/accounts/defaults/multisig/go.mod | 2 +- x/accounts/defaults/multisig/go.sum | 1 + x/accounts/go.mod | 2 +- x/accounts/go.sum | 1 + x/authz/go.mod | 2 +- x/authz/go.sum | 1 + x/bank/go.mod | 2 +- x/bank/go.sum | 1 + x/circuit/go.mod | 2 +- x/circuit/go.sum | 1 + x/consensus/go.mod | 2 +- x/consensus/go.sum | 1 + x/distribution/go.mod | 2 +- x/distribution/go.sum | 1 + x/epochs/go.mod | 2 +- x/epochs/go.sum | 1 + x/evidence/go.mod | 2 +- x/evidence/go.sum | 1 + x/feegrant/go.mod | 2 +- x/feegrant/go.sum | 1 + x/gov/go.mod | 2 +- x/gov/go.sum | 1 + x/group/go.mod | 2 +- x/group/go.sum | 1 + x/mint/go.mod | 2 +- x/mint/go.sum | 1 + x/nft/go.mod | 2 +- x/nft/go.sum | 1 + x/params/go.mod | 2 +- x/params/go.sum | 1 + x/protocolpool/go.mod | 2 +- x/protocolpool/go.sum | 1 + x/slashing/go.mod | 2 +- x/slashing/go.sum | 1 + x/staking/go.mod | 2 +- x/staking/go.sum | 1 + x/upgrade/go.mod | 2 +- x/upgrade/go.sum | 1 + 44 files changed, 45 insertions(+), 24 deletions(-) diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index 8a730ac2cf3f..63de9da46a46 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -11,10 +11,10 @@ import ( "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" - "github.com/cosmos/cosmos-sdk/client" sdkflags "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec/types" + authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" ) // AppOptions are autocli options for an app. These options can be built via depinject based on an app config. Ex: @@ -42,7 +42,8 @@ type AppOptions struct { ValidatorAddressCodec address.Codec ConsensusAddressCodec address.Codec - Cdc codec.Codec + Cdc codec.Codec + TxConfigOpts authtx.ConfigOptions } // EnhanceRootCommand enhances the provided root command with autocli AppOptions, diff --git a/go.mod b/go.mod index cdecebf2bd60..d367e1e412ee 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ module github.com/cosmos/cosmos-sdk require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/client/v2 v2.0.0-00010101000000-000000000000 cosmossdk.io/collections v0.4.0 cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 diff --git a/x/accounts/defaults/base/go.mod b/x/accounts/defaults/base/go.mod index 8c48af24a5bf..420336e6a5e3 100644 --- a/x/accounts/defaults/base/go.mod +++ b/x/accounts/defaults/base/go.mod @@ -23,7 +23,7 @@ require ( cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.4.1 // indirect cosmossdk.io/math v1.3.0 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect diff --git a/x/accounts/defaults/base/go.sum b/x/accounts/defaults/base/go.sum index cd9371822af4..4ea0707c1972 100644 --- a/x/accounts/defaults/base/go.sum +++ b/x/accounts/defaults/base/go.sum @@ -18,6 +18,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/accounts/defaults/lockup/go.mod b/x/accounts/defaults/lockup/go.mod index d261f5672a0b..4afa6ed4be5c 100644 --- a/x/accounts/defaults/lockup/go.mod +++ b/x/accounts/defaults/lockup/go.mod @@ -22,7 +22,7 @@ require ( cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.4.1 cosmossdk.io/math v1.3.0 - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect diff --git a/x/accounts/defaults/lockup/go.sum b/x/accounts/defaults/lockup/go.sum index c6ace37c13b6..7dd3f22317e9 100644 --- a/x/accounts/defaults/lockup/go.sum +++ b/x/accounts/defaults/lockup/go.sum @@ -18,6 +18,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/accounts/defaults/multisig/go.mod b/x/accounts/defaults/multisig/go.mod index f7d8659b157b..d7339a1a4282 100644 --- a/x/accounts/defaults/multisig/go.mod +++ b/x/accounts/defaults/multisig/go.mod @@ -23,7 +23,7 @@ require ( cosmossdk.io/depinject v1.0.0 // indirect cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.4.1 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect diff --git a/x/accounts/defaults/multisig/go.sum b/x/accounts/defaults/multisig/go.sum index cd9371822af4..4ea0707c1972 100644 --- a/x/accounts/defaults/multisig/go.sum +++ b/x/accounts/defaults/multisig/go.sum @@ -18,6 +18,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/accounts/go.mod b/x/accounts/go.mod index 16e2c6ef3c1d..f8d14416e5d9 100644 --- a/x/accounts/go.mod +++ b/x/accounts/go.mod @@ -31,7 +31,7 @@ require ( cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.4.1 // indirect cosmossdk.io/math v1.3.0 - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect filippo.io/edwards25519 v1.1.0 // indirect diff --git a/x/accounts/go.sum b/x/accounts/go.sum index cd9371822af4..4ea0707c1972 100644 --- a/x/accounts/go.sum +++ b/x/accounts/go.sum @@ -18,6 +18,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/authz/go.mod b/x/authz/go.mod index 1e34eb17d8be..e98d64d042a8 100644 --- a/x/authz/go.mod +++ b/x/authz/go.mod @@ -30,7 +30,7 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.2 // indirect diff --git a/x/authz/go.sum b/x/authz/go.sum index cd9371822af4..4ea0707c1972 100644 --- a/x/authz/go.sum +++ b/x/authz/go.sum @@ -18,6 +18,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/bank/go.mod b/x/bank/go.mod index 984ef646b580..938d20443cc7 100644 --- a/x/bank/go.mod +++ b/x/bank/go.mod @@ -160,7 +160,7 @@ require ( sigs.k8s.io/yaml v1.4.0 // indirect ) -require cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 +require cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac require ( github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect diff --git a/x/bank/go.sum b/x/bank/go.sum index cd9371822af4..4ea0707c1972 100644 --- a/x/bank/go.sum +++ b/x/bank/go.sum @@ -18,6 +18,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/circuit/go.mod b/x/circuit/go.mod index 54a731e78ffe..6db36c1c0090 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -24,7 +24,7 @@ require ( buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/log v1.4.1 // indirect cosmossdk.io/math v1.3.0 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect diff --git a/x/circuit/go.sum b/x/circuit/go.sum index 8fceb55731a7..c99722675474 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -20,6 +20,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/consensus/go.mod b/x/consensus/go.mod index d12915607923..63bcd3db469a 100644 --- a/x/consensus/go.mod +++ b/x/consensus/go.mod @@ -27,7 +27,7 @@ require ( cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.4.1 // indirect cosmossdk.io/math v1.3.0 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect diff --git a/x/consensus/go.sum b/x/consensus/go.sum index 8fceb55731a7..c99722675474 100644 --- a/x/consensus/go.sum +++ b/x/consensus/go.sum @@ -20,6 +20,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/distribution/go.mod b/x/distribution/go.mod index 7ee993aae9f4..5b1dfaa22b26 100644 --- a/x/distribution/go.mod +++ b/x/distribution/go.mod @@ -29,7 +29,7 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/log v1.4.1 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect diff --git a/x/distribution/go.sum b/x/distribution/go.sum index cd9371822af4..4ea0707c1972 100644 --- a/x/distribution/go.sum +++ b/x/distribution/go.sum @@ -18,6 +18,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/epochs/go.mod b/x/epochs/go.mod index 284e7f2deab2..475aa0ff8ebb 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -20,7 +20,7 @@ require ( google.golang.org/grpc v1.67.1 ) -require cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect +require cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect diff --git a/x/epochs/go.sum b/x/epochs/go.sum index 8fceb55731a7..c99722675474 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -20,6 +20,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/evidence/go.mod b/x/evidence/go.mod index 4de7e8a97cf8..18d238242fc5 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -28,7 +28,7 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/log v1.4.1 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 8fceb55731a7..c99722675474 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -20,6 +20,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 959204ea7189..966623a8c612 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -37,7 +37,7 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/log v1.4.1 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index efdf24e13ba5..823321bf0a5c 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -18,6 +18,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190 h1:XQJj9Dv9Gtze0l2TF79BU5lkP6MkUveTUuKICmxoz+o= cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190/go.mod h1:7WUGupOvmlHJoIMBz1JbObQxeo6/TDiuDBxmtod8HRg= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= diff --git a/x/gov/go.mod b/x/gov/go.mod index 1de77256af1e..c2d4c2316329 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -35,7 +35,7 @@ require ( require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect diff --git a/x/gov/go.sum b/x/gov/go.sum index 4e6d843a385a..d0d36e2bc9b0 100644 --- a/x/gov/go.sum +++ b/x/gov/go.sum @@ -18,6 +18,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/group/go.mod b/x/group/go.mod index 5c0a41a54ada..cb550d82fe58 100644 --- a/x/group/go.mod +++ b/x/group/go.mod @@ -38,7 +38,7 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/epochs v0.0.0-20240522060652-a1ae4c3e0337 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect diff --git a/x/group/go.sum b/x/group/go.sum index 827315f69da4..02433c79466d 100644 --- a/x/group/go.sum +++ b/x/group/go.sum @@ -18,6 +18,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/mint/go.mod b/x/mint/go.mod index 5780be9ba0aa..45d590635859 100644 --- a/x/mint/go.mod +++ b/x/mint/go.mod @@ -29,7 +29,7 @@ require ( require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect diff --git a/x/mint/go.sum b/x/mint/go.sum index 8fceb55731a7..c99722675474 100644 --- a/x/mint/go.sum +++ b/x/mint/go.sum @@ -20,6 +20,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/nft/go.mod b/x/nft/go.mod index a07aafaacf3a..6846b370e07d 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -26,7 +26,7 @@ require ( buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect diff --git a/x/nft/go.sum b/x/nft/go.sum index 8fceb55731a7..c99722675474 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -20,6 +20,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/params/go.mod b/x/params/go.mod index c4d16f371bda..0668aa4d0506 100644 --- a/x/params/go.mod +++ b/x/params/go.mod @@ -29,7 +29,7 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect diff --git a/x/params/go.sum b/x/params/go.sum index 4c27f0ad454a..c6002f7b0c4f 100644 --- a/x/params/go.sum +++ b/x/params/go.sum @@ -20,6 +20,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/protocolpool/go.mod b/x/protocolpool/go.mod index ce68008aadb4..16a67db69318 100644 --- a/x/protocolpool/go.mod +++ b/x/protocolpool/go.mod @@ -27,7 +27,7 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/log v1.4.1 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect diff --git a/x/protocolpool/go.sum b/x/protocolpool/go.sum index 8fceb55731a7..c99722675474 100644 --- a/x/protocolpool/go.sum +++ b/x/protocolpool/go.sum @@ -20,6 +20,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/slashing/go.mod b/x/slashing/go.mod index b08e4a964bac..0f942bf49ec1 100644 --- a/x/slashing/go.mod +++ b/x/slashing/go.mod @@ -30,7 +30,7 @@ require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/log v1.4.1 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect diff --git a/x/slashing/go.sum b/x/slashing/go.sum index 58ca35c37a24..fa79e90aff67 100644 --- a/x/slashing/go.sum +++ b/x/slashing/go.sum @@ -20,6 +20,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/staking/go.mod b/x/staking/go.mod index fac99dfe7a4b..d24abf090241 100644 --- a/x/staking/go.mod +++ b/x/staking/go.mod @@ -162,7 +162,7 @@ require ( ) require ( - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect github.com/cosmos/cosmos-db v1.0.3-0.20240911104526-ddc3f09bfc22 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/x/staking/go.sum b/x/staking/go.sum index cd9371822af4..4ea0707c1972 100644 --- a/x/staking/go.sum +++ b/x/staking/go.sum @@ -18,6 +18,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index 6f2aedce1541..dd37b61500b8 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -42,7 +42,7 @@ require ( cloud.google.com/go/storage v1.43.0 // indirect cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/math v1.3.0 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect + cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index 829d69c67197..3344b0384f31 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -208,6 +208,7 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190 h1:XQJj9Dv9Gtze0l2TF79BU5lkP6MkUveTUuKICmxoz+o= cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190/go.mod h1:7WUGupOvmlHJoIMBz1JbObQxeo6/TDiuDBxmtod8HRg= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= From a404604a8e54b2fa79d8d915f4e52c23acbeaac3 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 6 Nov 2024 12:47:21 +0100 Subject: [PATCH 05/52] add: default keyring --- client/v2/autocli/keyring/keyring.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/client/v2/autocli/keyring/keyring.go b/client/v2/autocli/keyring/keyring.go index 715337feffff..58f3d03d34a4 100644 --- a/client/v2/autocli/keyring/keyring.go +++ b/client/v2/autocli/keyring/keyring.go @@ -33,7 +33,19 @@ func NewKeyringInContext(ctx context.Context, k Keyring) context.Context { return context.WithValue(ctx, KeyringContextKey, NewKeyringImpl(k)) } +// TODO: godco func NewKeyringFromFlags(ctx context.Context, flagSet *pflag.FlagSet, ac address.Codec, input io.Reader, cdc codec.Codec) (Keyring, error) { + // Some commands as query expect access to the keyring but don't provide keyring flags. + // In such case a default keyring of backed test and rootDir homeDir is set. + if flagSet.Lookup("keyring-backend") == nil && flagSet.Lookup("keyring-dir") == nil { + dir, err := flagSet.GetString("home") + if err != nil { + return nil, err + } + + return defaultKeyring(dir, ac, input, cdc) + } + backEnd, err := flagSet.GetString("keyring-backend") if err != nil { return nil, err @@ -44,7 +56,10 @@ func NewKeyringFromFlags(ctx context.Context, flagSet *pflag.FlagSet, ac address return nil, err } if keyringDir == "" { - keyringDir, _ = flagSet.GetString("home") + keyringDir, err = flagSet.GetString("home") + if err != nil { + return nil, err + } } k, err := keyring.New(sdk.KeyringServiceName(), backEnd, keyringDir, input, cdc) @@ -55,6 +70,16 @@ func NewKeyringFromFlags(ctx context.Context, flagSet *pflag.FlagSet, ac address return keyring.NewAutoCLIKeyring(k, ac) } +// TODO: godoc +func defaultKeyring(rootDir string, ac address.Codec, input io.Reader, cdc codec.Codec) (Keyring, error) { + k, err := keyring.New(sdk.KeyringServiceName(), "test", rootDir, input, cdc) + if err != nil { + return nil, err + } + + return keyring.NewAutoCLIKeyring(k, ac) +} + func NewKeyringImpl(k Keyring) *KeyringImpl { return &KeyringImpl{k: k} } From 9509d1dddcf39b2905f7152de73b55f7492b9efb Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Thu, 7 Nov 2024 10:31:13 +0100 Subject: [PATCH 06/52] del: default keyring --- client/v2/autocli/common.go | 2 +- client/v2/autocli/keyring/keyring.go | 23 +---------------------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index b5391c16872c..1bce6c658716 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -66,7 +66,7 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip return err } - k, err := keyring.NewKeyringFromFlags(cmd.Context(), cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) + k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) b.SetKeyring(k) // global flag keyring must be set on PreRunE. return err diff --git a/client/v2/autocli/keyring/keyring.go b/client/v2/autocli/keyring/keyring.go index 58f3d03d34a4..eb6d03eed817 100644 --- a/client/v2/autocli/keyring/keyring.go +++ b/client/v2/autocli/keyring/keyring.go @@ -34,18 +34,7 @@ func NewKeyringInContext(ctx context.Context, k Keyring) context.Context { } // TODO: godco -func NewKeyringFromFlags(ctx context.Context, flagSet *pflag.FlagSet, ac address.Codec, input io.Reader, cdc codec.Codec) (Keyring, error) { - // Some commands as query expect access to the keyring but don't provide keyring flags. - // In such case a default keyring of backed test and rootDir homeDir is set. - if flagSet.Lookup("keyring-backend") == nil && flagSet.Lookup("keyring-dir") == nil { - dir, err := flagSet.GetString("home") - if err != nil { - return nil, err - } - - return defaultKeyring(dir, ac, input, cdc) - } - +func NewKeyringFromFlags(flagSet *pflag.FlagSet, ac address.Codec, input io.Reader, cdc codec.Codec) (Keyring, error) { backEnd, err := flagSet.GetString("keyring-backend") if err != nil { return nil, err @@ -70,16 +59,6 @@ func NewKeyringFromFlags(ctx context.Context, flagSet *pflag.FlagSet, ac address return keyring.NewAutoCLIKeyring(k, ac) } -// TODO: godoc -func defaultKeyring(rootDir string, ac address.Codec, input io.Reader, cdc codec.Codec) (Keyring, error) { - k, err := keyring.New(sdk.KeyringServiceName(), "test", rootDir, input, cdc) - if err != nil { - return nil, err - } - - return keyring.NewAutoCLIKeyring(k, ac) -} - func NewKeyringImpl(k Keyring) *KeyringImpl { return &KeyringImpl{k: k} } From 06ffcbe0ae4910a0bcb655f7825b0ce8a9ca03ff Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Thu, 7 Nov 2024 14:05:04 +0100 Subject: [PATCH 07/52] add: grpc query conn --- client/v2/autocli/app.go | 5 ----- client/v2/autocli/builder.go | 5 ----- client/v2/autocli/common.go | 43 ++++++++++++++++++++++++++++++++---- client/v2/autocli/query.go | 3 +-- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index a51c5e220082..2e9f438bbe84 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -4,7 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/gogoproto/proto" "github.com/spf13/cobra" - "google.golang.org/grpc" "google.golang.org/protobuf/reflect/protoregistry" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" @@ -15,7 +14,6 @@ import ( "cosmossdk.io/log" "cosmossdk.io/x/tx/signing" - "github.com/cosmos/cosmos-sdk/client" sdkflags "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec/types" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -76,9 +74,6 @@ func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error { ValidatorAddressCodec: appOptions.ValidatorAddressCodec, ConsensusAddressCodec: appOptions.ConsensusAddressCodec, }, - GetClientConn: func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { - return client.GetClientQueryContext(cmd) // TODO: implement client/v2/grpcconn - }, AddQueryConnFlags: func(c *cobra.Command) { sdkflags.AddQueryFlagsToCmd(c) sdkflags.AddKeyringFlags(c.Flags()) diff --git a/client/v2/autocli/builder.go b/client/v2/autocli/builder.go index d85341b68c75..2d70d5690970 100644 --- a/client/v2/autocli/builder.go +++ b/client/v2/autocli/builder.go @@ -2,7 +2,6 @@ package autocli import ( "github.com/spf13/cobra" - "google.golang.org/grpc" "cosmossdk.io/client/v2/autocli/flag" "github.com/cosmos/cosmos-sdk/codec" @@ -13,10 +12,6 @@ type Builder struct { // flag.Builder embeds the flag builder and its options. flag.Builder - // GetClientConn specifies how CLI commands will resolve a grpc.ClientConnInterface - // from a given context. - GetClientConn func(*cobra.Command) (grpc.ClientConnInterface, error) - // AddQueryConnFlags and AddTxConnFlags are functions that add flags to query and transaction commands AddQueryConnFlags func(*cobra.Command) AddTxConnFlags func(*cobra.Command) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 1bce6c658716..a5f81108413f 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -1,16 +1,23 @@ package autocli import ( + "crypto/tls" + "errors" + "fmt" + "strconv" + + "github.com/spf13/cobra" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" + grpcinsecure "google.golang.org/grpc/credentials/insecure" + "google.golang.org/protobuf/reflect/protoreflect" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli/config" "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" - "fmt" - "github.com/spf13/cobra" - "google.golang.org/protobuf/reflect/protoreflect" - "strconv" ) type cmdType int @@ -282,3 +289,31 @@ func (b *Builder) setFlagsFromConfig(cmd *cobra.Command, args []string) error { return nil } + +// TODO: godoc +func (b *Builder) getQueryClientConn(cmd *cobra.Command) (*grpc.ClientConn, error) { + if cmd.Flags().Lookup("grpc-insecure") == nil || cmd.Flags().Lookup("grpc-addr") == nil { + return nil, errors.New("grpc-insecure and grpc-addr flags are required") + } + + creds := grpcinsecure.NewCredentials() + insecure, err := cmd.Flags().GetBool("grpc-insecure") + if err != nil { + return nil, err + } + if !insecure { + creds = credentials.NewTLS(&tls.Config{MinVersion: tls.VersionTLS12}) + } + + addr, err := cmd.Flags().GetString("grpc-addr") + if err != nil { + return nil, err + } + + if addr == "" { + // TODO: fall to default by querying state via abci query. + return nil, errors.New("grpc-addr flag must be set") + } + + return grpc.NewClient(addr, []grpc.DialOption{grpc.WithTransportCredentials(creds)}...) +} diff --git a/client/v2/autocli/query.go b/client/v2/autocli/query.go index d308bcd7633a..3d6db547ccaf 100644 --- a/client/v2/autocli/query.go +++ b/client/v2/autocli/query.go @@ -116,7 +116,6 @@ func (b *Builder) AddQueryServiceCommands(cmd *cobra.Command, cmdDescriptor *aut // BuildQueryMethodCommand creates a gRPC query command for the given service method. This can be used to auto-generate // just a single command for a single service rpc method. func (b *Builder) BuildQueryMethodCommand(ctx context.Context, descriptor protoreflect.MethodDescriptor, options *autocliv1.RpcCommandOptions) (*cobra.Command, error) { - getClientConn := b.GetClientConn serviceDescriptor := descriptor.Parent().(protoreflect.ServiceDescriptor) methodName := fmt.Sprintf("/%s/%s", serviceDescriptor.FullName(), descriptor.Name()) outputType := util.ResolveMessageType(b.TypeResolver, descriptor.Output()) @@ -130,7 +129,7 @@ func (b *Builder) BuildQueryMethodCommand(ctx context.Context, descriptor protor } cmd, err := b.buildMethodCommandCommon(descriptor, options, func(cmd *cobra.Command, input protoreflect.Message) error { - clientConn, err := getClientConn(cmd) + clientConn, err := b.getQueryClientConn(cmd) if err != nil { return err } From 7e0583f0abebffa3446c6c03c7b77afe3d62e000 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Fri, 8 Nov 2024 12:02:55 +0100 Subject: [PATCH 08/52] add: default grpc qConn --- client/v2/autocli/builder.go | 4 +- client/v2/autocli/common.go | 65 +++++++----- client/v2/autocli/common_test.go | 3 - client/v2/autocli/keyring/keyring.go | 2 +- client/v2/autocli/msg.go | 13 ++- client/v2/autocli/msg_test.go | 2 + client/v2/broadcast/comet/clientConn.go | 134 ++++++++++++++++++++++++ client/v2/broadcast/comet/comet.go | 7 +- client/v2/broadcast/comet/comet_test.go | 4 +- client/v2/tx/tx.go | 75 +++++++++---- 10 files changed, 250 insertions(+), 59 deletions(-) create mode 100644 client/v2/broadcast/comet/clientConn.go diff --git a/client/v2/autocli/builder.go b/client/v2/autocli/builder.go index 2d70d5690970..bfd9e968a885 100644 --- a/client/v2/autocli/builder.go +++ b/client/v2/autocli/builder.go @@ -1,6 +1,7 @@ package autocli import ( + apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "github.com/spf13/cobra" "cosmossdk.io/client/v2/autocli/flag" @@ -16,7 +17,8 @@ type Builder struct { AddQueryConnFlags func(*cobra.Command) AddTxConnFlags func(*cobra.Command) - Cdc codec.Codec + Cdc codec.Codec + EnablesSignModes []apisigning.SignMode } // ValidateAndComplete the builder fields. diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index a5f81108413f..82ba1b523a8f 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -2,10 +2,10 @@ package autocli import ( "crypto/tls" - "errors" "fmt" "strconv" + gogogrpc "github.com/cosmos/gogoproto/grpc" "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -16,6 +16,7 @@ import ( "cosmossdk.io/client/v2/autocli/config" "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/autocli/print" + "cosmossdk.io/client/v2/broadcast/comet" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" ) @@ -67,17 +68,7 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip } cmd.Args = binder.CobraArgs - cmd.PreRunE = func(cmd *cobra.Command, args []string) error { - err := b.setFlagsFromConfig(cmd, args) - if err != nil { - return err - } - - k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) - b.SetKeyring(k) // global flag keyring must be set on PreRunE. - - return err - } + cmd.PreRunE = b.preRunE() cmd.RunE = func(cmd *cobra.Command, args []string) error { ctx = cmd.Context() @@ -249,6 +240,20 @@ func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error { return print.NewPrinter(output, cmd.OutOrStdout()).PrintBytes(out) } +func (b *Builder) preRunE() func(cmd *cobra.Command, args []string) error { + return func(cmd *cobra.Command, args []string) error { + err := b.setFlagsFromConfig(cmd, args) + if err != nil { + return err + } + + k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) + b.SetKeyring(k) // global flag keyring must be set on PreRunE. + + return err + } +} + func (b *Builder) setFlagsFromConfig(cmd *cobra.Command, args []string) error { conf, err := config.CreateClientConfigFromFlags(cmd.Flags()) if err != nil { @@ -291,28 +296,36 @@ func (b *Builder) setFlagsFromConfig(cmd *cobra.Command, args []string) error { } // TODO: godoc -func (b *Builder) getQueryClientConn(cmd *cobra.Command) (*grpc.ClientConn, error) { - if cmd.Flags().Lookup("grpc-insecure") == nil || cmd.Flags().Lookup("grpc-addr") == nil { - return nil, errors.New("grpc-insecure and grpc-addr flags are required") - } - +func (b *Builder) getQueryClientConn(cmd *cobra.Command) (gogogrpc.ClientConn, error) { + var err error creds := grpcinsecure.NewCredentials() - insecure, err := cmd.Flags().GetBool("grpc-insecure") - if err != nil { - return nil, err + + insecure := true + if cmd.Flags().Lookup("grpc-insecure") != nil { + insecure, err = cmd.Flags().GetBool("grpc-insecure") + if err != nil { + return nil, err + } } if !insecure { creds = credentials.NewTLS(&tls.Config{MinVersion: tls.VersionTLS12}) } - addr, err := cmd.Flags().GetString("grpc-addr") - if err != nil { - return nil, err + var addr string + if cmd.Flags().Lookup("grpc-addr") != nil { + addr, err = cmd.Flags().GetString("grpc-addr") + if err != nil { + return nil, err + } } - if addr == "" { - // TODO: fall to default by querying state via abci query. - return nil, errors.New("grpc-addr flag must be set") + // if grpc-addr has not been set, use the default clientConn + // TODO: default is comet + node, err := cmd.Flags().GetString("node") + if err != nil { + return nil, err + } + return comet.NewCometBFTBroadcaster(node, comet.BroadcastSync, b.Cdc, b.Cdc.InterfaceRegistry()) } return grpc.NewClient(addr, []grpc.DialOption{grpc.WithTransportCredentials(creds)}...) diff --git a/client/v2/autocli/common_test.go b/client/v2/autocli/common_test.go index 30827fb3d278..71430ea9848c 100644 --- a/client/v2/autocli/common_test.go +++ b/client/v2/autocli/common_test.go @@ -81,9 +81,6 @@ func initFixture(t *testing.T) *fixture { ValidatorAddressCodec: clientCtx.ValidatorAddressCodec, ConsensusAddressCodec: clientCtx.ConsensusAddressCodec, }, - GetClientConn: func(*cobra.Command) (grpc.ClientConnInterface, error) { - return conn, nil - }, AddQueryConnFlags: flags.AddQueryFlagsToCmd, AddTxConnFlags: flags.AddTxFlagsToCmd, } diff --git a/client/v2/autocli/keyring/keyring.go b/client/v2/autocli/keyring/keyring.go index eb6d03eed817..0c39d0f32208 100644 --- a/client/v2/autocli/keyring/keyring.go +++ b/client/v2/autocli/keyring/keyring.go @@ -33,7 +33,7 @@ func NewKeyringInContext(ctx context.Context, k Keyring) context.Context { return context.WithValue(ctx, KeyringContextKey, NewKeyringImpl(k)) } -// TODO: godco +// TODO: godoc func NewKeyringFromFlags(flagSet *pflag.FlagSet, ac address.Codec, input io.Reader, cdc codec.Codec) (Keyring, error) { backEnd, err := flagSet.GetString("keyring-backend") if err != nil { diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index 200963a86be2..5a2df173fc52 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -2,6 +2,7 @@ package autocli import ( "context" + "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/tx" "fmt" @@ -167,7 +168,17 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor msg := dynamicpb.NewMessage(input.Descriptor()) proto.Merge(msg, input.Interface()) - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) + if err != nil { + return err + } + + cConn, err := b.getQueryClientConn(cmd) + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(k, b.Cdc, b.AddressCodec, b.ValidatorAddressCodec, b.EnablesSignModes, cConn, cmd.Flags(), msg) return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) } diff --git a/client/v2/autocli/msg_test.go b/client/v2/autocli/msg_test.go index 11e6fd2d2fce..18743da8c4ee 100644 --- a/client/v2/autocli/msg_test.go +++ b/client/v2/autocli/msg_test.go @@ -55,6 +55,8 @@ func TestMsg(t *testing.T) { "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", "--generate-only", "--output", "json", + "--home", fixture.home, + "--keyring-backend", fixture.keyringBackend, ) assert.NilError(t, err) assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) diff --git a/client/v2/broadcast/comet/clientConn.go b/client/v2/broadcast/comet/clientConn.go new file mode 100644 index 000000000000..ee84055f0828 --- /dev/null +++ b/client/v2/broadcast/comet/clientConn.go @@ -0,0 +1,134 @@ +package comet + +import ( + "context" + "errors" + "strconv" + + abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" + rpcclient "github.com/cometbft/cometbft/rpc/client" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/encoding" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + + errorsmod "cosmossdk.io/errors" + gogogrpc "github.com/cosmos/gogoproto/grpc" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" +) + +const grpcBlockHeightHeader = "x-cosmos-block-height" + +var _ gogogrpc.ClientConn = &CometBFTBroadcaster{} + +func (c *CometBFTBroadcaster) NewStream(_ context.Context, _ *grpc.StreamDesc, _ string, _ ...grpc.CallOption) (grpc.ClientStream, error) { + return nil, errors.New("not implemented") +} + +// TODO: godoc +func (c *CometBFTBroadcaster) Invoke(ctx context.Context, method string, req, reply interface{}, opts ...grpc.CallOption) (err error) { + reqBz, err := c.getRPCCodec().Marshal(req) + if err != nil { + return err + } + + // parse height header + md, _ := metadata.FromOutgoingContext(ctx) + var height int64 + if heights := md.Get(grpcBlockHeightHeader); len(heights) > 0 { + height, err = strconv.ParseInt(heights[0], 10, 64) + if err != nil { + return err + } + if height < 0 { + return errorsmod.Wrapf( + sdkerrors.ErrInvalidRequest, + "client.Context.Invoke: height (%d) from %q must be >= 0", height, grpctypes.GRPCBlockHeightHeader) + } + } + + abciR := abci.QueryRequest{ + Path: method, + Data: reqBz, + Height: height, + } + + res, err := c.queryABCI(abciR) + if err != nil { + return err + } + + err = c.getRPCCodec().Unmarshal(res.Value, reply) + if err != nil { + return err + } + + // Create header metadata. For now the headers contain: + // - block height + // We then parse all the call options, if the call option is a + // HeaderCallOption, then we manually set the value of that header to the + // metadata. + md = metadata.Pairs(grpctypes.GRPCBlockHeightHeader, strconv.FormatInt(res.Height, 10)) + for _, callOpt := range opts { + header, ok := callOpt.(grpc.HeaderCallOption) + if !ok { + continue + } + + *header.HeaderAddr = md + } + + if c.ir != nil { + return types.UnpackInterfaces(reply, c.ir) + } + + return nil +} + +// TODO: godoc +func (c *CometBFTBroadcaster) queryABCI(req abci.QueryRequest) (abci.QueryResponse, error) { + opts := rpcclient.ABCIQueryOptions{ + Height: req.Height, + Prove: req.Prove, + } + + result, err := c.rpcClient.ABCIQueryWithOptions(context.Background(), req.Path, req.Data, opts) + if err != nil { + return abci.QueryResponse{}, err + } + + if !result.Response.IsOK() { + return abci.QueryResponse{}, sdkErrorToGRPCError(result.Response) + } + + return result.Response, nil +} + +// TODO: godoc +func sdkErrorToGRPCError(resp abci.QueryResponse) error { + switch resp.Code { + case sdkerrors.ErrInvalidRequest.ABCICode(): + return status.Error(codes.InvalidArgument, resp.Log) + case sdkerrors.ErrUnauthorized.ABCICode(): + return status.Error(codes.Unauthenticated, resp.Log) + case sdkerrors.ErrKeyNotFound.ABCICode(): + return status.Error(codes.NotFound, resp.Log) + default: + return status.Error(codes.Unknown, resp.Log) + } +} + +// TODO: godoc +func (c *CometBFTBroadcaster) getRPCCodec() encoding.Codec { + cdc, ok := c.cdc.(codec.GRPCCodecProvider) + if !ok { + return codec.NewProtoCodec(c.ir).GRPCCodec() + } + + return cdc.GRPCCodec() +} diff --git a/client/v2/broadcast/comet/comet.go b/client/v2/broadcast/comet/comet.go index 0a04d94a2829..3cf7eeb5645f 100644 --- a/client/v2/broadcast/comet/comet.go +++ b/client/v2/broadcast/comet/comet.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/cosmos/cosmos-sdk/codec/types" "strings" "github.com/cometbft/cometbft/mempool" @@ -66,11 +67,12 @@ var _ broadcast.Broadcaster = &CometBFTBroadcaster{} type CometBFTBroadcaster struct { rpcClient CometRPC mode string - cdc codec.JSONCodec + cdc codec.Codec + ir types.InterfaceRegistry } // NewCometBFTBroadcaster creates a new CometBFTBroadcaster. -func NewCometBFTBroadcaster(rpcURL, mode string, cdc codec.JSONCodec) (*CometBFTBroadcaster, error) { +func NewCometBFTBroadcaster(rpcURL, mode string, cdc codec.Codec, ir types.InterfaceRegistry) (*CometBFTBroadcaster, error) { if cdc == nil { return nil, errors.New("codec can't be nil") } @@ -88,6 +90,7 @@ func NewCometBFTBroadcaster(rpcURL, mode string, cdc codec.JSONCodec) (*CometBFT rpcClient: rpcClient, mode: mode, cdc: cdc, + ir: ir, }, nil } diff --git a/client/v2/broadcast/comet/comet_test.go b/client/v2/broadcast/comet/comet_test.go index 0eb8b81685ed..15b5fb0114d7 100644 --- a/client/v2/broadcast/comet/comet_test.go +++ b/client/v2/broadcast/comet/comet_test.go @@ -22,7 +22,7 @@ var cdc = testutil.CodecOptions{}.NewCodec() func TestNewCometBftBroadcaster(t *testing.T) { tests := []struct { name string - cdc codec.JSONCodec + cdc codec.Codec mode string want *CometBFTBroadcaster wantErr bool @@ -45,7 +45,7 @@ func TestNewCometBftBroadcaster(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := NewCometBFTBroadcaster("localhost:26657", tt.mode, tt.cdc) + got, err := NewCometBFTBroadcaster("localhost:26657", tt.mode, tt.cdc, testutil.CodecOptions{}.NewInterfaceRegistry()) if tt.wantErr { require.Error(t, err) require.Nil(t, got) diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index 4448a287bf9c..cf1ffd5e031c 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -5,32 +5,43 @@ import ( "context" "errors" "fmt" + "github.com/cosmos/cosmos-sdk/codec/types" "os" + "github.com/cosmos/gogoproto/grpc" "github.com/cosmos/gogoproto/proto" "github.com/spf13/pflag" apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/broadcast" "cosmossdk.io/client/v2/broadcast/comet" "cosmossdk.io/client/v2/internal/account" + "cosmossdk.io/core/address" "cosmossdk.io/core/transaction" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/input" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/crypto/keyring" ) // GenerateOrBroadcastTxCLIWithBroadcaster will either generate and print an unsigned transaction // or sign it and broadcast it with the specified broadcaster returning an error upon failure. -func GenerateOrBroadcastTxCLIWithBroadcaster(ctx client.Context, flagSet *pflag.FlagSet, broadcaster broadcast.Broadcaster, msgs ...transaction.Msg) error { +func GenerateOrBroadcastTxCLIWithBroadcaster( + keybase keyring.Keyring, + cdc codec.Codec, + addressCodec, validatorCodec address.Codec, + enablesSignModes []apitxsigning.SignMode, + conn grpc.ClientConn, + flagSet *pflag.FlagSet, + broadcaster broadcast.Broadcaster, + msgs ...transaction.Msg, +) error { if err := validateMessages(msgs...); err != nil { return err } - txf, err := newFactory(ctx, flagSet) + txf, err := newFactory(keybase, cdc, addressCodec, validatorCodec, enablesSignModes, conn, flagSet) if err != nil { return err } @@ -54,44 +65,54 @@ func GenerateOrBroadcastTxCLIWithBroadcaster(ctx client.Context, flagSet *pflag. // GenerateOrBroadcastTxCLI will either generate and print an unsigned transaction // or sign it and broadcast it using default CometBFT broadcaster, returning an error upon failure. -func GenerateOrBroadcastTxCLI(ctx client.Context, flagSet *pflag.FlagSet, msgs ...transaction.Msg) error { - cometBroadcaster, err := getCometBroadcaster(ctx.Codec, flagSet) +func GenerateOrBroadcastTxCLI( + keybase keyring.Keyring, + cdc codec.Codec, + addressCodec, validatorCodec address.Codec, + enablesSignModes []apitxsigning.SignMode, + conn grpc.ClientConn, + flagSet *pflag.FlagSet, + msgs ...transaction.Msg, +) error { + cometBroadcaster, err := getCometBroadcaster(cdc, cdc.InterfaceRegistry(), flagSet) if err != nil { return err } - return GenerateOrBroadcastTxCLIWithBroadcaster(ctx, flagSet, cometBroadcaster, msgs...) + return GenerateOrBroadcastTxCLIWithBroadcaster(keybase, cdc, addressCodec, validatorCodec, enablesSignModes, conn, flagSet, cometBroadcaster, msgs...) } // getCometBroadcaster returns a new CometBFT broadcaster based on the provided context and flag set. -func getCometBroadcaster(cdc codec.JSONCodec, flagSet *pflag.FlagSet) (broadcast.Broadcaster, error) { +func getCometBroadcaster(cdc codec.Codec, ir types.InterfaceRegistry, flagSet *pflag.FlagSet) (broadcast.Broadcaster, error) { url, _ := flagSet.GetString("node") mode, _ := flagSet.GetString("broadcast-mode") - return comet.NewCometBFTBroadcaster(url, mode, cdc) + return comet.NewCometBFTBroadcaster(url, mode, cdc, ir) } // newFactory creates a new transaction Factory based on the provided context and flag set. // It initializes a new CLI keyring, extracts transaction parameters from the flag set, // configures transaction settings, and sets up an account retriever for the transaction Factory. -func newFactory(ctx client.Context, flagSet *pflag.FlagSet) (Factory, error) { - k, err := keyring.NewAutoCLIKeyring(ctx.Keyring, ctx.AddressCodec) - if err != nil { - return Factory{}, err - } - +func newFactory( + keybase keyring.Keyring, + cdc codec.Codec, + addressCodec, validatorCodec address.Codec, + enablesSignModes []apitxsigning.SignMode, + conn grpc.ClientConn, + flagSet *pflag.FlagSet, +) (Factory, error) { txConfig, err := NewTxConfig(ConfigOptions{ - AddressCodec: ctx.AddressCodec, - Cdc: ctx.Codec, - ValidatorAddressCodec: ctx.ValidatorAddressCodec, - EnabledSignModes: ctx.TxConfig.SignModeHandler().SupportedModes(), + AddressCodec: addressCodec, + Cdc: cdc, + ValidatorAddressCodec: validatorCodec, + EnabledSignModes: enablesSignModes, }) if err != nil { return Factory{}, err } - accRetriever := account.NewAccountRetriever(ctx.AddressCodec, ctx, ctx.InterfaceRegistry) + accRetriever := account.NewAccountRetriever(addressCodec, conn, cdc.InterfaceRegistry()) - txf, err := NewFactoryFromFlagSet(flagSet, k, ctx.Codec, accRetriever, txConfig, ctx.AddressCodec, ctx) + txf, err := NewFactoryFromFlagSet(flagSet, keybase, cdc, accRetriever, txConfig, addressCodec, conn) if err != nil { return Factory{}, err } @@ -142,8 +163,16 @@ func dryRun(printer *print.Printer, txf Factory, msgs ...transaction.Msg) error } // SimulateTx simulates a tx and returns the simulation response obtained by the query. -func SimulateTx(ctx client.Context, flagSet *pflag.FlagSet, msgs ...transaction.Msg) (proto.Message, error) { - txf, err := newFactory(ctx, flagSet) +func SimulateTx( + keybase keyring.Keyring, + cdc codec.Codec, + addressCodec, validatorCodec address.Codec, + enablesSignModes []apitxsigning.SignMode, + conn grpc.ClientConn, + flagSet *pflag.FlagSet, + msgs ...transaction.Msg, +) (proto.Message, error) { + txf, err := newFactory(keybase, cdc, addressCodec, validatorCodec, enablesSignModes, conn, flagSet) if err != nil { return nil, err } From 76556fc940cb2b64a1c9cbb9f0223eead816e660 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 12 Nov 2024 13:51:58 +0100 Subject: [PATCH 09/52] update: address flag + tests --- client/v2/autocli/app.go | 8 +- client/v2/autocli/builder.go | 8 +- client/v2/autocli/common.go | 70 +++++----- client/v2/autocli/common_test.go | 22 +++- client/v2/autocli/flag/address.go | 123 +++++++++++------- client/v2/autocli/msg.go | 10 +- client/v2/autocli/msg_test.go | 8 +- client/v2/autocli/print/printer.go | 15 ++- client/v2/autocli/query.go | 2 +- .../v2/autocli/testdata/help-echo-msg.golden | 1 + client/v2/broadcast/comet/clientConn.go | 5 +- client/v2/tx/encoder.go | 7 +- client/v2/tx/factory.go | 31 ++--- client/v2/tx/tx.go | 11 +- client/v2/tx/types.go | 3 +- go.mod | 3 +- server/v2/cometbft/go.mod | 2 +- server/v2/cometbft/go.sum | 1 + x/accounts/defaults/base/go.mod | 2 +- x/accounts/defaults/lockup/go.mod | 2 +- x/accounts/defaults/multisig/go.mod | 2 +- x/accounts/go.mod | 2 +- x/authz/go.mod | 2 +- x/bank/go.mod | 2 +- x/circuit/go.mod | 2 +- x/circuit/go.sum | 1 + x/consensus/go.mod | 2 +- x/consensus/go.sum | 1 + x/distribution/go.mod | 2 +- x/epochs/go.mod | 2 +- x/epochs/go.sum | 1 + x/evidence/go.mod | 2 +- x/evidence/go.sum | 1 + x/feegrant/go.mod | 2 +- x/gov/go.mod | 2 +- x/group/go.mod | 2 +- x/mint/go.mod | 2 +- x/mint/go.sum | 1 + x/nft/go.mod | 2 +- x/nft/go.sum | 1 + x/params/go.mod | 2 +- x/params/go.sum | 1 + x/protocolpool/go.mod | 2 +- x/protocolpool/go.sum | 1 + x/slashing/go.mod | 2 +- x/slashing/go.sum | 1 + x/staking/go.mod | 2 +- x/upgrade/go.mod | 2 +- x/upgrade/go.sum | 1 + 49 files changed, 233 insertions(+), 149 deletions(-) diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index 2e9f438bbe84..a6f03229ecbc 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -1,6 +1,7 @@ package autocli import ( + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/gogoproto/proto" "github.com/spf13/cobra" @@ -46,6 +47,7 @@ type AppOptions struct { Cdc codec.Codec TxConfigOpts authtx.ConfigOptions + //Keyring keyring.Keyring skipValidation bool } @@ -74,12 +76,14 @@ func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error { ValidatorAddressCodec: appOptions.ValidatorAddressCodec, ConsensusAddressCodec: appOptions.ConsensusAddressCodec, }, + GetClientConn: getQueryClientConn(appOptions.Cdc, appOptions.Cdc.InterfaceRegistry()), AddQueryConnFlags: func(c *cobra.Command) { sdkflags.AddQueryFlagsToCmd(c) sdkflags.AddKeyringFlags(c.Flags()) }, - AddTxConnFlags: sdkflags.AddTxFlagsToCmd, - Cdc: appOptions.Cdc, + AddTxConnFlags: sdkflags.AddTxFlagsToCmd, + Cdc: appOptions.Cdc, + EnablesSignModes: []apitxsigning.SignMode{apitxsigning.SignMode_SIGN_MODE_DIRECT}, } return appOptions.EnhanceRootCommandWithBuilder(rootCmd, builder) diff --git a/client/v2/autocli/builder.go b/client/v2/autocli/builder.go index bfd9e968a885..323aee719b0f 100644 --- a/client/v2/autocli/builder.go +++ b/client/v2/autocli/builder.go @@ -1,10 +1,12 @@ package autocli import ( - apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "github.com/spf13/cobra" + "google.golang.org/grpc" + apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/client/v2/autocli/flag" + "github.com/cosmos/cosmos-sdk/codec" ) @@ -13,6 +15,10 @@ type Builder struct { // flag.Builder embeds the flag builder and its options. flag.Builder + // GetClientConn specifies how CLI commands will resolve a grpc.ClientConnInterface + // from a given context. + GetClientConn func(*cobra.Command) (grpc.ClientConnInterface, error) + // AddQueryConnFlags and AddTxConnFlags are functions that add flags to query and transaction commands AddQueryConnFlags func(*cobra.Command) AddTxConnFlags func(*cobra.Command) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 82ba1b523a8f..fa029634c1ea 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -5,7 +5,6 @@ import ( "fmt" "strconv" - gogogrpc "github.com/cosmos/gogoproto/grpc" "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -19,6 +18,9 @@ import ( "cosmossdk.io/client/v2/broadcast/comet" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" ) type cmdType int @@ -236,8 +238,11 @@ func enhanceCustomCmd(builder *Builder, cmd *cobra.Command, cmdType cmdType, mod // outOrStdoutFormat formats the output based on the output flag and writes it to the command's output stream. func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error { - output, _ := cmd.Flags().GetString(flags.FlagOutput) - return print.NewPrinter(output, cmd.OutOrStdout()).PrintBytes(out) + p, err := print.NewPrinter(cmd) + if err != nil { + return err + } + return p.PrintBytes(out) } func (b *Builder) preRunE() func(cmd *cobra.Command, args []string) error { @@ -248,6 +253,7 @@ func (b *Builder) preRunE() func(cmd *cobra.Command, args []string) error { } k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) + err = nil b.SetKeyring(k) // global flag keyring must be set on PreRunE. return err @@ -296,37 +302,39 @@ func (b *Builder) setFlagsFromConfig(cmd *cobra.Command, args []string) error { } // TODO: godoc -func (b *Builder) getQueryClientConn(cmd *cobra.Command) (gogogrpc.ClientConn, error) { - var err error - creds := grpcinsecure.NewCredentials() - - insecure := true - if cmd.Flags().Lookup("grpc-insecure") != nil { - insecure, err = cmd.Flags().GetBool("grpc-insecure") - if err != nil { - return nil, err +func getQueryClientConn(cdc codec.Codec, ir types.InterfaceRegistry) func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { + return func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { + var err error + creds := grpcinsecure.NewCredentials() + + insecure := true + if cmd.Flags().Lookup("grpc-insecure") != nil { + insecure, err = cmd.Flags().GetBool("grpc-insecure") + if err != nil { + return nil, err + } + } + if !insecure { + creds = credentials.NewTLS(&tls.Config{MinVersion: tls.VersionTLS12}) } - } - if !insecure { - creds = credentials.NewTLS(&tls.Config{MinVersion: tls.VersionTLS12}) - } - var addr string - if cmd.Flags().Lookup("grpc-addr") != nil { - addr, err = cmd.Flags().GetString("grpc-addr") - if err != nil { - return nil, err + var addr string + if cmd.Flags().Lookup("grpc-addr") != nil { + addr, err = cmd.Flags().GetString("grpc-addr") + if err != nil { + return nil, err + } } - } - if addr == "" { - // if grpc-addr has not been set, use the default clientConn - // TODO: default is comet - node, err := cmd.Flags().GetString("node") - if err != nil { - return nil, err + if addr == "" { + // if grpc-addr has not been set, use the default clientConn + // TODO: default is comet + node, err := cmd.Flags().GetString("node") + if err != nil { + return nil, err + } + return comet.NewCometBFTBroadcaster(node, comet.BroadcastSync, cdc, ir) } - return comet.NewCometBFTBroadcaster(node, comet.BroadcastSync, b.Cdc, b.Cdc.InterfaceRegistry()) - } - return grpc.NewClient(addr, []grpc.DialOption{grpc.WithTransportCredentials(creds)}...) + return grpc.NewClient(addr, []grpc.DialOption{grpc.WithTransportCredentials(creds)}...) + } } diff --git a/client/v2/autocli/common_test.go b/client/v2/autocli/common_test.go index 71430ea9848c..c03c94124cfa 100644 --- a/client/v2/autocli/common_test.go +++ b/client/v2/autocli/common_test.go @@ -32,6 +32,10 @@ type fixture struct { conn *testClientConn b *Builder clientCtx client.Context + + home string + chainID string + kBackend string } func initFixture(t *testing.T) *fixture { @@ -53,7 +57,7 @@ func initFixture(t *testing.T) *fixture { assert.NilError(t, err) encodingConfig := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, bank.AppModule{}) - kr, err := sdkkeyring.New(sdk.KeyringServiceName(), sdkkeyring.BackendMemory, home, nil, encodingConfig.Codec) + kr, err := sdkkeyring.New(sdk.KeyringServiceName(), sdkkeyring.BackendTest, home, nil, encodingConfig.Codec) assert.NilError(t, err) interfaceRegistry := encodingConfig.Codec.InterfaceRegistry() @@ -81,8 +85,12 @@ func initFixture(t *testing.T) *fixture { ValidatorAddressCodec: clientCtx.ValidatorAddressCodec, ConsensusAddressCodec: clientCtx.ConsensusAddressCodec, }, + GetClientConn: func(*cobra.Command) (grpc.ClientConnInterface, error) { + return conn, nil + }, AddQueryConnFlags: flags.AddQueryFlagsToCmd, - AddTxConnFlags: flags.AddTxFlagsToCmd, + AddTxConnFlags: addTxAndGlobalFlagsToCmd, + Cdc: encodingConfig.Codec, } assert.NilError(t, b.ValidateAndComplete()) @@ -90,9 +98,19 @@ func initFixture(t *testing.T) *fixture { conn: conn, b: b, clientCtx: clientCtx, + + home: home, + chainID: "autocli-test", + kBackend: sdkkeyring.BackendTest, } } +func addTxAndGlobalFlagsToCmd(cmd *cobra.Command) { + f := cmd.Flags() + f.String("home", "", "home directory") + flags.AddTxFlagsToCmd(cmd) +} + func runCmd(fixture *fixture, command func(moduleName string, f *fixture) (*cobra.Command, error), args ...string) (*bytes.Buffer, error) { out := &bytes.Buffer{} cmd, err := command("test", fixture) diff --git a/client/v2/autocli/flag/address.go b/client/v2/autocli/flag/address.go index f7784e400bf3..e790a1557371 100644 --- a/client/v2/autocli/flag/address.go +++ b/client/v2/autocli/flag/address.go @@ -38,48 +38,55 @@ type addressValue struct { ctx *context.Context addressCodec address.Codec - value string + cachedValue string + value string } -func (a addressValue) Get(protoreflect.Value) (protoreflect.Value, error) { - return protoreflect.ValueOfString(a.value), nil +func (a *addressValue) Get(protoreflect.Value) (protoreflect.Value, error) { + if a.isEmpty() { + return protoreflect.ValueOfString(""), nil + } + + return a.get() } -func (a addressValue) String() string { +func (a *addressValue) String() string { return a.value } // Set implements the flag.Value interface for addressValue. func (a *addressValue) Set(s string) error { - if keybase == nil { - return fmt.Errorf("keybase is nil") - } - - addr, err := keybase.LookupAddressByKeyName(s) + _, err := a.addressCodec.StringToBytes(s) if err == nil { - addrStr, err := a.addressCodec.BytesToString(addr) - if err != nil { - return fmt.Errorf("invalid account address got from keyring: %w", err) - } - - a.value = addrStr - return nil + a.cachedValue = s } - - _, err = a.addressCodec.StringToBytes(s) - if err != nil { - return fmt.Errorf("invalid account address or key name: %w", err) - } - a.value = s return nil } -func (a addressValue) Type() string { +func (a *addressValue) Type() string { return "account address or key name" } +func (a *addressValue) isEmpty() bool { + return a.value == "" && a.cachedValue == "" +} + +func (a *addressValue) get() (protoreflect.Value, error) { + if a.cachedValue != "" { + return protoreflect.ValueOfString(a.cachedValue), nil + } + + addr, err := getKey(a.value, a.addressCodec) + if err != nil { + return protoreflect.Value{}, err + } + a.cachedValue = addr + + return protoreflect.ValueOfString(addr), nil +} + type consensusAddressStringType struct{} func (a consensusAddressStringType) NewValue(ctx *context.Context, b *Builder) Value { @@ -100,33 +107,13 @@ type consensusAddressValue struct { } func (a consensusAddressValue) Get(protoreflect.Value) (protoreflect.Value, error) { - return protoreflect.ValueOfString(a.value), nil -} - -func (a consensusAddressValue) String() string { - return a.value -} - -func (a *consensusAddressValue) Set(s string) error { - if keybase == nil { - return fmt.Errorf("keybase is nil") + if a.isEmpty() { + return protoreflect.ValueOfString(""), nil } - addr, err := keybase.LookupAddressByKeyName(s) + addr, err := a.get() if err == nil { - addrStr, err := a.addressCodec.BytesToString(addr) - if err != nil { - return fmt.Errorf("invalid consensus address got from keyring: %w", err) - } - - a.value = addrStr - return nil - } - - _, err = a.addressCodec.StringToBytes(s) - if err == nil { - a.value = s - return nil + return addr, nil } // fallback to pubkey parsing @@ -135,15 +122,51 @@ func (a *consensusAddressValue) Set(s string) error { cdc := codec.NewProtoCodec(registry) var pk cryptotypes.PubKey - err2 := cdc.UnmarshalInterfaceJSON([]byte(s), &pk) + err2 := cdc.UnmarshalInterfaceJSON([]byte(a.value), &pk) if err2 != nil { - return fmt.Errorf("input isn't a pubkey (%w) or is an invalid account address (%w)", err, err2) + return protoreflect.Value{}, fmt.Errorf("input isn't a pubkey (%w) or is an invalid account address (%w)", err, err2) } a.value, err = a.addressCodec.BytesToString(pk.Address()) if err != nil { - return fmt.Errorf("invalid pubkey address: %w", err) + return protoreflect.Value{}, fmt.Errorf("invalid pubkey address: %w", err) } + a.cachedValue = a.value + + return protoreflect.ValueOfString(a.value), nil +} + +func (a consensusAddressValue) String() string { + return a.value +} + +func (a *consensusAddressValue) Set(s string) error { + _, err := a.addressCodec.StringToBytes(s) + if err == nil { + a.cachedValue = s + } + + a.value = s return nil } + +func getKey(k string, ac address.Codec) (string, error) { + if keybase != nil { + addr, err := keybase.LookupAddressByKeyName(k) + if err == nil { + addrStr, err := ac.BytesToString(addr) + if err != nil { + return "", fmt.Errorf("invalid account address got from keyring: %w", err) + } + return addrStr, nil + } + } + + _, err := ac.StringToBytes(k) + if err != nil { + return "", fmt.Errorf("invalid account address or key name: %w", err) + } + + return k, nil +} diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index 5a2df173fc52..9ecb03245a9c 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -14,6 +14,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli/flag" + "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" addresscodec "cosmossdk.io/core/address" @@ -173,12 +174,17 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor return err } - cConn, err := b.getQueryClientConn(cmd) + cConn, err := b.GetClientConn(cmd) if err != nil { return err } - return tx.GenerateOrBroadcastTxCLI(k, b.Cdc, b.AddressCodec, b.ValidatorAddressCodec, b.EnablesSignModes, cConn, cmd.Flags(), msg) + printer, err := print.NewPrinter(cmd) + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(cmd.Flags(), printer, k, b.Cdc, b.AddressCodec, b.ValidatorAddressCodec, b.EnablesSignModes, cConn, msg) return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) } diff --git a/client/v2/autocli/msg_test.go b/client/v2/autocli/msg_test.go index 18743da8c4ee..2bc86f9281e5 100644 --- a/client/v2/autocli/msg_test.go +++ b/client/v2/autocli/msg_test.go @@ -55,8 +55,7 @@ func TestMsg(t *testing.T) { "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", "--generate-only", "--output", "json", - "--home", fixture.home, - "--keyring-backend", fixture.keyringBackend, + "--generate-only", "--offline", ) assert.NilError(t, err) assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) @@ -76,6 +75,7 @@ func TestMsg(t *testing.T) { "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", "--generate-only", "--output", "json", + "--generate-only", "--offline", ) assert.NilError(t, err) assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) @@ -95,8 +95,8 @@ func TestMsg(t *testing.T) { }), "send", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", "--from", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", - "--generate-only", "--output", "json", + "--generate-only", "--offline", ) assert.NilError(t, err) assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) @@ -118,8 +118,8 @@ func TestMsg(t *testing.T) { }), "send", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", "--sender", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", - "--generate-only", "--output", "json", + "--generate-only", "--offline", ) assert.NilError(t, err) assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) diff --git a/client/v2/autocli/print/printer.go b/client/v2/autocli/print/printer.go index eb570b27a31d..62be430aedba 100644 --- a/client/v2/autocli/print/printer.go +++ b/client/v2/autocli/print/printer.go @@ -2,6 +2,7 @@ package print import ( "encoding/json" + "github.com/spf13/cobra" "io" "os" @@ -20,15 +21,15 @@ type Printer struct { } // NewPrinter creates a new Printer instance with default stdout -func NewPrinter(format string, out io.Writer) *Printer { - if format == "" { - format = jsonOutput +func NewPrinter(cmd *cobra.Command) (*Printer, error) { + outputFormat, err := cmd.Flags().GetString("output") + if err != nil { + return nil, err } - return &Printer{ - Output: out, - OutputFormat: format, - } + Output: cmd.OutOrStdout(), + OutputFormat: outputFormat, + }, nil } // PrintString prints the raw string diff --git a/client/v2/autocli/query.go b/client/v2/autocli/query.go index 3d6db547ccaf..8e95b4eddb0e 100644 --- a/client/v2/autocli/query.go +++ b/client/v2/autocli/query.go @@ -129,7 +129,7 @@ func (b *Builder) BuildQueryMethodCommand(ctx context.Context, descriptor protor } cmd, err := b.buildMethodCommandCommon(descriptor, options, func(cmd *cobra.Command, input protoreflect.Message) error { - clientConn, err := b.getQueryClientConn(cmd) + clientConn, err := b.GetClientConn(cmd) if err != nil { return err } diff --git a/client/v2/autocli/testdata/help-echo-msg.golden b/client/v2/autocli/testdata/help-echo-msg.golden index 1307509569c9..0761494efde8 100644 --- a/client/v2/autocli/testdata/help-echo-msg.golden +++ b/client/v2/autocli/testdata/help-echo-msg.golden @@ -18,6 +18,7 @@ Flags: --gas-prices string Determine the transaction fee by multiplying max gas units by gas prices (e.g. 0.1uatom), rounding up to nearest denom unit --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) -h, --help help for send + --home string home directory --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) (default "os") --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used --ledger Use a connected Ledger device diff --git a/client/v2/broadcast/comet/clientConn.go b/client/v2/broadcast/comet/clientConn.go index ee84055f0828..d76557247097 100644 --- a/client/v2/broadcast/comet/clientConn.go +++ b/client/v2/broadcast/comet/clientConn.go @@ -24,7 +24,10 @@ import ( const grpcBlockHeightHeader = "x-cosmos-block-height" -var _ gogogrpc.ClientConn = &CometBFTBroadcaster{} +var ( + _ gogogrpc.ClientConn = &CometBFTBroadcaster{} + _ grpc.ClientConnInterface = &CometBFTBroadcaster{} +) func (c *CometBFTBroadcaster) NewStream(_ context.Context, _ *grpc.StreamDesc, _ string, _ ...grpc.CallOption) (grpc.ClientStream, error) { return nil, errors.New("not implemented") diff --git a/client/v2/tx/encoder.go b/client/v2/tx/encoder.go index 3e917b34b4c3..09011c8315e4 100644 --- a/client/v2/tx/encoder.go +++ b/client/v2/tx/encoder.go @@ -19,9 +19,10 @@ var ( // jsonMarshalOptions configures JSON marshaling for protobuf messages. jsonMarshalOptions = protojson.MarshalOptions{ - Indent: "", - UseProtoNames: true, - UseEnumNumbers: false, + Indent: "", + UseProtoNames: true, + UseEnumNumbers: false, + EmitUnpopulated: true, } // textMarshalOptions diff --git a/client/v2/tx/factory.go b/client/v2/tx/factory.go index 8007caaee4f8..a54900ea75e5 100644 --- a/client/v2/tx/factory.go +++ b/client/v2/tx/factory.go @@ -87,30 +87,31 @@ func NewFactory(keybase keyring.Keyring, cdc codec.BinaryCodec, accRetriever acc // validateFlagSet checks the provided flags for consistency and requirements based on the operation mode. func validateFlagSet(flags *pflag.FlagSet, offline bool) error { + dryRun, _ := flags.GetBool(flags2.FlagDryRun) + if offline && dryRun { + return errors.New("dry-run: cannot use offline mode") + } + + generateOnly, _ := flags.GetBool(flags2.FlagGenerateOnly) + chainID, _ := flags.GetString(flags2.FlagChainID) if offline { - if !flags.Changed(flags2.FlagAccountNumber) || !flags.Changed(flags2.FlagSequence) { + if !generateOnly && (!flags.Changed(flags2.FlagAccountNumber) || !flags.Changed(flags2.FlagSequence)) { return errors.New("account-number and sequence must be set in offline mode") } + if generateOnly && chainID != "" { + return errors.New("chain ID cannot be used when offline and generate-only flags are set") + } + gas, _ := flags.GetString(flags2.FlagGas) gasSetting, _ := flags2.ParseGasSetting(gas) if gasSetting.Simulate { return errors.New("simulate and offline flags cannot be set at the same time") } - } - - generateOnly, _ := flags.GetBool(flags2.FlagGenerateOnly) - chainID, _ := flags.GetString(flags2.FlagChainID) - if offline && generateOnly && chainID != "" { - return errors.New("chain ID cannot be used when offline and generate-only flags are set") - } - if chainID == "" { - return errors.New("chain ID required but not specified") - } - - dryRun, _ := flags.GetBool(flags2.FlagDryRun) - if offline && dryRun { - return errors.New("dry-run: cannot use offline mode") + } else { + if chainID == "" { + return errors.New("chain ID required but not specified") + } } return nil diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index cf1ffd5e031c..c659ba907ad6 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -28,12 +28,13 @@ import ( // GenerateOrBroadcastTxCLIWithBroadcaster will either generate and print an unsigned transaction // or sign it and broadcast it with the specified broadcaster returning an error upon failure. func GenerateOrBroadcastTxCLIWithBroadcaster( + flagSet *pflag.FlagSet, + printer *print.Printer, keybase keyring.Keyring, cdc codec.Codec, addressCodec, validatorCodec address.Codec, enablesSignModes []apitxsigning.SignMode, conn grpc.ClientConn, - flagSet *pflag.FlagSet, broadcaster broadcast.Broadcaster, msgs ...transaction.Msg, ) error { @@ -46,9 +47,6 @@ func GenerateOrBroadcastTxCLIWithBroadcaster( return err } - output, _ := flagSet.GetString("output") - printer := print.NewPrinter(output, os.Stdout) - genOnly, _ := flagSet.GetBool(flagGenerateOnly) if genOnly { return generateOnly(printer, txf, msgs...) @@ -66,12 +64,13 @@ func GenerateOrBroadcastTxCLIWithBroadcaster( // GenerateOrBroadcastTxCLI will either generate and print an unsigned transaction // or sign it and broadcast it using default CometBFT broadcaster, returning an error upon failure. func GenerateOrBroadcastTxCLI( + flagSet *pflag.FlagSet, + printer *print.Printer, keybase keyring.Keyring, cdc codec.Codec, addressCodec, validatorCodec address.Codec, enablesSignModes []apitxsigning.SignMode, conn grpc.ClientConn, - flagSet *pflag.FlagSet, msgs ...transaction.Msg, ) error { cometBroadcaster, err := getCometBroadcaster(cdc, cdc.InterfaceRegistry(), flagSet) @@ -79,7 +78,7 @@ func GenerateOrBroadcastTxCLI( return err } - return GenerateOrBroadcastTxCLIWithBroadcaster(keybase, cdc, addressCodec, validatorCodec, enablesSignModes, conn, flagSet, cometBroadcaster, msgs...) + return GenerateOrBroadcastTxCLIWithBroadcaster(flagSet, printer, keybase, cdc, addressCodec, validatorCodec, enablesSignModes, conn, cometBroadcaster, msgs...) } // getCometBroadcaster returns a new CometBFT broadcaster based on the provided context and flag set. diff --git a/client/v2/tx/types.go b/client/v2/tx/types.go index a50b0b996b1d..bd83cc994d58 100644 --- a/client/v2/tx/types.go +++ b/client/v2/tx/types.go @@ -161,7 +161,8 @@ func txParamsFromFlagSet(flags *pflag.FlagSet, keybase keyring2.Keyring, ac addr var fromName, fromAddress string var addr []byte isDryRun, _ := flags.GetBool(flagDryRun) - if isDryRun { + generaOnly, _ := flags.GetBool(flagGenerateOnly) + if isDryRun || generaOnly { addr, err = ac.StringToBytes(from) } else { fromName, fromAddress, _, err = keybase.KeyInfo(from) diff --git a/go.mod b/go.mod index 989c93e49508..a81a22830eb1 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,8 @@ module github.com/cosmos/cosmos-sdk require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/client/v2 v2.0.0-00010101000000-000000000000 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/server/v2/cometbft/go.mod b/server/v2/cometbft/go.mod index 9953c7fe6aae..d415d8be3766 100644 --- a/server/v2/cometbft/go.mod +++ b/server/v2/cometbft/go.mod @@ -18,7 +18,7 @@ replace ( require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 cosmossdk.io/log v1.4.1 diff --git a/server/v2/cometbft/go.sum b/server/v2/cometbft/go.sum index a938ee149eb7..7ee7f38da46f 100644 --- a/server/v2/cometbft/go.sum +++ b/server/v2/cometbft/go.sum @@ -6,6 +6,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= diff --git a/x/accounts/defaults/base/go.mod b/x/accounts/defaults/base/go.mod index 80690ef5c1b9..7ac57d3627aa 100644 --- a/x/accounts/defaults/base/go.mod +++ b/x/accounts/defaults/base/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/depinject v1.1.0 cosmossdk.io/x/accounts v0.0.0-20240913065641-0064ccbce64e diff --git a/x/accounts/defaults/lockup/go.mod b/x/accounts/defaults/lockup/go.mod index 4d8baa44ad44..eee9435bfe19 100644 --- a/x/accounts/defaults/lockup/go.mod +++ b/x/accounts/defaults/lockup/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/x/accounts/defaults/lockup go 1.23.1 require ( - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/x/accounts v0.0.0-20240226161501-23359a0b6d91 cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 diff --git a/x/accounts/defaults/multisig/go.mod b/x/accounts/defaults/multisig/go.mod index 8f295f2b47e3..932749dee02b 100644 --- a/x/accounts/defaults/multisig/go.mod +++ b/x/accounts/defaults/multisig/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/x/accounts/defaults/multisig go 1.23.1 require ( - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/math v1.3.0 cosmossdk.io/x/accounts v0.0.0-00010101000000-000000000000 diff --git a/x/accounts/go.mod b/x/accounts/go.mod index b461e82683e9..25f9734ad240 100644 --- a/x/accounts/go.mod +++ b/x/accounts/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/x/authz/go.mod b/x/authz/go.mod index 8759375550fa..3da4f51970b9 100644 --- a/x/authz/go.mod +++ b/x/authz/go.mod @@ -29,7 +29,7 @@ require ( require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect - cosmossdk.io/collections v0.4.0 // indirect + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a // indirect cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect diff --git a/x/bank/go.mod b/x/bank/go.mod index 25dbf03fcc42..91e3562688fd 100644 --- a/x/bank/go.mod +++ b/x/bank/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/depinject v1.1.0 cosmossdk.io/errors v1.0.1 diff --git a/x/circuit/go.mod b/x/circuit/go.mod index 193dc8826a1c..42984167b999 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/x/circuit/go.sum b/x/circuit/go.sum index 76d55873addd..7418dbbad86c 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -6,6 +6,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= diff --git a/x/consensus/go.mod b/x/consensus/go.mod index 07ac7e475470..2096263b13b9 100644 --- a/x/consensus/go.mod +++ b/x/consensus/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/x/consensus/go.sum b/x/consensus/go.sum index 76d55873addd..7418dbbad86c 100644 --- a/x/consensus/go.sum +++ b/x/consensus/go.sum @@ -6,6 +6,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= diff --git a/x/distribution/go.mod b/x/distribution/go.mod index 2b40844a6e2b..613728602841 100644 --- a/x/distribution/go.mod +++ b/x/distribution/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/x/epochs/go.mod b/x/epochs/go.mod index ae70e7c29e64..6455b581f06e 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/x/epochs/go.sum b/x/epochs/go.sum index 76d55873addd..7418dbbad86c 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -6,6 +6,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= diff --git a/x/evidence/go.mod b/x/evidence/go.mod index 9607ae6ef8e5..5e766e62f8c7 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/x/evidence/go.sum b/x/evidence/go.sum index 76d55873addd..7418dbbad86c 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -6,6 +6,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index 037eb7f51ffa..3b92bd05f5df 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/x/gov/go.mod b/x/gov/go.mod index c0b2fd4dbe7f..02b6fef11c0b 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/x/group/go.mod b/x/group/go.mod index dcec15ff94c8..0495494a5066 100644 --- a/x/group/go.mod +++ b/x/group/go.mod @@ -37,7 +37,7 @@ require ( require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect - cosmossdk.io/collections v0.4.0 // indirect + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a // indirect cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/epochs v0.0.0-20240522060652-a1ae4c3e0337 // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect diff --git a/x/mint/go.mod b/x/mint/go.mod index 04c52cb9f26c..8f24c9d8fa19 100644 --- a/x/mint/go.mod +++ b/x/mint/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/x/mint/go.sum b/x/mint/go.sum index 76d55873addd..7418dbbad86c 100644 --- a/x/mint/go.sum +++ b/x/mint/go.sum @@ -6,6 +6,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= diff --git a/x/nft/go.mod b/x/nft/go.mod index 4e2e2185ef24..7f6e39fef892 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -24,7 +24,7 @@ require ( require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect - cosmossdk.io/collections v0.4.0 // indirect + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a // indirect cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 // indirect cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect diff --git a/x/nft/go.sum b/x/nft/go.sum index 76d55873addd..7418dbbad86c 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -6,6 +6,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= diff --git a/x/params/go.mod b/x/params/go.mod index f78042ea0011..724b516d9377 100644 --- a/x/params/go.mod +++ b/x/params/go.mod @@ -28,7 +28,7 @@ require ( require ( buf.build/gen/go/cometbft/cometbft/protocolbuffers/go v1.35.1-20240701160653-fedbb9acfd2f.1 // indirect buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect - cosmossdk.io/collections v0.4.0 // indirect + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a // indirect cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/tx v1.0.0-alpha.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect diff --git a/x/params/go.sum b/x/params/go.sum index b3bdc4c818d9..e0ab09b312f3 100644 --- a/x/params/go.sum +++ b/x/params/go.sum @@ -6,6 +6,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= diff --git a/x/protocolpool/go.mod b/x/protocolpool/go.mod index d65dbde8c034..77f51b366aa9 100644 --- a/x/protocolpool/go.mod +++ b/x/protocolpool/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/x/protocolpool/go.sum b/x/protocolpool/go.sum index 76d55873addd..7418dbbad86c 100644 --- a/x/protocolpool/go.sum +++ b/x/protocolpool/go.sum @@ -6,6 +6,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= diff --git a/x/slashing/go.mod b/x/slashing/go.mod index 359b841030d4..0bf3e82fb818 100644 --- a/x/slashing/go.mod +++ b/x/slashing/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/x/slashing/go.sum b/x/slashing/go.sum index bd44dd0a8f3a..09e782532486 100644 --- a/x/slashing/go.sum +++ b/x/slashing/go.sum @@ -6,6 +6,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= diff --git a/x/staking/go.mod b/x/staking/go.mod index df6244bfedf1..082cf12905d3 100644 --- a/x/staking/go.mod +++ b/x/staking/go.mod @@ -4,7 +4,7 @@ go 1.23.1 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/collections v0.4.0 + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a cosmossdk.io/core v1.0.0-alpha.5 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/depinject v1.1.0 diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index cc3468c7cc24..6ad10d5a3e03 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -40,7 +40,7 @@ require ( cloud.google.com/go/compute/metadata v0.5.0 // indirect cloud.google.com/go/iam v1.1.13 // indirect cloud.google.com/go/storage v1.43.0 // indirect - cosmossdk.io/collections v0.4.0 // indirect + cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a // indirect cosmossdk.io/math v1.3.0 // indirect cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index 7094771a0638..a3dfa03b4cb5 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -194,6 +194,7 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.5 h1:McjYXAQ6XcT20v2uHyH7PhoWH8V+mebzfVFqT3GinsI= cosmossdk.io/core v1.0.0-alpha.5/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= From 3b2c8d570d561bfbd2865518807ba5437a87228c Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 13 Nov 2024 10:59:58 +0100 Subject: [PATCH 10/52] del: client.Context from offchain --- client/v2/offchain/cli.go | 45 ++++++++-- client/v2/offchain/common_test.go | 131 ++---------------------------- client/v2/offchain/sign.go | 33 ++++---- client/v2/offchain/sign_test.go | 16 ++-- client/v2/offchain/verify.go | 19 +++-- client/v2/offchain/verify_test.go | 33 ++------ 6 files changed, 93 insertions(+), 184 deletions(-) diff --git a/client/v2/offchain/cli.go b/client/v2/offchain/cli.go index 7738a6204451..1278eddaa3d0 100644 --- a/client/v2/offchain/cli.go +++ b/client/v2/offchain/cli.go @@ -1,11 +1,18 @@ package offchain import ( + "cosmossdk.io/client/v2/autocli/keyring" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "os" "path/filepath" "github.com/spf13/cobra" + "cosmossdk.io/client/v2/autocli/config" v2flags "cosmossdk.io/client/v2/internal/flags" "github.com/cosmos/cosmos-sdk/client" @@ -15,6 +22,7 @@ import ( const ( flagEncoding = "encoding" flagFileFormat = "file-format" + flagBech32 = "bech32" ) // OffChain off-chain utilities. @@ -31,6 +39,7 @@ func OffChain() *cobra.Command { ) flags.AddKeyringFlags(cmd.PersistentFlags()) + cmd.PersistentFlags().String(flagBech32, "cosmos", "address bech32 prefix") return cmd } @@ -42,6 +51,19 @@ func SignFile() *cobra.Command { Long: "Sign a file using a given key.", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { + ir := types.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(ir) + + c, err := config.CreateClientConfigFromFlags(cmd.Flags()) + if err != nil { + return err + } + + keyringBackend := c.KeyringBackend + if !cmd.Flags().Changed(flags.FlagKeyringBackend) { + cmd.Flags().Set(flags.FlagKeyringBackend, keyringBackend) + } + clientCtx := client.GetClientContextFromCmd(cmd) bz, err := os.ReadFile(args[1]) @@ -53,8 +75,17 @@ func SignFile() *cobra.Command { outputFormat, _ := cmd.Flags().GetString(v2flags.FlagOutput) outputFile, _ := cmd.Flags().GetString(flags.FlagOutputDocument) signMode, _ := cmd.Flags().GetString(flags.FlagSignMode) + bech32Prefix, _ := cmd.Flags().GetString(flagBech32) - signedTx, err := Sign(clientCtx, bz, args[0], encoding, signMode, outputFormat) + ac := address.NewBech32Codec(bech32Prefix) + vc := address.NewBech32Codec(sdk.GetBech32PrefixValAddr(bech32Prefix)) + k, err := keyring.NewKeyringFromFlags(cmd.Flags(), clientCtx.AddressCodec, cmd.InOrStdin(), clientCtx.Codec) + if err != nil { + return err + } + + signedTx, err := Sign(bz, clientCtx, k, cdc, ac, + vc, ir, args[0], encoding, signMode, outputFormat) if err != nil { return err } @@ -87,10 +118,8 @@ func VerifyFile() *cobra.Command { Long: "Verify a previously signed file with the given key.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } + ir := types.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(ir) bz, err := os.ReadFile(args[0]) if err != nil { @@ -98,8 +127,12 @@ func VerifyFile() *cobra.Command { } fileFormat, _ := cmd.Flags().GetString(flagFileFormat) + bech32Prefix, _ := cmd.Flags().GetString(flagBech32) + + ac := address.NewBech32Codec(bech32Prefix) + vc := address.NewBech32Codec(sdk.GetBech32PrefixValAddr(bech32Prefix)) - err = Verify(clientCtx, bz, fileFormat) + err = Verify(cdc, ac, vc, bz, fileFormat) if err == nil { cmd.Println("Verification OK!") } diff --git a/client/v2/offchain/common_test.go b/client/v2/offchain/common_test.go index 5b862fcb20bb..8c7d02546e15 100644 --- a/client/v2/offchain/common_test.go +++ b/client/v2/offchain/common_test.go @@ -2,32 +2,16 @@ package offchain import ( "context" - "testing" - - "github.com/stretchr/testify/require" + "errors" + gogogrpc "github.com/cosmos/gogoproto/grpc" "google.golang.org/grpc" - bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" - "cosmossdk.io/x/tx/signing" - "cosmossdk.io/x/tx/signing/aminojson" - "cosmossdk.io/x/tx/signing/direct" - "cosmossdk.io/x/tx/signing/directaux" - "cosmossdk.io/x/tx/signing/textual" - - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/codec/testutil" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" ) -const ( - addressCodecPrefix = "cosmos" - validatorAddressCodecPrefix = "cosmosvaloper" - mnemonic = "have embark stumble card pistol fun gauge obtain forget oil awesome lottery unfold corn sure original exist siren pudding spread uphold dwarf goddess card" -) +const mnemonic = "have embark stumble card pistol fun gauge obtain forget oil awesome lottery unfold corn sure original exist siren pudding spread uphold dwarf goddess card" func getCodec() codec.Codec { registry := testutil.CodecOptions{}.NewInterfaceRegistry() @@ -36,111 +20,14 @@ func getCodec() codec.Codec { return codec.NewProtoCodec(registry) } -func newGRPCCoinMetadataQueryFn(grpcConn grpc.ClientConnInterface) textual.CoinMetadataQueryFn { - return func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) { - bankQueryClient := bankv1beta1.NewQueryClient(grpcConn) - res, err := bankQueryClient.DenomMetadata(ctx, &bankv1beta1.QueryDenomMetadataRequest{ - Denom: denom, - }) - if err != nil { - return nil, err - } - - return res.Metadata, nil - } -} - -// testConfig fulfills client.TxConfig although SignModeHandler is the only method implemented. -type testConfig struct { - handler *signing.HandlerMap -} - -func (t testConfig) SignModeHandler() *signing.HandlerMap { - return t.handler -} - -func (t testConfig) TxEncoder() sdk.TxEncoder { - return nil -} - -func (t testConfig) TxDecoder() sdk.TxDecoder { - return nil -} - -func (t testConfig) TxJSONEncoder() sdk.TxEncoder { - return nil -} - -func (t testConfig) TxJSONDecoder() sdk.TxDecoder { - return nil -} - -func (t testConfig) MarshalSignatureJSON(v2s []signingtypes.SignatureV2) ([]byte, error) { - return nil, nil -} - -func (t testConfig) UnmarshalSignatureJSON(bytes []byte) ([]signingtypes.SignatureV2, error) { - return nil, nil -} +var _ gogogrpc.ClientConn = mockClientConn{} -func (t testConfig) NewTxBuilder() client.TxBuilder { - return nil -} - -func (t testConfig) WrapTxBuilder(s sdk.Tx) (client.TxBuilder, error) { - return nil, nil -} +type mockClientConn struct{} -func (t testConfig) SigningContext() *signing.Context { - return nil +func (c mockClientConn) Invoke(_ context.Context, _ string, _, _ interface{}, _ ...grpc.CallOption) error { + return errors.New("not implemented") } -func newTestConfig(t *testing.T) *testConfig { - t.Helper() - - enabledSignModes := []signingtypes.SignMode{ - signingtypes.SignMode_SIGN_MODE_DIRECT, - signingtypes.SignMode_SIGN_MODE_DIRECT_AUX, - signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, - signingtypes.SignMode_SIGN_MODE_TEXTUAL, - } - - var err error - signingOptions := signing.Options{ - AddressCodec: address.NewBech32Codec(addressCodecPrefix), - ValidatorAddressCodec: address.NewBech32Codec(validatorAddressCodecPrefix), - } - signingContext, err := signing.NewContext(signingOptions) - require.NoError(t, err) - - lenSignModes := len(enabledSignModes) - handlers := make([]signing.SignModeHandler, lenSignModes) - for i, m := range enabledSignModes { - var err error - switch m { - case signingtypes.SignMode_SIGN_MODE_DIRECT: - handlers[i] = &direct.SignModeHandler{} - case signingtypes.SignMode_SIGN_MODE_DIRECT_AUX: - handlers[i], err = directaux.NewSignModeHandler(directaux.SignModeHandlerOptions{ - TypeResolver: signingOptions.TypeResolver, - SignersContext: signingContext, - }) - require.NoError(t, err) - case signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: - handlers[i] = aminojson.NewSignModeHandler(aminojson.SignModeHandlerOptions{ - FileResolver: signingOptions.FileResolver, - TypeResolver: signingOptions.TypeResolver, - }) - case signingtypes.SignMode_SIGN_MODE_TEXTUAL: - handlers[i], err = textual.NewSignModeHandler(textual.SignModeOptions{ - CoinMetadataQuerier: newGRPCCoinMetadataQueryFn(client.Context{}), - FileResolver: signingOptions.FileResolver, - TypeResolver: signingOptions.TypeResolver, - }) - require.NoError(t, err) - } - } - - handler := signing.NewHandlerMap(handlers...) - return &testConfig{handler: handler} +func (c mockClientConn) NewStream(_ context.Context, _ *grpc.StreamDesc, _ string, _ ...grpc.CallOption) (grpc.ClientStream, error) { + return nil, errors.New("not implemented") } diff --git a/client/v2/offchain/sign.go b/client/v2/offchain/sign.go index 8dfcb907c089..4ea7f98c575b 100644 --- a/client/v2/offchain/sign.go +++ b/client/v2/offchain/sign.go @@ -3,14 +3,17 @@ package offchain import ( "context" "fmt" + gogogrpc "github.com/cosmos/gogoproto/grpc" apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/internal/account" "cosmossdk.io/client/v2/internal/offchain" clitx "cosmossdk.io/client/v2/tx" + "cosmossdk.io/core/address" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/version" ) @@ -29,28 +32,30 @@ var enabledSignModes = []apisigning.SignMode{ } // Sign signs given bytes using the specified encoder and SignMode. -func Sign(ctx client.Context, rawBytes []byte, fromName, encoding, signMode, output string) (string, error) { +func Sign( + rawBytes []byte, + conn gogogrpc.ClientConn, + keybase keyring.Keyring, + cdc codec.BinaryCodec, addressCodec, validatorAddressCodec address.Codec, + ir types.InterfaceRegistry, + fromName, encoding, signMode, output string, +) (string, error) { digest, err := encodeDigest(encoding, rawBytes) if err != nil { return "", err } - keybase, err := keyring.NewAutoCLIKeyring(ctx.Keyring, ctx.AddressCodec) - if err != nil { - return "", err - } - txConfig, err := clitx.NewTxConfig(clitx.ConfigOptions{ - AddressCodec: ctx.AddressCodec, - Cdc: ctx.Codec, - ValidatorAddressCodec: ctx.ValidatorAddressCodec, + AddressCodec: addressCodec, + Cdc: cdc, + ValidatorAddressCodec: validatorAddressCodec, EnabledSignModes: enabledSignModes, }) if err != nil { return "", err } - accRetriever := account.NewAccountRetriever(ctx.AddressCodec, ctx, ctx.InterfaceRegistry) + accRetriever := account.NewAccountRetriever(addressCodec, conn, ir) sm, err := getSignMode(signMode) if err != nil { @@ -66,7 +71,7 @@ func Sign(ctx client.Context, rawBytes []byte, fromName, encoding, signMode, out }, } - txf, err := clitx.NewFactory(keybase, ctx.Codec, accRetriever, txConfig, ctx.AddressCodec, ctx, params) + txf, err := clitx.NewFactory(keybase, cdc, accRetriever, txConfig, addressCodec, conn, params) if err != nil { return "", err } @@ -76,7 +81,7 @@ func Sign(ctx client.Context, rawBytes []byte, fromName, encoding, signMode, out return "", err } - addr, err := ctx.AddressCodec.BytesToString(pubKey.Address()) + addr, err := addressCodec.BytesToString(pubKey.Address()) if err != nil { return "", err } diff --git a/client/v2/offchain/sign_test.go b/client/v2/offchain/sign_test.go index 839872866629..08d02031947c 100644 --- a/client/v2/offchain/sign_test.go +++ b/client/v2/offchain/sign_test.go @@ -5,24 +5,21 @@ import ( "github.com/stretchr/testify/require" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" ) func TestSign(t *testing.T) { + ac := address.NewBech32Codec("cosmos") + vc := address.NewBech32Codec("cosmosvaloper") k := keyring.NewInMemory(getCodec()) _, err := k.NewAccount("signVerify", mnemonic, "", "m/44'/118'/0'/0/0", hd.Secp256k1) require.NoError(t, err) - ctx := client.Context{ - TxConfig: newTestConfig(t), - Codec: getCodec(), - AddressCodec: address.NewBech32Codec("cosmos"), - ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), - Keyring: k, - } + autoKeyring, err := keyring.NewAutoCLIKeyring(k, ac) + require.NoError(t, err) + tests := []struct { name string rawBytes []byte @@ -52,7 +49,8 @@ func TestSign(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := Sign(ctx, tt.rawBytes, "signVerify", tt.encoding, tt.signMode, "json") + got, err := Sign(tt.rawBytes, mockClientConn{}, autoKeyring, getCodec(), ac, vc, getCodec().InterfaceRegistry(), + "signVerify", tt.encoding, tt.signMode, "json") if tt.wantErr { require.Error(t, err) } else { diff --git a/client/v2/offchain/verify.go b/client/v2/offchain/verify.go index 2c064faccc71..87cfc25a9327 100644 --- a/client/v2/offchain/verify.go +++ b/client/v2/offchain/verify.go @@ -3,25 +3,26 @@ package offchain import ( "bytes" "context" + "cosmossdk.io/core/address" "errors" "fmt" + "github.com/cosmos/cosmos-sdk/codec" "google.golang.org/protobuf/types/known/anypb" clitx "cosmossdk.io/client/v2/tx" txsigning "cosmossdk.io/x/tx/signing" - "github.com/cosmos/cosmos-sdk/client" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) // Verify verifies a digest after unmarshalling it. -func Verify(ctx client.Context, digest []byte, fileFormat string) error { +func Verify(cdc codec.Codec, addressCodec, validatorAddressCodec address.Codec, digest []byte, fileFormat string) error { txConfig, err := clitx.NewTxConfig(clitx.ConfigOptions{ - AddressCodec: ctx.AddressCodec, - Cdc: ctx.Codec, - ValidatorAddressCodec: ctx.ValidatorAddressCodec, + AddressCodec: addressCodec, + Cdc: cdc, + ValidatorAddressCodec: validatorAddressCodec, EnabledSignModes: enabledSignModes, }) if err != nil { @@ -33,12 +34,12 @@ func Verify(ctx client.Context, digest []byte, fileFormat string) error { return err } - return verify(ctx, dTx) + return verify(addressCodec, txConfig, dTx) } // verify verifies given Tx. -func verify(ctx client.Context, dTx clitx.Tx) error { - signModeHandler := ctx.TxConfig.SignModeHandler() +func verify(addressCodec address.Codec, txConfig clitx.TxConfig, dTx clitx.Tx) error { + signModeHandler := txConfig.SignModeHandler() signers, err := dTx.GetSigners() if err != nil { @@ -60,7 +61,7 @@ func verify(ctx client.Context, dTx clitx.Tx) error { return errors.New("signature does not match its respective signer") } - addr, err := ctx.AddressCodec.BytesToString(pubKey.Address()) + addr, err := addressCodec.BytesToString(pubKey.Address()) if err != nil { return err } diff --git a/client/v2/offchain/verify_test.go b/client/v2/offchain/verify_test.go index 56345504d80e..5e22bb131df5 100644 --- a/client/v2/offchain/verify_test.go +++ b/client/v2/offchain/verify_test.go @@ -8,57 +8,44 @@ import ( _ "cosmossdk.io/api/cosmos/crypto/secp256k1" clitx "cosmossdk.io/client/v2/tx" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" ) func Test_Verify(t *testing.T) { - ctx := client.Context{ - TxConfig: newTestConfig(t), - Codec: getCodec(), - AddressCodec: address.NewBech32Codec("cosmos"), - ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), - } - tests := []struct { name string digest []byte fileFormat string - ctx client.Context wantErr bool }{ { name: "verify json", digest: []byte("{\"body\":{\"messages\":[{\"@type\":\"/offchain.MsgSignArbitraryData\", \"app_domain\":\"\", \"signer\":\"cosmos16877zjk85kwlap3wclpmx34e0xllg2erc7u7m4\", \"data\":\"{\\n\\t\\\"name\\\": \\\"Sarah\\\",\\n\\t\\\"surname\\\": \\\"Connor\\\",\\n\\t\\\"age\\\": 29\\n}\\n\"}], \"timeout_timestamp\":\"0001-01-01T00:00:00Z\"}, \"auth_info\":{\"signer_infos\":[{\"public_key\":{\"@type\":\"/cosmos.crypto.secp256k1.PubKey\", \"key\":\"Ahhu3idSSUAQXtDBvBjUlCPWH3od4rXyWgb7L4scSj4m\"}, \"mode_info\":{\"single\":{\"mode\":\"SIGN_MODE_DIRECT\"}}}], \"fee\":{}}, \"signatures\":[\"tdXsO5uNqIBFSBKEA1e3Wrcb6ejriP9HwlcBTkU7EUJzuezjg6Rvr1a+Kp6umCAN7MWoBHRT2cmqzDfg6RjaYA==\"]}"), fileFormat: "json", - ctx: ctx, }, { name: "wrong signer json", digest: []byte("{\"body\":{\"messages\":[{\"@type\":\"/offchain.MsgSignArbitraryData\", \"app_domain\":\"\", \"signer\":\"cosmos1xv9e39mkhhyg5aneu2myj82t7029sv48qu3pgj\", \"data\":\"{\\n\\t\\\"name\\\": \\\"Sarah\\\",\\n\\t\\\"surname\\\": \\\"Connor\\\",\\n\\t\\\"age\\\": 29\\n}\\n\"}], \"timeout_timestamp\":\"0001-01-01T00:00:00Z\"}, \"auth_info\":{\"signer_infos\":[{\"public_key\":{\"@type\":\"/cosmos.crypto.secp256k1.PubKey\", \"key\":\"Ahhu3idSSUAQXtDBvBjUlCPWH3od4rXyWgb7L4scSj4m\"}, \"mode_info\":{\"single\":{\"mode\":\"SIGN_MODE_DIRECT\"}}}], \"fee\":{}}, \"signatures\":[\"tdXsO5uNqIBFSBKEA1e3Wrcb6ejriP9HwlcBTkU7EUJzuezjg6Rvr1a+Kp6umCAN7MWoBHRT2cmqzDfg6RjaYA==\"]}"), fileFormat: "json", - ctx: ctx, wantErr: true, }, { name: "verify text", digest: []byte("body:{messages:{[/offchain.MsgSignArbitraryData]:{app_domain:\"\" signer:\"cosmos16877zjk85kwlap3wclpmx34e0xllg2erc7u7m4\" data:\"{\\n\\t\\\"name\\\": \\\"Sarah\\\",\\n\\t\\\"surname\\\": \\\"Connor\\\",\\n\\t\\\"age\\\": 29\\n}\\n\"}} timeout_timestamp:{seconds:-62135596800}} auth_info:{signer_infos:{public_key:{[/cosmos.crypto.secp256k1.PubKey]:{key:\"\\x02\\x18n\\xde'RI@\\x10^\\xd0\\xc1\\xbc\\x18Ԕ#\\xd6\\x1fz\\x1d\\xe2\\xb5\\xf2Z\\x06\\xfb/\\x8b\\x1cJ>&\"}} mode_info:{single:{mode:SIGN_MODE_DIRECT}}} fee:{}} signatures:\"\\xb5\\xd5\\xec;\\x9b\\x8d\\xa8\\x80EH\\x12\\x84\\x03W\\xb7Z\\xb7\\x1b\\xe9\\xe8\\xeb\\x88\\xffG\\xc2W\\x01NE;\\x11Bs\\xb9\\xecヤo\\xafV\\xbe*\\x9e\\xae\\x98 \\r\\xecŨ\\x04tS\\xd9ɪ\\xcc7\\xe0\\xe9\\x18\\xda`\"\n"), fileFormat: "text", - ctx: ctx, }, { name: "wrong signer text", digest: []byte("body:{messages:{[/offchain.MsgSignArbitraryData]:{app_domain:\"\" signer:\"cosmos1xv9e39mkhhyg5aneu2myj82t7029sv48qu3pgj\" data:\"{\\n\\t\\\"name\\\": \\\"Sarah\\\",\\n\\t\\\"surname\\\": \\\"Connor\\\",\\n\\t\\\"age\\\": 29\\n}\\n\"}} timeout_timestamp:{seconds:-62135596800}} auth_info:{signer_infos:{public_key:{[/cosmos.crypto.secp256k1.PubKey]:{key:\"\\x02\\x18n\\xde'RI@\\x10^\\xd0\\xc1\\xbc\\x18Ԕ#\\xd6\\x1fz\\x1d\\xe2\\xb5\\xf2Z\\x06\\xfb/\\x8b\\x1cJ>&\"}} mode_info:{single:{mode:SIGN_MODE_DIRECT}}} fee:{}} signatures:\"\\xb5\\xd5\\xec;\\x9b\\x8d\\xa8\\x80EH\\x12\\x84\\x03W\\xb7Z\\xb7\\x1b\\xe9\\xe8\\xeb\\x88\\xffG\\xc2W\\x01NE;\\x11Bs\\xb9\\xecヤo\\xafV\\xbe*\\x9e\\xae\\x98 \\r\\xecŨ\\x04tS\\xd9ɪ\\xcc7\\xe0\\xe9\\x18\\xda`\"\n"), fileFormat: "text", - ctx: ctx, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - err := Verify(tt.ctx, tt.digest, tt.fileFormat) + err := Verify(getCodec(), address.NewBech32Codec("cosmos"), address.NewBech32Codec("cosmosvaloper"), tt.digest, tt.fileFormat) if tt.wantErr { require.Error(t, err) } else { @@ -69,22 +56,20 @@ func Test_Verify(t *testing.T) { } func Test_SignVerify(t *testing.T) { + ac := address.NewBech32Codec("cosmos") + vc := address.NewBech32Codec("cosmosvaloper") + k := keyring.NewInMemory(getCodec()) _, err := k.NewAccount("signVerify", mnemonic, "", "m/44'/118'/0'/0/0", hd.Secp256k1) require.NoError(t, err) + + autoKeyring, err := keyring.NewAutoCLIKeyring(k, ac) + require.NoError(t, err) - ctx := client.Context{ - TxConfig: newTestConfig(t), - Codec: getCodec(), - AddressCodec: address.NewBech32Codec("cosmos"), - ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), - Keyring: k, - } - - tx, err := Sign(ctx, []byte("Hello World!"), "signVerify", "no-encoding", "direct", "json") + tx, err := Sign([]byte("Hello World!"), mockClientConn{}, autoKeyring, getCodec(), ac, vc, getCodec().InterfaceRegistry(), "signVerify", "no-encoding", "direct", "json") require.NoError(t, err) - err = Verify(ctx, []byte(tx), "json") + err = Verify(getCodec(), ac, vc, []byte(tx), "json") require.NoError(t, err) } From f67063c63b22104d0e5ce9d7ba3c0d06e2b0d91f Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 13 Nov 2024 11:13:01 +0100 Subject: [PATCH 11/52] update: offchain --- client/v2/offchain/cli.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/client/v2/offchain/cli.go b/client/v2/offchain/cli.go index 1278eddaa3d0..696a7dfb87f9 100644 --- a/client/v2/offchain/cli.go +++ b/client/v2/offchain/cli.go @@ -2,9 +2,11 @@ package offchain import ( "cosmossdk.io/client/v2/autocli/keyring" + "cosmossdk.io/client/v2/broadcast/comet" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "os" @@ -15,7 +17,6 @@ import ( "cosmossdk.io/client/v2/autocli/config" v2flags "cosmossdk.io/client/v2/internal/flags" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" ) @@ -52,6 +53,7 @@ func SignFile() *cobra.Command { Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { ir := types.NewInterfaceRegistry() + cryptocodec.RegisterInterfaces(ir) cdc := codec.NewProtoCodec(ir) c, err := config.CreateClientConfigFromFlags(cmd.Flags()) @@ -64,8 +66,6 @@ func SignFile() *cobra.Command { cmd.Flags().Set(flags.FlagKeyringBackend, keyringBackend) } - clientCtx := client.GetClientContextFromCmd(cmd) - bz, err := os.ReadFile(args[1]) if err != nil { return err @@ -79,13 +79,18 @@ func SignFile() *cobra.Command { ac := address.NewBech32Codec(bech32Prefix) vc := address.NewBech32Codec(sdk.GetBech32PrefixValAddr(bech32Prefix)) - k, err := keyring.NewKeyringFromFlags(cmd.Flags(), clientCtx.AddressCodec, cmd.InOrStdin(), clientCtx.Codec) + k, err := keyring.NewKeyringFromFlags(cmd.Flags(), ac, cmd.InOrStdin(), cdc) + if err != nil { + return err + } + + // off-chain does not need to query any information + conn, err := comet.NewCometBFTBroadcaster("", comet.BroadcastSync, cdc, ir) if err != nil { return err } - signedTx, err := Sign(bz, clientCtx, k, cdc, ac, - vc, ir, args[0], encoding, signMode, outputFormat) + signedTx, err := Sign(bz, conn, k, cdc, ac, vc, ir, args[0], encoding, signMode, outputFormat) if err != nil { return err } From 7482befcef8210e7053b3e68384ff7081655b333 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 13 Nov 2024 11:17:09 +0100 Subject: [PATCH 12/52] add: generateOrBroadcastTxWithV2 --- client/v2/autocli/keyring/keyring.go | 4 +-- client/v2/autocli/msg.go | 43 ++++++++++++++++------------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/client/v2/autocli/keyring/keyring.go b/client/v2/autocli/keyring/keyring.go index 0c39d0f32208..de43c5cbb2e4 100644 --- a/client/v2/autocli/keyring/keyring.go +++ b/client/v2/autocli/keyring/keyring.go @@ -34,7 +34,7 @@ func NewKeyringInContext(ctx context.Context, k Keyring) context.Context { } // TODO: godoc -func NewKeyringFromFlags(flagSet *pflag.FlagSet, ac address.Codec, input io.Reader, cdc codec.Codec) (Keyring, error) { +func NewKeyringFromFlags(flagSet *pflag.FlagSet, ac address.Codec, input io.Reader, cdc codec.Codec, opts ...keyring.Option) (Keyring, error) { backEnd, err := flagSet.GetString("keyring-backend") if err != nil { return nil, err @@ -51,7 +51,7 @@ func NewKeyringFromFlags(flagSet *pflag.FlagSet, ac address.Codec, input io.Read } } - k, err := keyring.New(sdk.KeyringServiceName(), backEnd, keyringDir, input, cdc) + k, err := keyring.New(sdk.KeyringServiceName(), backEnd, keyringDir, input, cdc, opts...) if err != nil { return nil, err } diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index 9ecb03245a9c..ed214d14557d 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -2,8 +2,6 @@ package autocli import ( "context" - "cosmossdk.io/client/v2/autocli/keyring" - "cosmossdk.io/client/v2/tx" "fmt" gogoproto "github.com/cosmos/gogoproto/proto" @@ -14,10 +12,13 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli/flag" + "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" + v2tx "cosmossdk.io/client/v2/tx" addresscodec "cosmossdk.io/core/address" + "cosmossdk.io/core/transaction" // the following will be extracted to a separate module // https://github.com/cosmos/cosmos-sdk/issues/14403 @@ -169,22 +170,6 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor msg := dynamicpb.NewMessage(input.Descriptor()) proto.Merge(msg, input.Interface()) - k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) - if err != nil { - return err - } - - cConn, err := b.GetClientConn(cmd) - if err != nil { - return err - } - - printer, err := print.NewPrinter(cmd) - if err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(cmd.Flags(), printer, k, b.Cdc, b.AddressCodec, b.ValidatorAddressCodec, b.EnablesSignModes, cConn, msg) return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) } @@ -213,7 +198,7 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor func (b *Builder) handleGovProposal( cmd *cobra.Command, input protoreflect.Message, - clientCtx client.Context, // TODO: this could be just the address + clientCtx client.Context, addressCodec addresscodec.Codec, fd protoreflect.FieldDescriptor, ) error { @@ -247,3 +232,23 @@ func (b *Builder) handleGovProposal( return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal) } + +// generateOrBroadcastTxWithV2 generates or broadcasts a transaction with the provided messages using v2 transaction handling. +func (b *Builder) generateOrBroadcastTxWithV2(cmd *cobra.Command, msgs ...transaction.Msg) error { + k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) + if err != nil { + return err + } + + cConn, err := b.GetClientConn(cmd) + if err != nil { + return err + } + + printer, err := print.NewPrinter(cmd) + if err != nil { + return err + } + + return v2tx.GenerateOrBroadcastTxCLI(cmd.Flags(), printer, k, b.Cdc, b.AddressCodec, b.ValidatorAddressCodec, b.EnablesSignModes, cConn, msgs...) +} From f3320d6220fae816d9ada7902eae7b3acdf73f95 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 13 Nov 2024 11:24:03 +0100 Subject: [PATCH 13/52] godoc --- client/v2/autocli/common.go | 4 +++- client/v2/autocli/config/config.go | 2 +- client/v2/autocli/flag/builder.go | 1 - client/v2/autocli/keyring/keyring.go | 4 +++- client/v2/broadcast/comet/clientConn.go | 18 ++++++++++++++---- client/v2/tx/tx.go | 10 ++++++---- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index fa029634c1ea..ae27f533b2cc 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -301,7 +301,9 @@ func (b *Builder) setFlagsFromConfig(cmd *cobra.Command, args []string) error { return nil } -// TODO: godoc +// getQueryClientConn returns a function that creates a gRPC client connection based on command flags. +// It handles the creation of secure or insecure connections and falls back to a CometBFT broadcaster +// if no gRPC address is specified. func getQueryClientConn(cdc codec.Codec, ir types.InterfaceRegistry) func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { return func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { var err error diff --git a/client/v2/autocli/config/config.go b/client/v2/autocli/config/config.go index b69d4bcba2ea..680271cc6510 100644 --- a/client/v2/autocli/config/config.go +++ b/client/v2/autocli/config/config.go @@ -64,7 +64,7 @@ func CreateClientConfig(homeDir, chainID string, v *viper.Viper, customClientTem if chainID != "" { // chain-id will be written to the client.toml while initiating the chain. - v.Set("chain-id", chainID) // TODO: use FlagChainId + v.Set("chain-id", chainID) } if err = v.Unmarshal(&customConfig); err != nil { diff --git a/client/v2/autocli/flag/builder.go b/client/v2/autocli/flag/builder.go index 2c2c35bba158..151a34f7b2c2 100644 --- a/client/v2/autocli/flag/builder.go +++ b/client/v2/autocli/flag/builder.go @@ -33,7 +33,6 @@ const ( // keybase is a global variable that holds the keyring instance used for key management // and signing operations across the autocli flag package. It must be set in PreRunE // of the root command. -// TODO: this is super hacky :/ var keybase keyring.Keyring // Builder manages options for building pflag flags for protobuf messages. diff --git a/client/v2/autocli/keyring/keyring.go b/client/v2/autocli/keyring/keyring.go index de43c5cbb2e4..5aad3ecceeec 100644 --- a/client/v2/autocli/keyring/keyring.go +++ b/client/v2/autocli/keyring/keyring.go @@ -33,7 +33,9 @@ func NewKeyringInContext(ctx context.Context, k Keyring) context.Context { return context.WithValue(ctx, KeyringContextKey, NewKeyringImpl(k)) } -// TODO: godoc +// NewKeyringFromFlags creates a new Keyring instance based on command-line flags. +// It retrieves the keyring backend and directory from flags, creates a new keyring, +// and wraps it with an AutoCLI-compatible interface. func NewKeyringFromFlags(flagSet *pflag.FlagSet, ac address.Codec, input io.Reader, cdc codec.Codec, opts ...keyring.Option) (Keyring, error) { backEnd, err := flagSet.GetString("keyring-backend") if err != nil { diff --git a/client/v2/broadcast/comet/clientConn.go b/client/v2/broadcast/comet/clientConn.go index d76557247097..06976a858da5 100644 --- a/client/v2/broadcast/comet/clientConn.go +++ b/client/v2/broadcast/comet/clientConn.go @@ -33,7 +33,8 @@ func (c *CometBFTBroadcaster) NewStream(_ context.Context, _ *grpc.StreamDesc, _ return nil, errors.New("not implemented") } -// TODO: godoc +// Invoke implements the gRPC ClientConn interface by forwarding the RPC call to CometBFT's ABCI Query. +// It marshals the request, sends it as an ABCI query, and unmarshals the response. func (c *CometBFTBroadcaster) Invoke(ctx context.Context, method string, req, reply interface{}, opts ...grpc.CallOption) (err error) { reqBz, err := c.getRPCCodec().Marshal(req) if err != nil { @@ -93,7 +94,9 @@ func (c *CometBFTBroadcaster) Invoke(ctx context.Context, method string, req, re return nil } -// TODO: godoc +// queryABCI performs an ABCI query request to the CometBFT RPC client. +// If the RPC query fails or returns a non-OK response, it will return an error. +// The response is converted from ABCI error codes to gRPC status errors. func (c *CometBFTBroadcaster) queryABCI(req abci.QueryRequest) (abci.QueryResponse, error) { opts := rpcclient.ABCIQueryOptions{ Height: req.Height, @@ -112,7 +115,12 @@ func (c *CometBFTBroadcaster) queryABCI(req abci.QueryRequest) (abci.QueryRespon return result.Response, nil } -// TODO: godoc +// sdkErrorToGRPCError converts an ABCI query response error code to an appropriate gRPC status error. +// It maps common SDK error codes to their gRPC equivalents: +// - ErrInvalidRequest -> InvalidArgument +// - ErrUnauthorized -> Unauthenticated +// - ErrKeyNotFound -> NotFound +// Any other error codes are mapped to Unknown. func sdkErrorToGRPCError(resp abci.QueryResponse) error { switch resp.Code { case sdkerrors.ErrInvalidRequest.ABCICode(): @@ -126,7 +134,9 @@ func sdkErrorToGRPCError(resp abci.QueryResponse) error { } } -// TODO: godoc +// getRPCCodec returns the gRPC codec for the CometBFT broadcaster. +// If the broadcaster's codec implements GRPCCodecProvider, it returns its gRPC codec. +// Otherwise, it creates a new ProtoCodec with the broadcaster's interface registry and returns its gRPC codec. func (c *CometBFTBroadcaster) getRPCCodec() encoding.Codec { cdc, ok := c.cdc.(codec.GRPCCodecProvider) if !ok { diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index c659ba907ad6..c9e8bac28d49 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -28,6 +28,7 @@ import ( // GenerateOrBroadcastTxCLIWithBroadcaster will either generate and print an unsigned transaction // or sign it and broadcast it with the specified broadcaster returning an error upon failure. func GenerateOrBroadcastTxCLIWithBroadcaster( + ctx context.Context, flagSet *pflag.FlagSet, printer *print.Printer, keybase keyring.Keyring, @@ -58,12 +59,13 @@ func GenerateOrBroadcastTxCLIWithBroadcaster( } skipConfirm, _ := flagSet.GetBool("yes") - return BroadcastTx(printer, txf, broadcaster, skipConfirm, msgs...) + return BroadcastTx(ctx, printer, txf, broadcaster, skipConfirm, msgs...) } // GenerateOrBroadcastTxCLI will either generate and print an unsigned transaction // or sign it and broadcast it using default CometBFT broadcaster, returning an error upon failure. func GenerateOrBroadcastTxCLI( + ctx context.Context, flagSet *pflag.FlagSet, printer *print.Printer, keybase keyring.Keyring, @@ -78,7 +80,7 @@ func GenerateOrBroadcastTxCLI( return err } - return GenerateOrBroadcastTxCLIWithBroadcaster(flagSet, printer, keybase, cdc, addressCodec, validatorCodec, enablesSignModes, conn, cometBroadcaster, msgs...) + return GenerateOrBroadcastTxCLIWithBroadcaster(ctx, flagSet, printer, keybase, cdc, addressCodec, validatorCodec, enablesSignModes, conn, cometBroadcaster, msgs...) } // getCometBroadcaster returns a new CometBFT broadcaster based on the provided context and flag set. @@ -183,7 +185,7 @@ func SimulateTx( // BroadcastTx attempts to generate, sign and broadcast a transaction with the // given set of messages. It will also simulate gas requirements if necessary. // It will return an error upon failure. -func BroadcastTx(printer *print.Printer, txf Factory, broadcaster broadcast.Broadcaster, skipConfirm bool, msgs ...transaction.Msg) error { +func BroadcastTx(ctx context.Context, printer *print.Printer, txf Factory, broadcaster broadcast.Broadcaster, skipConfirm bool, msgs ...transaction.Msg) error { if txf.simulateAndExecute() { err := txf.calculateGas(msgs...) if err != nil { @@ -227,7 +229,7 @@ func BroadcastTx(printer *print.Printer, txf Factory, broadcaster broadcast.Broa } } - signedTx, err := txf.sign(context.Background(), true) // TODO: pass ctx from upper call + signedTx, err := txf.sign(ctx, true) if err != nil { return err } From 5198686af5281d4a139e229fb4b09eee7ee1eb35 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 13 Nov 2024 11:50:04 +0100 Subject: [PATCH 14/52] happy lint --- client/v2/autocli/app.go | 6 +++--- client/v2/autocli/keyring/keyring.go | 5 ++--- client/v2/autocli/msg.go | 2 +- client/v2/autocli/print/printer.go | 2 +- client/v2/broadcast/comet/clientConn.go | 6 +++--- client/v2/broadcast/comet/comet.go | 2 +- client/v2/offchain/cli.go | 15 +++++++-------- client/v2/offchain/common_test.go | 1 + client/v2/offchain/sign.go | 1 + client/v2/offchain/verify.go | 4 ++-- client/v2/offchain/verify_test.go | 2 +- client/v2/tx/tx.go | 3 ++- 12 files changed, 25 insertions(+), 24 deletions(-) diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index a6f03229ecbc..ed557ed82302 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -1,13 +1,12 @@ package autocli import ( - apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/gogoproto/proto" "github.com/spf13/cobra" "google.golang.org/protobuf/reflect/protoregistry" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/client/v2/autocli/flag" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" @@ -16,6 +15,7 @@ import ( "cosmossdk.io/x/tx/signing" sdkflags "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" ) @@ -47,7 +47,7 @@ type AppOptions struct { Cdc codec.Codec TxConfigOpts authtx.ConfigOptions - //Keyring keyring.Keyring + // Keyring keyring.Keyring skipValidation bool } diff --git a/client/v2/autocli/keyring/keyring.go b/client/v2/autocli/keyring/keyring.go index 5aad3ecceeec..ba5ceb23d568 100644 --- a/client/v2/autocli/keyring/keyring.go +++ b/client/v2/autocli/keyring/keyring.go @@ -4,16 +4,15 @@ import ( "context" "io" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/spf13/pflag" signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/core/address" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) // KeyringContextKey is the key used to store the keyring in the context. diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index ed214d14557d..c01ab3e3c474 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -250,5 +250,5 @@ func (b *Builder) generateOrBroadcastTxWithV2(cmd *cobra.Command, msgs ...transa return err } - return v2tx.GenerateOrBroadcastTxCLI(cmd.Flags(), printer, k, b.Cdc, b.AddressCodec, b.ValidatorAddressCodec, b.EnablesSignModes, cConn, msgs...) + return v2tx.GenerateOrBroadcastTxCLI(cmd.Context(), cmd.Flags(), printer, k, b.Cdc, b.AddressCodec, b.ValidatorAddressCodec, b.EnablesSignModes, cConn, msgs...) } diff --git a/client/v2/autocli/print/printer.go b/client/v2/autocli/print/printer.go index 62be430aedba..5e391cfc1f6f 100644 --- a/client/v2/autocli/print/printer.go +++ b/client/v2/autocli/print/printer.go @@ -2,10 +2,10 @@ package print import ( "encoding/json" - "github.com/spf13/cobra" "io" "os" + "github.com/spf13/cobra" "sigs.k8s.io/yaml" ) diff --git a/client/v2/broadcast/comet/clientConn.go b/client/v2/broadcast/comet/clientConn.go index 06976a858da5..2b37ca2db547 100644 --- a/client/v2/broadcast/comet/clientConn.go +++ b/client/v2/broadcast/comet/clientConn.go @@ -7,8 +7,7 @@ import ( abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" rpcclient "github.com/cometbft/cometbft/rpc/client" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" + gogogrpc "github.com/cosmos/gogoproto/grpc" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/encoding" @@ -16,10 +15,11 @@ import ( "google.golang.org/grpc/status" errorsmod "cosmossdk.io/errors" - gogogrpc "github.com/cosmos/gogoproto/grpc" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" ) const grpcBlockHeightHeader = "x-cosmos-block-height" diff --git a/client/v2/broadcast/comet/comet.go b/client/v2/broadcast/comet/comet.go index 3cf7eeb5645f..fdfc5b66ad8a 100644 --- a/client/v2/broadcast/comet/comet.go +++ b/client/v2/broadcast/comet/comet.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/cosmos/cosmos-sdk/codec/types" "strings" "github.com/cometbft/cometbft/mempool" @@ -18,6 +17,7 @@ import ( "cosmossdk.io/client/v2/broadcast" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) diff --git a/client/v2/offchain/cli.go b/client/v2/offchain/cli.go index 696a7dfb87f9..1e8b64ac0cc1 100644 --- a/client/v2/offchain/cli.go +++ b/client/v2/offchain/cli.go @@ -1,23 +1,22 @@ package offchain import ( - "cosmossdk.io/client/v2/autocli/keyring" - "cosmossdk.io/client/v2/broadcast/comet" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/address" - "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "os" "path/filepath" "github.com/spf13/cobra" "cosmossdk.io/client/v2/autocli/config" + "cosmossdk.io/client/v2/autocli/keyring" + "cosmossdk.io/client/v2/broadcast/comet" v2flags "cosmossdk.io/client/v2/internal/flags" "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" ) const ( diff --git a/client/v2/offchain/common_test.go b/client/v2/offchain/common_test.go index 8c7d02546e15..d455fa74d102 100644 --- a/client/v2/offchain/common_test.go +++ b/client/v2/offchain/common_test.go @@ -3,6 +3,7 @@ package offchain import ( "context" "errors" + gogogrpc "github.com/cosmos/gogoproto/grpc" "google.golang.org/grpc" diff --git a/client/v2/offchain/sign.go b/client/v2/offchain/sign.go index 4ea7f98c575b..f2c76d5d398d 100644 --- a/client/v2/offchain/sign.go +++ b/client/v2/offchain/sign.go @@ -3,6 +3,7 @@ package offchain import ( "context" "fmt" + gogogrpc "github.com/cosmos/gogoproto/grpc" apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" diff --git a/client/v2/offchain/verify.go b/client/v2/offchain/verify.go index 87cfc25a9327..a0de3d6e8e0a 100644 --- a/client/v2/offchain/verify.go +++ b/client/v2/offchain/verify.go @@ -3,16 +3,16 @@ package offchain import ( "bytes" "context" - "cosmossdk.io/core/address" "errors" "fmt" - "github.com/cosmos/cosmos-sdk/codec" "google.golang.org/protobuf/types/known/anypb" clitx "cosmossdk.io/client/v2/tx" + "cosmossdk.io/core/address" txsigning "cosmossdk.io/x/tx/signing" + "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) diff --git a/client/v2/offchain/verify_test.go b/client/v2/offchain/verify_test.go index 5e22bb131df5..e25cfbe17b09 100644 --- a/client/v2/offchain/verify_test.go +++ b/client/v2/offchain/verify_test.go @@ -62,7 +62,7 @@ func Test_SignVerify(t *testing.T) { k := keyring.NewInMemory(getCodec()) _, err := k.NewAccount("signVerify", mnemonic, "", "m/44'/118'/0'/0/0", hd.Secp256k1) require.NoError(t, err) - + autoKeyring, err := keyring.NewAutoCLIKeyring(k, ac) require.NoError(t, err) diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index c9e8bac28d49..375922fd30ed 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -5,9 +5,9 @@ import ( "context" "errors" "fmt" - "github.com/cosmos/cosmos-sdk/codec/types" "os" + "github.com/cosmos/gogoproto/grpc" "github.com/cosmos/gogoproto/proto" "github.com/spf13/pflag" @@ -23,6 +23,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/input" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" ) // GenerateOrBroadcastTxCLIWithBroadcaster will either generate and print an unsigned transaction From 1a8f7b5e2267e55ccd5863a0cc55575b42d0c790 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 13 Nov 2024 11:56:56 +0100 Subject: [PATCH 15/52] undo config --- client/config/config.go | 91 +++++++++++++++++++++++++++++----------- client/config/toml.go | 92 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 23 deletions(-) create mode 100644 client/config/toml.go diff --git a/client/config/config.go b/client/config/config.go index b1688f7d7e7e..b1aae234cceb 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -2,14 +2,17 @@ package config import ( "crypto/tls" + "errors" "fmt" + "os" + "path/filepath" + "google.golang.org/grpc" "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" - "cosmossdk.io/client/v2/autocli/config" - "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" ) // DefaultConfig returns default config for the client.toml @@ -24,17 +27,25 @@ func DefaultConfig() *Config { } } -type ( - // ClientConfig is an alias for Config for backward compatibility - // Deprecated: use Config instead which avoid name stuttering - ClientConfig config.Config - - Config = config.Config - - GRPCConfig = config.GRPCConfig -) +// ClientConfig is an alias for Config for backward compatibility +// Deprecated: use Config instead which avoid name stuttering +type ClientConfig Config + +type Config struct { + ChainID string `mapstructure:"chain-id" json:"chain-id"` + KeyringBackend string `mapstructure:"keyring-backend" json:"keyring-backend"` + KeyringDefaultKeyName string `mapstructure:"keyring-default-keyname" json:"keyring-default-keyname"` + Output string `mapstructure:"output" json:"output"` + Node string `mapstructure:"node" json:"node"` + BroadcastMode string `mapstructure:"broadcast-mode" json:"broadcast-mode"` + GRPC GRPCConfig `mapstructure:",squash"` +} -var DefaultClientConfigTemplate = config.DefaultClientConfigTemplate +// GRPCConfig holds the gRPC client configuration. +type GRPCConfig struct { + Address string `mapstructure:"grpc-address" json:"grpc-address"` + Insecure bool `mapstructure:"grpc-insecure" json:"grpc-insecure"` +} // ReadFromClientConfig reads values from client.toml file and updates them in client.Context // It uses CreateClientConfig internally with no custom template and custom config. @@ -48,43 +59,80 @@ func ReadFromClientConfig(ctx client.Context) (client.Context, error) { // It takes a customClientTemplate and customConfig as input that can be used to overwrite the default config and enhance the client.toml file. // The custom template/config must be both provided or be "" and nil. func CreateClientConfig(ctx client.Context, customClientTemplate string, customConfig interface{}) (client.Context, error) { - conf, err := config.CreateClientConfig(ctx.HomeDir, ctx.ChainID, ctx.Viper, customClientTemplate, customConfig) + configPath := filepath.Join(ctx.HomeDir, "config") + configFilePath := filepath.Join(configPath, "client.toml") + + // when client.toml does not exist create and init with default values + if _, err := os.Stat(configFilePath); os.IsNotExist(err) { + if err := os.MkdirAll(configPath, os.ModePerm); err != nil { + return ctx, fmt.Errorf("couldn't make client config: %w", err) + } + + if (customClientTemplate != "" && customConfig == nil) || (customClientTemplate == "" && customConfig != nil) { + return ctx, errors.New("customClientTemplate and customConfig should be both nil or not nil") + } + + if customClientTemplate != "" { + if err := setConfigTemplate(customClientTemplate); err != nil { + return ctx, fmt.Errorf("couldn't set client config template: %w", err) + } + + if ctx.ChainID != "" { + // chain-id will be written to the client.toml while initiating the chain. + ctx.Viper.Set(flags.FlagChainID, ctx.ChainID) + } + + if err = ctx.Viper.Unmarshal(&customConfig); err != nil { + return ctx, fmt.Errorf("failed to parse custom client config: %w", err) + } + + if err := writeConfigFile(configFilePath, customConfig); err != nil { + return ctx, fmt.Errorf("could not write client config to the file: %w", err) + } + + } else { + conf := DefaultConfig() + if ctx.ChainID != "" { + // chain-id will be written to the client.toml while initiating the chain. + conf.ChainID = ctx.ChainID + } + + if err := writeConfigFile(configFilePath, conf); err != nil { + return ctx, fmt.Errorf("could not write client config to the file: %w", err) + } + } + } + + conf, err := getClientConfig(configPath, ctx.Viper) if err != nil { return ctx, fmt.Errorf("couldn't get client config: %w", err) } - // we need to update KeyringDir field on client.Context first cause it is used in NewKeyringFromBackend ctx = ctx.WithOutputFormat(conf.Output). WithChainID(conf.ChainID). WithKeyringDir(ctx.HomeDir). WithKeyringDefaultKeyName(conf.KeyringDefaultKeyName) - keyring, err := client.NewKeyringFromBackend(ctx, conf.KeyringBackend) if err != nil { return ctx, fmt.Errorf("couldn't get keyring: %w", err) } - // https://github.com/cosmos/cosmos-sdk/issues/8986 client, err := client.NewClientFromNode(conf.Node) if err != nil { return ctx, fmt.Errorf("couldn't get client from nodeURI: %w", err) } - ctx = ctx. WithNodeURI(conf.Node). WithBroadcastMode(conf.BroadcastMode). WithClient(client). WithKeyring(keyring) - if conf.GRPC.Address != "" { grpcClient, err := getGRPCClient(conf.GRPC) if err != nil { return ctx, fmt.Errorf("couldn't get grpc client: %w", err) } - ctx = ctx.WithGRPCClient(grpcClient) } - return ctx, nil } @@ -95,16 +143,13 @@ func getGRPCClient(grpcConfig GRPCConfig) (*grpc.ClientConn, error) { transport := grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{ MinVersion: tls.VersionTLS12, })) - if grpcConfig.Insecure { transport = grpc.WithTransportCredentials(insecure.NewCredentials()) } - dialOptions := []grpc.DialOption{transport} grpcClient, err := grpc.NewClient(grpcConfig.Address, dialOptions...) if err != nil { return nil, fmt.Errorf("failed to dial gRPC server at %s: %w", grpcConfig.Address, err) } - return grpcClient, nil } diff --git a/client/config/toml.go b/client/config/toml.go new file mode 100644 index 000000000000..35787219a236 --- /dev/null +++ b/client/config/toml.go @@ -0,0 +1,92 @@ +package config + +import ( + "bytes" + "os" + "text/template" + + "github.com/spf13/viper" +) + +const ( + DefaultClientConfigTemplate = `# This is a TOML config file. +# For more information, see https://github.com/toml-lang/toml + +############################################################################### +### Client Configuration ### +############################################################################### + +# The network chain ID +chain-id = "{{ .ChainID }}" +# The keyring's backend, where the keys are stored (os|file|kwallet|pass|test|memory) +keyring-backend = "{{ .KeyringBackend }}" +# Default key name, if set, defines the default key to use for signing transaction when the --from flag is not specified +keyring-default-keyname = "{{ .KeyringDefaultKeyName }}" +# CLI output format (text|json) +output = "{{ .Output }}" +# : to CometBFT RPC interface for this chain +node = "{{ .Node }}" +# Transaction broadcasting mode (sync|async) +broadcast-mode = "{{ .BroadcastMode }}" + +# gRPC server endpoint to which the client will connect. +# It can be overwritten by the --grpc-addr flag in each command. +grpc-address = "{{ .GRPC.Address }}" + +# Allow the gRPC client to connect over insecure channels. +# It can be overwritten by the --grpc-insecure flag in each command. +grpc-insecure = {{ .GRPC.Insecure }} +` +) + +var configTemplate *template.Template + +func init() { + var err error + + tmpl := template.New("clientConfigFileTemplate") + if configTemplate, err = tmpl.Parse(DefaultClientConfigTemplate); err != nil { + panic(err) + } +} + +// setConfigTemplate sets the custom app config template for +// the application +func setConfigTemplate(customTemplate string) error { + tmpl := template.New("clientConfigFileTemplate") + var err error + if configTemplate, err = tmpl.Parse(customTemplate); err != nil { + return err + } + + return nil +} + +// writeConfigFile renders config using the template and writes it to +// configFilePath. +func writeConfigFile(configFilePath string, config interface{}) error { + var buffer bytes.Buffer + if err := configTemplate.Execute(&buffer, config); err != nil { + return err + } + + return os.WriteFile(configFilePath, buffer.Bytes(), 0o600) +} + +// getClientConfig reads values from client.toml file and unmarshalls them into ClientConfig +func getClientConfig(configPath string, v *viper.Viper) (*Config, error) { + v.AddConfigPath(configPath) + v.SetConfigName("client") + v.SetConfigType("toml") + + if err := v.ReadInConfig(); err != nil { + return nil, err + } + + conf := DefaultConfig() + if err := v.Unmarshal(conf); err != nil { + return nil, err + } + + return conf, nil +} From 68b5fed6496f44f9fd087e2b8647e79977aeb955 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 13 Nov 2024 12:15:43 +0100 Subject: [PATCH 16/52] scripts/go-mod-tidy-all.sh --- client/v2/go.mod | 6 +++--- go.sum | 3 +-- x/accounts/defaults/base/go.sum | 1 - x/accounts/defaults/lockup/go.sum | 1 - x/accounts/defaults/multisig/go.sum | 1 - x/accounts/go.sum | 1 - x/authz/go.sum | 3 +-- x/bank/go.sum | 1 - x/distribution/go.sum | 1 - x/feegrant/go.sum | 1 - x/gov/go.sum | 1 - x/group/go.sum | 3 +-- x/params/go.sum | 6 ++---- x/staking/go.sum | 1 - x/upgrade/go.sum | 6 ++---- 15 files changed, 10 insertions(+), 26 deletions(-) diff --git a/client/v2/go.mod b/client/v2/go.mod index e0d910542455..1314c5744f21 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -35,7 +35,7 @@ require ( buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a // indirect cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e // indirect - cosmossdk.io/errors v1.0.1 // indirect + cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.5.0 cosmossdk.io/math v1.3.0 cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac // indirect @@ -60,7 +60,7 @@ require ( github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f github.com/cometbft/cometbft-db v0.15.0 // indirect - github.com/cometbft/cometbft/api v1.0.0-rc.1 // indirect + github.com/cometbft/cometbft/api v1.0.0-rc.1 github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.0.3-0.20240911104526-ddc3f09bfc22 // indirect github.com/cosmos/crypto v0.1.2 // indirect @@ -148,7 +148,7 @@ require ( github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect - github.com/spf13/viper v1.19.0 // indirect + github.com/spf13/viper v1.19.0 github.com/stretchr/testify v1.9.0 github.com/subosito/gotenv v1.6.0 // indirect github.com/supranational/blst v0.3.13 // indirect diff --git a/go.sum b/go.sum index 184e69ea0d61..7e3b45320ad9 100644 --- a/go.sum +++ b/go.sum @@ -16,9 +16,8 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= +cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/accounts/defaults/base/go.sum b/x/accounts/defaults/base/go.sum index 695ef4a39e89..315102153bd4 100644 --- a/x/accounts/defaults/base/go.sum +++ b/x/accounts/defaults/base/go.sum @@ -18,7 +18,6 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/accounts/defaults/lockup/go.sum b/x/accounts/defaults/lockup/go.sum index b4bef3001bc6..ec99eb7013b7 100644 --- a/x/accounts/defaults/lockup/go.sum +++ b/x/accounts/defaults/lockup/go.sum @@ -18,7 +18,6 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/accounts/defaults/multisig/go.sum b/x/accounts/defaults/multisig/go.sum index 695ef4a39e89..315102153bd4 100644 --- a/x/accounts/defaults/multisig/go.sum +++ b/x/accounts/defaults/multisig/go.sum @@ -18,7 +18,6 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/accounts/go.sum b/x/accounts/go.sum index 695ef4a39e89..315102153bd4 100644 --- a/x/accounts/go.sum +++ b/x/accounts/go.sum @@ -18,7 +18,6 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/authz/go.sum b/x/authz/go.sum index 695ef4a39e89..e63fa4b96aff 100644 --- a/x/authz/go.sum +++ b/x/authz/go.sum @@ -16,8 +16,7 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc= cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= diff --git a/x/bank/go.sum b/x/bank/go.sum index 695ef4a39e89..315102153bd4 100644 --- a/x/bank/go.sum +++ b/x/bank/go.sum @@ -18,7 +18,6 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/distribution/go.sum b/x/distribution/go.sum index 695ef4a39e89..315102153bd4 100644 --- a/x/distribution/go.sum +++ b/x/distribution/go.sum @@ -18,7 +18,6 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index b78d42dc21d9..2e8b78985122 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -18,7 +18,6 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190 h1:XQJj9Dv9Gtze0l2TF79BU5lkP6MkUveTUuKICmxoz+o= cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190/go.mod h1:7WUGupOvmlHJoIMBz1JbObQxeo6/TDiuDBxmtod8HRg= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= diff --git a/x/gov/go.sum b/x/gov/go.sum index 4ee8602f5280..e8ea170d71b6 100644 --- a/x/gov/go.sum +++ b/x/gov/go.sum @@ -18,7 +18,6 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/group/go.sum b/x/group/go.sum index 9224cb28a413..fb2dd72ae329 100644 --- a/x/group/go.sum +++ b/x/group/go.sum @@ -16,8 +16,7 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc= cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= diff --git a/x/params/go.sum b/x/params/go.sum index a334587e2be5..012f90197a8a 100644 --- a/x/params/go.sum +++ b/x/params/go.sum @@ -4,8 +4,7 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.1-20240130113600-88ef6483f90f.1/go.mod h1:zqi/LZjZhyvjCMTEVIwAf5VRlkLduuCfqmZxgoormq0= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a h1:9DxUD+82dO3c+R3XqwW+a7i4nVLiN6I0g2rp2rLOh7E= cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= @@ -19,8 +18,7 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc= cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= diff --git a/x/staking/go.sum b/x/staking/go.sum index 695ef4a39e89..315102153bd4 100644 --- a/x/staking/go.sum +++ b/x/staking/go.sum @@ -18,7 +18,6 @@ cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index ddea90988f80..75e205e47294 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -192,8 +192,7 @@ cloud.google.com/go/webrisk v1.4.0/go.mod h1:Hn8X6Zr+ziE2aNd8SliSDWpEnSS1u4R9+xX cloud.google.com/go/webrisk v1.5.0/go.mod h1:iPG6fr52Tv7sGk0H6qUFzmL3HHZev1htXuWDEEsqMTg= cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1Vwf+KmJENM0= cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= +cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a h1:9DxUD+82dO3c+R3XqwW+a7i4nVLiN6I0g2rp2rLOh7E= cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= @@ -207,8 +206,7 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= -cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc= cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190 h1:XQJj9Dv9Gtze0l2TF79BU5lkP6MkUveTUuKICmxoz+o= cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190/go.mod h1:7WUGupOvmlHJoIMBz1JbObQxeo6/TDiuDBxmtod8HRg= From fe28cec49c2d193a10632b6ae66c8e3d4d4f8e3c Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 13 Nov 2024 12:38:54 +0100 Subject: [PATCH 17/52] format config --- client/config/config.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/client/config/config.go b/client/config/config.go index b1aae234cceb..246ed98c7b9a 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -107,32 +107,39 @@ func CreateClientConfig(ctx client.Context, customClientTemplate string, customC if err != nil { return ctx, fmt.Errorf("couldn't get client config: %w", err) } + // we need to update KeyringDir field on client.Context first cause it is used in NewKeyringFromBackend ctx = ctx.WithOutputFormat(conf.Output). WithChainID(conf.ChainID). WithKeyringDir(ctx.HomeDir). WithKeyringDefaultKeyName(conf.KeyringDefaultKeyName) + keyring, err := client.NewKeyringFromBackend(ctx, conf.KeyringBackend) if err != nil { return ctx, fmt.Errorf("couldn't get keyring: %w", err) } + // https://github.com/cosmos/cosmos-sdk/issues/8986 client, err := client.NewClientFromNode(conf.Node) if err != nil { return ctx, fmt.Errorf("couldn't get client from nodeURI: %w", err) } + ctx = ctx. WithNodeURI(conf.Node). WithBroadcastMode(conf.BroadcastMode). WithClient(client). WithKeyring(keyring) + if conf.GRPC.Address != "" { grpcClient, err := getGRPCClient(conf.GRPC) if err != nil { return ctx, fmt.Errorf("couldn't get grpc client: %w", err) } + ctx = ctx.WithGRPCClient(grpcClient) } + return ctx, nil } @@ -143,13 +150,16 @@ func getGRPCClient(grpcConfig GRPCConfig) (*grpc.ClientConn, error) { transport := grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{ MinVersion: tls.VersionTLS12, })) + if grpcConfig.Insecure { transport = grpc.WithTransportCredentials(insecure.NewCredentials()) } + dialOptions := []grpc.DialOption{transport} grpcClient, err := grpc.NewClient(grpcConfig.Address, dialOptions...) if err != nil { return nil, fmt.Errorf("failed to dial gRPC server at %s: %w", grpcConfig.Address, err) } + return grpcClient, nil } From 4d47bc4db2b466f8b665565a5c256e9bd05a8e05 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 13 Nov 2024 18:23:04 +0100 Subject: [PATCH 18/52] fix: keyring just if needed --- client/v2/autocli/app.go | 1 - client/v2/autocli/common.go | 29 +++++++++++++++++------------ client/v2/autocli/common_test.go | 4 ++-- client/v2/autocli/msg_test.go | 11 +++++++---- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index ed557ed82302..7aabdf44c116 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -47,7 +47,6 @@ type AppOptions struct { Cdc codec.Codec TxConfigOpts authtx.ConfigOptions - // Keyring keyring.Keyring skipValidation bool } diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index ae27f533b2cc..43ed23fd3a12 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -252,11 +252,16 @@ func (b *Builder) preRunE() func(cmd *cobra.Command, args []string) error { return err } - k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) - err = nil - b.SetKeyring(k) // global flag keyring must be set on PreRunE. + // if the command uses the keyring this must be set + if cmd.Flags().Lookup("keyring-dir") != nil && cmd.Flags().Lookup("keyring-backend") != nil { + k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) + if err != nil { + return err + } + b.SetKeyring(k) // global flag keyring must be set on PreRunE. + } - return err + return nil } } @@ -267,35 +272,35 @@ func (b *Builder) setFlagsFromConfig(cmd *cobra.Command, args []string) error { } if cmd.Flags().Lookup("chain-id") != nil && !cmd.Flags().Changed("chain-id") { - cmd.Flags().Set("chain-id", conf.ChainID) + _ = cmd.Flags().Set("chain-id", conf.ChainID) } if cmd.Flags().Lookup("keyring-backend") != nil && !cmd.Flags().Changed("keyring-backend") { - cmd.Flags().Set("keyring-backend", conf.KeyringBackend) + _ = cmd.Flags().Set("keyring-backend", conf.KeyringBackend) } if cmd.Flags().Lookup("from") != nil && !cmd.Flags().Changed("from") { - cmd.Flags().Set("from", conf.KeyringDefaultKeyName) + _ = cmd.Flags().Set("from", conf.KeyringDefaultKeyName) } if cmd.Flags().Lookup("output") != nil && !cmd.Flags().Changed("output") { - cmd.Flags().Set("output", conf.Output) + _ = cmd.Flags().Set("output", conf.Output) } if cmd.Flags().Lookup("node") != nil && !cmd.Flags().Changed("node") { - cmd.Flags().Set("node", conf.Node) + _ = cmd.Flags().Set("node", conf.Node) } if cmd.Flags().Lookup("broadcast-mode") != nil && !cmd.Flags().Changed("broadcast-mode") { - cmd.Flags().Set("broadcast-mode", conf.BroadcastMode) + _ = cmd.Flags().Set("broadcast-mode", conf.BroadcastMode) } if cmd.Flags().Lookup("grpc-addr") != nil && !cmd.Flags().Changed("grpc-addr") { - cmd.Flags().Set("grpc-addr", conf.GRPC.Address) + _ = cmd.Flags().Set("grpc-addr", conf.GRPC.Address) } if cmd.Flags().Lookup("grpc-insecure") != nil && !cmd.Flags().Changed("grpc-insecure") { - cmd.Flags().Set("grpc-insecure", strconv.FormatBool(conf.GRPC.Insecure)) + _ = cmd.Flags().Set("grpc-insecure", strconv.FormatBool(conf.GRPC.Insecure)) } return nil diff --git a/client/v2/autocli/common_test.go b/client/v2/autocli/common_test.go index c03c94124cfa..b40f1a6dbc26 100644 --- a/client/v2/autocli/common_test.go +++ b/client/v2/autocli/common_test.go @@ -57,7 +57,7 @@ func initFixture(t *testing.T) *fixture { assert.NilError(t, err) encodingConfig := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, bank.AppModule{}) - kr, err := sdkkeyring.New(sdk.KeyringServiceName(), sdkkeyring.BackendTest, home, nil, encodingConfig.Codec) + kr, err := sdkkeyring.New(sdk.KeyringServiceName(), sdkkeyring.BackendMemory, home, nil, encodingConfig.Codec) assert.NilError(t, err) interfaceRegistry := encodingConfig.Codec.InterfaceRegistry() @@ -101,7 +101,7 @@ func initFixture(t *testing.T) *fixture { home: home, chainID: "autocli-test", - kBackend: sdkkeyring.BackendTest, + kBackend: sdkkeyring.BackendMemory, } } diff --git a/client/v2/autocli/msg_test.go b/client/v2/autocli/msg_test.go index 2bc86f9281e5..a86fc8ebcca7 100644 --- a/client/v2/autocli/msg_test.go +++ b/client/v2/autocli/msg_test.go @@ -55,7 +55,7 @@ func TestMsg(t *testing.T) { "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", "--generate-only", "--output", "json", - "--generate-only", "--offline", + "--chain-id", fixture.chainID, ) assert.NilError(t, err) assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) @@ -75,7 +75,7 @@ func TestMsg(t *testing.T) { "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", "--generate-only", "--output", "json", - "--generate-only", "--offline", + "--chain-id", fixture.chainID, ) assert.NilError(t, err) assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) @@ -96,7 +96,9 @@ func TestMsg(t *testing.T) { "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", "--from", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "--output", "json", - "--generate-only", "--offline", + "--generate-only", + "--chain-id", fixture.chainID, + "--keyring-backend", fixture.kBackend, ) assert.NilError(t, err) assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) @@ -119,7 +121,8 @@ func TestMsg(t *testing.T) { "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", "--sender", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "--output", "json", - "--generate-only", "--offline", + "--generate-only", + "--chain-id", fixture.chainID, ) assert.NilError(t, err) assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) From 879db325678f0f774aefb356505a1ceafc0016bb Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 13 Nov 2024 18:52:20 +0100 Subject: [PATCH 19/52] lint --- client/v2/autocli/msg.go | 2 ++ client/v2/offchain/cli.go | 2 +- client/v2/tx/factory.go | 6 ++---- client/v2/tx/tx.go | 1 - simapp/simd/cmd/root.go | 6 +++++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index c01ab3e3c474..0d09f99ae2e0 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -234,6 +234,8 @@ func (b *Builder) handleGovProposal( } // generateOrBroadcastTxWithV2 generates or broadcasts a transaction with the provided messages using v2 transaction handling. +// +//nolint:unused // It'll be used once BuildMsgMethodCommand is updated to use factory v2. func (b *Builder) generateOrBroadcastTxWithV2(cmd *cobra.Command, msgs ...transaction.Msg) error { k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) if err != nil { diff --git a/client/v2/offchain/cli.go b/client/v2/offchain/cli.go index 1e8b64ac0cc1..c85c81aee52d 100644 --- a/client/v2/offchain/cli.go +++ b/client/v2/offchain/cli.go @@ -62,7 +62,7 @@ func SignFile() *cobra.Command { keyringBackend := c.KeyringBackend if !cmd.Flags().Changed(flags.FlagKeyringBackend) { - cmd.Flags().Set(flags.FlagKeyringBackend, keyringBackend) + _ = cmd.Flags().Set(flags.FlagKeyringBackend, keyringBackend) } bz, err := os.ReadFile(args[1]) diff --git a/client/v2/tx/factory.go b/client/v2/tx/factory.go index a54900ea75e5..9e5f4df2ec02 100644 --- a/client/v2/tx/factory.go +++ b/client/v2/tx/factory.go @@ -108,10 +108,8 @@ func validateFlagSet(flags *pflag.FlagSet, offline bool) error { if gasSetting.Simulate { return errors.New("simulate and offline flags cannot be set at the same time") } - } else { - if chainID == "" { - return errors.New("chain ID required but not specified") - } + } else if chainID == "" { + return errors.New("chain ID required but not specified") } return nil diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index 375922fd30ed..01c9ada6b0f4 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -7,7 +7,6 @@ import ( "fmt" "os" - "github.com/cosmos/gogoproto/grpc" "github.com/cosmos/gogoproto/proto" "github.com/spf13/pflag" diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index cc7cf47742c1..edbbc3fc71b8 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -121,7 +121,11 @@ func NewRootCmd() *cobra.Command { } autoCliOpts := tempApp.AutoCliOpts() - autoCliOpts.ClientCtx = initClientCtx + autoCliOpts.InterfaceRegistry = initClientCtx.InterfaceRegistry + autoCliOpts.AddressCodec = initClientCtx.AddressCodec + autoCliOpts.ValidatorAddressCodec = initClientCtx.ValidatorAddressCodec + autoCliOpts.ConsensusAddressCodec = initClientCtx.ConsensusAddressCodec + autoCliOpts.Cdc = initClientCtx.Codec nodeCmds := nodeservice.NewNodeCommands() autoCliOpts.ModuleOptions[nodeCmds.Name()] = nodeCmds.AutoCLIOptions() From ed9d0060d1dbc9762eb4f5f2eb7d4f478d851720 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Thu, 14 Nov 2024 11:59:09 +0100 Subject: [PATCH 20/52] fix: tests --- client/v2/autocli/app.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index 7aabdf44c116..d051c6e91b99 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -42,8 +42,8 @@ type AppOptions struct { InterfaceRegistry types.InterfaceRegistry AddressCodec address.Codec - ValidatorAddressCodec address.Codec - ConsensusAddressCodec address.Codec + ValidatorAddressCodec address.ValidatorAddressCodec + ConsensusAddressCodec address.ConsensusAddressCodec Cdc codec.Codec TxConfigOpts authtx.ConfigOptions @@ -180,6 +180,7 @@ func NewAppOptionsFromConfig( InterfaceRegistry: interfaceRegistry, ModuleOptions: moduleOptions, skipValidation: true, + Cdc: codec.NewProtoCodec(interfaceRegistry), }, nil } From c6a699c6754cb420ed26bb900d97a42763c456a8 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Mon, 18 Nov 2024 12:30:45 +0100 Subject: [PATCH 21/52] udpate: use context --- client/v2/autocli/app.go | 14 ++-- client/v2/autocli/builder.go | 2 +- client/v2/autocli/common.go | 53 +++++++++--- client/v2/autocli/context/context.go | 50 ++++++++++++ client/v2/autocli/flag/address.go | 117 +++++++++++++-------------- client/v2/autocli/flag/builder.go | 12 --- client/v2/autocli/msg.go | 17 +--- client/v2/tx/tx.go | 67 +++++++-------- simapp/simd/cmd/root.go | 1 - 9 files changed, 184 insertions(+), 149 deletions(-) create mode 100644 client/v2/autocli/context/context.go diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index d051c6e91b99..fce600090c0e 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -40,7 +40,6 @@ type AppOptions struct { // module or need to be improved. ModuleOptions map[string]*autocliv1.ModuleOptions `optional:"true"` - InterfaceRegistry types.InterfaceRegistry AddressCodec address.Codec ValidatorAddressCodec address.ValidatorAddressCodec ConsensusAddressCodec address.ConsensusAddressCodec @@ -70,7 +69,7 @@ func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error { builder := &Builder{ Builder: flag.Builder{ TypeResolver: protoregistry.GlobalTypes, - FileResolver: appOptions.InterfaceRegistry, + FileResolver: appOptions.Cdc.InterfaceRegistry(), AddressCodec: appOptions.AddressCodec, ValidatorAddressCodec: appOptions.ValidatorAddressCodec, ConsensusAddressCodec: appOptions.ConsensusAddressCodec, @@ -82,7 +81,7 @@ func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error { }, AddTxConnFlags: sdkflags.AddTxFlagsToCmd, Cdc: appOptions.Cdc, - EnablesSignModes: []apitxsigning.SignMode{apitxsigning.SignMode_SIGN_MODE_DIRECT}, + EnabledSignModes: []apitxsigning.SignMode{apitxsigning.SignMode_SIGN_MODE_DIRECT}, } return appOptions.EnhanceRootCommandWithBuilder(rootCmd, builder) @@ -176,11 +175,10 @@ func NewAppOptionsFromConfig( } return AppOptions{ - Modules: cfg.Modules, - InterfaceRegistry: interfaceRegistry, - ModuleOptions: moduleOptions, - skipValidation: true, - Cdc: codec.NewProtoCodec(interfaceRegistry), + Modules: cfg.Modules, + ModuleOptions: moduleOptions, + skipValidation: true, + Cdc: codec.NewProtoCodec(interfaceRegistry), }, nil } diff --git a/client/v2/autocli/builder.go b/client/v2/autocli/builder.go index 323aee719b0f..bd1744ef888a 100644 --- a/client/v2/autocli/builder.go +++ b/client/v2/autocli/builder.go @@ -24,7 +24,7 @@ type Builder struct { AddTxConnFlags func(*cobra.Command) Cdc codec.Codec - EnablesSignModes []apisigning.SignMode + EnabledSignModes []apisigning.SignMode } // ValidateAndComplete the builder fields. diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 43ed23fd3a12..8df8d48f9fda 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -1,10 +1,13 @@ package autocli import ( + "context" "crypto/tls" "fmt" "strconv" + "cosmossdk.io/client/v2/autocli/keyring" + "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -13,7 +16,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli/config" - "cosmossdk.io/client/v2/autocli/keyring" + clientcontext "cosmossdk.io/client/v2/autocli/context" "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/broadcast/comet" "cosmossdk.io/client/v2/internal/flags" @@ -73,7 +76,10 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip cmd.PreRunE = b.preRunE() cmd.RunE = func(cmd *cobra.Command, args []string) error { - ctx = cmd.Context() + ctx, err = b.getContext(cmd) + if err != nil { + return err + } input, err := binder.BuildMessage(args) if err != nil { @@ -245,6 +251,40 @@ func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error { return p.PrintBytes(out) } +// getContext creates and returns a new context.Context with a clientcontext.Context value. +// It initializes a printer and, if necessary, a keyring based on command flags. +func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { + printer, err := print.NewPrinter(cmd) + if err != nil { + return nil, err + } + + // if the command uses the keyring this must be set + var k keyring.Keyring + if cmd.Flags().Lookup("keyring-dir") != nil && cmd.Flags().Lookup("keyring-backend") != nil { + k, err = keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) + if err != nil { + return nil, err + } + } + + clientCtx := clientcontext.Context{ + Flags: cmd.Flags(), + AddressCodec: b.AddressCodec, + ValidatorAddressCodec: b.ValidatorAddressCodec, + ConsensusAddressCodec: b.ConsensusAddressCodec, + Cdc: b.Cdc, + Printer: printer, + Keyring: k, + EnabledSignmodes: b.EnabledSignModes, + } + + return context.WithValue(cmd.Context(), clientcontext.ContextKey, clientCtx), nil +} + +// preRunE returns a function that sets flags from the configuration before running a command. +// It is used as a PreRunE hook for cobra commands to ensure flags are properly initialized +// from the configuration before command execution. func (b *Builder) preRunE() func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { err := b.setFlagsFromConfig(cmd, args) @@ -252,15 +292,6 @@ func (b *Builder) preRunE() func(cmd *cobra.Command, args []string) error { return err } - // if the command uses the keyring this must be set - if cmd.Flags().Lookup("keyring-dir") != nil && cmd.Flags().Lookup("keyring-backend") != nil { - k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) - if err != nil { - return err - } - b.SetKeyring(k) // global flag keyring must be set on PreRunE. - } - return nil } } diff --git a/client/v2/autocli/context/context.go b/client/v2/autocli/context/context.go new file mode 100644 index 000000000000..6ab2ea113002 --- /dev/null +++ b/client/v2/autocli/context/context.go @@ -0,0 +1,50 @@ +package context + +import ( + gocontext "context" + "errors" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/spf13/pflag" + + apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/client/v2/autocli/keyring" + "cosmossdk.io/client/v2/autocli/print" + "cosmossdk.io/core/address" +) + +// ContextKey is the key used to store and retrieve the autocli.Context from a context.Context. +const ContextKey = "autocli.context" + +// Context represents the client context used in autocli commands. +// It contains various components needed for command execution. +type Context struct { + gocontext.Context + + Flags *pflag.FlagSet + + AddressCodec address.Codec + ValidatorAddressCodec address.ValidatorAddressCodec + ConsensusAddressCodec address.ConsensusAddressCodec + + Cdc codec.Codec + + Printer *print.Printer + + Keyring keyring.Keyring + + EnabledSignmodes []apisigning.SignMode +} + +// ClientContextFromGoContext returns the autocli.Context from a given Go context. +// It checks if the context contains a valid autocli.Context and returns it. +func ClientContextFromGoContext(ctx gocontext.Context) (*Context, error) { + if c := ctx.Value(ContextKey); c != nil { + cliCtx, ok := c.(Context) + if !ok { + return nil, errors.New("invalid context") + } + return &cliCtx, nil + } + return nil, errors.New("invalid context") +} diff --git a/client/v2/autocli/flag/address.go b/client/v2/autocli/flag/address.go index e790a1557371..12adddd31423 100644 --- a/client/v2/autocli/flag/address.go +++ b/client/v2/autocli/flag/address.go @@ -6,6 +6,8 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" + clientcontext "cosmossdk.io/client/v2/autocli/context" + "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/codec" @@ -38,16 +40,11 @@ type addressValue struct { ctx *context.Context addressCodec address.Codec - cachedValue string - value string + value string } func (a *addressValue) Get(protoreflect.Value) (protoreflect.Value, error) { - if a.isEmpty() { - return protoreflect.ValueOfString(""), nil - } - - return a.get() + return protoreflect.ValueOfString(a.value), nil } func (a *addressValue) String() string { @@ -56,10 +53,24 @@ func (a *addressValue) String() string { // Set implements the flag.Value interface for addressValue. func (a *addressValue) Set(s string) error { - _, err := a.addressCodec.StringToBytes(s) + // we get the keyring on set, as in NewValue the context is the parent context (before RunE) + k := getKeyringFromCtx(a.ctx) + addr, err := k.LookupAddressByKeyName(s) if err == nil { - a.cachedValue = s + addrStr, err := a.addressCodec.BytesToString(addr) + if err != nil { + return fmt.Errorf("invalid account address got from keyring: %w", err) + } + + a.value = addrStr + return nil } + + _, err = a.addressCodec.StringToBytes(s) + if err != nil { + return fmt.Errorf("invalid account address or key name: %w", err) + } + a.value = s return nil @@ -69,24 +80,6 @@ func (a *addressValue) Type() string { return "account address or key name" } -func (a *addressValue) isEmpty() bool { - return a.value == "" && a.cachedValue == "" -} - -func (a *addressValue) get() (protoreflect.Value, error) { - if a.cachedValue != "" { - return protoreflect.ValueOfString(a.cachedValue), nil - } - - addr, err := getKey(a.value, a.addressCodec) - if err != nil { - return protoreflect.Value{}, err - } - a.cachedValue = addr - - return protoreflect.ValueOfString(addr), nil -} - type consensusAddressStringType struct{} func (a consensusAddressStringType) NewValue(ctx *context.Context, b *Builder) Value { @@ -107,13 +100,31 @@ type consensusAddressValue struct { } func (a consensusAddressValue) Get(protoreflect.Value) (protoreflect.Value, error) { - if a.isEmpty() { - return protoreflect.ValueOfString(""), nil + return protoreflect.ValueOfString(a.value), nil +} + +func (a consensusAddressValue) String() string { + return a.value +} + +func (a *consensusAddressValue) Set(s string) error { + // we get the keyring on set, as in NewValue the context is the parent context (before RunE) + k := getKeyringFromCtx(a.ctx) + addr, err := k.LookupAddressByKeyName(s) + if err == nil { + addrStr, err := a.addressCodec.BytesToString(addr) + if err != nil { + return fmt.Errorf("invalid consensus address got from keyring: %w", err) + } + + a.value = addrStr + return nil } - addr, err := a.get() + _, err = a.addressCodec.StringToBytes(s) if err == nil { - return addr, nil + a.value = s + return nil } // fallback to pubkey parsing @@ -122,51 +133,31 @@ func (a consensusAddressValue) Get(protoreflect.Value) (protoreflect.Value, erro cdc := codec.NewProtoCodec(registry) var pk cryptotypes.PubKey - err2 := cdc.UnmarshalInterfaceJSON([]byte(a.value), &pk) + err2 := cdc.UnmarshalInterfaceJSON([]byte(s), &pk) if err2 != nil { - return protoreflect.Value{}, fmt.Errorf("input isn't a pubkey (%w) or is an invalid account address (%w)", err, err2) + return fmt.Errorf("input isn't a pubkey (%w) or is an invalid account address (%w)", err, err2) } a.value, err = a.addressCodec.BytesToString(pk.Address()) if err != nil { - return protoreflect.Value{}, fmt.Errorf("invalid pubkey address: %w", err) + return fmt.Errorf("invalid pubkey address: %w", err) } - a.cachedValue = a.value - - return protoreflect.ValueOfString(a.value), nil -} - -func (a consensusAddressValue) String() string { - return a.value -} - -func (a *consensusAddressValue) Set(s string) error { - _, err := a.addressCodec.StringToBytes(s) - if err == nil { - a.cachedValue = s - } - - a.value = s return nil } -func getKey(k string, ac address.Codec) (string, error) { - if keybase != nil { - addr, err := keybase.LookupAddressByKeyName(k) - if err == nil { - addrStr, err := ac.BytesToString(addr) - if err != nil { - return "", fmt.Errorf("invalid account address got from keyring: %w", err) - } - return addrStr, nil - } +// getKeyringFromCtx retrieves the keyring from the provided context. +// If the context is nil or does not contain a valid client context, +// it returns a no-op keyring implementation. +func getKeyringFromCtx(ctx *context.Context) keyring.Keyring { + if *ctx == nil { + return keyring.NoKeyring{} } - _, err := ac.StringToBytes(k) + c, err := clientcontext.ClientContextFromGoContext(*ctx) if err != nil { - return "", fmt.Errorf("invalid account address or key name: %w", err) + return keyring.NoKeyring{} } - return k, nil + return c.Keyring } diff --git a/client/v2/autocli/flag/builder.go b/client/v2/autocli/flag/builder.go index 151a34f7b2c2..bdd42634dd35 100644 --- a/client/v2/autocli/flag/builder.go +++ b/client/v2/autocli/flag/builder.go @@ -16,7 +16,6 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" msgv1 "cosmossdk.io/api/cosmos/msg/v1" - "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" "cosmossdk.io/core/address" @@ -30,11 +29,6 @@ const ( DecScalarType = "cosmos.Dec" ) -// keybase is a global variable that holds the keyring instance used for key management -// and signing operations across the autocli flag package. It must be set in PreRunE -// of the root command. -var keybase keyring.Keyring - // Builder manages options for building pflag flags for protobuf messages. type Builder struct { // TypeResolver specifies how protobuf types will be resolved. If it is @@ -60,12 +54,6 @@ type Builder struct { ConsensusAddressCodec address.ConsensusAddressCodec } -// SetKeyring sets the global keyring instance used for key management and signing operations. -// The keyring must be set in PreRunE of the root command. -func (b *Builder) SetKeyring(k keyring.Keyring) { - keybase = k -} - func (b *Builder) init() { if b.messageFlagTypes == nil { b.messageFlagTypes = map[protoreflect.FullName]Type{} diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index 0d09f99ae2e0..eeb80c30261f 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -12,14 +12,11 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli/flag" - "cosmossdk.io/client/v2/autocli/keyring" - "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" v2tx "cosmossdk.io/client/v2/tx" addresscodec "cosmossdk.io/core/address" "cosmossdk.io/core/transaction" - // the following will be extracted to a separate module // https://github.com/cosmos/cosmos-sdk/issues/14403 govcli "cosmossdk.io/x/gov/client/cli" @@ -236,21 +233,11 @@ func (b *Builder) handleGovProposal( // generateOrBroadcastTxWithV2 generates or broadcasts a transaction with the provided messages using v2 transaction handling. // //nolint:unused // It'll be used once BuildMsgMethodCommand is updated to use factory v2. -func (b *Builder) generateOrBroadcastTxWithV2(cmd *cobra.Command, msgs ...transaction.Msg) error { - k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) - if err != nil { - return err - } - +func (b *Builder) generateOrBroadcastTxWithV2(ctx context.Context, cmd *cobra.Command, msgs ...transaction.Msg) error { cConn, err := b.GetClientConn(cmd) if err != nil { return err } - printer, err := print.NewPrinter(cmd) - if err != nil { - return err - } - - return v2tx.GenerateOrBroadcastTxCLI(cmd.Context(), cmd.Flags(), printer, k, b.Cdc, b.AddressCodec, b.ValidatorAddressCodec, b.EnablesSignModes, cConn, msgs...) + return v2tx.GenerateOrBroadcastTxCLI(ctx, cConn, msgs...) } diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index 01c9ada6b0f4..f4bed842da2e 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -12,12 +12,11 @@ import ( "github.com/spf13/pflag" apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - "cosmossdk.io/client/v2/autocli/keyring" + clientcontext "cosmossdk.io/client/v2/autocli/context" "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/broadcast" "cosmossdk.io/client/v2/broadcast/comet" "cosmossdk.io/client/v2/internal/account" - "cosmossdk.io/core/address" "cosmossdk.io/core/transaction" "github.com/cosmos/cosmos-sdk/client/input" @@ -29,58 +28,56 @@ import ( // or sign it and broadcast it with the specified broadcaster returning an error upon failure. func GenerateOrBroadcastTxCLIWithBroadcaster( ctx context.Context, - flagSet *pflag.FlagSet, - printer *print.Printer, - keybase keyring.Keyring, - cdc codec.Codec, - addressCodec, validatorCodec address.Codec, - enablesSignModes []apitxsigning.SignMode, conn grpc.ClientConn, broadcaster broadcast.Broadcaster, msgs ...transaction.Msg, ) error { + clientCtx, err := clientcontext.ClientContextFromGoContext(ctx) + if err != nil { + return err + } + if err := validateMessages(msgs...); err != nil { return err } - txf, err := newFactory(keybase, cdc, addressCodec, validatorCodec, enablesSignModes, conn, flagSet) + txf, err := newFactory(clientCtx, conn, clientCtx.Flags) if err != nil { return err } - genOnly, _ := flagSet.GetBool(flagGenerateOnly) + genOnly, _ := clientCtx.Flags.GetBool(flagGenerateOnly) if genOnly { - return generateOnly(printer, txf, msgs...) + return generateOnly(clientCtx.Printer, txf, msgs...) } - isDryRun, _ := flagSet.GetBool(flagDryRun) + isDryRun, _ := clientCtx.Flags.GetBool(flagDryRun) if isDryRun { - return dryRun(printer, txf, msgs...) + return dryRun(clientCtx.Printer, txf, msgs...) } - skipConfirm, _ := flagSet.GetBool("yes") - return BroadcastTx(ctx, printer, txf, broadcaster, skipConfirm, msgs...) + skipConfirm, _ := clientCtx.Flags.GetBool("yes") + return BroadcastTx(ctx, clientCtx.Printer, txf, broadcaster, skipConfirm, msgs...) } // GenerateOrBroadcastTxCLI will either generate and print an unsigned transaction // or sign it and broadcast it using default CometBFT broadcaster, returning an error upon failure. func GenerateOrBroadcastTxCLI( ctx context.Context, - flagSet *pflag.FlagSet, - printer *print.Printer, - keybase keyring.Keyring, - cdc codec.Codec, - addressCodec, validatorCodec address.Codec, - enablesSignModes []apitxsigning.SignMode, conn grpc.ClientConn, msgs ...transaction.Msg, ) error { - cometBroadcaster, err := getCometBroadcaster(cdc, cdc.InterfaceRegistry(), flagSet) + c, err := clientcontext.ClientContextFromGoContext(ctx) + if err != nil { + return err + } + + cometBroadcaster, err := getCometBroadcaster(c.Cdc, c.Cdc.InterfaceRegistry(), c.Flags) if err != nil { return err } - return GenerateOrBroadcastTxCLIWithBroadcaster(ctx, flagSet, printer, keybase, cdc, addressCodec, validatorCodec, enablesSignModes, conn, cometBroadcaster, msgs...) + return GenerateOrBroadcastTxCLIWithBroadcaster(ctx, conn, cometBroadcaster, msgs...) } // getCometBroadcaster returns a new CometBFT broadcaster based on the provided context and flag set. @@ -94,26 +91,23 @@ func getCometBroadcaster(cdc codec.Codec, ir types.InterfaceRegistry, flagSet *p // It initializes a new CLI keyring, extracts transaction parameters from the flag set, // configures transaction settings, and sets up an account retriever for the transaction Factory. func newFactory( - keybase keyring.Keyring, - cdc codec.Codec, - addressCodec, validatorCodec address.Codec, - enablesSignModes []apitxsigning.SignMode, + ctx *clientcontext.Context, conn grpc.ClientConn, flagSet *pflag.FlagSet, ) (Factory, error) { txConfig, err := NewTxConfig(ConfigOptions{ - AddressCodec: addressCodec, - Cdc: cdc, - ValidatorAddressCodec: validatorCodec, - EnabledSignModes: enablesSignModes, + AddressCodec: ctx.AddressCodec, + Cdc: ctx.Cdc, + ValidatorAddressCodec: ctx.ValidatorAddressCodec, + EnabledSignModes: ctx.EnabledSignmodes, }) if err != nil { return Factory{}, err } - accRetriever := account.NewAccountRetriever(addressCodec, conn, cdc.InterfaceRegistry()) + accRetriever := account.NewAccountRetriever(ctx.AddressCodec, conn, ctx.Cdc.InterfaceRegistry()) - txf, err := NewFactoryFromFlagSet(flagSet, keybase, cdc, accRetriever, txConfig, addressCodec, conn) + txf, err := NewFactoryFromFlagSet(flagSet, ctx.Keyring, ctx.Cdc, accRetriever, txConfig, ctx.AddressCodec, conn) if err != nil { return Factory{}, err } @@ -165,15 +159,12 @@ func dryRun(printer *print.Printer, txf Factory, msgs ...transaction.Msg) error // SimulateTx simulates a tx and returns the simulation response obtained by the query. func SimulateTx( - keybase keyring.Keyring, - cdc codec.Codec, - addressCodec, validatorCodec address.Codec, - enablesSignModes []apitxsigning.SignMode, + ctx *clientcontext.Context, conn grpc.ClientConn, flagSet *pflag.FlagSet, msgs ...transaction.Msg, ) (proto.Message, error) { - txf, err := newFactory(keybase, cdc, addressCodec, validatorCodec, enablesSignModes, conn, flagSet) + txf, err := newFactory(ctx, conn, flagSet) if err != nil { return nil, err } diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index edbbc3fc71b8..7851629e7716 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -121,7 +121,6 @@ func NewRootCmd() *cobra.Command { } autoCliOpts := tempApp.AutoCliOpts() - autoCliOpts.InterfaceRegistry = initClientCtx.InterfaceRegistry autoCliOpts.AddressCodec = initClientCtx.AddressCodec autoCliOpts.ValidatorAddressCodec = initClientCtx.ValidatorAddressCodec autoCliOpts.ConsensusAddressCodec = initClientCtx.ConsensusAddressCodec From 488c7816907bada64bf15bdee5b0711548d9ab79 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Mon, 18 Nov 2024 12:36:39 +0100 Subject: [PATCH 22/52] updates --- client/v2/autocli/app.go | 11 +++++++---- client/v2/autocli/keyring/keyring.go | 9 +-------- client/v2/tx/types.go | 4 ++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index fce600090c0e..9d3b9008d37d 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -40,11 +40,14 @@ type AppOptions struct { // module or need to be improved. ModuleOptions map[string]*autocliv1.ModuleOptions `optional:"true"` - AddressCodec address.Codec - ValidatorAddressCodec address.ValidatorAddressCodec - ConsensusAddressCodec address.ConsensusAddressCodec + AddressCodec address.Codec // AddressCodec is used to encode/decode account addresses. + ValidatorAddressCodec address.ValidatorAddressCodec // ValidatorAddressCodec is used to encode/decode validator addresses. + ConsensusAddressCodec address.ConsensusAddressCodec // ConsensusAddressCodec is used to encode/decode consensus addresses. - Cdc codec.Codec + // Cdc is the codec used for binary encoding/decoding of messages. + Cdc codec.Codec + + // TxConfigOpts contains options for configuring transaction handling. TxConfigOpts authtx.ConfigOptions skipValidation bool diff --git a/client/v2/autocli/keyring/keyring.go b/client/v2/autocli/keyring/keyring.go index ba5ceb23d568..73c523a6e0f3 100644 --- a/client/v2/autocli/keyring/keyring.go +++ b/client/v2/autocli/keyring/keyring.go @@ -1,7 +1,6 @@ package keyring import ( - "context" "io" "github.com/spf13/pflag" @@ -12,7 +11,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) // KeyringContextKey is the key used to store the keyring in the context. @@ -27,11 +25,6 @@ type KeyringImpl struct { k Keyring } -// NewKeyringInContext returns a new context with the keyring set. -func NewKeyringInContext(ctx context.Context, k Keyring) context.Context { - return context.WithValue(ctx, KeyringContextKey, NewKeyringImpl(k)) -} - // NewKeyringFromFlags creates a new Keyring instance based on command-line flags. // It retrieves the keyring backend and directory from flags, creates a new keyring, // and wraps it with an AutoCLI-compatible interface. @@ -52,7 +45,7 @@ func NewKeyringFromFlags(flagSet *pflag.FlagSet, ac address.Codec, input io.Read } } - k, err := keyring.New(sdk.KeyringServiceName(), backEnd, keyringDir, input, cdc, opts...) + k, err := keyring.New("autoclikeyring", backEnd, keyringDir, input, cdc, opts...) if err != nil { return nil, err } diff --git a/client/v2/tx/types.go b/client/v2/tx/types.go index bd83cc994d58..0f151fc16515 100644 --- a/client/v2/tx/types.go +++ b/client/v2/tx/types.go @@ -161,8 +161,8 @@ func txParamsFromFlagSet(flags *pflag.FlagSet, keybase keyring2.Keyring, ac addr var fromName, fromAddress string var addr []byte isDryRun, _ := flags.GetBool(flagDryRun) - generaOnly, _ := flags.GetBool(flagGenerateOnly) - if isDryRun || generaOnly { + generateOnly, _ := flags.GetBool(flagGenerateOnly) + if isDryRun || generateOnly { addr, err = ac.StringToBytes(from) } else { fromName, fromAddress, _, err = keybase.KeyInfo(from) From 4401ad8ab8834c1c4ef86ef15796c49a21a5cd6d Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Mon, 18 Nov 2024 12:41:47 +0100 Subject: [PATCH 23/52] fix lint --- client/v2/autocli/common.go | 3 +-- client/v2/autocli/context/context.go | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 8df8d48f9fda..e376a6e9ddcf 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -6,8 +6,6 @@ import ( "fmt" "strconv" - "cosmossdk.io/client/v2/autocli/keyring" - "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -17,6 +15,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli/config" clientcontext "cosmossdk.io/client/v2/autocli/context" + "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/broadcast/comet" "cosmossdk.io/client/v2/internal/flags" diff --git a/client/v2/autocli/context/context.go b/client/v2/autocli/context/context.go index 6ab2ea113002..523f25459475 100644 --- a/client/v2/autocli/context/context.go +++ b/client/v2/autocli/context/context.go @@ -4,13 +4,14 @@ import ( gocontext "context" "errors" - "github.com/cosmos/cosmos-sdk/codec" "github.com/spf13/pflag" apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/core/address" + + "github.com/cosmos/cosmos-sdk/codec" ) // ContextKey is the key used to store and retrieve the autocli.Context from a context.Context. From f81c59c621cd2a41d0e1a5ecca2ccead1e132be0 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Mon, 18 Nov 2024 13:44:08 +0100 Subject: [PATCH 24/52] update: toml config --- client/v2/autocli/common.go | 4 +- client/v2/autocli/config/config.go | 58 +++++++---------------- client/v2/autocli/config/toml.go | 76 ++++++------------------------ 3 files changed, 33 insertions(+), 105 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index e376a6e9ddcf..32bc0da27074 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -286,7 +286,7 @@ func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { // from the configuration before command execution. func (b *Builder) preRunE() func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { - err := b.setFlagsFromConfig(cmd, args) + err := b.setFlagsFromConfig(cmd) if err != nil { return err } @@ -295,7 +295,7 @@ func (b *Builder) preRunE() func(cmd *cobra.Command, args []string) error { } } -func (b *Builder) setFlagsFromConfig(cmd *cobra.Command, args []string) error { +func (b *Builder) setFlagsFromConfig(cmd *cobra.Command) error { conf, err := config.CreateClientConfigFromFlags(cmd.Flags()) if err != nil { return err diff --git a/client/v2/autocli/config/config.go b/client/v2/autocli/config/config.go index 680271cc6510..ac458f7f84e0 100644 --- a/client/v2/autocli/config/config.go +++ b/client/v2/autocli/config/config.go @@ -13,19 +13,19 @@ import ( ) type Config struct { - ChainID string `mapstructure:"chain-id" json:"chain-id"` - KeyringBackend string `mapstructure:"keyring-backend" json:"keyring-backend"` - KeyringDefaultKeyName string `mapstructure:"keyring-default-keyname" json:"keyring-default-keyname"` - Output string `mapstructure:"output" json:"output"` - Node string `mapstructure:"node" json:"node"` - BroadcastMode string `mapstructure:"broadcast-mode" json:"broadcast-mode"` + ChainID string `mapstructure:"chain-id" toml:"chain-id"` + KeyringBackend string `mapstructure:"keyring-backend" toml:"keyring-backend"` + KeyringDefaultKeyName string `mapstructure:"keyring-default-keyname" toml:"keyring-default-keyname"` + Output string `mapstructure:"output" toml:"output"` + Node string `mapstructure:"node" toml:"node"` + BroadcastMode string `mapstructure:"broadcast-mode" toml:"broadcast-mode"` GRPC GRPCConfig `mapstructure:",squash"` } // GRPCConfig holds the gRPC client configuration. type GRPCConfig struct { - Address string `mapstructure:"grpc-address" json:"grpc-address"` - Insecure bool `mapstructure:"grpc-insecure" json:"grpc-insecure"` + Address string `mapstructure:"grpc-address" toml:"grpc-address"` + Insecure bool `mapstructure:"grpc-insecure" toml:"grpc-insecure"` } func DefaultConfig() *Config { @@ -39,7 +39,7 @@ func DefaultConfig() *Config { } } -func CreateClientConfig(homeDir, chainID string, v *viper.Viper, customClientTemplate string, customConfig interface{}) (*Config, error) { +func CreateClientConfig(homeDir, chainID string, v *viper.Viper) (*Config, error) { if homeDir == "" { return nil, errors.New("home dir can't be empty") } @@ -53,42 +53,18 @@ func CreateClientConfig(homeDir, chainID string, v *viper.Viper, customClientTem return nil, fmt.Errorf("couldn't make client config: %w", err) } - if (customClientTemplate != "" && customConfig == nil) || (customClientTemplate == "" && customConfig != nil) { - return nil, errors.New("customClientTemplate and customConfig should be both nil or not nil") + conf := DefaultConfig() + if chainID != "" { + // chain-id will be written to the client.toml while initiating the chain. + conf.ChainID = chainID } - if customClientTemplate != "" { - if err := setConfigTemplate(customClientTemplate); err != nil { - return nil, fmt.Errorf("couldn't set client config template: %w", err) - } - - if chainID != "" { - // chain-id will be written to the client.toml while initiating the chain. - v.Set("chain-id", chainID) - } - - if err = v.Unmarshal(&customConfig); err != nil { - return nil, fmt.Errorf("failed to parse custom client config: %w", err) - } - - if err := writeConfigFile(configFilePath, customConfig); err != nil { - return nil, fmt.Errorf("could not write client config to the file: %w", err) - } - - } else { - conf := DefaultConfig() - if chainID != "" { - // chain-id will be written to the client.toml while initiating the chain. - conf.ChainID = chainID - } - - if err := writeConfigFile(configFilePath, conf); err != nil { - return nil, fmt.Errorf("could not write client config to the file: %w", err) - } + if err := writeConfigFile(configFilePath, conf); err != nil { + return nil, fmt.Errorf("could not write client config to the file: %w", err) } } - conf, err := getClientConfig(configPath, v) + conf, err := readConfig(configPath, v) if err != nil { return nil, fmt.Errorf("couldn't get client config: %w", err) } @@ -113,5 +89,5 @@ func CreateClientConfigFromFlags(set *pflag.FlagSet) (*Config, error) { v.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) v.AutomaticEnv() - return CreateClientConfig(homeDir, chainID, v, "", nil) + return CreateClientConfig(homeDir, chainID, v) } diff --git a/client/v2/autocli/config/toml.go b/client/v2/autocli/config/toml.go index 35787219a236..ae1a95c538cb 100644 --- a/client/v2/autocli/config/toml.go +++ b/client/v2/autocli/config/toml.go @@ -1,83 +1,35 @@ package config import ( - "bytes" "os" - "text/template" + "github.com/pelletier/go-toml/v2" "github.com/spf13/viper" ) -const ( - DefaultClientConfigTemplate = `# This is a TOML config file. -# For more information, see https://github.com/toml-lang/toml - -############################################################################### -### Client Configuration ### -############################################################################### - -# The network chain ID -chain-id = "{{ .ChainID }}" -# The keyring's backend, where the keys are stored (os|file|kwallet|pass|test|memory) -keyring-backend = "{{ .KeyringBackend }}" -# Default key name, if set, defines the default key to use for signing transaction when the --from flag is not specified -keyring-default-keyname = "{{ .KeyringDefaultKeyName }}" -# CLI output format (text|json) -output = "{{ .Output }}" -# : to CometBFT RPC interface for this chain -node = "{{ .Node }}" -# Transaction broadcasting mode (sync|async) -broadcast-mode = "{{ .BroadcastMode }}" - -# gRPC server endpoint to which the client will connect. -# It can be overwritten by the --grpc-addr flag in each command. -grpc-address = "{{ .GRPC.Address }}" - -# Allow the gRPC client to connect over insecure channels. -# It can be overwritten by the --grpc-insecure flag in each command. -grpc-insecure = {{ .GRPC.Insecure }} -` -) - -var configTemplate *template.Template - -func init() { - var err error - - tmpl := template.New("clientConfigFileTemplate") - if configTemplate, err = tmpl.Parse(DefaultClientConfigTemplate); err != nil { - panic(err) - } -} - -// setConfigTemplate sets the custom app config template for -// the application -func setConfigTemplate(customTemplate string) error { - tmpl := template.New("clientConfigFileTemplate") - var err error - if configTemplate, err = tmpl.Parse(customTemplate); err != nil { - return err - } - - return nil -} - // writeConfigFile renders config using the template and writes it to // configFilePath. -func writeConfigFile(configFilePath string, config interface{}) error { - var buffer bytes.Buffer - if err := configTemplate.Execute(&buffer, config); err != nil { +func writeConfigFile(configFilePath string, config *Config) error { + b, err := toml.Marshal(config) + if err != nil { return err } - return os.WriteFile(configFilePath, buffer.Bytes(), 0o600) + if _, err := os.Stat(configFilePath); os.IsNotExist(err) { + if err := os.MkdirAll(configFilePath, os.ModePerm); err != nil { + return err + } + } + + return os.WriteFile(configFilePath, b, 0o600) } -// getClientConfig reads values from client.toml file and unmarshalls them into ClientConfig -func getClientConfig(configPath string, v *viper.Viper) (*Config, error) { +// readConfig reads values from client.toml file and unmarshalls them into ClientConfig +func readConfig(configPath string, v *viper.Viper) (*Config, error) { v.AddConfigPath(configPath) v.SetConfigName("client") v.SetConfigType("toml") + v.AddConfigPath(configPath) if err := v.ReadInConfig(); err != nil { return nil, err From 4727ae4053d4448ace3f0a0f4dd980b049cea673 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Mon, 18 Nov 2024 13:55:09 +0100 Subject: [PATCH 25/52] rabbit suggestions --- client/v2/autocli/print/printer.go | 9 +++++++++ client/v2/broadcast/comet/clientConn.go | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/client/v2/autocli/print/printer.go b/client/v2/autocli/print/printer.go index 5e391cfc1f6f..5d6b5a9898af 100644 --- a/client/v2/autocli/print/printer.go +++ b/client/v2/autocli/print/printer.go @@ -2,6 +2,7 @@ package print import ( "encoding/json" + "fmt" "io" "os" @@ -26,6 +27,11 @@ func NewPrinter(cmd *cobra.Command) (*Printer, error) { if err != nil { return nil, err } + + if outputFormat != jsonOutput && outputFormat != textOutput { + return nil, fmt.Errorf("unsupported output format: %s", outputFormat) + } + return &Printer{ Output: cmd.OutOrStdout(), OutputFormat: outputFormat, @@ -46,6 +52,9 @@ func (p *Printer) PrintRaw(toPrint json.RawMessage) error { func (p *Printer) PrintBytes(out []byte) error { var err error if p.OutputFormat == textOutput { + if !json.Valid(out) { + return fmt.Errorf("invalid JSON") + } out, err = yaml.JSONToYAML(out) if err != nil { return err diff --git a/client/v2/broadcast/comet/clientConn.go b/client/v2/broadcast/comet/clientConn.go index 2b37ca2db547..b54a6c253681 100644 --- a/client/v2/broadcast/comet/clientConn.go +++ b/client/v2/broadcast/comet/clientConn.go @@ -62,7 +62,7 @@ func (c *CometBFTBroadcaster) Invoke(ctx context.Context, method string, req, re Height: height, } - res, err := c.queryABCI(abciR) + res, err := c.queryABCI(ctx, abciR) if err != nil { return err } @@ -97,13 +97,13 @@ func (c *CometBFTBroadcaster) Invoke(ctx context.Context, method string, req, re // queryABCI performs an ABCI query request to the CometBFT RPC client. // If the RPC query fails or returns a non-OK response, it will return an error. // The response is converted from ABCI error codes to gRPC status errors. -func (c *CometBFTBroadcaster) queryABCI(req abci.QueryRequest) (abci.QueryResponse, error) { +func (c *CometBFTBroadcaster) queryABCI(ctx context.Context, req abci.QueryRequest) (abci.QueryResponse, error) { opts := rpcclient.ABCIQueryOptions{ Height: req.Height, Prove: req.Prove, } - result, err := c.rpcClient.ABCIQueryWithOptions(context.Background(), req.Path, req.Data, opts) + result, err := c.rpcClient.ABCIQueryWithOptions(ctx, req.Path, req.Data, opts) if err != nil { return abci.QueryResponse{}, err } From 958c1060919805a2deac5acf22a08584649ef638 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Mon, 18 Nov 2024 14:08:06 +0100 Subject: [PATCH 26/52] update: offchain --- client/v2/offchain/cli.go | 22 ++++++++++++++++++---- client/v2/offchain/sign.go | 23 +++++++++-------------- client/v2/offchain/sign_test.go | 11 +++++++++-- client/v2/offchain/verify.go | 12 ++++++------ client/v2/offchain/verify_test.go | 21 +++++++++++++++++---- 5 files changed, 59 insertions(+), 30 deletions(-) diff --git a/client/v2/offchain/cli.go b/client/v2/offchain/cli.go index c85c81aee52d..f64e88c6fbc4 100644 --- a/client/v2/offchain/cli.go +++ b/client/v2/offchain/cli.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" "cosmossdk.io/client/v2/autocli/config" + clientcontext "cosmossdk.io/client/v2/autocli/context" "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/broadcast/comet" v2flags "cosmossdk.io/client/v2/internal/flags" @@ -77,7 +78,6 @@ func SignFile() *cobra.Command { bech32Prefix, _ := cmd.Flags().GetString(flagBech32) ac := address.NewBech32Codec(bech32Prefix) - vc := address.NewBech32Codec(sdk.GetBech32PrefixValAddr(bech32Prefix)) k, err := keyring.NewKeyringFromFlags(cmd.Flags(), ac, cmd.InOrStdin(), cdc) if err != nil { return err @@ -89,7 +89,15 @@ func SignFile() *cobra.Command { return err } - signedTx, err := Sign(bz, conn, k, cdc, ac, vc, ir, args[0], encoding, signMode, outputFormat) + ctx := clientcontext.Context{ + Flags: cmd.Flags(), + AddressCodec: ac, + ValidatorAddressCodec: address.NewBech32Codec(sdk.GetBech32PrefixValAddr(bech32Prefix)), + Cdc: cdc, + Keyring: k, + } + + signedTx, err := Sign(ctx, bz, conn, args[0], encoding, signMode, outputFormat) if err != nil { return err } @@ -134,9 +142,15 @@ func VerifyFile() *cobra.Command { bech32Prefix, _ := cmd.Flags().GetString(flagBech32) ac := address.NewBech32Codec(bech32Prefix) - vc := address.NewBech32Codec(sdk.GetBech32PrefixValAddr(bech32Prefix)) - err = Verify(cdc, ac, vc, bz, fileFormat) + ctx := clientcontext.Context{ + Flags: cmd.Flags(), + AddressCodec: ac, + ValidatorAddressCodec: address.NewBech32Codec(sdk.GetBech32PrefixValAddr(bech32Prefix)), + Cdc: cdc, + } + + err = Verify(ctx, bz, fileFormat) if err == nil { cmd.Println("Verification OK!") } diff --git a/client/v2/offchain/sign.go b/client/v2/offchain/sign.go index f2c76d5d398d..3bd62878db4d 100644 --- a/client/v2/offchain/sign.go +++ b/client/v2/offchain/sign.go @@ -7,14 +7,11 @@ import ( gogogrpc "github.com/cosmos/gogoproto/grpc" apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - "cosmossdk.io/client/v2/autocli/keyring" + clientcontext "cosmossdk.io/client/v2/autocli/context" "cosmossdk.io/client/v2/internal/account" "cosmossdk.io/client/v2/internal/offchain" clitx "cosmossdk.io/client/v2/tx" - "cosmossdk.io/core/address" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/version" ) @@ -34,11 +31,9 @@ var enabledSignModes = []apisigning.SignMode{ // Sign signs given bytes using the specified encoder and SignMode. func Sign( + ctx clientcontext.Context, rawBytes []byte, conn gogogrpc.ClientConn, - keybase keyring.Keyring, - cdc codec.BinaryCodec, addressCodec, validatorAddressCodec address.Codec, - ir types.InterfaceRegistry, fromName, encoding, signMode, output string, ) (string, error) { digest, err := encodeDigest(encoding, rawBytes) @@ -47,16 +42,16 @@ func Sign( } txConfig, err := clitx.NewTxConfig(clitx.ConfigOptions{ - AddressCodec: addressCodec, - Cdc: cdc, - ValidatorAddressCodec: validatorAddressCodec, + AddressCodec: ctx.AddressCodec, + Cdc: ctx.Cdc, + ValidatorAddressCodec: ctx.ValidatorAddressCodec, EnabledSignModes: enabledSignModes, }) if err != nil { return "", err } - accRetriever := account.NewAccountRetriever(addressCodec, conn, ir) + accRetriever := account.NewAccountRetriever(ctx.AddressCodec, conn, ctx.Cdc.InterfaceRegistry()) sm, err := getSignMode(signMode) if err != nil { @@ -72,17 +67,17 @@ func Sign( }, } - txf, err := clitx.NewFactory(keybase, cdc, accRetriever, txConfig, addressCodec, conn, params) + txf, err := clitx.NewFactory(ctx.Keyring, ctx.Cdc, accRetriever, txConfig, ctx.AddressCodec, conn, params) if err != nil { return "", err } - pubKey, err := keybase.GetPubKey(fromName) + pubKey, err := ctx.Keyring.GetPubKey(fromName) if err != nil { return "", err } - addr, err := addressCodec.BytesToString(pubKey.Address()) + addr, err := ctx.AddressCodec.BytesToString(pubKey.Address()) if err != nil { return "", err } diff --git a/client/v2/offchain/sign_test.go b/client/v2/offchain/sign_test.go index 08d02031947c..db3d9ced19b4 100644 --- a/client/v2/offchain/sign_test.go +++ b/client/v2/offchain/sign_test.go @@ -5,6 +5,8 @@ import ( "github.com/stretchr/testify/require" + clientcontext "cosmossdk.io/client/v2/autocli/context" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -20,6 +22,12 @@ func TestSign(t *testing.T) { autoKeyring, err := keyring.NewAutoCLIKeyring(k, ac) require.NoError(t, err) + ctx := clientcontext.Context{ + AddressCodec: ac, + ValidatorAddressCodec: vc, + Cdc: getCodec(), + Keyring: autoKeyring, + } tests := []struct { name string rawBytes []byte @@ -49,8 +57,7 @@ func TestSign(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := Sign(tt.rawBytes, mockClientConn{}, autoKeyring, getCodec(), ac, vc, getCodec().InterfaceRegistry(), - "signVerify", tt.encoding, tt.signMode, "json") + got, err := Sign(ctx, tt.rawBytes, mockClientConn{}, "signVerify", tt.encoding, tt.signMode, "json") if tt.wantErr { require.Error(t, err) } else { diff --git a/client/v2/offchain/verify.go b/client/v2/offchain/verify.go index a0de3d6e8e0a..52fffe4eedee 100644 --- a/client/v2/offchain/verify.go +++ b/client/v2/offchain/verify.go @@ -8,21 +8,21 @@ import ( "google.golang.org/protobuf/types/known/anypb" + clientcontext "cosmossdk.io/client/v2/autocli/context" clitx "cosmossdk.io/client/v2/tx" "cosmossdk.io/core/address" txsigning "cosmossdk.io/x/tx/signing" - "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" ) // Verify verifies a digest after unmarshalling it. -func Verify(cdc codec.Codec, addressCodec, validatorAddressCodec address.Codec, digest []byte, fileFormat string) error { +func Verify(ctx clientcontext.Context, digest []byte, fileFormat string) error { txConfig, err := clitx.NewTxConfig(clitx.ConfigOptions{ - AddressCodec: addressCodec, - Cdc: cdc, - ValidatorAddressCodec: validatorAddressCodec, + AddressCodec: ctx.AddressCodec, + Cdc: ctx.Cdc, + ValidatorAddressCodec: ctx.ValidatorAddressCodec, EnabledSignModes: enabledSignModes, }) if err != nil { @@ -34,7 +34,7 @@ func Verify(cdc codec.Codec, addressCodec, validatorAddressCodec address.Codec, return err } - return verify(addressCodec, txConfig, dTx) + return verify(ctx.AddressCodec, txConfig, dTx) } // verify verifies given Tx. diff --git a/client/v2/offchain/verify_test.go b/client/v2/offchain/verify_test.go index e25cfbe17b09..7efa9f9b4e1a 100644 --- a/client/v2/offchain/verify_test.go +++ b/client/v2/offchain/verify_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" _ "cosmossdk.io/api/cosmos/crypto/secp256k1" + clientcontext "cosmossdk.io/client/v2/autocli/context" clitx "cosmossdk.io/client/v2/tx" "github.com/cosmos/cosmos-sdk/codec/address" @@ -14,6 +15,12 @@ import ( ) func Test_Verify(t *testing.T) { + ctx := clientcontext.Context{ + AddressCodec: address.NewBech32Codec("cosmos"), + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + Cdc: getCodec(), + } + tests := []struct { name string digest []byte @@ -45,7 +52,7 @@ func Test_Verify(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - err := Verify(getCodec(), address.NewBech32Codec("cosmos"), address.NewBech32Codec("cosmosvaloper"), tt.digest, tt.fileFormat) + err := Verify(ctx, tt.digest, tt.fileFormat) if tt.wantErr { require.Error(t, err) } else { @@ -57,7 +64,6 @@ func Test_Verify(t *testing.T) { func Test_SignVerify(t *testing.T) { ac := address.NewBech32Codec("cosmos") - vc := address.NewBech32Codec("cosmosvaloper") k := keyring.NewInMemory(getCodec()) _, err := k.NewAccount("signVerify", mnemonic, "", "m/44'/118'/0'/0/0", hd.Secp256k1) @@ -66,10 +72,17 @@ func Test_SignVerify(t *testing.T) { autoKeyring, err := keyring.NewAutoCLIKeyring(k, ac) require.NoError(t, err) - tx, err := Sign([]byte("Hello World!"), mockClientConn{}, autoKeyring, getCodec(), ac, vc, getCodec().InterfaceRegistry(), "signVerify", "no-encoding", "direct", "json") + ctx := clientcontext.Context{ + AddressCodec: address.NewBech32Codec("cosmos"), + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + Cdc: getCodec(), + Keyring: autoKeyring, + } + + tx, err := Sign(ctx, []byte("Hello World!"), mockClientConn{}, "signVerify", "no-encoding", "direct", "json") require.NoError(t, err) - err = Verify(getCodec(), ac, vc, []byte(tx), "json") + err = Verify(ctx, []byte(tx), "json") require.NoError(t, err) } From 54254d4dfa76cf2ed7ea5a2e501f89badf41737c Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 19 Nov 2024 10:19:16 +0100 Subject: [PATCH 27/52] lint --- client/v2/autocli/context/context.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/v2/autocli/context/context.go b/client/v2/autocli/context/context.go index 523f25459475..7eeb9291c382 100644 --- a/client/v2/autocli/context/context.go +++ b/client/v2/autocli/context/context.go @@ -14,8 +14,11 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) +// key is a custom type used as a context key to prevent collisions in the context.Context value store. +type key string + // ContextKey is the key used to store and retrieve the autocli.Context from a context.Context. -const ContextKey = "autocli.context" +const ContextKey key = "autocli.context" // Context represents the client context used in autocli commands. // It contains various components needed for command execution. From 79adc323759c746f33927bf83d03b78a5ede7b37 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 19 Nov 2024 10:20:10 +0100 Subject: [PATCH 28/52] tidy-all --- client/v2/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/v2/go.mod b/client/v2/go.mod index 1314c5744f21..38d3e9187c92 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -130,7 +130,7 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect github.com/oklog/run v1.1.0 // indirect - github.com/pelletier/go-toml/v2 v2.2.3 // indirect + github.com/pelletier/go-toml/v2 v2.2.3 github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect From 8c2523564fb27e05ef59b2f7c873466048475b82 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 19 Nov 2024 10:42:57 +0100 Subject: [PATCH 29/52] rabbit suggestions --- client/v2/autocli/common.go | 34 ++++++++++++++++++++-------- client/v2/autocli/config/toml.go | 6 ++--- client/v2/autocli/context/context.go | 6 ++--- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 32bc0da27074..2c155acfd811 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -250,7 +250,7 @@ func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error { return p.PrintBytes(out) } -// getContext creates and returns a new context.Context with a clientcontext.Context value. +// getContext creates and returns a new context.Context with an autocli.Context value. // It initializes a printer and, if necessary, a keyring based on command flags. func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { printer, err := print.NewPrinter(cmd) @@ -302,35 +302,51 @@ func (b *Builder) setFlagsFromConfig(cmd *cobra.Command) error { } if cmd.Flags().Lookup("chain-id") != nil && !cmd.Flags().Changed("chain-id") { - _ = cmd.Flags().Set("chain-id", conf.ChainID) + if err = cmd.Flags().Set("chain-id", conf.ChainID); err != nil { + return err + } } if cmd.Flags().Lookup("keyring-backend") != nil && !cmd.Flags().Changed("keyring-backend") { - _ = cmd.Flags().Set("keyring-backend", conf.KeyringBackend) + if err = cmd.Flags().Set("keyring-backend", conf.KeyringBackend); err != nil { + return err + } } if cmd.Flags().Lookup("from") != nil && !cmd.Flags().Changed("from") { - _ = cmd.Flags().Set("from", conf.KeyringDefaultKeyName) + if err = cmd.Flags().Set("from", conf.KeyringDefaultKeyName); err != nil { + return err + } } if cmd.Flags().Lookup("output") != nil && !cmd.Flags().Changed("output") { - _ = cmd.Flags().Set("output", conf.Output) + if err = cmd.Flags().Set("output", conf.Output); err != nil { + return err + } } if cmd.Flags().Lookup("node") != nil && !cmd.Flags().Changed("node") { - _ = cmd.Flags().Set("node", conf.Node) + if err = cmd.Flags().Set("node", conf.Node); err != nil { + return err + } } if cmd.Flags().Lookup("broadcast-mode") != nil && !cmd.Flags().Changed("broadcast-mode") { - _ = cmd.Flags().Set("broadcast-mode", conf.BroadcastMode) + if err = cmd.Flags().Set("broadcast-mode", conf.BroadcastMode); err != nil { + return err + } } if cmd.Flags().Lookup("grpc-addr") != nil && !cmd.Flags().Changed("grpc-addr") { - _ = cmd.Flags().Set("grpc-addr", conf.GRPC.Address) + if err = cmd.Flags().Set("grpc-addr", conf.GRPC.Address); err != nil { + return err + } } if cmd.Flags().Lookup("grpc-insecure") != nil && !cmd.Flags().Changed("grpc-insecure") { - _ = cmd.Flags().Set("grpc-insecure", strconv.FormatBool(conf.GRPC.Insecure)) + if err = cmd.Flags().Set("grpc-insecure", strconv.FormatBool(conf.GRPC.Insecure)); err != nil { + return err + } } return nil diff --git a/client/v2/autocli/config/toml.go b/client/v2/autocli/config/toml.go index ae1a95c538cb..87336c05f9ac 100644 --- a/client/v2/autocli/config/toml.go +++ b/client/v2/autocli/config/toml.go @@ -2,6 +2,7 @@ package config import ( "os" + "path/filepath" "github.com/pelletier/go-toml/v2" "github.com/spf13/viper" @@ -15,8 +16,8 @@ func writeConfigFile(configFilePath string, config *Config) error { return err } - if _, err := os.Stat(configFilePath); os.IsNotExist(err) { - if err := os.MkdirAll(configFilePath, os.ModePerm); err != nil { + if dir := filepath.Dir(configFilePath); dir != "" { + if err := os.MkdirAll(dir, os.ModePerm); err != nil { return err } } @@ -29,7 +30,6 @@ func readConfig(configPath string, v *viper.Viper) (*Config, error) { v.AddConfigPath(configPath) v.SetConfigName("client") v.SetConfigType("toml") - v.AddConfigPath(configPath) if err := v.ReadInConfig(); err != nil { return nil, err diff --git a/client/v2/autocli/context/context.go b/client/v2/autocli/context/context.go index 7eeb9291c382..43e11ced47c7 100644 --- a/client/v2/autocli/context/context.go +++ b/client/v2/autocli/context/context.go @@ -23,8 +23,6 @@ const ContextKey key = "autocli.context" // Context represents the client context used in autocli commands. // It contains various components needed for command execution. type Context struct { - gocontext.Context - Flags *pflag.FlagSet AddressCodec address.Codec @@ -46,9 +44,9 @@ func ClientContextFromGoContext(ctx gocontext.Context) (*Context, error) { if c := ctx.Value(ContextKey); c != nil { cliCtx, ok := c.(Context) if !ok { - return nil, errors.New("invalid context") + return nil, errors.New("context value is not of type autocli.Context") } return &cliCtx, nil } - return nil, errors.New("invalid context") + return nil, errors.New("context does not contain autocli.Context value") } From ae69fecdfea69a414efcda915a856eb578f77eba Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 19 Nov 2024 10:43:14 +0100 Subject: [PATCH 30/52] mint_test system test tag --- tests/systemtests/mint_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/systemtests/mint_test.go b/tests/systemtests/mint_test.go index c95aaaee1233..e0ee3b72411b 100644 --- a/tests/systemtests/mint_test.go +++ b/tests/systemtests/mint_test.go @@ -1,3 +1,5 @@ +//go:build system_test + package systemtests import ( From 2f4029a19780dceb5dec9b15978bd869c5d9ef8b Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 20 Nov 2024 11:00:24 +0100 Subject: [PATCH 31/52] remove ir from comet --- client/v2/autocli/app.go | 2 +- client/v2/autocli/common.go | 5 ++--- client/v2/broadcast/comet/clientConn.go | 6 +++--- client/v2/broadcast/comet/comet.go | 5 +---- client/v2/broadcast/comet/comet_test.go | 2 +- client/v2/offchain/cli.go | 2 +- client/v2/tx/tx.go | 7 +++---- 7 files changed, 12 insertions(+), 17 deletions(-) diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index 9d3b9008d37d..ed0aefa13d96 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -77,7 +77,7 @@ func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error { ValidatorAddressCodec: appOptions.ValidatorAddressCodec, ConsensusAddressCodec: appOptions.ConsensusAddressCodec, }, - GetClientConn: getQueryClientConn(appOptions.Cdc, appOptions.Cdc.InterfaceRegistry()), + GetClientConn: getQueryClientConn(appOptions.Cdc), AddQueryConnFlags: func(c *cobra.Command) { sdkflags.AddQueryFlagsToCmd(c) sdkflags.AddKeyringFlags(c.Flags()) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 2c155acfd811..4cf8ce7c274a 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -22,7 +22,6 @@ import ( "cosmossdk.io/client/v2/internal/util" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" ) type cmdType int @@ -355,7 +354,7 @@ func (b *Builder) setFlagsFromConfig(cmd *cobra.Command) error { // getQueryClientConn returns a function that creates a gRPC client connection based on command flags. // It handles the creation of secure or insecure connections and falls back to a CometBFT broadcaster // if no gRPC address is specified. -func getQueryClientConn(cdc codec.Codec, ir types.InterfaceRegistry) func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { +func getQueryClientConn(cdc codec.Codec) func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { return func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { var err error creds := grpcinsecure.NewCredentials() @@ -385,7 +384,7 @@ func getQueryClientConn(cdc codec.Codec, ir types.InterfaceRegistry) func(cmd *c if err != nil { return nil, err } - return comet.NewCometBFTBroadcaster(node, comet.BroadcastSync, cdc, ir) + return comet.NewCometBFTBroadcaster(node, comet.BroadcastSync, cdc) } return grpc.NewClient(addr, []grpc.DialOption{grpc.WithTransportCredentials(creds)}...) diff --git a/client/v2/broadcast/comet/clientConn.go b/client/v2/broadcast/comet/clientConn.go index b54a6c253681..ebc61300ce45 100644 --- a/client/v2/broadcast/comet/clientConn.go +++ b/client/v2/broadcast/comet/clientConn.go @@ -87,8 +87,8 @@ func (c *CometBFTBroadcaster) Invoke(ctx context.Context, method string, req, re *header.HeaderAddr = md } - if c.ir != nil { - return types.UnpackInterfaces(reply, c.ir) + if c.cdc.InterfaceRegistry() != nil { + return types.UnpackInterfaces(reply, c.cdc.InterfaceRegistry()) } return nil @@ -140,7 +140,7 @@ func sdkErrorToGRPCError(resp abci.QueryResponse) error { func (c *CometBFTBroadcaster) getRPCCodec() encoding.Codec { cdc, ok := c.cdc.(codec.GRPCCodecProvider) if !ok { - return codec.NewProtoCodec(c.ir).GRPCCodec() + return codec.NewProtoCodec(c.cdc.InterfaceRegistry()).GRPCCodec() } return cdc.GRPCCodec() diff --git a/client/v2/broadcast/comet/comet.go b/client/v2/broadcast/comet/comet.go index fdfc5b66ad8a..3ff2e37a44dc 100644 --- a/client/v2/broadcast/comet/comet.go +++ b/client/v2/broadcast/comet/comet.go @@ -17,7 +17,6 @@ import ( "cosmossdk.io/client/v2/broadcast" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -68,11 +67,10 @@ type CometBFTBroadcaster struct { rpcClient CometRPC mode string cdc codec.Codec - ir types.InterfaceRegistry } // NewCometBFTBroadcaster creates a new CometBFTBroadcaster. -func NewCometBFTBroadcaster(rpcURL, mode string, cdc codec.Codec, ir types.InterfaceRegistry) (*CometBFTBroadcaster, error) { +func NewCometBFTBroadcaster(rpcURL, mode string, cdc codec.Codec) (*CometBFTBroadcaster, error) { if cdc == nil { return nil, errors.New("codec can't be nil") } @@ -90,7 +88,6 @@ func NewCometBFTBroadcaster(rpcURL, mode string, cdc codec.Codec, ir types.Inter rpcClient: rpcClient, mode: mode, cdc: cdc, - ir: ir, }, nil } diff --git a/client/v2/broadcast/comet/comet_test.go b/client/v2/broadcast/comet/comet_test.go index 15b5fb0114d7..69c032f2e12d 100644 --- a/client/v2/broadcast/comet/comet_test.go +++ b/client/v2/broadcast/comet/comet_test.go @@ -45,7 +45,7 @@ func TestNewCometBftBroadcaster(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := NewCometBFTBroadcaster("localhost:26657", tt.mode, tt.cdc, testutil.CodecOptions{}.NewInterfaceRegistry()) + got, err := NewCometBFTBroadcaster("localhost:26657", tt.mode, tt.cdc) if tt.wantErr { require.Error(t, err) require.Nil(t, got) diff --git a/client/v2/offchain/cli.go b/client/v2/offchain/cli.go index f64e88c6fbc4..eb6bab46bd9c 100644 --- a/client/v2/offchain/cli.go +++ b/client/v2/offchain/cli.go @@ -84,7 +84,7 @@ func SignFile() *cobra.Command { } // off-chain does not need to query any information - conn, err := comet.NewCometBFTBroadcaster("", comet.BroadcastSync, cdc, ir) + conn, err := comet.NewCometBFTBroadcaster("", comet.BroadcastSync, cdc) if err != nil { return err } diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index f4bed842da2e..112e390aa756 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -21,7 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/input" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" ) // GenerateOrBroadcastTxCLIWithBroadcaster will either generate and print an unsigned transaction @@ -72,7 +71,7 @@ func GenerateOrBroadcastTxCLI( return err } - cometBroadcaster, err := getCometBroadcaster(c.Cdc, c.Cdc.InterfaceRegistry(), c.Flags) + cometBroadcaster, err := getCometBroadcaster(c.Cdc, c.Flags) if err != nil { return err } @@ -81,10 +80,10 @@ func GenerateOrBroadcastTxCLI( } // getCometBroadcaster returns a new CometBFT broadcaster based on the provided context and flag set. -func getCometBroadcaster(cdc codec.Codec, ir types.InterfaceRegistry, flagSet *pflag.FlagSet) (broadcast.Broadcaster, error) { +func getCometBroadcaster(cdc codec.Codec, flagSet *pflag.FlagSet) (broadcast.Broadcaster, error) { url, _ := flagSet.GetString("node") mode, _ := flagSet.GetString("broadcast-mode") - return comet.NewCometBFTBroadcaster(url, mode, cdc, ir) + return comet.NewCometBFTBroadcaster(url, mode, cdc) } // newFactory creates a new transaction Factory based on the provided context and flag set. From 67227790d6e4acced76d05e8e4b714fad046a4e2 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 20 Nov 2024 12:55:58 +0100 Subject: [PATCH 32/52] updates --- client/v2/autocli/app.go | 3 +- client/v2/autocli/builder.go | 4 +- client/v2/autocli/common.go | 18 +++- client/v2/autocli/config/config.go | 54 ++++++++++-- client/v2/autocli/config/toml.go | 44 ---------- client/v2/autocli/context/context.go | 10 +-- client/v2/autocli/msg.go | 4 +- .../comet/{clientConn.go => client_conn.go} | 0 .../v2/{autocli => internal}/print/printer.go | 0 client/v2/tx/tx.go | 85 +++++++++---------- 10 files changed, 110 insertions(+), 112 deletions(-) delete mode 100644 client/v2/autocli/config/toml.go rename client/v2/broadcast/comet/{clientConn.go => client_conn.go} (100%) rename client/v2/{autocli => internal}/print/printer.go (100%) diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index ed0aefa13d96..5e1316b4127d 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -6,7 +6,6 @@ import ( "google.golang.org/protobuf/reflect/protoregistry" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/client/v2/autocli/flag" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" @@ -84,7 +83,7 @@ func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error { }, AddTxConnFlags: sdkflags.AddTxFlagsToCmd, Cdc: appOptions.Cdc, - EnabledSignModes: []apitxsigning.SignMode{apitxsigning.SignMode_SIGN_MODE_DIRECT}, + EnabledSignModes: appOptions.TxConfigOpts.EnabledSignModes, } return appOptions.EnhanceRootCommandWithBuilder(rootCmd, builder) diff --git a/client/v2/autocli/builder.go b/client/v2/autocli/builder.go index bd1744ef888a..475dac8af6d6 100644 --- a/client/v2/autocli/builder.go +++ b/client/v2/autocli/builder.go @@ -4,10 +4,10 @@ import ( "github.com/spf13/cobra" "google.golang.org/grpc" - apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/client/v2/autocli/flag" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/types/tx/signing" ) // Builder manages options for building CLI commands. @@ -24,7 +24,7 @@ type Builder struct { AddTxConnFlags func(*cobra.Command) Cdc codec.Codec - EnabledSignModes []apisigning.SignMode + EnabledSignModes []signing.SignMode } // ValidateAndComplete the builder fields. diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 4cf8ce7c274a..470c31bae828 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -6,6 +6,9 @@ import ( "fmt" "strconv" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -16,9 +19,9 @@ import ( "cosmossdk.io/client/v2/autocli/config" clientcontext "cosmossdk.io/client/v2/autocli/context" "cosmossdk.io/client/v2/autocli/keyring" - "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/broadcast/comet" "cosmossdk.io/client/v2/internal/flags" + "cosmossdk.io/client/v2/internal/print" "cosmossdk.io/client/v2/internal/util" "github.com/cosmos/cosmos-sdk/codec" @@ -264,6 +267,8 @@ func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { if err != nil { return nil, err } + } else { + k = keyring.NoKeyring{} } clientCtx := clientcontext.Context{ @@ -274,7 +279,7 @@ func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { Cdc: b.Cdc, Printer: printer, Keyring: k, - EnabledSignmodes: b.EnabledSignModes, + EnabledSignmodes: signModesToApiSingModes(b.EnabledSignModes), } return context.WithValue(cmd.Context(), clientcontext.ContextKey, clientCtx), nil @@ -390,3 +395,12 @@ func getQueryClientConn(cdc codec.Codec) func(cmd *cobra.Command) (grpc.ClientCo return grpc.NewClient(addr, []grpc.DialOption{grpc.WithTransportCredentials(creds)}...) } } + +// signModesToApiSingModes converts a slice of signing.SignMode to a slice of apitxsigning.SignMode. +func signModesToApiSingModes(modes []signing.SignMode) []apitxsigning.SignMode { + r := make([]apitxsigning.SignMode, len(modes)) + for i, m := range modes { + r[i] = apitxsigning.SignMode(m) + } + return r +} diff --git a/client/v2/autocli/config/config.go b/client/v2/autocli/config/config.go index ac458f7f84e0..348ca932cc9f 100644 --- a/client/v2/autocli/config/config.go +++ b/client/v2/autocli/config/config.go @@ -8,24 +8,25 @@ import ( "path/filepath" "strings" + "github.com/pelletier/go-toml/v2" "github.com/spf13/pflag" "github.com/spf13/viper" ) type Config struct { - ChainID string `mapstructure:"chain-id" toml:"chain-id"` - KeyringBackend string `mapstructure:"keyring-backend" toml:"keyring-backend"` - KeyringDefaultKeyName string `mapstructure:"keyring-default-keyname" toml:"keyring-default-keyname"` - Output string `mapstructure:"output" toml:"output"` - Node string `mapstructure:"node" toml:"node"` - BroadcastMode string `mapstructure:"broadcast-mode" toml:"broadcast-mode"` - GRPC GRPCConfig `mapstructure:",squash"` + ChainID string `mapstructure:"chain-id" toml:"chain-id" comment:"The chain ID of the blockchain network"` + KeyringBackend string `mapstructure:"keyring-backend" toml:"keyring-backend" comment:"The keyring backend to use (os|file|kwallet|pass|test|memory)"` + KeyringDefaultKeyName string `mapstructure:"keyring-default-keyname" toml:"keyring-default-keyname" comment:"The default key name to use for signing transactions"` + Output string `mapstructure:"output" toml:"output" comment:"The output format for queries (text|json)"` + Node string `mapstructure:"node" toml:"node" comment:"The RPC endpoint URL for the node to connect to"` + BroadcastMode string `mapstructure:"broadcast-mode" toml:"broadcast-mode" comment:"How transactions are broadcast to the network (sync|async|block)"` + GRPC GRPCConfig `mapstructure:",squash" comment:"The gRPC client configuration"` } // GRPCConfig holds the gRPC client configuration. type GRPCConfig struct { - Address string `mapstructure:"grpc-address" toml:"grpc-address"` - Insecure bool `mapstructure:"grpc-insecure" toml:"grpc-insecure"` + Address string `mapstructure:"grpc-address" toml:"grpc-address" comment:"The gRPC server address to connect to"` + Insecure bool `mapstructure:"grpc-insecure" toml:"grpc-insecure" comment:"Allow gRPC over insecure connections"` } func DefaultConfig() *Config { @@ -91,3 +92,38 @@ func CreateClientConfigFromFlags(set *pflag.FlagSet) (*Config, error) { return CreateClientConfig(homeDir, chainID, v) } + +// writeConfigFile renders config using the template and writes it to +// configFilePath. +func writeConfigFile(configFilePath string, config *Config) error { + b, err := toml.Marshal(config) + if err != nil { + return err + } + + if dir := filepath.Dir(configFilePath); dir != "" { + if err := os.MkdirAll(dir, os.ModePerm); err != nil { + return err + } + } + + return os.WriteFile(configFilePath, b, 0o600) +} + +// readConfig reads values from client.toml file and unmarshalls them into ClientConfig +func readConfig(configPath string, v *viper.Viper) (*Config, error) { + v.AddConfigPath(configPath) + v.SetConfigName("client") + v.SetConfigType("toml") + + if err := v.ReadInConfig(); err != nil { + return nil, err + } + + conf := DefaultConfig() + if err := v.Unmarshal(conf); err != nil { + return nil, err + } + + return conf, nil +} diff --git a/client/v2/autocli/config/toml.go b/client/v2/autocli/config/toml.go deleted file mode 100644 index 87336c05f9ac..000000000000 --- a/client/v2/autocli/config/toml.go +++ /dev/null @@ -1,44 +0,0 @@ -package config - -import ( - "os" - "path/filepath" - - "github.com/pelletier/go-toml/v2" - "github.com/spf13/viper" -) - -// writeConfigFile renders config using the template and writes it to -// configFilePath. -func writeConfigFile(configFilePath string, config *Config) error { - b, err := toml.Marshal(config) - if err != nil { - return err - } - - if dir := filepath.Dir(configFilePath); dir != "" { - if err := os.MkdirAll(dir, os.ModePerm); err != nil { - return err - } - } - - return os.WriteFile(configFilePath, b, 0o600) -} - -// readConfig reads values from client.toml file and unmarshalls them into ClientConfig -func readConfig(configPath string, v *viper.Viper) (*Config, error) { - v.AddConfigPath(configPath) - v.SetConfigName("client") - v.SetConfigType("toml") - - if err := v.ReadInConfig(); err != nil { - return nil, err - } - - conf := DefaultConfig() - if err := v.Unmarshal(conf); err != nil { - return nil, err - } - - return conf, nil -} diff --git a/client/v2/autocli/context/context.go b/client/v2/autocli/context/context.go index 43e11ced47c7..63e56ccc60c3 100644 --- a/client/v2/autocli/context/context.go +++ b/client/v2/autocli/context/context.go @@ -8,17 +8,17 @@ import ( apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/client/v2/autocli/keyring" - "cosmossdk.io/client/v2/autocli/print" + "cosmossdk.io/client/v2/internal/print" "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/codec" ) -// key is a custom type used as a context key to prevent collisions in the context.Context value store. -type key string +// ContextKey is a key used to store and retrieve Context from a Go context.Context. +var ContextKey contextKey -// ContextKey is the key used to store and retrieve the autocli.Context from a context.Context. -const ContextKey key = "autocli.context" +// contextKey is an empty struct used as a key type for storing Context in a context.Context. +type contextKey struct{} // Context represents the client context used in autocli commands. // It contains various components needed for command execution. diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index eeb80c30261f..9e6ba0cc99b6 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -233,10 +233,10 @@ func (b *Builder) handleGovProposal( // generateOrBroadcastTxWithV2 generates or broadcasts a transaction with the provided messages using v2 transaction handling. // //nolint:unused // It'll be used once BuildMsgMethodCommand is updated to use factory v2. -func (b *Builder) generateOrBroadcastTxWithV2(ctx context.Context, cmd *cobra.Command, msgs ...transaction.Msg) error { +func (b *Builder) generateOrBroadcastTxWithV2(ctx context.Context, cmd *cobra.Command, msgs ...transaction.Msg) ([]byte, error) { cConn, err := b.GetClientConn(cmd) if err != nil { - return err + return nil, err } return v2tx.GenerateOrBroadcastTxCLI(ctx, cConn, msgs...) diff --git a/client/v2/broadcast/comet/clientConn.go b/client/v2/broadcast/comet/client_conn.go similarity index 100% rename from client/v2/broadcast/comet/clientConn.go rename to client/v2/broadcast/comet/client_conn.go diff --git a/client/v2/autocli/print/printer.go b/client/v2/internal/print/printer.go similarity index 100% rename from client/v2/autocli/print/printer.go rename to client/v2/internal/print/printer.go diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index 112e390aa756..aa8da33ef962 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -13,10 +13,10 @@ import ( apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" clientcontext "cosmossdk.io/client/v2/autocli/context" - "cosmossdk.io/client/v2/autocli/print" "cosmossdk.io/client/v2/broadcast" "cosmossdk.io/client/v2/broadcast/comet" "cosmossdk.io/client/v2/internal/account" + "cosmossdk.io/client/v2/internal/print" "cosmossdk.io/core/transaction" "github.com/cosmos/cosmos-sdk/client/input" @@ -30,29 +30,29 @@ func GenerateOrBroadcastTxCLIWithBroadcaster( conn grpc.ClientConn, broadcaster broadcast.Broadcaster, msgs ...transaction.Msg, -) error { +) ([]byte, error) { clientCtx, err := clientcontext.ClientContextFromGoContext(ctx) if err != nil { - return err + return nil, err } if err := validateMessages(msgs...); err != nil { - return err + return nil, err } - txf, err := newFactory(clientCtx, conn, clientCtx.Flags) + txf, err := newFactory(clientCtx, conn) if err != nil { - return err + return nil, err } genOnly, _ := clientCtx.Flags.GetBool(flagGenerateOnly) if genOnly { - return generateOnly(clientCtx.Printer, txf, msgs...) + return generateOnly(txf, msgs...) } isDryRun, _ := clientCtx.Flags.GetBool(flagDryRun) if isDryRun { - return dryRun(clientCtx.Printer, txf, msgs...) + return dryRun(txf, msgs...) } skipConfirm, _ := clientCtx.Flags.GetBool("yes") @@ -65,15 +65,15 @@ func GenerateOrBroadcastTxCLI( ctx context.Context, conn grpc.ClientConn, msgs ...transaction.Msg, -) error { +) ([]byte, error) { c, err := clientcontext.ClientContextFromGoContext(ctx) if err != nil { - return err + return nil, err } cometBroadcaster, err := getCometBroadcaster(c.Cdc, c.Flags) if err != nil { - return err + return nil, err } return GenerateOrBroadcastTxCLIWithBroadcaster(ctx, conn, cometBroadcaster, msgs...) @@ -89,11 +89,7 @@ func getCometBroadcaster(cdc codec.Codec, flagSet *pflag.FlagSet) (broadcast.Bro // newFactory creates a new transaction Factory based on the provided context and flag set. // It initializes a new CLI keyring, extracts transaction parameters from the flag set, // configures transaction settings, and sets up an account retriever for the transaction Factory. -func newFactory( - ctx *clientcontext.Context, - conn grpc.ClientConn, - flagSet *pflag.FlagSet, -) (Factory, error) { +func newFactory(ctx *clientcontext.Context, conn grpc.ClientConn) (Factory, error) { txConfig, err := NewTxConfig(ConfigOptions{ AddressCodec: ctx.AddressCodec, Cdc: ctx.Cdc, @@ -106,7 +102,7 @@ func newFactory( accRetriever := account.NewAccountRetriever(ctx.AddressCodec, conn, ctx.Cdc.InterfaceRegistry()) - txf, err := NewFactoryFromFlagSet(flagSet, ctx.Keyring, ctx.Cdc, accRetriever, txConfig, ctx.AddressCodec, conn) + txf, err := NewFactoryFromFlagSet(ctx.Flags, ctx.Keyring, ctx.Cdc, accRetriever, txConfig, ctx.AddressCodec, conn) if err != nil { return Factory{}, err } @@ -136,34 +132,29 @@ func validateMessages(msgs ...transaction.Msg) error { // generateOnly prepares the transaction and prints the unsigned transaction string. // It first calls Prepare on the transaction factory to set up any necessary pre-conditions. // If preparation is successful, it generates an unsigned transaction string using the provided messages. -func generateOnly(printer *print.Printer, txf Factory, msgs ...transaction.Msg) error { +func generateOnly(txf Factory, msgs ...transaction.Msg) ([]byte, error) { uTx, err := txf.UnsignedTxString(msgs...) if err != nil { - return err + return nil, err } - return printer.PrintString(uTx) + return []byte(uTx), nil } // dryRun performs a dry run of the transaction to estimate the gas required. // It prepares the transaction factory and simulates the transaction with the provided messages. -func dryRun(printer *print.Printer, txf Factory, msgs ...transaction.Msg) error { +func dryRun(txf Factory, msgs ...transaction.Msg) ([]byte, error) { _, gas, err := txf.Simulate(msgs...) if err != nil { - return err + return nil, err } - return printer.PrintString(fmt.Sprintf("%s\n", GasEstimateResponse{GasEstimate: gas})) + return []byte(fmt.Sprintf("%s\n", GasEstimateResponse{GasEstimate: gas})), nil } // SimulateTx simulates a tx and returns the simulation response obtained by the query. -func SimulateTx( - ctx *clientcontext.Context, - conn grpc.ClientConn, - flagSet *pflag.FlagSet, - msgs ...transaction.Msg, -) (proto.Message, error) { - txf, err := newFactory(ctx, conn, flagSet) +func SimulateTx(ctx *clientcontext.Context, conn grpc.ClientConn, msgs ...transaction.Msg) (proto.Message, error) { + txf, err := newFactory(ctx, conn) if err != nil { return nil, err } @@ -175,32 +166,39 @@ func SimulateTx( // BroadcastTx attempts to generate, sign and broadcast a transaction with the // given set of messages. It will also simulate gas requirements if necessary. // It will return an error upon failure. -func BroadcastTx(ctx context.Context, printer *print.Printer, txf Factory, broadcaster broadcast.Broadcaster, skipConfirm bool, msgs ...transaction.Msg) error { +func BroadcastTx( + ctx context.Context, + printer *print.Printer, + txf Factory, + broadcaster broadcast.Broadcaster, + skipConfirm bool, + msgs ...transaction.Msg, +) ([]byte, error) { if txf.simulateAndExecute() { err := txf.calculateGas(msgs...) if err != nil { - return err + return nil, err } } err := txf.BuildUnsignedTx(msgs...) if err != nil { - return err + return nil, err } if !skipConfirm { encoder := txf.txConfig.TxJSONEncoder() if encoder == nil { - return errors.New("failed to encode transaction: tx json encoder is nil") + return nil, errors.New("failed to encode transaction: tx json encoder is nil") } unsigTx, err := txf.getTx() if err != nil { - return err + return nil, err } txBytes, err := encoder(unsigTx) if err != nil { - return fmt.Errorf("failed to encode transaction: %w", err) + return nil, fmt.Errorf("failed to encode transaction: %w", err) } if err := printer.PrintRaw(txBytes); err != nil { @@ -211,30 +209,25 @@ func BroadcastTx(ctx context.Context, printer *print.Printer, txf Factory, broad ok, err := input.GetConfirmation("confirm transaction before signing and broadcasting", buf, os.Stderr) if err != nil { _, _ = fmt.Fprintf(os.Stderr, "error: %v\ncanceled transaction\n", err) - return err + return nil, err } if !ok { _, _ = fmt.Fprintln(os.Stderr, "canceled transaction") - return nil + return nil, nil } } signedTx, err := txf.sign(ctx, true) if err != nil { - return err + return nil, err } txBytes, err := txf.txConfig.TxEncoder()(signedTx) if err != nil { - return err - } - - res, err := broadcaster.Broadcast(context.Background(), txBytes) - if err != nil { - return err + return nil, err } - return printer.PrintBytes(res) + return broadcaster.Broadcast(context.Background(), txBytes) } // countDirectSigners counts the number of DIRECT signers in a signature data. From f9b7320b43bcb3be7527d92c417c7fb3eb1e0b13 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 20 Nov 2024 13:02:34 +0100 Subject: [PATCH 33/52] lint --- client/v2/autocli/common.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 470c31bae828..9dfb6d7b1bb9 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -6,9 +6,6 @@ import ( "fmt" "strconv" - apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -16,6 +13,7 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/client/v2/autocli/config" clientcontext "cosmossdk.io/client/v2/autocli/context" "cosmossdk.io/client/v2/autocli/keyring" @@ -25,6 +23,7 @@ import ( "cosmossdk.io/client/v2/internal/util" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/types/tx/signing" ) type cmdType int From 6e4a04b8915b1e50a737741f17f85238c4300fd6 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 20 Nov 2024 13:16:42 +0100 Subject: [PATCH 34/52] rabbit suggestions --- client/v2/autocli/common.go | 4 ++-- client/v2/autocli/config/config.go | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 9dfb6d7b1bb9..bfbfc604a8df 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -278,7 +278,7 @@ func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { Cdc: b.Cdc, Printer: printer, Keyring: k, - EnabledSignmodes: signModesToApiSingModes(b.EnabledSignModes), + EnabledSignmodes: signModesToApiSignModes(b.EnabledSignModes), } return context.WithValue(cmd.Context(), clientcontext.ContextKey, clientCtx), nil @@ -396,7 +396,7 @@ func getQueryClientConn(cdc codec.Codec) func(cmd *cobra.Command) (grpc.ClientCo } // signModesToApiSingModes converts a slice of signing.SignMode to a slice of apitxsigning.SignMode. -func signModesToApiSingModes(modes []signing.SignMode) []apitxsigning.SignMode { +func signModesToApiSignModes(modes []signing.SignMode) []apitxsigning.SignMode { r := make([]apitxsigning.SignMode, len(modes)) for i, m := range modes { r[i] = apitxsigning.SignMode(m) diff --git a/client/v2/autocli/config/config.go b/client/v2/autocli/config/config.go index 348ca932cc9f..c6d33e7e75db 100644 --- a/client/v2/autocli/config/config.go +++ b/client/v2/autocli/config/config.go @@ -40,6 +40,7 @@ func DefaultConfig() *Config { } } +// CreateClientConfig creates a new client configuration or reads an existing one. func CreateClientConfig(homeDir, chainID string, v *viper.Viper) (*Config, error) { if homeDir == "" { return nil, errors.New("home dir can't be empty") @@ -73,12 +74,19 @@ func CreateClientConfig(homeDir, chainID string, v *viper.Viper) (*Config, error return conf, nil } +// CreateClientConfigFromFlags creates a client configuration from command-line flags. func CreateClientConfigFromFlags(set *pflag.FlagSet) (*Config, error) { - homeDir, _ := set.GetString("home") + homeDir, err := set.GetString("home") + if err != nil { + return nil, err + } if homeDir == "" { return DefaultConfig(), nil } - chainID, _ := set.GetString("chain-id") + chainID, err := set.GetString("chain-id") + if err != nil { + return nil, err + } v := viper.New() executableName, err := os.Executable() From d0938d34d52342a7d78fcd1ac7c1e8b7baaeb5f8 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 20 Nov 2024 13:47:17 +0100 Subject: [PATCH 35/52] go-mod-tidy-all --- x/authz/go.sum | 3 +-- x/group/go.sum | 3 +-- x/params/go.sum | 6 ++---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/x/authz/go.sum b/x/authz/go.sum index 556ef8b95d1d..40d4c4d41f00 100644 --- a/x/authz/go.sum +++ b/x/authz/go.sum @@ -16,9 +16,8 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= +cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/group/go.sum b/x/group/go.sum index a6539feebda6..a833d553f6b1 100644 --- a/x/group/go.sum +++ b/x/group/go.sum @@ -16,9 +16,8 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= +cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= diff --git a/x/params/go.sum b/x/params/go.sum index a0bd3353538d..4bd8e2b678d1 100644 --- a/x/params/go.sum +++ b/x/params/go.sum @@ -4,9 +4,8 @@ buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88e buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1/go.mod h1:17Ax38yd8pg56din4ecwSDBRCSX0qLcif5Cdf8ayto4= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a h1:9DxUD+82dO3c+R3XqwW+a7i4nVLiN6I0g2rp2rLOh7E= -cosmossdk.io/collections v0.4.1-0.20241104084251-838f1557af0a/go.mod h1:DcD++Yfcq0OFtM3CJNYLIBjfZ+4DEyeJ/AUk6gkwlOE= cosmossdk.io/core v1.0.0-alpha.6 h1:5ukC4JcQKmemLQXcAgu/QoOvJI50hpBkIIg4ZT2EN8E= cosmossdk.io/core v1.0.0-alpha.6/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e h1:F+ScucYxwrrDJU8guJXQXpGhdpziYSbxW6HMP2wCNxs= @@ -19,9 +18,8 @@ cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g= cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= +cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 h1:DmOoS/1PeY6Ih0hAVlJ69kLMUrLV+TCbfICrZtB1vdU= cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac h1:3joNZZWZ3k7fMsrBDL1ktuQ2xQwYLZOaDhkruadDFmc= -cosmossdk.io/schema v0.3.1-0.20241010135032-192601639cac/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= From e0abf39297f5f7d85903f86454102de0f6cbf641 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 20 Nov 2024 16:40:46 +0100 Subject: [PATCH 36/52] fix --- client/v2/autocli/config/config.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/client/v2/autocli/config/config.go b/client/v2/autocli/config/config.go index c6d33e7e75db..4ff5cda3c05e 100644 --- a/client/v2/autocli/config/config.go +++ b/client/v2/autocli/config/config.go @@ -76,10 +76,7 @@ func CreateClientConfig(homeDir, chainID string, v *viper.Viper) (*Config, error // CreateClientConfigFromFlags creates a client configuration from command-line flags. func CreateClientConfigFromFlags(set *pflag.FlagSet) (*Config, error) { - homeDir, err := set.GetString("home") - if err != nil { - return nil, err - } + homeDir, _ := set.GetString("home") if homeDir == "" { return DefaultConfig(), nil } From dab815dab9f4c38ac9408cf7cc63f75eb8de8b8a Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 20 Nov 2024 17:12:54 +0100 Subject: [PATCH 37/52] fix --- client/v2/autocli/config/config.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/client/v2/autocli/config/config.go b/client/v2/autocli/config/config.go index 4ff5cda3c05e..8b7c048616ce 100644 --- a/client/v2/autocli/config/config.go +++ b/client/v2/autocli/config/config.go @@ -80,10 +80,7 @@ func CreateClientConfigFromFlags(set *pflag.FlagSet) (*Config, error) { if homeDir == "" { return DefaultConfig(), nil } - chainID, err := set.GetString("chain-id") - if err != nil { - return nil, err - } + chainID, _ := set.GetString("chain-id") v := viper.New() executableName, err := os.Executable() From 2ff6fab2b35a8a50e9f411265cb5c79e78a936ec Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Fri, 22 Nov 2024 10:42:17 +0100 Subject: [PATCH 38/52] del: printer from context --- client/v2/autocli/common.go | 12 +++++------- client/v2/autocli/context/context.go | 4 ++-- client/v2/tx/tx.go | 25 +++++++++++++++++++++---- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index bfbfc604a8df..c31cff33c40c 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -254,13 +254,11 @@ func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error { // getContext creates and returns a new context.Context with an autocli.Context value. // It initializes a printer and, if necessary, a keyring based on command flags. func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { - printer, err := print.NewPrinter(cmd) - if err != nil { - return nil, err - } - // if the command uses the keyring this must be set - var k keyring.Keyring + var ( + k keyring.Keyring + err error + ) if cmd.Flags().Lookup("keyring-dir") != nil && cmd.Flags().Lookup("keyring-backend") != nil { k, err = keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) if err != nil { @@ -276,7 +274,7 @@ func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { ValidatorAddressCodec: b.ValidatorAddressCodec, ConsensusAddressCodec: b.ConsensusAddressCodec, Cdc: b.Cdc, - Printer: printer, + OutputWriter: cmd.OutOrStdout(), Keyring: k, EnabledSignmodes: signModesToApiSignModes(b.EnabledSignModes), } diff --git a/client/v2/autocli/context/context.go b/client/v2/autocli/context/context.go index 63e56ccc60c3..970dcac07489 100644 --- a/client/v2/autocli/context/context.go +++ b/client/v2/autocli/context/context.go @@ -3,12 +3,12 @@ package context import ( gocontext "context" "errors" + "io" "github.com/spf13/pflag" apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/client/v2/autocli/keyring" - "cosmossdk.io/client/v2/internal/print" "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/codec" @@ -31,7 +31,7 @@ type Context struct { Cdc codec.Codec - Printer *print.Printer + OutputWriter io.Writer Keyring keyring.Keyring diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index aa8da33ef962..114af24ddf1e 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -56,7 +56,7 @@ func GenerateOrBroadcastTxCLIWithBroadcaster( } skipConfirm, _ := clientCtx.Flags.GetBool("yes") - return BroadcastTx(ctx, clientCtx.Printer, txf, broadcaster, skipConfirm, msgs...) + return BroadcastTx(ctx, txf, broadcaster, skipConfirm, msgs...) } // GenerateOrBroadcastTxCLI will either generate and print an unsigned transaction @@ -168,7 +168,6 @@ func SimulateTx(ctx *clientcontext.Context, conn grpc.ClientConn, msgs ...transa // It will return an error upon failure. func BroadcastTx( ctx context.Context, - printer *print.Printer, txf Factory, broadcaster broadcast.Broadcaster, skipConfirm bool, @@ -201,8 +200,26 @@ func BroadcastTx( return nil, fmt.Errorf("failed to encode transaction: %w", err) } - if err := printer.PrintRaw(txBytes); err != nil { - _, _ = fmt.Fprintf(os.Stderr, "error: %v\n%s\n", err, txBytes) + clientCtx, err := clientcontext.ClientContextFromGoContext(ctx) + if err == nil { + format, err := clientCtx.Flags.GetString("format") + if err != nil { + return nil, err + } + printer := print.Printer{ + Output: clientCtx.OutputWriter, + OutputFormat: format, + } + if err := printer.PrintRaw(txBytes); err != nil { + _, err = fmt.Fprintf(os.Stderr, "error: %v\n%s\n", err, txBytes) + return nil, err + } + } else { + // default output writer and format + _, err = os.Stdout.Write(txBytes) + if err != nil { + return nil, err + } } buf := bufio.NewReader(os.Stdin) From 2949a28c4b56e5ffcfa516fd5b8942321d00c954 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Fri, 22 Nov 2024 11:08:46 +0100 Subject: [PATCH 39/52] rabbit --- client/v2/autocli/common.go | 2 +- client/v2/tx/tx.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 3707b6cf1d1a..d526c1b10b46 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -402,7 +402,7 @@ func getQueryClientConn(cdc codec.Codec) func(cmd *cobra.Command) (grpc.ClientCo } } -// signModesToApiSingModes converts a slice of signing.SignMode to a slice of apitxsigning.SignMode. +// signModesToApiSignModes converts a slice of signing.SignMode to a slice of apitxsigning.SignMode. func signModesToApiSignModes(modes []signing.SignMode) []apitxsigning.SignMode { r := make([]apitxsigning.SignMode, len(modes)) for i, m := range modes { diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index 114af24ddf1e..56ddc878cbb0 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -40,7 +40,7 @@ func GenerateOrBroadcastTxCLIWithBroadcaster( return nil, err } - txf, err := newFactory(clientCtx, conn) + txf, err := newFactory(*clientCtx, conn) if err != nil { return nil, err } @@ -89,7 +89,7 @@ func getCometBroadcaster(cdc codec.Codec, flagSet *pflag.FlagSet) (broadcast.Bro // newFactory creates a new transaction Factory based on the provided context and flag set. // It initializes a new CLI keyring, extracts transaction parameters from the flag set, // configures transaction settings, and sets up an account retriever for the transaction Factory. -func newFactory(ctx *clientcontext.Context, conn grpc.ClientConn) (Factory, error) { +func newFactory(ctx clientcontext.Context, conn grpc.ClientConn) (Factory, error) { txConfig, err := NewTxConfig(ConfigOptions{ AddressCodec: ctx.AddressCodec, Cdc: ctx.Cdc, @@ -153,7 +153,7 @@ func dryRun(txf Factory, msgs ...transaction.Msg) ([]byte, error) { } // SimulateTx simulates a tx and returns the simulation response obtained by the query. -func SimulateTx(ctx *clientcontext.Context, conn grpc.ClientConn, msgs ...transaction.Msg) (proto.Message, error) { +func SimulateTx(ctx clientcontext.Context, conn grpc.ClientConn, msgs ...transaction.Msg) (proto.Message, error) { txf, err := newFactory(ctx, conn) if err != nil { return nil, err @@ -244,7 +244,7 @@ func BroadcastTx( return nil, err } - return broadcaster.Broadcast(context.Background(), txBytes) + return broadcaster.Broadcast(ctx, txBytes) } // countDirectSigners counts the number of DIRECT signers in a signature data. From 11ebebf7cf714fe9f4f68ffcc6970ecaa02d241f Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Fri, 22 Nov 2024 12:59:02 +0100 Subject: [PATCH 40/52] update: flags, remove confirmation --- client/v2/autocli/common.go | 74 +++++++++------------------- client/v2/autocli/context/context.go | 4 -- client/v2/internal/flags/flags.go | 18 +++++++ client/v2/internal/print/printer.go | 6 ++- client/v2/offchain/cli.go | 4 +- client/v2/tx/tx.go | 71 ++------------------------ 6 files changed, 53 insertions(+), 124 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index d526c1b10b46..f071914fc64e 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -6,6 +6,8 @@ import ( "fmt" "strconv" + flags2 "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -268,7 +270,7 @@ func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { k keyring.Keyring err error ) - if cmd.Flags().Lookup("keyring-dir") != nil && cmd.Flags().Lookup("keyring-backend") != nil { + if cmd.Flags().Lookup(flags.FlagKeyringDir) != nil && cmd.Flags().Lookup(flags.FlagKeyringBackend) != nil { k, err = keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) if err != nil { return nil, err @@ -283,7 +285,6 @@ func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { ValidatorAddressCodec: b.ValidatorAddressCodec, ConsensusAddressCodec: b.ConsensusAddressCodec, Cdc: b.Cdc, - OutputWriter: cmd.OutOrStdout(), Keyring: k, EnabledSignmodes: signModesToApiSignModes(b.EnabledSignModes), } @@ -305,57 +306,30 @@ func (b *Builder) preRunE() func(cmd *cobra.Command, args []string) error { } } +// setFlagsFromConfig sets command flags from the provided configuration. +// It only sets flags that haven't been explicitly changed by the user. func (b *Builder) setFlagsFromConfig(cmd *cobra.Command) error { conf, err := config.CreateClientConfigFromFlags(cmd.Flags()) if err != nil { return err } - if cmd.Flags().Lookup("chain-id") != nil && !cmd.Flags().Changed("chain-id") { - if err = cmd.Flags().Set("chain-id", conf.ChainID); err != nil { - return err - } - } - - if cmd.Flags().Lookup("keyring-backend") != nil && !cmd.Flags().Changed("keyring-backend") { - if err = cmd.Flags().Set("keyring-backend", conf.KeyringBackend); err != nil { - return err - } - } - - if cmd.Flags().Lookup("from") != nil && !cmd.Flags().Changed("from") { - if err = cmd.Flags().Set("from", conf.KeyringDefaultKeyName); err != nil { - return err - } - } - - if cmd.Flags().Lookup("output") != nil && !cmd.Flags().Changed("output") { - if err = cmd.Flags().Set("output", conf.Output); err != nil { - return err - } - } - - if cmd.Flags().Lookup("node") != nil && !cmd.Flags().Changed("node") { - if err = cmd.Flags().Set("node", conf.Node); err != nil { - return err - } - } - - if cmd.Flags().Lookup("broadcast-mode") != nil && !cmd.Flags().Changed("broadcast-mode") { - if err = cmd.Flags().Set("broadcast-mode", conf.BroadcastMode); err != nil { - return err - } + flagsToSet := map[string]string{ + flags.FlagChainID: conf.ChainID, + flags.FlagKeyringBackend: conf.KeyringBackend, + flags.FlagFrom: conf.KeyringDefaultKeyName, + flags.FlagOutput: conf.Output, + flags.FlagNode: conf.Node, + flags.FlagBroadcastMode: conf.BroadcastMode, + flags.FlagGrpcAddress: conf.GRPC.Address, + flags2.FlagGRPCInsecure: strconv.FormatBool(conf.GRPC.Insecure), } - if cmd.Flags().Lookup("grpc-addr") != nil && !cmd.Flags().Changed("grpc-addr") { - if err = cmd.Flags().Set("grpc-addr", conf.GRPC.Address); err != nil { - return err - } - } - - if cmd.Flags().Lookup("grpc-insecure") != nil && !cmd.Flags().Changed("grpc-insecure") { - if err = cmd.Flags().Set("grpc-insecure", strconv.FormatBool(conf.GRPC.Insecure)); err != nil { - return err + for flagName, value := range flagsToSet { + if flag := cmd.Flags().Lookup(flagName); flag != nil && !cmd.Flags().Changed(flagName) { + if err := cmd.Flags().Set(flagName, value); err != nil { + return err + } } } @@ -371,8 +345,8 @@ func getQueryClientConn(cdc codec.Codec) func(cmd *cobra.Command) (grpc.ClientCo creds := grpcinsecure.NewCredentials() insecure := true - if cmd.Flags().Lookup("grpc-insecure") != nil { - insecure, err = cmd.Flags().GetBool("grpc-insecure") + if cmd.Flags().Lookup(flags.FlagGrpcInsecure) != nil { + insecure, err = cmd.Flags().GetBool(flags.FlagGrpcInsecure) if err != nil { return nil, err } @@ -382,8 +356,8 @@ func getQueryClientConn(cdc codec.Codec) func(cmd *cobra.Command) (grpc.ClientCo } var addr string - if cmd.Flags().Lookup("grpc-addr") != nil { - addr, err = cmd.Flags().GetString("grpc-addr") + if cmd.Flags().Lookup(flags.FlagGrpcAddress) != nil { + addr, err = cmd.Flags().GetString(flags.FlagGrpcAddress) if err != nil { return nil, err } @@ -391,7 +365,7 @@ func getQueryClientConn(cdc codec.Codec) func(cmd *cobra.Command) (grpc.ClientCo if addr == "" { // if grpc-addr has not been set, use the default clientConn // TODO: default is comet - node, err := cmd.Flags().GetString("node") + node, err := cmd.Flags().GetString(flags.FlagNode) if err != nil { return nil, err } diff --git a/client/v2/autocli/context/context.go b/client/v2/autocli/context/context.go index 970dcac07489..f18db03a8cd6 100644 --- a/client/v2/autocli/context/context.go +++ b/client/v2/autocli/context/context.go @@ -3,8 +3,6 @@ package context import ( gocontext "context" "errors" - "io" - "github.com/spf13/pflag" apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" @@ -31,8 +29,6 @@ type Context struct { Cdc codec.Codec - OutputWriter io.Writer - Keyring keyring.Keyring EnabledSignmodes []apisigning.SignMode diff --git a/client/v2/internal/flags/flags.go b/client/v2/internal/flags/flags.go index d06cef708cad..8edb44c597d5 100644 --- a/client/v2/internal/flags/flags.go +++ b/client/v2/internal/flags/flags.go @@ -2,6 +2,9 @@ package flags // This defines flag names that can be used in autocli. const ( + // FlagChainID is the flag to specify the chain ID of the network. + FlagChainID = "chain-id" + // FlagFrom is the flag to set the from address with which to sign the transaction. FlagFrom = "from" @@ -14,9 +17,24 @@ const ( // FlagNoPrompt is the flag to not use a prompt for commands. FlagNoPrompt = "no-prompt" + // FlagKeyringDir is the flag to specify the directory where the keyring is stored. + FlagKeyringDir = "keyring-dir" + // FlagKeyringBackend is the flag to specify which backend to use for the keyring (e.g. os, file, test). + FlagKeyringBackend = "keyring-backend" + // FlagNoProposal is the flag convert a gov proposal command into a normal command. // This is used to allow user of chains with custom authority to not use gov submit proposals for usual proposal commands. FlagNoProposal = "no-proposal" + + // FlagNode is the flag to specify the node address to connect to. + FlagNode = "node" + // FlagBroadcastMode is the flag to specify the broadcast mode for transactions. + FlagBroadcastMode = "broadcast-mode" + + // FlagGrpcAddress is the flag to specify the gRPC server address to connect to. + FlagGrpcAddress = "grpc-addr" + // FlagGrpcInsecure is the flag to allow insecure gRPC connections. + FlagGrpcInsecure = "grpc-insecure" ) // List of supported output formats diff --git a/client/v2/internal/print/printer.go b/client/v2/internal/print/printer.go index 5d6b5a9898af..631281bcb0a2 100644 --- a/client/v2/internal/print/printer.go +++ b/client/v2/internal/print/printer.go @@ -8,11 +8,13 @@ import ( "github.com/spf13/cobra" "sigs.k8s.io/yaml" + + "cosmossdk.io/client/v2/internal/flags" ) const ( - jsonOutput = "json" - textOutput = "text" + jsonOutput = flags.OutputFormatJSON + textOutput = flags.OutputFormatText ) // Printer handles formatted output of different types of data diff --git a/client/v2/offchain/cli.go b/client/v2/offchain/cli.go index eb6bab46bd9c..5eca8c4006c9 100644 --- a/client/v2/offchain/cli.go +++ b/client/v2/offchain/cli.go @@ -62,8 +62,8 @@ func SignFile() *cobra.Command { } keyringBackend := c.KeyringBackend - if !cmd.Flags().Changed(flags.FlagKeyringBackend) { - _ = cmd.Flags().Set(flags.FlagKeyringBackend, keyringBackend) + if !cmd.Flags().Changed(v2flags.FlagKeyringBackend) { + _ = cmd.Flags().Set(v2flags.FlagKeyringBackend, keyringBackend) } bz, err := os.ReadFile(args[1]) diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index 56ddc878cbb0..c74f7156b0c0 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -1,12 +1,8 @@ package tx import ( - "bufio" "context" - "errors" "fmt" - "os" - "github.com/cosmos/gogoproto/grpc" "github.com/cosmos/gogoproto/proto" "github.com/spf13/pflag" @@ -16,10 +12,9 @@ import ( "cosmossdk.io/client/v2/broadcast" "cosmossdk.io/client/v2/broadcast/comet" "cosmossdk.io/client/v2/internal/account" - "cosmossdk.io/client/v2/internal/print" + "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/core/transaction" - "github.com/cosmos/cosmos-sdk/client/input" "github.com/cosmos/cosmos-sdk/codec" ) @@ -55,8 +50,7 @@ func GenerateOrBroadcastTxCLIWithBroadcaster( return dryRun(txf, msgs...) } - skipConfirm, _ := clientCtx.Flags.GetBool("yes") - return BroadcastTx(ctx, txf, broadcaster, skipConfirm, msgs...) + return BroadcastTx(ctx, txf, broadcaster, msgs...) } // GenerateOrBroadcastTxCLI will either generate and print an unsigned transaction @@ -81,8 +75,8 @@ func GenerateOrBroadcastTxCLI( // getCometBroadcaster returns a new CometBFT broadcaster based on the provided context and flag set. func getCometBroadcaster(cdc codec.Codec, flagSet *pflag.FlagSet) (broadcast.Broadcaster, error) { - url, _ := flagSet.GetString("node") - mode, _ := flagSet.GetString("broadcast-mode") + url, _ := flagSet.GetString(flags.FlagNode) + mode, _ := flagSet.GetString(flags.FlagBroadcastMode) return comet.NewCometBFTBroadcaster(url, mode, cdc) } @@ -166,13 +160,7 @@ func SimulateTx(ctx clientcontext.Context, conn grpc.ClientConn, msgs ...transac // BroadcastTx attempts to generate, sign and broadcast a transaction with the // given set of messages. It will also simulate gas requirements if necessary. // It will return an error upon failure. -func BroadcastTx( - ctx context.Context, - txf Factory, - broadcaster broadcast.Broadcaster, - skipConfirm bool, - msgs ...transaction.Msg, -) ([]byte, error) { +func BroadcastTx(ctx context.Context, txf Factory, broadcaster broadcast.Broadcaster, msgs ...transaction.Msg) ([]byte, error) { if txf.simulateAndExecute() { err := txf.calculateGas(msgs...) if err != nil { @@ -185,55 +173,6 @@ func BroadcastTx( return nil, err } - if !skipConfirm { - encoder := txf.txConfig.TxJSONEncoder() - if encoder == nil { - return nil, errors.New("failed to encode transaction: tx json encoder is nil") - } - - unsigTx, err := txf.getTx() - if err != nil { - return nil, err - } - txBytes, err := encoder(unsigTx) - if err != nil { - return nil, fmt.Errorf("failed to encode transaction: %w", err) - } - - clientCtx, err := clientcontext.ClientContextFromGoContext(ctx) - if err == nil { - format, err := clientCtx.Flags.GetString("format") - if err != nil { - return nil, err - } - printer := print.Printer{ - Output: clientCtx.OutputWriter, - OutputFormat: format, - } - if err := printer.PrintRaw(txBytes); err != nil { - _, err = fmt.Fprintf(os.Stderr, "error: %v\n%s\n", err, txBytes) - return nil, err - } - } else { - // default output writer and format - _, err = os.Stdout.Write(txBytes) - if err != nil { - return nil, err - } - } - - buf := bufio.NewReader(os.Stdin) - ok, err := input.GetConfirmation("confirm transaction before signing and broadcasting", buf, os.Stderr) - if err != nil { - _, _ = fmt.Fprintf(os.Stderr, "error: %v\ncanceled transaction\n", err) - return nil, err - } - if !ok { - _, _ = fmt.Fprintln(os.Stderr, "canceled transaction") - return nil, nil - } - } - signedTx, err := txf.sign(ctx, true) if err != nil { return nil, err From 9c7eb261c6ffcc1d8aa148195ccca48820f24738 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Mon, 25 Nov 2024 11:00:37 +0100 Subject: [PATCH 41/52] update: generate broadcast --- client/v2/autocli/common.go | 2 +- client/v2/autocli/context/context.go | 7 +++++ client/v2/autocli/msg.go | 23 ++++++++++++-- client/v2/broadcast/comet/client_conn.go | 5 ++-- client/v2/tx/factory.go | 4 +-- client/v2/tx/tx.go | 38 +++++++++++++++++------- 6 files changed, 60 insertions(+), 19 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index f071914fc64e..4f2e38b5b8b7 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -289,7 +289,7 @@ func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { EnabledSignmodes: signModesToApiSignModes(b.EnabledSignModes), } - return context.WithValue(cmd.Context(), clientcontext.ContextKey, clientCtx), nil + return clientcontext.SetInContext(cmd.Context(), clientCtx), nil } // preRunE returns a function that sets flags from the configuration before running a command. diff --git a/client/v2/autocli/context/context.go b/client/v2/autocli/context/context.go index f18db03a8cd6..273d54d30279 100644 --- a/client/v2/autocli/context/context.go +++ b/client/v2/autocli/context/context.go @@ -3,6 +3,7 @@ package context import ( gocontext "context" "errors" + "github.com/spf13/pflag" apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" @@ -34,6 +35,12 @@ type Context struct { EnabledSignmodes []apisigning.SignMode } +// SetInContext stores the provided autocli.Context in the given Go context.Context. +// It returns a new context.Context containing the autocli.Context value. +func SetInContext(goCtx gocontext.Context, cliCtx Context) gocontext.Context { + return gocontext.WithValue(goCtx, ContextKey, cliCtx) +} + // ClientContextFromGoContext returns the autocli.Context from a given Go context. // It checks if the context contains a valid autocli.Context and returns it. func ClientContextFromGoContext(ctx gocontext.Context) (*Context, error) { diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index 9e6ba0cc99b6..76c19868678f 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -13,6 +13,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/autocli/flag" "cosmossdk.io/client/v2/internal/flags" + "cosmossdk.io/client/v2/internal/print" "cosmossdk.io/client/v2/internal/util" v2tx "cosmossdk.io/client/v2/tx" addresscodec "cosmossdk.io/core/address" @@ -233,11 +234,27 @@ func (b *Builder) handleGovProposal( // generateOrBroadcastTxWithV2 generates or broadcasts a transaction with the provided messages using v2 transaction handling. // //nolint:unused // It'll be used once BuildMsgMethodCommand is updated to use factory v2. -func (b *Builder) generateOrBroadcastTxWithV2(ctx context.Context, cmd *cobra.Command, msgs ...transaction.Msg) ([]byte, error) { +func (b *Builder) generateOrBroadcastTxWithV2(cmd *cobra.Command, msgs ...transaction.Msg) error { + ctx, err := b.getContext(cmd) + if err != nil { + return err + } + cConn, err := b.GetClientConn(cmd) if err != nil { - return nil, err + return err + } + + bz, err := v2tx.GenerateOrBroadcastTxCLI(ctx, cConn, msgs...) + if err != nil { + return err + } + + output, _ := cmd.Flags().GetString(flags.FlagOutput) + p := print.Printer{ + Output: cmd.OutOrStdout(), + OutputFormat: output, } - return v2tx.GenerateOrBroadcastTxCLI(ctx, cConn, msgs...) + return p.PrintBytes(bz) } diff --git a/client/v2/broadcast/comet/client_conn.go b/client/v2/broadcast/comet/client_conn.go index ebc61300ce45..df93b1af86e3 100644 --- a/client/v2/broadcast/comet/client_conn.go +++ b/client/v2/broadcast/comet/client_conn.go @@ -19,7 +19,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" ) const grpcBlockHeightHeader = "x-cosmos-block-height" @@ -52,7 +51,7 @@ func (c *CometBFTBroadcaster) Invoke(ctx context.Context, method string, req, re if height < 0 { return errorsmod.Wrapf( sdkerrors.ErrInvalidRequest, - "client.Context.Invoke: height (%d) from %q must be >= 0", height, grpctypes.GRPCBlockHeightHeader) + "client.Context.Invoke: height (%d) from %q must be >= 0", height, grpcBlockHeightHeader) } } @@ -77,7 +76,7 @@ func (c *CometBFTBroadcaster) Invoke(ctx context.Context, method string, req, re // We then parse all the call options, if the call option is a // HeaderCallOption, then we manually set the value of that header to the // metadata. - md = metadata.Pairs(grpctypes.GRPCBlockHeightHeader, strconv.FormatInt(res.Height, 10)) + md = metadata.Pairs(grpcBlockHeightHeader, strconv.FormatInt(res.Height, 10)) for _, callOpt := range opts { header, ok := callOpt.(grpc.HeaderCallOption) if !ok { diff --git a/client/v2/tx/factory.go b/client/v2/tx/factory.go index 9e5f4df2ec02..6b18f492426c 100644 --- a/client/v2/tx/factory.go +++ b/client/v2/tx/factory.go @@ -44,7 +44,7 @@ type Factory struct { txConfig TxConfig txParams TxParameters - tx txState + tx *txState } func NewFactoryFromFlagSet(flags *pflag.FlagSet, keybase keyring.Keyring, cdc codec.BinaryCodec, accRetriever account.AccountRetriever, @@ -81,7 +81,7 @@ func NewFactory(keybase keyring.Keyring, cdc codec.BinaryCodec, accRetriever acc txConfig: txConfig, txParams: parameters, - tx: txState{}, + tx: &txState{}, }, nil } diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index c74f7156b0c0..abf5093f59aa 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -2,10 +2,8 @@ package tx import ( "context" + "errors" "fmt" - "github.com/cosmos/gogoproto/grpc" - "github.com/cosmos/gogoproto/proto" - "github.com/spf13/pflag" apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" clientcontext "cosmossdk.io/client/v2/autocli/context" @@ -14,6 +12,9 @@ import ( "cosmossdk.io/client/v2/internal/account" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/core/transaction" + "github.com/cosmos/gogoproto/grpc" + "github.com/cosmos/gogoproto/proto" + "github.com/spf13/pflag" "github.com/cosmos/cosmos-sdk/codec" ) @@ -50,7 +51,12 @@ func GenerateOrBroadcastTxCLIWithBroadcaster( return dryRun(txf, msgs...) } - return BroadcastTx(ctx, txf, broadcaster, msgs...) + err = GenerateTx(txf, msgs...) + if err != nil { + return nil, err + } + + return BroadcastTx(ctx, txf, broadcaster) } // GenerateOrBroadcastTxCLI will either generate and print an unsigned transaction @@ -157,20 +163,32 @@ func SimulateTx(ctx clientcontext.Context, conn grpc.ClientConn, msgs ...transac return simulation, err } -// BroadcastTx attempts to generate, sign and broadcast a transaction with the -// given set of messages. It will also simulate gas requirements if necessary. -// It will return an error upon failure. -func BroadcastTx(ctx context.Context, txf Factory, broadcaster broadcast.Broadcaster, msgs ...transaction.Msg) ([]byte, error) { +// GenerateTx generates an unsigned transaction using the provided transaction factory and messages. +// If simulation and execution are enabled, it first calculates the gas requirements. +// It then builds the unsigned transaction with the provided messages. +func GenerateTx(txf Factory, msgs ...transaction.Msg) error { if txf.simulateAndExecute() { err := txf.calculateGas(msgs...) if err != nil { - return nil, err + return err } } err := txf.BuildUnsignedTx(msgs...) if err != nil { - return nil, err + return err + } + + return nil +} + +// BroadcastTx attempts to sign and broadcast a transaction using the provided factory and broadcaster. +// GenerateTx must be called first to prepare the transaction for signing. +// This function then signs the transaction using the factory's signing capabilities, encodes it, +// and finally broadcasts it using the provided broadcaster. +func BroadcastTx(ctx context.Context, txf Factory, broadcaster broadcast.Broadcaster) ([]byte, error) { + if len(txf.tx.msgs) == 0 { + return nil, errors.New("no messages to broadcast") } signedTx, err := txf.sign(ctx, true) From ff44a719c80feb6585180327dccc872023f435ee Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 26 Nov 2024 07:47:45 +0100 Subject: [PATCH 42/52] update: move context --- client/v2/autocli/common.go | 2 +- client/v2/autocli/config/config.go | 6 ++++-- client/v2/autocli/flag/address.go | 2 +- client/v2/{autocli => }/context/context.go | 0 client/v2/go.mod | 2 +- client/v2/internal/flags/flags.go | 3 +++ client/v2/offchain/cli.go | 2 +- client/v2/offchain/sign.go | 2 +- client/v2/offchain/sign_test.go | 2 +- client/v2/offchain/verify.go | 2 +- client/v2/offchain/verify_test.go | 2 +- client/v2/tx/tx.go | 2 +- 12 files changed, 16 insertions(+), 11 deletions(-) rename client/v2/{autocli => }/context/context.go (100%) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 4f2e38b5b8b7..4b6656e3a21d 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -17,9 +17,9 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/client/v2/autocli/config" - clientcontext "cosmossdk.io/client/v2/autocli/context" "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/broadcast/comet" + clientcontext "cosmossdk.io/client/v2/context" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/print" "cosmossdk.io/client/v2/internal/util" diff --git a/client/v2/autocli/config/config.go b/client/v2/autocli/config/config.go index 8b7c048616ce..c775acc5ce18 100644 --- a/client/v2/autocli/config/config.go +++ b/client/v2/autocli/config/config.go @@ -11,6 +11,8 @@ import ( "github.com/pelletier/go-toml/v2" "github.com/spf13/pflag" "github.com/spf13/viper" + + "cosmossdk.io/client/v2/internal/flags" ) type Config struct { @@ -76,11 +78,11 @@ func CreateClientConfig(homeDir, chainID string, v *viper.Viper) (*Config, error // CreateClientConfigFromFlags creates a client configuration from command-line flags. func CreateClientConfigFromFlags(set *pflag.FlagSet) (*Config, error) { - homeDir, _ := set.GetString("home") + homeDir, _ := set.GetString(flags.FlagHome) if homeDir == "" { return DefaultConfig(), nil } - chainID, _ := set.GetString("chain-id") + chainID, _ := set.GetString(flags.FlagChainID) v := viper.New() executableName, err := os.Executable() diff --git a/client/v2/autocli/flag/address.go b/client/v2/autocli/flag/address.go index 12adddd31423..f7ba4310675f 100644 --- a/client/v2/autocli/flag/address.go +++ b/client/v2/autocli/flag/address.go @@ -6,8 +6,8 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" - clientcontext "cosmossdk.io/client/v2/autocli/context" "cosmossdk.io/client/v2/autocli/keyring" + clientcontext "cosmossdk.io/client/v2/context" "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/codec" diff --git a/client/v2/autocli/context/context.go b/client/v2/context/context.go similarity index 100% rename from client/v2/autocli/context/context.go rename to client/v2/context/context.go diff --git a/client/v2/go.mod b/client/v2/go.mod index d0e5f8a85fbe..d29de144b084 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -147,7 +147,7 @@ require ( github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect - github.com/spf13/viper v1.19.0 // indirect + github.com/spf13/viper v1.19.0 github.com/stretchr/testify v1.10.0 github.com/subosito/gotenv v1.6.0 // indirect github.com/supranational/blst v0.3.13 // indirect diff --git a/client/v2/internal/flags/flags.go b/client/v2/internal/flags/flags.go index 8edb44c597d5..7f684ac43544 100644 --- a/client/v2/internal/flags/flags.go +++ b/client/v2/internal/flags/flags.go @@ -2,6 +2,9 @@ package flags // This defines flag names that can be used in autocli. const ( + // FlagHome is the flag to specify the home dir of the app. + FlagHome = "home" + // FlagChainID is the flag to specify the chain ID of the network. FlagChainID = "chain-id" diff --git a/client/v2/offchain/cli.go b/client/v2/offchain/cli.go index 5eca8c4006c9..024df5663912 100644 --- a/client/v2/offchain/cli.go +++ b/client/v2/offchain/cli.go @@ -7,9 +7,9 @@ import ( "github.com/spf13/cobra" "cosmossdk.io/client/v2/autocli/config" - clientcontext "cosmossdk.io/client/v2/autocli/context" "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/client/v2/broadcast/comet" + clientcontext "cosmossdk.io/client/v2/context" v2flags "cosmossdk.io/client/v2/internal/flags" "github.com/cosmos/cosmos-sdk/client/flags" diff --git a/client/v2/offchain/sign.go b/client/v2/offchain/sign.go index 3bd62878db4d..1ce41de31857 100644 --- a/client/v2/offchain/sign.go +++ b/client/v2/offchain/sign.go @@ -7,7 +7,7 @@ import ( gogogrpc "github.com/cosmos/gogoproto/grpc" apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - clientcontext "cosmossdk.io/client/v2/autocli/context" + clientcontext "cosmossdk.io/client/v2/context" "cosmossdk.io/client/v2/internal/account" "cosmossdk.io/client/v2/internal/offchain" clitx "cosmossdk.io/client/v2/tx" diff --git a/client/v2/offchain/sign_test.go b/client/v2/offchain/sign_test.go index db3d9ced19b4..cb95b0485c39 100644 --- a/client/v2/offchain/sign_test.go +++ b/client/v2/offchain/sign_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - clientcontext "cosmossdk.io/client/v2/autocli/context" + clientcontext "cosmossdk.io/client/v2/context" "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/hd" diff --git a/client/v2/offchain/verify.go b/client/v2/offchain/verify.go index 52fffe4eedee..5e87cb90129b 100644 --- a/client/v2/offchain/verify.go +++ b/client/v2/offchain/verify.go @@ -8,7 +8,7 @@ import ( "google.golang.org/protobuf/types/known/anypb" - clientcontext "cosmossdk.io/client/v2/autocli/context" + clientcontext "cosmossdk.io/client/v2/context" clitx "cosmossdk.io/client/v2/tx" "cosmossdk.io/core/address" txsigning "cosmossdk.io/x/tx/signing" diff --git a/client/v2/offchain/verify_test.go b/client/v2/offchain/verify_test.go index 7efa9f9b4e1a..d45648bd07c6 100644 --- a/client/v2/offchain/verify_test.go +++ b/client/v2/offchain/verify_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" _ "cosmossdk.io/api/cosmos/crypto/secp256k1" - clientcontext "cosmossdk.io/client/v2/autocli/context" + clientcontext "cosmossdk.io/client/v2/context" clitx "cosmossdk.io/client/v2/tx" "github.com/cosmos/cosmos-sdk/codec/address" diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index abf5093f59aa..44951095fbb0 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -6,9 +6,9 @@ import ( "fmt" apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - clientcontext "cosmossdk.io/client/v2/autocli/context" "cosmossdk.io/client/v2/broadcast" "cosmossdk.io/client/v2/broadcast/comet" + clientcontext "cosmossdk.io/client/v2/context" "cosmossdk.io/client/v2/internal/account" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/core/transaction" From e289671766bf4cbe08eda9898eae5a1b192019f7 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 26 Nov 2024 17:09:00 +0100 Subject: [PATCH 43/52] update: generateAndBroadcast --- client/v2/autocli/msg.go | 53 +++++++++++++- client/v2/tx/flags.go | 34 ++++----- client/v2/tx/tx.go | 154 ++++++++++++++++++++++++++++++--------- client/v2/tx/types.go | 32 ++++---- 4 files changed, 203 insertions(+), 70 deletions(-) diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index 76c19868678f..51e769710b5c 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -1,8 +1,10 @@ package autocli import ( + "bufio" "context" "fmt" + "os" gogoproto "github.com/cosmos/gogoproto/proto" "github.com/spf13/cobra" @@ -18,6 +20,7 @@ import ( v2tx "cosmossdk.io/client/v2/tx" addresscodec "cosmossdk.io/core/address" "cosmossdk.io/core/transaction" + // the following will be extracted to a separate module // https://github.com/cosmos/cosmos-sdk/issues/14403 govcli "cosmossdk.io/x/gov/client/cli" @@ -25,6 +28,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/input" clienttx "github.com/cosmos/cosmos-sdk/client/tx" ) @@ -168,7 +172,9 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor msg := dynamicpb.NewMessage(input.Descriptor()) proto.Merge(msg, input.Interface()) - return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + return b.generateOrBroadcastTxWithV2(cmd, msg) + + // return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) } cmd, err := b.buildMethodCommandCommon(descriptor, options, execFunc) @@ -245,7 +251,21 @@ func (b *Builder) generateOrBroadcastTxWithV2(cmd *cobra.Command, msgs ...transa return err } - bz, err := v2tx.GenerateOrBroadcastTxCLI(ctx, cConn, msgs...) + var bz []byte + genOnly, _ := cmd.Flags().GetBool(v2tx.FlagGenerateOnly) + isDryRun, _ := cmd.Flags().GetBool(v2tx.FlagDryRun) + if genOnly { + bz, err = v2tx.GenerateOnly(ctx, cConn, msgs...) + } else if isDryRun { + bz, err = v2tx.DryRun(ctx, cConn, msgs...) + } else { + skipConfirm, _ := cmd.Flags().GetBool("yes") + if skipConfirm { + bz, err = v2tx.GenerateAndBroadcastTxCLI(ctx, cConn, msgs...) + } else { + bz, err = v2tx.GenerateAndBroadcastTxCLIWithPrompt(ctx, cConn, b.userConfirmation(cmd), msgs...) + } + } if err != nil { return err } @@ -258,3 +278,32 @@ func (b *Builder) generateOrBroadcastTxWithV2(cmd *cobra.Command, msgs ...transa return p.PrintBytes(bz) } + +// userConfirmation returns a function that prompts the user for confirmation +// before signing and broadcasting a transaction. +func (b *Builder) userConfirmation(cmd *cobra.Command) func([]byte) (bool, error) { + format, _ := cmd.Flags().GetString(flags.FlagOutput) + printer := print.Printer{ + Output: cmd.OutOrStdout(), + OutputFormat: format, + } + + return func(bz []byte) (bool, error) { + err := printer.PrintBytes(bz) + if err != nil { + return false, err + } + buf := bufio.NewReader(os.Stdin) + ok, err := input.GetConfirmation("confirm transaction before signing and broadcasting", buf, os.Stderr) + if err != nil { + _, _ = fmt.Fprintf(os.Stderr, "error: %v\ncanceled transaction\n", err) + return false, err + } + if !ok { + _, _ = fmt.Fprintln(os.Stderr, "canceled transaction") + return false, nil + } + + return true, nil + } +} diff --git a/client/v2/tx/flags.go b/client/v2/tx/flags.go index 6ef8584042f7..9d0a7c4a74d9 100644 --- a/client/v2/tx/flags.go +++ b/client/v2/tx/flags.go @@ -10,23 +10,23 @@ const ( defaultGasLimit = 200000 gasFlagAuto = "auto" - flagTimeoutTimestamp = "timeout-timestamp" - flagChainID = "chain-id" - flagNote = "note" - flagSignMode = "sign-mode" - flagAccountNumber = "account-number" - flagSequence = "sequence" - flagFrom = "from" - flagDryRun = "dry-run" - flagGas = "gas" - flagGasAdjustment = "gas-adjustment" - flagGasPrices = "gas-prices" - flagFees = "fees" - flagFeePayer = "fee-payer" - flagFeeGranter = "fee-granter" - flagUnordered = "unordered" - flagOffline = "offline" - flagGenerateOnly = "generate-only" + FlagTimeoutTimestamp = "timeout-timestamp" + FlagChainID = "chain-id" + FlagNote = "note" + FlagSignMode = "sign-mode" + FlagAccountNumber = "account-number" + FlagSequence = "sequence" + FlagFrom = "from" + FlagDryRun = "dry-run" + FlagGas = "gas" + FlagGasAdjustment = "gas-adjustment" + FlagGasPrices = "gas-prices" + FlagFees = "fees" + FlagFeePayer = "fee-payer" + FlagFeeGranter = "fee-granter" + FlagUnordered = "unordered" + FlagOffline = "offline" + FlagGenerateOnly = "generate-only" ) // parseGasSetting parses a string gas value. The value may either be 'auto', diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index 44951095fbb0..9724f3f9a03f 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -5,6 +5,10 @@ import ( "errors" "fmt" + "github.com/cosmos/gogoproto/grpc" + "github.com/cosmos/gogoproto/proto" + "github.com/spf13/pflag" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/client/v2/broadcast" "cosmossdk.io/client/v2/broadcast/comet" @@ -12,71 +16,124 @@ import ( "cosmossdk.io/client/v2/internal/account" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/core/transaction" - "github.com/cosmos/gogoproto/grpc" - "github.com/cosmos/gogoproto/proto" - "github.com/spf13/pflag" "github.com/cosmos/cosmos-sdk/codec" ) -// GenerateOrBroadcastTxCLIWithBroadcaster will either generate and print an unsigned transaction +// GenerateAndBroadcastTxCLIWithBroadcaster will either generate and print an unsigned transaction // or sign it and broadcast it with the specified broadcaster returning an error upon failure. -func GenerateOrBroadcastTxCLIWithBroadcaster( +func GenerateAndBroadcastTxCLIWithBroadcaster( ctx context.Context, conn grpc.ClientConn, broadcaster broadcast.Broadcaster, msgs ...transaction.Msg, ) ([]byte, error) { - clientCtx, err := clientcontext.ClientContextFromGoContext(ctx) + txf, err := initFactory(ctx, conn, msgs...) if err != nil { return nil, err } - if err := validateMessages(msgs...); err != nil { + err = generateTx(txf, msgs...) + if err != nil { return nil, err } - txf, err := newFactory(*clientCtx, conn) + return BroadcastTx(ctx, txf, broadcaster) +} + +// GenerateAndBroadcastTxCLI will either generate and print an unsigned transaction +// or sign it and broadcast it using default CometBFT broadcaster, returning an error upon failure. +func GenerateAndBroadcastTxCLI(ctx context.Context, conn grpc.ClientConn, msgs ...transaction.Msg) ([]byte, error) { + cBroadcaster, err := cometBroadcaster(ctx) if err != nil { return nil, err } - genOnly, _ := clientCtx.Flags.GetBool(flagGenerateOnly) - if genOnly { - return generateOnly(txf, msgs...) + return GenerateAndBroadcastTxCLIWithBroadcaster(ctx, conn, cBroadcaster, msgs...) +} + +// GenerateAndBroadcastTxCLIWithPrompt generates, signs and broadcasts a transaction after prompting the user for confirmation. +// It takes a context, gRPC client connection, prompt function for user confirmation, and transaction messages. +// The prompt function receives the unsigned transaction bytes and returns a boolean indicating user confirmation and any error. +// Returns the broadcast response bytes and any error encountered. +func GenerateAndBroadcastTxCLIWithPrompt( + ctx context.Context, + conn grpc.ClientConn, + prompt func([]byte) (bool, error), + msgs ...transaction.Msg, +) ([]byte, error) { + txf, err := initFactory(ctx, conn, msgs...) + if err != nil { + return nil, err } - isDryRun, _ := clientCtx.Flags.GetBool(flagDryRun) - if isDryRun { - return dryRun(txf, msgs...) + err = generateTx(txf, msgs...) + if err != nil { + return nil, err } - err = GenerateTx(txf, msgs...) + confirmed, err := askConfirmation(txf, prompt) if err != nil { return nil, err } + if !confirmed { + return nil, nil + } - return BroadcastTx(ctx, txf, broadcaster) + cBroadcaster, err := cometBroadcaster(ctx) + if err != nil { + return nil, err + } + + return BroadcastTx(ctx, txf, cBroadcaster) } -// GenerateOrBroadcastTxCLI will either generate and print an unsigned transaction -// or sign it and broadcast it using default CometBFT broadcaster, returning an error upon failure. -func GenerateOrBroadcastTxCLI( - ctx context.Context, - conn grpc.ClientConn, - msgs ...transaction.Msg, -) ([]byte, error) { - c, err := clientcontext.ClientContextFromGoContext(ctx) +// GenerateOnly generates an unsigned transaction without broadcasting it. +// It initializes a transaction factory using the provided context, connection and messages, +// then generates an unsigned transaction. +// Returns the unsigned transaction bytes and any error encountered. +func GenerateOnly(ctx context.Context, conn grpc.ClientConn, msgs ...transaction.Msg) ([]byte, error) { + txf, err := initFactory(ctx, conn) if err != nil { return nil, err } - cometBroadcaster, err := getCometBroadcaster(c.Cdc, c.Flags) + return generateOnly(txf, msgs...) +} + +// DryRun simulates a transaction without broadcasting it to the network. +// It initializes a transaction factory using the provided context, connection and messages, +// then performs a dry run simulation of the transaction. +// Returns the simulation response bytes and any error encountered. +func DryRun(ctx context.Context, conn grpc.ClientConn, msgs ...transaction.Msg) ([]byte, error) { + txf, err := initFactory(ctx, conn, msgs...) if err != nil { return nil, err } - return GenerateOrBroadcastTxCLIWithBroadcaster(ctx, conn, cometBroadcaster, msgs...) + return dryRun(txf, msgs...) +} + +// initFactory initializes a new transaction Factory and validates the provided messages. +// It retrieves the client v2 context from the provided context, validates all messages, +// and creates a new transaction Factory using the client context and connection. +// Returns the initialized Factory and any error encountered. +func initFactory(ctx context.Context, conn grpc.ClientConn, msgs ...transaction.Msg) (Factory, error) { + clientCtx, err := clientcontext.ClientContextFromGoContext(ctx) + if err != nil { + return Factory{}, err + } + + if err := validateMessages(msgs...); err != nil { + return Factory{}, err + } + + txf, err := newFactory(*clientCtx, conn) + if err != nil { + return Factory{}, err + } + + return txf, nil } // getCometBroadcaster returns a new CometBFT broadcaster based on the provided context and flag set. @@ -149,7 +206,7 @@ func dryRun(txf Factory, msgs ...transaction.Msg) ([]byte, error) { return nil, err } - return []byte(fmt.Sprintf("%s\n", GasEstimateResponse{GasEstimate: gas})), nil + return []byte(fmt.Sprintf(`{"gas_estimate": %d}`, gas)), nil } // SimulateTx simulates a tx and returns the simulation response obtained by the query. @@ -163,10 +220,10 @@ func SimulateTx(ctx clientcontext.Context, conn grpc.ClientConn, msgs ...transac return simulation, err } -// GenerateTx generates an unsigned transaction using the provided transaction factory and messages. +// generateTx generates an unsigned transaction using the provided transaction factory and messages. // If simulation and execution are enabled, it first calculates the gas requirements. // It then builds the unsigned transaction with the provided messages. -func GenerateTx(txf Factory, msgs ...transaction.Msg) error { +func generateTx(txf Factory, msgs ...transaction.Msg) error { if txf.simulateAndExecute() { err := txf.calculateGas(msgs...) if err != nil { @@ -174,12 +231,7 @@ func GenerateTx(txf Factory, msgs ...transaction.Msg) error { } } - err := txf.BuildUnsignedTx(msgs...) - if err != nil { - return err - } - - return nil + return txf.BuildUnsignedTx(msgs...) } // BroadcastTx attempts to sign and broadcast a transaction using the provided factory and broadcaster. @@ -225,6 +277,38 @@ func countDirectSigners(sigData SignatureData) int { } } +// cometBroadcaster returns a broadcast.Broadcaster implementation that uses the CometBFT RPC client. +// It extracts the client context from the provided context and uses it to create a CometBFT broadcaster. +func cometBroadcaster(ctx context.Context) (broadcast.Broadcaster, error) { + c, err := clientcontext.ClientContextFromGoContext(ctx) + if err != nil { + return nil, err + } + + return getCometBroadcaster(c.Cdc, c.Flags) +} + +// askConfirmation encodes the transaction as JSON and prompts the user for confirmation using the provided prompter function. +// It returns the user's confirmation response and any error that occurred during the process. +func askConfirmation(txf Factory, prompter func([]byte) (bool, error)) (bool, error) { + encoder := txf.txConfig.TxJSONEncoder() + if encoder == nil { + return false, errors.New("failed to encode transaction: tx json encoder is nil") + } + + tx, err := txf.getTx() + if err != nil { + return false, err + } + + txBytes, err := encoder(tx) + if err != nil { + return false, fmt.Errorf("failed to encode transaction: %w", err) + } + + return prompter(txBytes) +} + // getSignMode returns the corresponding apitxsigning.SignMode based on the provided mode string. func getSignMode(mode string) apitxsigning.SignMode { switch mode { diff --git a/client/v2/tx/types.go b/client/v2/tx/types.go index 0f151fc16515..801e246acae5 100644 --- a/client/v2/tx/types.go +++ b/client/v2/tx/types.go @@ -148,20 +148,20 @@ type Tx interface { // txParamsFromFlagSet extracts the transaction parameters from the provided FlagSet. func txParamsFromFlagSet(flags *pflag.FlagSet, keybase keyring2.Keyring, ac address.Codec) (params TxParameters, err error) { - timestampUnix, _ := flags.GetInt64(flagTimeoutTimestamp) + timestampUnix, _ := flags.GetInt64(FlagTimeoutTimestamp) timeoutTimestamp := time.Unix(timestampUnix, 0) - chainID, _ := flags.GetString(flagChainID) - memo, _ := flags.GetString(flagNote) - signMode, _ := flags.GetString(flagSignMode) + chainID, _ := flags.GetString(FlagChainID) + memo, _ := flags.GetString(FlagNote) + signMode, _ := flags.GetString(FlagSignMode) - accNumber, _ := flags.GetUint64(flagAccountNumber) - sequence, _ := flags.GetUint64(flagSequence) - from, _ := flags.GetString(flagFrom) + accNumber, _ := flags.GetUint64(FlagAccountNumber) + sequence, _ := flags.GetUint64(FlagSequence) + from, _ := flags.GetString(FlagFrom) var fromName, fromAddress string var addr []byte - isDryRun, _ := flags.GetBool(flagDryRun) - generateOnly, _ := flags.GetBool(flagGenerateOnly) + isDryRun, _ := flags.GetBool(FlagDryRun) + generateOnly, _ := flags.GetBool(FlagGenerateOnly) if isDryRun || generateOnly { addr, err = ac.StringToBytes(from) } else { @@ -174,16 +174,16 @@ func txParamsFromFlagSet(flags *pflag.FlagSet, keybase keyring2.Keyring, ac addr return params, err } - gas, _ := flags.GetString(flagGas) + gas, _ := flags.GetString(FlagGas) simulate, gasValue, _ := parseGasSetting(gas) - gasAdjustment, _ := flags.GetFloat64(flagGasAdjustment) - gasPrices, _ := flags.GetString(flagGasPrices) + gasAdjustment, _ := flags.GetFloat64(FlagGasAdjustment) + gasPrices, _ := flags.GetString(FlagGasPrices) - fees, _ := flags.GetString(flagFees) - feePayer, _ := flags.GetString(flagFeePayer) - feeGrater, _ := flags.GetString(flagFeeGranter) + fees, _ := flags.GetString(FlagFees) + feePayer, _ := flags.GetString(FlagFeePayer) + feeGrater, _ := flags.GetString(FlagFeeGranter) - unordered, _ := flags.GetBool(flagUnordered) + unordered, _ := flags.GetBool(FlagUnordered) gasConfig, err := NewGasConfig(gasValue, gasAdjustment, gasPrices) if err != nil { From 6cafaa85f07093a6b60c27d7c60df917727c7fe9 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 26 Nov 2024 17:16:22 +0100 Subject: [PATCH 44/52] update: flag import --- client/v2/autocli/common.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index 4b6656e3a21d..d1968be1526e 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -6,8 +6,6 @@ import ( "fmt" "strconv" - flags2 "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -322,7 +320,7 @@ func (b *Builder) setFlagsFromConfig(cmd *cobra.Command) error { flags.FlagNode: conf.Node, flags.FlagBroadcastMode: conf.BroadcastMode, flags.FlagGrpcAddress: conf.GRPC.Address, - flags2.FlagGRPCInsecure: strconv.FormatBool(conf.GRPC.Insecure), + flags.FlagGrpcInsecure: strconv.FormatBool(conf.GRPC.Insecure), } for flagName, value := range flagsToSet { From 6e1f112133f8e59717e18bc6d015cc5f38a3bea9 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 26 Nov 2024 17:24:24 +0100 Subject: [PATCH 45/52] fix: don't use v2 still --- client/v2/autocli/msg.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index 51e769710b5c..4aa703b279ff 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -172,9 +172,7 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor msg := dynamicpb.NewMessage(input.Descriptor()) proto.Merge(msg, input.Interface()) - return b.generateOrBroadcastTxWithV2(cmd, msg) - - // return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) } cmd, err := b.buildMethodCommandCommon(descriptor, options, execFunc) From a509f03b50a796fffaf3740e72748f769b089780 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 27 Nov 2024 11:43:08 +0100 Subject: [PATCH 46/52] update: use cmd as input output --- client/v2/autocli/msg.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index 4aa703b279ff..a2c40d598948 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -4,8 +4,6 @@ import ( "bufio" "context" "fmt" - "os" - gogoproto "github.com/cosmos/gogoproto/proto" "github.com/spf13/cobra" "google.golang.org/protobuf/proto" @@ -291,14 +289,14 @@ func (b *Builder) userConfirmation(cmd *cobra.Command) func([]byte) (bool, error if err != nil { return false, err } - buf := bufio.NewReader(os.Stdin) - ok, err := input.GetConfirmation("confirm transaction before signing and broadcasting", buf, os.Stderr) + buf := bufio.NewReader(cmd.InOrStdin()) + ok, err := input.GetConfirmation("confirm transaction before signing and broadcasting", buf, cmd.ErrOrStderr()) if err != nil { - _, _ = fmt.Fprintf(os.Stderr, "error: %v\ncanceled transaction\n", err) + _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "error: %v\ncanceled transaction\n", err) return false, err } if !ok { - _, _ = fmt.Fprintln(os.Stderr, "canceled transaction") + _, _ = fmt.Fprintln(cmd.ErrOrStderr(), "canceled transaction") return false, nil } From d8909edd9b62717fef71281602103eadc0282dee Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 27 Nov 2024 12:32:35 +0100 Subject: [PATCH 47/52] fix: populate query height --- client/v2/autocli/query.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/client/v2/autocli/query.go b/client/v2/autocli/query.go index 8e95b4eddb0e..aaf648f3578d 100644 --- a/client/v2/autocli/query.go +++ b/client/v2/autocli/query.go @@ -8,15 +8,15 @@ import ( "strings" "time" - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - "cosmossdk.io/math" - "cosmossdk.io/x/tx/signing/aminojson" - "github.com/spf13/cobra" + "google.golang.org/grpc/metadata" "google.golang.org/protobuf/reflect/protoreflect" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" + "cosmossdk.io/math" + "cosmossdk.io/x/tx/signing/aminojson" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -135,7 +135,7 @@ func (b *Builder) BuildQueryMethodCommand(ctx context.Context, descriptor protor } output := outputType.New() - if err := clientConn.Invoke(cmd.Context(), methodName, input.Interface(), output.Interface()); err != nil { + if err := clientConn.Invoke(b.queryContext(cmd.Context(), cmd), methodName, input.Interface(), output.Interface()); err != nil { return err } @@ -169,6 +169,25 @@ func (b *Builder) BuildQueryMethodCommand(ctx context.Context, descriptor protor return cmd, nil } +// queryContext returns a new context with metadata for block height if specified. +// If the context already has metadata, it is returned as-is. Otherwise, if a height +// flag is present on the command, it adds an x-cosmos-block-height metadata value +// with the specified height. +func (b *Builder) queryContext(ctx context.Context, cmd *cobra.Command) context.Context { + md, _ := metadata.FromOutgoingContext(ctx) + if md != nil { + return ctx + } + + md = map[string][]string{} + if cmd.Flags().Lookup("height") != nil { + h, _ := cmd.Flags().GetInt64("height") + md["x-cosmos-block-height"] = []string{fmt.Sprintf("%d", h)} + } + + return metadata.NewOutgoingContext(ctx, md) +} + func encoder(encoder aminojson.Encoder) aminojson.Encoder { return encoder.DefineTypeEncoding("google.protobuf.Duration", func(_ *aminojson.Encoder, msg protoreflect.Message, w io.Writer) error { var ( From ae00cea0814f3af72c7b3c85ea19319665255537 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 27 Nov 2024 12:39:57 +0100 Subject: [PATCH 48/52] lint --- client/v2/autocli/msg.go | 1 + 1 file changed, 1 insertion(+) diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index a2c40d598948..b12ea015e761 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -4,6 +4,7 @@ import ( "bufio" "context" "fmt" + gogoproto "github.com/cosmos/gogoproto/proto" "github.com/spf13/cobra" "google.golang.org/protobuf/proto" From d4b36f9cab377548b8619e11af106b00b7cd92ac Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Wed, 27 Nov 2024 13:39:15 +0100 Subject: [PATCH 49/52] lint :) --- client/v2/autocli/msg.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index b12ea015e761..9b30a56fe375 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -278,6 +278,8 @@ func (b *Builder) generateOrBroadcastTxWithV2(cmd *cobra.Command, msgs ...transa // userConfirmation returns a function that prompts the user for confirmation // before signing and broadcasting a transaction. +// +//nolint:unused // It is used in generateOrBroadcastTxWithV2 however linting is complaining. func (b *Builder) userConfirmation(cmd *cobra.Command) func([]byte) (bool, error) { format, _ := cmd.Flags().GetString(flags.FlagOutput) printer := print.Printer{ From d63f4687c198868e7a0067b84269311cfffb9867 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Fri, 29 Nov 2024 11:00:47 +0100 Subject: [PATCH 50/52] typo --- client/v2/autocli/common.go | 2 +- client/v2/context/context.go | 2 +- client/v2/tx/tx.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/v2/autocli/common.go b/client/v2/autocli/common.go index d1968be1526e..ff3b5b184f5a 100644 --- a/client/v2/autocli/common.go +++ b/client/v2/autocli/common.go @@ -284,7 +284,7 @@ func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { ConsensusAddressCodec: b.ConsensusAddressCodec, Cdc: b.Cdc, Keyring: k, - EnabledSignmodes: signModesToApiSignModes(b.EnabledSignModes), + EnabledSignModes: signModesToApiSignModes(b.EnabledSignModes), } return clientcontext.SetInContext(cmd.Context(), clientCtx), nil diff --git a/client/v2/context/context.go b/client/v2/context/context.go index 273d54d30279..fdb65b517498 100644 --- a/client/v2/context/context.go +++ b/client/v2/context/context.go @@ -32,7 +32,7 @@ type Context struct { Keyring keyring.Keyring - EnabledSignmodes []apisigning.SignMode + EnabledSignModes []apisigning.SignMode } // SetInContext stores the provided autocli.Context in the given Go context.Context. diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go index 9724f3f9a03f..34278e48a024 100644 --- a/client/v2/tx/tx.go +++ b/client/v2/tx/tx.go @@ -151,7 +151,7 @@ func newFactory(ctx clientcontext.Context, conn grpc.ClientConn) (Factory, error AddressCodec: ctx.AddressCodec, Cdc: ctx.Cdc, ValidatorAddressCodec: ctx.ValidatorAddressCodec, - EnabledSignModes: ctx.EnabledSignmodes, + EnabledSignModes: ctx.EnabledSignModes, }) if err != nil { return Factory{}, err From f67151de670d45d7ad2bfc25ac192e6d9cb6e83e Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Fri, 29 Nov 2024 11:21:31 +0100 Subject: [PATCH 51/52] changelog --- client/v2/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/client/v2/CHANGELOG.md b/client/v2/CHANGELOG.md index 5cff1928e437..27f312a99925 100644 --- a/client/v2/CHANGELOG.md +++ b/client/v2/CHANGELOG.md @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes * [#17709](https://github.com/cosmos/cosmos-sdk/pull/17709) Address codecs have been removed from `autocli.AppOptions` and `flag.Builder`. Instead client/v2 uses the address codecs present in the context (introduced in [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503)). +* [#22493](https://github.com/cosmos/cosmos-sdk/pull/22493) Refactored `client/v2` package to remove v1 context dependencies, while introducing new packages for client configuration, context management, and formatted output with improved transaction handling and flag support. ### Bug Fixes From e2e2a03f4860f089d04c6a6c6a4e60efc411c475 Mon Sep 17 00:00:00 2001 From: Julian Toledano Date: Tue, 3 Dec 2024 13:21:20 +0100 Subject: [PATCH 52/52] go mod tidy --- client/v2/go.mod | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/v2/go.mod b/client/v2/go.mod index b39ea3a3eaf8..ced3d482adfc 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -36,7 +36,7 @@ require ( buf.build/gen/go/cosmos/gogo-proto/protocolbuffers/go v1.35.2-20240130113600-88ef6483f90f.1 // indirect cosmossdk.io/collections v0.4.1-0.20241128094659-bd76b47e1d8b // indirect cosmossdk.io/core/testing v0.0.0-20241108153815-606544c7be7e // indirect - cosmossdk.io/errors v1.0.1 // indirect + cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.5.0 cosmossdk.io/math v1.4.0 cosmossdk.io/schema v0.3.1-0.20241128094659-bd76b47e1d8b // indirect @@ -60,7 +60,7 @@ require ( github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/cometbft/cometbft v1.0.0-rc2.0.20241127125717-4ce33b646ac9 github.com/cometbft/cometbft-db v1.0.1 // indirect - github.com/cometbft/cometbft/api v1.0.0-rc2 // indirect + github.com/cometbft/cometbft/api v1.0.0-rc2 github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.1.0 // indirect github.com/cosmos/go-bip39 v1.0.0 @@ -127,7 +127,7 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect github.com/oklog/run v1.1.0 // indirect - github.com/pelletier/go-toml/v2 v2.2.3 // indirect + github.com/pelletier/go-toml/v2 v2.2.3 github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect @@ -145,7 +145,7 @@ require ( github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect - github.com/spf13/viper v1.19.0 // indirect + github.com/spf13/viper v1.19.0 github.com/stretchr/testify v1.10.0 github.com/subosito/gotenv v1.6.0 // indirect github.com/supranational/blst v0.3.13 // indirect