github.com/cosmos/cosmos-sdk@v0.50.10/x/auth/tx/legacy_amino_json.go (about) 1 package tx 2 3 import ( 4 "fmt" 5 6 errorsmod "cosmossdk.io/errors" 7 8 sdk "github.com/cosmos/cosmos-sdk/types" 9 sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" 10 signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" 11 "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" 12 "github.com/cosmos/cosmos-sdk/x/auth/signing" 13 ) 14 15 const aminoNonCriticalFieldsError = "protobuf transaction contains unknown non-critical fields. This is a transaction malleability issue and SIGN_MODE_LEGACY_AMINO_JSON cannot be used." 16 17 var _ signing.SignModeHandler = signModeLegacyAminoJSONHandler{} 18 19 // signModeLegacyAminoJSONHandler defines the SIGN_MODE_LEGACY_AMINO_JSON 20 // SignModeHandler. 21 type signModeLegacyAminoJSONHandler struct{} 22 23 // NewSignModeLegacyAminoJSONHandler returns a new signModeLegacyAminoJSONHandler. 24 // Note: The public constructor is only used for testing. 25 // Deprecated: Please use x/tx/signing/aminojson instead. 26 func NewSignModeLegacyAminoJSONHandler() signing.SignModeHandler { 27 return signModeLegacyAminoJSONHandler{} 28 } 29 30 // Deprecated: Please use x/tx/signing/aminojson instead. 31 func (s signModeLegacyAminoJSONHandler) DefaultMode() signingtypes.SignMode { 32 return signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON 33 } 34 35 // Deprecated: Please use x/tx/signing/aminojson instead. 36 func (s signModeLegacyAminoJSONHandler) Modes() []signingtypes.SignMode { 37 return []signingtypes.SignMode{signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} 38 } 39 40 // Deprecated: Please use x/tx/signing/aminojson instead. 41 func (s signModeLegacyAminoJSONHandler) GetSignBytes(mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx) ([]byte, error) { 42 if mode != signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON { 43 return nil, fmt.Errorf("expected %s, got %s", signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, mode) 44 } 45 46 protoTx, ok := tx.(*wrapper) 47 if !ok { 48 return nil, fmt.Errorf("can only handle a protobuf Tx, got %T", tx) 49 } 50 51 if protoTx.txBodyHasUnknownNonCriticals { 52 return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, aminoNonCriticalFieldsError) 53 } 54 55 body := protoTx.tx.Body 56 57 if len(body.ExtensionOptions) != 0 || len(body.NonCriticalExtensionOptions) != 0 { 58 return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "%s does not support protobuf extension options", signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON) 59 } 60 61 addr := data.Address 62 if addr == "" { 63 return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "got empty address in %s handler", signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON) 64 } 65 66 return legacytx.StdSignBytes( 67 data.ChainID, data.AccountNumber, data.Sequence, protoTx.GetTimeoutHeight(), 68 legacytx.StdFee{ 69 Amount: protoTx.GetFee(), 70 Gas: protoTx.GetGas(), 71 Payer: protoTx.tx.AuthInfo.Fee.Payer, 72 Granter: protoTx.tx.AuthInfo.Fee.Granter, 73 }, 74 tx.GetMsgs(), protoTx.GetMemo(), 75 ), nil 76 }