basecoin: fix codecs, add some tests
This commit is contained in:
parent
a74293e4ba
commit
6d3b5cb402
|
@ -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
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ type Account interface {
|
|||
SetSequence(int64) error
|
||||
|
||||
GetCoins() Coins
|
||||
SetCoins(Coins)
|
||||
SetCoins(Coins) error
|
||||
|
||||
Get(key interface{}) (value interface{}, err error)
|
||||
Set(key interface{}, value interface{}) error
|
||||
|
|
|
@ -57,7 +57,7 @@ type StdTx struct {
|
|||
|
||||
func (tx StdTx) GetFeePayer() crypto.Address { return tx.Signatures[0].PubKey.Address() }
|
||||
func (tx StdTx) GetTxBytes() []byte {
|
||||
bz, err := wire.MarshalBinary(tx)
|
||||
bz, err := wire.MarshalBinary(tx) // XXX: this is bad
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ import (
|
|||
//-----------------------------------------------------------
|
||||
// BaseAccount
|
||||
|
||||
var _ sdk.Account = (*BaseAccount)(nil)
|
||||
|
||||
// BaseAccount - coin account structure
|
||||
type BaseAccount struct {
|
||||
Address crypto.Address `json:"address"`
|
||||
|
|
Loading…
Reference in New Issue