-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec.go
35 lines (30 loc) · 903 Bytes
/
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
package watcher
import (
cryptocodec "github.com/brc20-collab/brczero/app/crypto/ethsecp256k1"
app "github.com/brc20-collab/brczero/app/types"
"github.com/brc20-collab/brczero/libs/cosmos-sdk/codec"
"github.com/brc20-collab/brczero/libs/cosmos-sdk/x/auth/exported"
)
var WatchCdc *codec.Codec
func init() {
WatchCdc = codec.New()
cryptocodec.RegisterCodec(WatchCdc)
codec.RegisterCrypto(WatchCdc)
WatchCdc.RegisterInterface((*exported.Account)(nil), nil)
app.RegisterCodec(WatchCdc)
}
func EncodeAccount(acc *app.EthAccount) ([]byte, error) {
bz, err := WatchCdc.MarshalBinaryWithSizer(acc, false)
if err != nil {
return nil, err
}
return bz, nil
}
func DecodeAccount(bz []byte) (*app.EthAccount, error) {
var acc app.EthAccount
val, err := WatchCdc.UnmarshalBinaryBareWithRegisteredUnmarshaller(bz, &acc)
if err != nil {
return nil, err
}
return val.(*app.EthAccount), nil
}