/
codec.go
40 lines (34 loc) · 1.4 KB
/
codec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package cosmos
import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/simapp"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
authTx "github.com/cosmos/cosmos-sdk/x/auth/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
ibctypes "github.com/cosmos/ibc-go/v5/modules/core/types"
)
func DefaultEncoding() simappparams.EncodingConfig {
// core modules
cfg := simappparams.MakeTestEncodingConfig()
std.RegisterLegacyAminoCodec(cfg.Amino)
std.RegisterInterfaces(cfg.InterfaceRegistry)
simapp.ModuleBasics.RegisterLegacyAminoCodec(cfg.Amino)
simapp.ModuleBasics.RegisterInterfaces(cfg.InterfaceRegistry)
// external modules
banktypes.RegisterInterfaces(cfg.InterfaceRegistry)
ibctypes.RegisterInterfaces(cfg.InterfaceRegistry)
transfertypes.RegisterInterfaces(cfg.InterfaceRegistry)
return cfg
}
func decodeTX(interfaceRegistry codectypes.InterfaceRegistry, txbz []byte) (sdk.Tx, error) {
cdc := codec.NewProtoCodec(interfaceRegistry)
return authTx.DefaultTxDecoder(cdc)(txbz)
}
func encodeTxToJSON(interfaceRegistry codectypes.InterfaceRegistry, tx sdk.Tx) ([]byte, error) {
cdc := codec.NewProtoCodec(interfaceRegistry)
return authTx.DefaultJSONTxEncoder(cdc)(tx)
}