Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!Feat/client v2 #19738

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err
}
}

if clientCtx.Viper == nil {
clientCtx = clientCtx.WithViper("")
}

if err = clientCtx.Viper.BindPFlags(flagSet); err != nil {
return clientCtx, fmt.Errorf("failed to bind flags to viper: %w", err)
}

return clientCtx, nil
}

Expand Down
19 changes: 19 additions & 0 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package flags

import (
apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
"fmt"
"strconv"

Expand Down Expand Up @@ -201,3 +202,21 @@ func ParseGasSetting(gasStr string) (GasSetting, error) {
return GasSetting{false, gas}, nil
}
}

func ParseSignModeStr(signModeStr string) apisigning.SignMode {
signMode := apisigning.SignMode_SIGN_MODE_UNSPECIFIED
switch signModeStr {
case SignModeDirect:
signMode = apisigning.SignMode_SIGN_MODE_DIRECT
case SignModeLegacyAminoJSON:
signMode = apisigning.SignMode_SIGN_MODE_LEGACY_AMINO_JSON
case SignModeDirectAux:
signMode = apisigning.SignMode_SIGN_MODE_DIRECT_AUX
case SignModeTextual:
signMode = apisigning.SignMode_SIGN_MODE_TEXTUAL
case SignModeEIP191:
signMode = apisigning.SignMode_SIGN_MODE_EIP_191
}

return signMode
}
12 changes: 6 additions & 6 deletions client/tx/aux_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/cosmos/gogoproto/proto"
"google.golang.org/protobuf/types/known/anypb"

txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1"
apitx "cosmossdk.io/api/cosmos/tx/v1beta1"
txsigning "cosmossdk.io/x/tx/signing"
"cosmossdk.io/x/tx/signing/aminojson"

Expand All @@ -25,7 +25,7 @@ type AuxTxBuilder struct {
// - b.msgs is used for constructing the AMINO sign bz,
// - b.body is used for constructing the DIRECT_AUX sign bz.
msgs []sdk.Msg
body *txv1beta1.TxBody
body *apitx.TxBody
auxSignerData *tx.AuxSignerData
}

Expand Down Expand Up @@ -208,7 +208,7 @@ func (b *AuxTxBuilder) GetSignBytes() ([]byte, error) {
FileResolver: proto.HybridResolver,
})

auxBody := &txv1beta1.TxBody{
auxBody := &apitx.TxBody{
Messages: body.Messages,
Memo: body.Memo,
TimeoutHeight: body.TimeoutHeight,
Expand All @@ -231,13 +231,13 @@ func (b *AuxTxBuilder) GetSignBytes() ([]byte, error) {
},
txsigning.TxData{
Body: auxBody,
AuthInfo: &txv1beta1.AuthInfo{
AuthInfo: &apitx.AuthInfo{
SignerInfos: nil,
// Aux signer never signs over fee.
// For LEGACY_AMINO_JSON, we use the convention to sign
// over empty fees.
// ref: https://github.com/cosmos/cosmos-sdk/pull/10348
Fee: &txv1beta1.Fee{},
Fee: &apitx.Fee{},
},
},
)
Expand All @@ -261,7 +261,7 @@ func (b *AuxTxBuilder) GetAuxSignerData() (tx.AuxSignerData, error) {

func (b *AuxTxBuilder) checkEmptyFields() {
if b.body == nil {
b.body = &txv1beta1.TxBody{}
b.body = &apitx.TxBody{}
}

if b.auxSignerData == nil {
Expand Down
19 changes: 18 additions & 1 deletion client/v2/autocli/keyring/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@ package keyring

import (
signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)

// Options are used to configure a keyring.
type Options struct{}

type Option func(*Options)

// KeyType reflects a human-readable type for key listing.
type KeyType uint

type Record struct{}

// Keyring is an interface used for signing transactions.
// It aims to be simplistic and easy to use.
type Keyring interface {
Expand All @@ -18,6 +27,14 @@ type Keyring interface {
// GetPubKey returns the public key of the key with the given name.
GetPubKey(name string) (cryptotypes.PubKey, error)

// Key and KeyByAddress return keys by uid and address respectively.
Key(uid string) (*Record, error)
KeyByAddress(address []byte) (*Record, error)

GetRecordAddress(record *Record) ([]byte, error)
GetRecordName(record *Record) string
GetRecordType(record *Record) KeyType

// Sign signs the given bytes with the key with the given name.
Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error)
}
20 changes: 20 additions & 0 deletions client/v2/autocli/keyring/no_keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ var errNoKeyring = errors.New("no keyring configured")

type NoKeyring struct{}

func (k NoKeyring) Key(uid string) (*Record, error) {
return nil, errNoKeyring
}

func (k NoKeyring) KeyByAddress(address []byte) (*Record, error) {
return nil, errNoKeyring
}

func (k NoKeyring) GetRecordAddress(record *Record) ([]byte, error) {
return nil, errNoKeyring
}

func (k NoKeyring) GetRecordName(record *Record) string {
return ""
}

func (k NoKeyring) GetRecordType(record *Record) KeyType {
return 0
}

func (k NoKeyring) List() ([]string, error) {
return nil, errNoKeyring
}
Expand Down
Loading
Loading