basecoin: fix codecs, add some tests

This commit is contained in:
Ethan Buchman
2018-01-20 18:11:38 -08:00
committed by Jae Kwon
parent a74293e4ba
commit 6d3b5cb402
7 changed files with 29 additions and 9 deletions
@@ -78,6 +78,7 @@ func (app *BasecoinApp) initSDKApp() {
func (app *BasecoinApp) initCodec() {
app.cdc = wire.NewCodec()
app.registerMsgs()
}
// depends on initSDKApp()
+4
View File
@@ -3,6 +3,7 @@ package app
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
crypto "github.com/tendermint/go-crypto"
)
// Set via `app.App.SetTxDecoder(app.decodeTx)`
@@ -16,6 +17,9 @@ func (app *BasecoinApp) decodeTx(txBytes []byte) (sdk.Tx, error) {
func (app *BasecoinApp) registerMsgs() {
cdc := app.cdc
// Register the crypto
crypto.RegisterWire(cdc)
// Register the Msg interface.
cdc.RegisterInterface((*sdk.Msg)(nil), nil)
cdc.RegisterConcrete(bank.SendMsg{}, "cosmos-sdk/SendMsg", nil) // XXX refactor out
+1 -1
View File
@@ -40,6 +40,6 @@ func (app *BasecoinApp) initMultiStore() {
func (app *BasecoinApp) initAppStore() {
app.accStore = auth.NewAccountStore(
app.mainStoreKey,
types.AppAccountCodec{},
types.NewAppAccountCodecFromWireCodec(app.cdc),
)
}
+19 -6
View File
@@ -1,9 +1,14 @@
package types
import (
wire "github.com/tendermint/go-wire"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
)
var _ sdk.Account = (*AppAccount)(nil)
type AppAccount struct {
auth.BaseAccount
@@ -21,16 +26,24 @@ func (acc *AppAccount) SetName(name string) {
//----------------------------------------
type AppAccountCodec struct{}
type AppAccountCodec struct {
cdc *wire.Codec
}
func NewAppAccountCodecFromWireCodec(cdc *wire.Codec) AppAccountCodec {
return AppAccountCodec{cdc}
}
func (_ AppAccountCodec) Prototype() interface{} {
return AppAccount{}
return &AppAccount{}
}
func (_ AppAccountCodec) Encode(o interface{}) (bz []byte, err error) {
panic("not yet implemented")
func (aac AppAccountCodec) Encode(o interface{}) (bz []byte, err error) {
return aac.cdc.MarshalBinary(o)
}
func (_ AppAccountCodec) Decode(bz []byte) (o interface{}, err error) {
panic("not yet implemented")
func (aac AppAccountCodec) Decode(bz []byte) (o interface{}, err error) {
o = aac.Prototype()
err = aac.cdc.UnmarshalBinary(bz, o)
return o, err
}