-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Textual SignModeHandler (#14650)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
- Loading branch information
1 parent
5233d5e
commit 40f7e5d
Showing
16 changed files
with
188 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package tx | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cosmos/cosmos-sdk/x/bank/types" | ||
) | ||
|
||
// BankKeeper defines the contract needed for tx-related APIs | ||
type BankKeeper interface { | ||
DenomMetadata(c context.Context, req *types.QueryDenomMetadataRequest) (*types.QueryDenomMetadataResponse, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package tx | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"cosmossdk.io/x/tx/textual" | ||
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" | ||
"google.golang.org/protobuf/types/known/anypb" | ||
|
||
txsigning "cosmossdk.io/x/tx/signing" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
) | ||
|
||
// signModeTextualHandler defines the SIGN_MODE_TEXTUAL SignModeHandler. | ||
// It is currently not enabled by default, but you can enable it manually | ||
// for TESTING purposes. It will be enabled once SIGN_MODE_TEXTUAL is fully | ||
// released, see https://github.com/cosmos/cosmos-sdk/issues/11970. | ||
type signModeTextualHandler struct { | ||
t textual.Textual | ||
} | ||
|
||
var _ signing.SignModeHandler = signModeTextualHandler{} | ||
|
||
// DefaultMode implements SignModeHandler.DefaultMode | ||
func (signModeTextualHandler) DefaultMode() signingtypes.SignMode { | ||
return signingtypes.SignMode_SIGN_MODE_TEXTUAL | ||
} | ||
|
||
// Modes implements SignModeHandler.Modes | ||
func (signModeTextualHandler) Modes() []signingtypes.SignMode { | ||
return []signingtypes.SignMode{signingtypes.SignMode_SIGN_MODE_TEXTUAL} | ||
} | ||
|
||
// GetSignBytes implements SignModeHandler.GetSignBytes | ||
func (h signModeTextualHandler) GetSignBytes(mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx) ([]byte, error) { | ||
panic("SIGN_MODE_TEXTUAL needs GetSignBytesWithContext") | ||
} | ||
|
||
// GetSignBytesWithContext implements SignModeHandler.GetSignBytesWithContext | ||
func (h signModeTextualHandler) GetSignBytesWithContext(ctx context.Context, mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx) ([]byte, error) { | ||
if mode != signingtypes.SignMode_SIGN_MODE_TEXTUAL { | ||
return nil, fmt.Errorf("expected %s, got %s", signingtypes.SignMode_SIGN_MODE_TEXTUAL, mode) | ||
} | ||
|
||
protoTx, ok := tx.(*wrapper) | ||
if !ok { | ||
return nil, fmt.Errorf("can only handle a protobuf Tx, got %T", tx) | ||
} | ||
|
||
bodyBz := protoTx.getBodyBytes() | ||
authInfoBz := protoTx.getAuthInfoBytes() | ||
|
||
pbAny, err := codectypes.NewAnyWithValue(data.PubKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return h.t.GetSignBytes(ctx, bodyBz, authInfoBz, txsigning.SignerData{ | ||
Address: data.Address, | ||
ChainId: data.ChainID, | ||
AccountNumber: data.AccountNumber, | ||
Sequence: data.Sequence, | ||
PubKey: &anypb.Any{ | ||
TypeUrl: pbAny.TypeUrl, | ||
Value: pbAny.Value, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters