github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/evm/watcher/codec.go (about)

     1  package watcher
     2  
     3  import (
     4  	cryptocodec "github.com/fibonacci-chain/fbc/app/crypto/ethsecp256k1"
     5  	app "github.com/fibonacci-chain/fbc/app/types"
     6  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec"
     7  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/exported"
     8  )
     9  
    10  var WatchCdc *codec.Codec
    11  
    12  func init() {
    13  	WatchCdc = codec.New()
    14  	cryptocodec.RegisterCodec(WatchCdc)
    15  	codec.RegisterCrypto(WatchCdc)
    16  	WatchCdc.RegisterInterface((*exported.Account)(nil), nil)
    17  	app.RegisterCodec(WatchCdc)
    18  }
    19  
    20  func EncodeAccount(acc *app.EthAccount) ([]byte, error) {
    21  	bz, err := WatchCdc.MarshalBinaryWithSizer(acc, false)
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  	return bz, nil
    26  }
    27  
    28  func DecodeAccount(bz []byte) (*app.EthAccount, error) {
    29  	var acc app.EthAccount
    30  	val, err := WatchCdc.UnmarshalBinaryBareWithRegisteredUnmarshaller(bz, &acc)
    31  	if err != nil {
    32  		return nil, err
    33  	}
    34  	return val.(*app.EthAccount), nil
    35  }