/
codec.go
40 lines (35 loc) · 1.11 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 types
import (
"fmt"
"github.com/FiboChain/fbc/libs/cosmos-sdk/codec"
"github.com/tendermint/go-amino"
)
const (
// EthAccountName is the amino encoding name for EthAccount
EthAccountName = "fibochain/EthAccount"
)
// RegisterCodec registers the account interfaces and concrete types on the
// provided Amino codec.
func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(&EthAccount{}, EthAccountName, nil)
cdc.RegisterConcreteUnmarshaller(EthAccountName, func(cdc *amino.Codec, data []byte) (interface{}, int, error) {
var cacc componentAccount
var acc = &cacc.ethAccount
acc.BaseAccount = &cacc.baseAccount
err := acc.UnmarshalFromAmino(cdc, data)
if err != nil {
return nil, 0, err
}
return acc, len(data), nil
})
cdc.RegisterConcreteMarshaller(EthAccountName, func(cdc *amino.Codec, v interface{}) ([]byte, error) {
if acc, ok := v.(*EthAccount); ok {
return acc.MarshalToAmino(cdc)
} else if acc, ok := v.(EthAccount); ok {
return acc.MarshalToAmino(cdc)
} else {
return nil, fmt.Errorf("%T is not an EthAccount", v)
}
})
cdc.EnableBufferMarshaler(EthAccount{})
}