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

fix: support custom tx config and sign modes #10553

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions x/auth/tx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signin
}
}

// CustomTxConfig returns a new protobuf TxConfig using the provided ProtoCodec, sign modes, and (de/en)coders. The
// first enabled sign mode will become the default sign mode.
func CustomTxConfig(
handler signing.SignModeHandler,
decoder sdk.TxDecoder,
encoder sdk.TxEncoder,
jsonDecoder sdk.TxDecoder,
jsonEncoder sdk.TxEncoder,
protoCodec codec.ProtoCodecMarshaler,
Comment on lines +39 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see wanting to add additional sign modes, but overloading all the decoders and encoders seems like a smell here.

) client.TxConfig {
return &config{
handler: handler,
decoder: decoder,
encoder: encoder,
jsonDecoder: jsonDecoder,
jsonEncoder: jsonEncoder,
protoCodec: protoCodec,
}
}

func (g config) NewTxBuilder() client.TxBuilder {
return newBuilder(g.protoCodec)
}
Expand Down
10 changes: 8 additions & 2 deletions x/auth/tx/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/signing"
)

var _ signing.SignModeHandler = signModeDirectHandler{}

// NewSignModeDirectHandler creates a new Direct SignModeHandler
// instance.
func NewSignModeDirectHandler() signing.SignModeHandler {
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
return signModeDirectHandler{}
}

// signModeDirectHandler defines the SIGN_MODE_DIRECT SignModeHandler
type signModeDirectHandler struct{}

var _ signing.SignModeHandler = signModeDirectHandler{}

// DefaultMode implements SignModeHandler.DefaultMode
func (signModeDirectHandler) DefaultMode() signingtypes.SignMode {
return signingtypes.SignMode_SIGN_MODE_DIRECT
Expand Down
6 changes: 6 additions & 0 deletions x/auth/tx/direct_aux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import (

var _ signing.SignModeHandler = signModeDirectAuxHandler{}

// NewSignModeDirectAuxHandler creates a new Direct Aux SignModeHandler
// instance.
func NewSignModeDirectAuxHandler() signing.SignModeHandler {
return signModeDirectAuxHandler{}
}

// signModeDirectAuxHandler defines the SIGN_MODE_DIRECT_AUX SignModeHandler
type signModeDirectAuxHandler struct{}

Expand Down
6 changes: 6 additions & 0 deletions x/auth/tx/legacy_amino_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const aminoNonCriticalFieldsError = "protobuf transaction contains unknown non-c

var _ signing.SignModeHandler = signModeLegacyAminoJSONHandler{}

// NewSignModeLegacyAminoJSONHandler creates a new legacy Amino SignModeHandler
// instance.
func NewSignModeLegacyAminoJSONHandler() signing.SignModeHandler {
return signModeLegacyAminoJSONHandler{}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to expose that function?


// signModeLegacyAminoJSONHandler defines the SIGN_MODE_LEGACY_AMINO_JSON
// SignModeHandler.
type signModeLegacyAminoJSONHandler struct{}
Expand Down
6 changes: 3 additions & 3 deletions x/auth/tx/mode_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func makeSignModeHandler(modes []signingtypes.SignMode) signing.SignModeHandler
for i, mode := range modes {
switch mode {
case signingtypes.SignMode_SIGN_MODE_DIRECT:
handlers[i] = signModeDirectHandler{}
handlers[i] = NewSignModeDirectHandler()
case signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON:
handlers[i] = signModeLegacyAminoJSONHandler{}
handlers[i] = NewSignModeLegacyAminoJSONHandler()
case signingtypes.SignMode_SIGN_MODE_DIRECT_AUX:
handlers[i] = signModeDirectAuxHandler{}
handlers[i] = NewSignModeDirectAuxHandler()
default:
panic(fmt.Errorf("unsupported sign mode %+v", mode))
}
Expand Down