2018-02-28 19:40:39 -08:00
|
|
|
//nolint
|
2018-02-21 07:04:54 -08:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2018-02-21 07:28:18 -08:00
|
|
|
"fmt"
|
2018-02-21 07:04:54 -08:00
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-12-27 09:57:54 -08:00
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2018-02-21 07:04:54 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// An sdk.Tx which is its own sdk.Msg.
|
|
|
|
type kvstoreTx struct {
|
|
|
|
key []byte
|
|
|
|
value []byte
|
|
|
|
bytes []byte
|
|
|
|
}
|
|
|
|
|
2018-02-21 07:28:18 -08:00
|
|
|
var _ sdk.Tx = kvstoreTx{}
|
|
|
|
|
|
|
|
func NewTx(key, value string) kvstoreTx {
|
|
|
|
bytes := fmt.Sprintf("%s=%s", key, value)
|
|
|
|
return kvstoreTx{
|
|
|
|
key: []byte(key),
|
|
|
|
value: []byte(value),
|
|
|
|
bytes: []byte(bytes),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-23 12:23:55 -07:00
|
|
|
func (tx kvstoreTx) Route() string {
|
2018-02-21 07:04:54 -08:00
|
|
|
return "kvstore"
|
|
|
|
}
|
|
|
|
|
2018-10-23 12:23:55 -07:00
|
|
|
func (tx kvstoreTx) Type() string {
|
2018-09-17 07:34:06 -07:00
|
|
|
return "kvstore_tx"
|
|
|
|
}
|
|
|
|
|
2018-06-21 15:05:25 -07:00
|
|
|
func (tx kvstoreTx) GetMsgs() []sdk.Msg {
|
|
|
|
return []sdk.Msg{tx}
|
2018-02-21 07:04:54 -08:00
|
|
|
}
|
|
|
|
|
2018-06-20 12:27:36 -07:00
|
|
|
func (tx kvstoreTx) GetMemo() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2018-02-21 07:04:54 -08:00
|
|
|
func (tx kvstoreTx) GetSignBytes() []byte {
|
|
|
|
return tx.bytes
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should the app be calling this? Or only handlers?
|
2019-12-27 09:57:54 -08:00
|
|
|
func (tx kvstoreTx) ValidateBasic() error {
|
2018-02-21 07:04:54 -08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-07-06 00:06:53 -07:00
|
|
|
func (tx kvstoreTx) GetSigners() []sdk.AccAddress {
|
2018-02-21 07:04:54 -08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// takes raw transaction bytes and decodes them into an sdk.Tx. An sdk.Tx has
|
|
|
|
// all the signatures and can be used to authenticate.
|
2019-12-27 09:57:54 -08:00
|
|
|
func decodeTx(txBytes []byte) (sdk.Tx, error) {
|
2018-02-21 07:04:54 -08:00
|
|
|
var tx sdk.Tx
|
|
|
|
|
|
|
|
split := bytes.Split(txBytes, []byte("="))
|
|
|
|
if len(split) == 1 {
|
|
|
|
k := split[0]
|
|
|
|
tx = kvstoreTx{k, k, txBytes}
|
|
|
|
} else if len(split) == 2 {
|
|
|
|
k, v := split[0], split[1]
|
|
|
|
tx = kvstoreTx{k, v, txBytes}
|
|
|
|
} else {
|
2019-12-27 09:57:54 -08:00
|
|
|
return nil, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "too many '='")
|
2018-02-21 07:04:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tx, nil
|
|
|
|
}
|