diff --git a/client/v2/autocli/builder.go b/client/v2/autocli/builder.go index f92147df324b..d42330aa8dbb 100644 --- a/client/v2/autocli/builder.go +++ b/client/v2/autocli/builder.go @@ -1,13 +1,10 @@ package autocli import ( - "errors" - "github.com/spf13/cobra" "google.golang.org/grpc" "cosmossdk.io/client/v2/autocli/flag" - "cosmossdk.io/client/v2/autocli/keyring" "github.com/cosmos/cosmos-sdk/client" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -35,32 +32,6 @@ type Builder struct { // ValidateAndComplete the builder fields. // It returns an error if any of the required fields are missing. -// If the Logger is nil, it will be set to a nop logger. -// If the keyring is nil, it will be set to a no keyring. func (b *Builder) ValidateAndComplete() error { - if b.Builder.AddressCodec == nil { - return errors.New("address codec is required in flag builder") - } - - if b.Builder.ValidatorAddressCodec == nil { - return errors.New("validator address codec is required in flag builder") - } - - if b.Builder.ConsensusAddressCodec == nil { - return errors.New("consensus address codec is required in flag builder") - } - - if b.Builder.Keyring == nil { - b.Keyring = keyring.NoKeyring{} - } - - if b.Builder.TypeResolver == nil { - return errors.New("type resolver is required in flag builder") - } - - if b.Builder.FileResolver == nil { - return errors.New("file resolver is required in flag builder") - } - - return nil + return b.Builder.ValidateAndComplete() } diff --git a/client/v2/autocli/flag/address.go b/client/v2/autocli/flag/address.go index ddc7e6bf2c08..507a7267a9fc 100644 --- a/client/v2/autocli/flag/address.go +++ b/client/v2/autocli/flag/address.go @@ -13,7 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) type addressStringType struct{} @@ -133,6 +132,10 @@ func (a *consensusAddressValue) Set(s string) error { return fmt.Errorf("input isn't a pubkey %w or is an invalid account address: %w", err, err2) } - a.value = sdk.ConsAddress(pk.Address()).String() + a.value, err = a.addressCodec.BytesToString(pk.Address()) + if err != nil { + return fmt.Errorf("invalid pubkey address: %w", err) + } + return nil } diff --git a/client/v2/autocli/flag/builder.go b/client/v2/autocli/flag/builder.go index 45f030eaad87..2fa1c81507a9 100644 --- a/client/v2/autocli/flag/builder.go +++ b/client/v2/autocli/flag/builder.go @@ -2,6 +2,7 @@ package flag import ( "context" + "errors" "fmt" "strconv" @@ -73,6 +74,37 @@ func (b *Builder) init() { } } +// ValidateAndComplete the flag builder fields. +// It returns an error if any of the required fields are missing. +// If the keyring is nil, it will be set to a no keyring. +func (b *Builder) ValidateAndComplete() error { + if b.AddressCodec == nil { + return errors.New("address codec is required in flag builder") + } + + if b.ValidatorAddressCodec == nil { + return errors.New("validator address codec is required in flag builder") + } + + if b.ConsensusAddressCodec == nil { + return errors.New("consensus address codec is required in flag builder") + } + + if b.Keyring == nil { + b.Keyring = keyring.NoKeyring{} + } + + if b.TypeResolver == nil { + return errors.New("type resolver is required in flag builder") + } + + if b.FileResolver == nil { + return errors.New("file resolver is required in flag builder") + } + + return nil +} + // DefineMessageFlagType allows to extend custom protobuf message type handling for flags (and positional arguments). func (b *Builder) DefineMessageFlagType(messageName protoreflect.FullName, flagType Type) { b.init() diff --git a/client/v2/autocli/query_test.go b/client/v2/autocli/query_test.go index b1945f83995a..6ed940bb6faf 100644 --- a/client/v2/autocli/query_test.go +++ b/client/v2/autocli/query_test.go @@ -729,6 +729,5 @@ func TestDurationMarshal(t *testing.T) { out, err := runCmd(fixture.conn, fixture.b, buildModuleQueryCommand, "echo", "1", "abc", "--duration", "1s") assert.NilError(t, err) - fmt.Println(out.String()) assert.Assert(t, strings.Contains(out.String(), "duration: 1s")) }