-
Notifications
You must be signed in to change notification settings - Fork 182
/
codec.go
61 lines (54 loc) · 2.01 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package types
import (
"github.com/okex/exchain/libs/cosmos-sdk/codec"
"github.com/tendermint/go-amino"
)
// ModuleCdc defines the evm module's codec
var ModuleCdc = codec.New()
const (
MsgEthereumTxName = "ethermint/MsgEthereumTx"
ChainConfigName = "ethermint/ChainConfig"
TxDataName = "ethermint/TxData"
ManageContractDeploymentWhitelistProposalName = "okexchain/evm/ManageContractDeploymentWhitelistProposal"
ManageContractBlockedListProposalName = "okexchain/evm/ManageContractBlockedListProposal"
)
// RegisterCodec registers all the necessary types and interfaces for the
// evm module
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(&MsgEthereumTx{}, MsgEthereumTxName, nil)
cdc.RegisterConcrete(TxData{}, TxDataName, nil)
cdc.RegisterConcrete(ChainConfig{}, ChainConfigName, nil)
cdc.RegisterConcrete(ManageContractDeploymentWhitelistProposal{}, ManageContractDeploymentWhitelistProposalName, nil)
cdc.RegisterConcrete(ManageContractBlockedListProposal{}, ManageContractBlockedListProposalName, nil)
cdc.RegisterConcrete(ManageContractMethodBlockedListProposal{}, "okexchain/evm/ManageContractMethodBlockedListProposal", nil)
cdc.RegisterConcreteUnmarshaller(ChainConfigName, func(c *amino.Codec, bytes []byte) (interface{}, int, error) {
var cc ChainConfig
err := cc.UnmarshalFromAmino(c, bytes)
if err != nil {
return ChainConfig{}, 0, err
} else {
return cc, len(bytes), nil
}
})
cdc.RegisterConcreteUnmarshaller(MsgEthereumTxName, func(c *amino.Codec, bytes []byte) (interface{}, int, error) {
var msg MsgEthereumTx
err := msg.UnmarshalFromAmino(c, bytes)
if err != nil {
return nil, 0, err
}
return &msg, len(bytes), nil
})
cdc.RegisterConcreteUnmarshaller(TxDataName, func(c *amino.Codec, bytes []byte) (interface{}, int, error) {
var tx TxData
err := tx.UnmarshalFromAmino(c, bytes)
if err != nil {
return nil, 0, err
}
return tx, len(bytes), nil
})
}
func init() {
RegisterCodec(ModuleCdc)
codec.RegisterCrypto(ModuleCdc)
ModuleCdc.Seal()
}