Co-authored-by: Julien Robert <julien@rbrt.fr> Co-authored-by: marbar3778 <marbar3778@yahoo.com>
This commit is contained in:
parent
b3ec532227
commit
c0beb19986
@ -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()
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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"))
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user