basecoin: fix codecs, add some tests
This commit is contained in:
@@ -78,6 +78,7 @@ func (app *BasecoinApp) initSDKApp() {
|
||||
|
||||
func (app *BasecoinApp) initCodec() {
|
||||
app.cdc = wire.NewCodec()
|
||||
app.registerMsgs()
|
||||
}
|
||||
|
||||
// depends on initSDKApp()
|
||||
@@ -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
|
||||
|
||||
@@ -40,6 +40,6 @@ func (app *BasecoinApp) initMultiStore() {
|
||||
func (app *BasecoinApp) initAppStore() {
|
||||
app.accStore = auth.NewAccountStore(
|
||||
app.mainStoreKey,
|
||||
types.AppAccountCodec{},
|
||||
types.NewAppAccountCodecFromWireCodec(app.cdc),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user