github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/server/mock/tx.go (about) 1 // nolint 2 package mock 3 4 import ( 5 "bytes" 6 "fmt" 7 "math/big" 8 9 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 10 sdkerrors "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/errors" 11 ) 12 13 // An sdk.Tx which is its own sdk.Msg. 14 type kvstoreTx struct { 15 sdk.BaseTx 16 17 key []byte 18 value []byte 19 bytes []byte 20 } 21 22 var _ sdk.Tx = (*kvstoreTx)(nil) 23 24 func NewTx(key, value string) *kvstoreTx { 25 bytes := fmt.Sprintf("%s=%s", key, value) 26 return &kvstoreTx{ 27 key: []byte(key), 28 value: []byte(value), 29 bytes: []byte(bytes), 30 } 31 } 32 33 func (tx *kvstoreTx) Route() string { 34 return "kvstore" 35 } 36 37 func (tx *kvstoreTx) Type() string { 38 return "kvstore_tx" 39 } 40 41 func (tx *kvstoreTx) GetMsgs() []sdk.Msg { 42 return []sdk.Msg{tx} 43 } 44 45 func (tx *kvstoreTx) GetMemo() string { 46 return "" 47 } 48 49 func (tx *kvstoreTx) GetSignBytes() []byte { 50 return tx.bytes 51 } 52 53 // Should the app be calling this? Or only handlers? 54 func (tx *kvstoreTx) ValidateBasic() error { 55 return nil 56 } 57 58 func (tx *kvstoreTx) GetSigners() []sdk.AccAddress { 59 return nil 60 } 61 62 func (tx *kvstoreTx) GetType() sdk.TransactionType { 63 return sdk.UnknownType 64 } 65 66 func (tx *kvstoreTx) GetFrom() string { 67 return "" 68 } 69 70 func (tx *kvstoreTx) GetSender(_ sdk.Context) string { 71 return "" 72 } 73 74 func (tx *kvstoreTx) GetNonce() uint64 { 75 return 0 76 } 77 78 func (tx *kvstoreTx) GetGasPrice() *big.Int { 79 return big.NewInt(0) 80 } 81 82 func (tx *kvstoreTx) GetTxFnSignatureInfo() ([]byte, int) { 83 return nil, 0 84 } 85 86 func (tx *kvstoreTx) GetGas() uint64 { 87 return 0 88 } 89 90 // takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has 91 // all the signatures and can be used to authenticate. 92 func decodeTx(txBytes []byte, _ ...int64) (sdk.Tx, error) { 93 var tx sdk.Tx 94 95 split := bytes.Split(txBytes, []byte("=")) 96 if len(split) == 1 { 97 k := split[0] 98 tx = &kvstoreTx{key: k, value: k, bytes: txBytes} 99 } else if len(split) == 2 { 100 k, v := split[0], split[1] 101 tx = &kvstoreTx{key: k, value: v, bytes: txBytes} 102 } else { 103 return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "too many '='") 104 } 105 106 return tx, nil 107 }