github.com/Finschia/finschia-sdk@v0.49.1/x/auth/tx/legacy_amino_json.go (about) 1 package tx 2 3 import ( 4 "fmt" 5 6 sdk "github.com/Finschia/finschia-sdk/types" 7 sdkerrors "github.com/Finschia/finschia-sdk/types/errors" 8 signingtypes "github.com/Finschia/finschia-sdk/types/tx/signing" 9 "github.com/Finschia/finschia-sdk/x/auth/legacy/legacytx" 10 "github.com/Finschia/finschia-sdk/x/auth/signing" 11 ) 12 13 const aminoNonCriticalFieldsError = "protobuf transaction contains unknown non-critical fields. This is a transaction malleability issue and SIGN_MODE_LEGACY_AMINO_JSON cannot be used." 14 15 var _ signing.SignModeHandler = signModeLegacyAminoJSONHandler{} 16 17 // signModeLegacyAminoJSONHandler defines the SIGN_MODE_LEGACY_AMINO_JSON 18 // SignModeHandler. 19 type signModeLegacyAminoJSONHandler struct{} 20 21 func (s signModeLegacyAminoJSONHandler) DefaultMode() signingtypes.SignMode { 22 return signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON 23 } 24 25 func (s signModeLegacyAminoJSONHandler) Modes() []signingtypes.SignMode { 26 return []signingtypes.SignMode{signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON} 27 } 28 29 func (s signModeLegacyAminoJSONHandler) GetSignBytes(mode signingtypes.SignMode, data signing.SignerData, tx sdk.Tx) ([]byte, error) { 30 if mode != signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON { 31 return nil, fmt.Errorf("expected %s, got %s", signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, mode) 32 } 33 34 protoTx, ok := tx.(*wrapper) 35 if !ok { 36 return nil, fmt.Errorf("can only handle a protobuf Tx, got %T", tx) 37 } 38 39 if protoTx.txBodyHasUnknownNonCriticals { 40 return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, aminoNonCriticalFieldsError) 41 } 42 43 body := protoTx.tx.Body 44 45 if len(body.ExtensionOptions) != 0 || len(body.NonCriticalExtensionOptions) != 0 { 46 return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "SIGN_MODE_LEGACY_AMINO_JSON does not support protobuf extension options.") 47 } 48 49 return legacytx.StdSignBytes( 50 data.ChainID, data.AccountNumber, data.Sequence, protoTx.GetTimeoutHeight(), 51 legacytx.StdFee{Amount: protoTx.GetFee(), Gas: protoTx.GetGas()}, 52 tx.GetMsgs(), protoTx.GetMemo(), 53 ), nil 54 }