diff --git a/Gopkg.lock b/Gopkg.lock index 2de9e117e..7d61f6f1b 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -183,7 +183,7 @@ branch = "master" name = "github.com/rcrowley/go-metrics" packages = ["."] - revision = "8732c616f52954686704c8645fe1a9d59e9df7c1" + revision = "d932a24a8ccb8fcadc993e5c6c58f93dac168294" [[projects]] name = "github.com/spf13/afero" @@ -261,8 +261,8 @@ "server", "types" ] - revision = "46686763ba8ea595ede16530ed4a40fb38f49f94" - version = "v0.10.2" + revision = "c62aed95f2ce399ec815b0cafe478af002cdc4e6" + version = "v0.10.3-dev" [[projects]] branch = "master" @@ -274,6 +274,12 @@ ] revision = "d8387025d2b9d158cf4efb07e7ebf814bcce2057" +[[projects]] + name = "github.com/tendermint/go-amino" + packages = ["."] + revision = "42246108ff925a457fb709475070a03dfd3e2b5c" + version = "0.9.6" + [[projects]] name = "github.com/tendermint/go-crypto" packages = [ @@ -283,17 +289,13 @@ "keys/words", "keys/words/wordlist" ] - revision = "c3e19f3ea26f5c3357e0bcbb799b0761ef923755" - version = "v0.5.0" + revision = "5d5f580f49ca66c13400938c64334186068c8b7c" + version = "v0.6.1" [[projects]] name = "github.com/tendermint/go-wire" - packages = [ - ".", - "data" - ] + packages = ["."] revision = "fa721242b042ecd4c6ed1a934ee740db4f74e45c" - source = "github.com/tendermint/go-amino" version = "v0.7.3" [[projects]] @@ -338,13 +340,13 @@ "state/txindex/null", "types", "types/priv_validator", - "version", - "wire" + "version" ] - revision = "a1dd329d72e78d4770e602359bad5b7b1e8b72a3" - version = "v0.18.0-rc1" + revision = "02531ca5a3a3d521e33bffa528583ff5b78d0594" + version = "0.19.0-rc1" [[projects]] + branch = "develop" name = "github.com/tendermint/tmlibs" packages = [ "autofile", @@ -360,7 +362,6 @@ "pubsub/query" ] revision = "2e24b64fc121dcdf1cabceab8dc2f7257675483c" - version = "0.8.1" [[projects]] branch = "master" @@ -390,13 +391,13 @@ "lex/httplex", "trace" ] - revision = "b3c676e531a6dc479fa1b35ac961c13f5e2b4d2e" + revision = "61147c48b25b599e5b561d2e9c4f3e1ef489ca41" [[projects]] branch = "master" name = "golang.org/x/sys" packages = ["unix"] - revision = "1d206c9fa8975fb4cf00df1dc8bf3283dc24ba0e" + revision = "3b87a42e500a6dc65dae1a55d0b641295971163e" [[projects]] name = "golang.org/x/text" @@ -423,7 +424,7 @@ branch = "master" name = "google.golang.org/genproto" packages = ["googleapis/rpc/status"] - revision = "35de2414665fc36f56b72d982c5af480d86de5ab" + revision = "ce84044298496ef4b54b4a0a0909ba593cc60e30" [[projects]] name = "google.golang.org/grpc" @@ -458,6 +459,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "67298e1f8058b85f082dbd32123f2779b11bda282616e595141dba41a8675c39" + inputs-digest = "2d266cd1c87ae063451b8c6cbce64d24463fd6edc61aa391be618c0447b7cd57" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 1431c8b15..b3517e970 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -70,7 +70,7 @@ [[constraint]] name = "github.com/tendermint/tendermint" - version = "~0.18.0-rc1" + version = "0.19.0-rc1" [[override]] name = "github.com/tendermint/tmlibs" diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 1658c591d..29b224c46 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -432,7 +432,7 @@ func makePubKey(secret string) crypto.PubKey { func makePrivKey(secret string) crypto.PrivKey { privKey := crypto.GenPrivKeyEd25519FromSecret([]byte(secret)) - return privKey.Wrap() + return privKey } func secret(index int) string { diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 48cc35a8e..585d1570e 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -25,6 +25,7 @@ import ( ctypes "github.com/tendermint/tendermint/rpc/core/types" tmrpc "github.com/tendermint/tendermint/rpc/lib/server" tmtypes "github.com/tendermint/tendermint/types" + pvm "github.com/tendermint/tendermint/types/priv_validator" "github.com/tendermint/tmlibs/cli" dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/tmlibs/log" @@ -341,7 +342,7 @@ func startTMAndLCD() (*nm.Node, net.Listener, error) { logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) logger = log.NewFilter(logger, log.AllowError()) privValidatorFile := config.PrivValidatorFile() - privVal := tmtypes.LoadOrGenPrivValidatorFS(privValidatorFile) + privVal := pvm.LoadOrGenFilePV(privValidatorFile) dbs := map[string]dbm.DB{ "main": dbm.NewMemDB(), "acc": dbm.NewMemDB(), @@ -370,7 +371,7 @@ func startTMAndLCD() (*nm.Node, net.Listener, error) { if err != nil { return nil, nil, err } - genDoc.AppStateJSON = stateBytes + genDoc.AppState = stateBytes cdc := wire.NewCodec() diff --git a/client/rpc/status.go b/client/rpc/status.go index 8ea8a5ad6..0339a355b 100644 --- a/client/rpc/status.go +++ b/client/rpc/status.go @@ -7,7 +7,6 @@ import ( "strconv" "github.com/spf13/cobra" - wire "github.com/tendermint/go-wire" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" @@ -41,8 +40,8 @@ func printNodeStatus(cmd *cobra.Command, args []string) error { return err } - output, err := wire.MarshalJSON(status) - // output, err := json.MarshalIndent(res, " ", "") + output, err := cdc.MarshalJSON(status) + // output, err := cdc.MarshalJSONIndent(res, " ", "") if err != nil { return err } diff --git a/client/rpc/wire.go b/client/rpc/wire.go new file mode 100644 index 000000000..f454decb3 --- /dev/null +++ b/client/rpc/wire.go @@ -0,0 +1,17 @@ +package rpc + +import ( + "github.com/cosmos/cosmos-sdk/wire" + ctypes "github.com/tendermint/tendermint/rpc/core/types" +) + +var cdc *wire.Codec + +func init() { + cdc = wire.NewCodec() + RegisterWire(cdc) +} + +func RegisterWire(cdc *wire.Codec) { + ctypes.RegisterAmino(cdc) +} diff --git a/examples/democoin/app/app.go b/examples/democoin/app/app.go index 2ee79bd5b..efa1236fa 100644 --- a/examples/democoin/app/app.go +++ b/examples/democoin/app/app.go @@ -4,7 +4,6 @@ import ( "encoding/json" abci "github.com/tendermint/abci/types" - oldwire "github.com/tendermint/go-wire" cmn "github.com/tendermint/tmlibs/common" dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/tmlibs/log" @@ -95,41 +94,25 @@ func NewDemocoinApp(logger log.Logger, dbs map[string]dbm.DB) *DemocoinApp { } // custom tx codec -// TODO: use new go-wire func MakeCodec() *wire.Codec { - const msgTypeSend = 0x1 - const msgTypeIssue = 0x2 - const msgTypeQuiz = 0x3 - const msgTypeSetTrend = 0x4 - const msgTypeMine = 0x5 - const msgTypeIBCTransferMsg = 0x6 - const msgTypeIBCReceiveMsg = 0x7 - const msgTypeBondMsg = 0x8 - const msgTypeUnbondMsg = 0x9 - var _ = oldwire.RegisterInterface( - struct{ sdk.Msg }{}, - oldwire.ConcreteType{bank.SendMsg{}, msgTypeSend}, - oldwire.ConcreteType{bank.IssueMsg{}, msgTypeIssue}, - oldwire.ConcreteType{cool.QuizMsg{}, msgTypeQuiz}, - oldwire.ConcreteType{cool.SetTrendMsg{}, msgTypeSetTrend}, - oldwire.ConcreteType{pow.MineMsg{}, msgTypeMine}, - oldwire.ConcreteType{ibc.IBCTransferMsg{}, msgTypeIBCTransferMsg}, - oldwire.ConcreteType{ibc.IBCReceiveMsg{}, msgTypeIBCReceiveMsg}, - oldwire.ConcreteType{simplestake.BondMsg{}, msgTypeBondMsg}, - oldwire.ConcreteType{simplestake.UnbondMsg{}, msgTypeUnbondMsg}, - ) + var cdc = wire.NewCodec() - const accTypeApp = 0x1 - var _ = oldwire.RegisterInterface( - struct{ sdk.Account }{}, - oldwire.ConcreteType{&types.AppAccount{}, accTypeApp}, - ) - cdc := wire.NewCodec() + // Register Msgs + cdc.RegisterInterface((*sdk.Msg)(nil), nil) + cdc.RegisterConcrete(bank.SendMsg{}, "democoin/Send", nil) + cdc.RegisterConcrete(bank.IssueMsg{}, "democoin/Issue", nil) + cdc.RegisterConcrete(cool.QuizMsg{}, "democoin/Quiz", nil) + cdc.RegisterConcrete(cool.SetTrendMsg{}, "democoin/SetTrend", nil) + cdc.RegisterConcrete(pow.MineMsg{}, "democoin/Mine", nil) + cdc.RegisterConcrete(ibc.IBCTransferMsg{}, "democoin/IBCTransferMsg", nil) + cdc.RegisterConcrete(ibc.IBCReceiveMsg{}, "democoin/IBCReceiveMsg", nil) + cdc.RegisterConcrete(simplestake.BondMsg{}, "democoin/BondMsg", nil) + cdc.RegisterConcrete(simplestake.UnbondMsg{}, "democoin/UnbondMsg", nil) + + // Register AppAccount + cdc.RegisterInterface((*sdk.Account)(nil), nil) + cdc.RegisterConcrete(&types.AppAccount{}, "democoin/Account", nil) - // cdc.RegisterInterface((*sdk.Msg)(nil), nil) - // bank.RegisterWire(cdc) // Register bank.[SendMsg,IssueMsg] types. - // crypto.RegisterWire(cdc) // Register crypto.[PubKey,PrivKey,Signature] types. - // ibc.RegisterWire(cdc) // Register ibc.[IBCTransferMsg, IBCReceiveMsg] types. return cdc } diff --git a/examples/democoin/types/account.go b/examples/democoin/types/account.go index b5d5a0d03..d90525f1d 100644 --- a/examples/democoin/types/account.go +++ b/examples/democoin/types/account.go @@ -15,7 +15,7 @@ var _ sdk.Account = (*AppAccount)(nil) // extending auth.BaseAccount with custom fields. // // This is compatible with the stock auth.AccountStore, since -// auth.AccountStore uses the flexible go-wire library. +// auth.AccountStore uses the flexible go-amino library. type AppAccount struct { auth.BaseAccount Name string `json:"name"` diff --git a/server/init.go b/server/init.go index 688bc38e3..09d97338e 100644 --- a/server/init.go +++ b/server/init.go @@ -13,6 +13,7 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/p2p" tmtypes "github.com/tendermint/tendermint/types" + pvm "github.com/tendermint/tendermint/types/priv_validator" cmn "github.com/tendermint/tmlibs/common" dbm "github.com/tendermint/tmlibs/db" ) @@ -109,12 +110,12 @@ func (c initCmd) run(cmd *cobra.Command, args []string) error { func (c initCmd) initTendermintFiles(config *cfg.Config, info *testnetInformation) error { // private validator privValFile := config.PrivValidatorFile() - var privValidator *tmtypes.PrivValidatorFS + var privValidator *pvm.FilePV if cmn.FileExists(privValFile) { - privValidator = tmtypes.LoadPrivValidatorFS(privValFile) + privValidator = pvm.LoadFilePV(privValFile) c.context.Logger.Info("Found private validator", "path", privValFile) } else { - privValidator = tmtypes.GenPrivValidatorFS(privValFile) + privValidator = pvm.GenFilePV(privValFile) privValidator.Save() c.context.Logger.Info("Generated private validator", "path", privValFile) } diff --git a/server/start.go b/server/start.go index 6aee5d316..a4ff9852e 100644 --- a/server/start.go +++ b/server/start.go @@ -11,7 +11,7 @@ import ( tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" "github.com/tendermint/tendermint/node" "github.com/tendermint/tendermint/proxy" - "github.com/tendermint/tendermint/types" + pvm "github.com/tendermint/tendermint/types/priv_validator" cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/log" ) @@ -95,7 +95,7 @@ func (s startCmd) startInProcess() error { // Create & start tendermint node n, err := node.NewNode(cfg, - types.LoadOrGenPrivValidatorFS(cfg.PrivValidatorFile()), + pvm.LoadOrGenFilePV(cfg.PrivValidatorFile()), proxy.NewLocalClientCreator(app), node.DefaultGenesisDocProviderFunc(cfg), node.DefaultDBProvider, diff --git a/server/tm_cmds.go b/server/tm_cmds.go index 3e0aefa94..2a9b680e5 100644 --- a/server/tm_cmds.go +++ b/server/tm_cmds.go @@ -5,10 +5,9 @@ import ( "github.com/spf13/cobra" - "github.com/tendermint/go-wire/data" tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" "github.com/tendermint/tendermint/p2p" - "github.com/tendermint/tendermint/types" + pvm "github.com/tendermint/tendermint/types/priv_validator" ) // ShowNodeIDCmd - ported from Tendermint, dump node ID to stdout @@ -53,8 +52,8 @@ type showValidator struct { func (s showValidator) run(cmd *cobra.Command, args []string) error { cfg := s.context.Config - privValidator := types.LoadOrGenPrivValidatorFS(cfg.PrivValidatorFile()) - pubKeyJSONBytes, err := data.ToJSON(privValidator.PubKey) + privValidator := pvm.LoadOrGenFilePV(cfg.PrivValidatorFile()) + pubKeyJSONBytes, err := cdc.MarshalJSON(privValidator.PubKey) if err != nil { return err } diff --git a/server/wire.go b/server/wire.go new file mode 100644 index 000000000..261e7cfe1 --- /dev/null +++ b/server/wire.go @@ -0,0 +1,12 @@ +package server + +import ( + "github.com/cosmos/cosmos-sdk/wire" +) + +var cdc *wire.Codec + +func init() { + cdc = wire.NewCodec() + wire.RegisterCrypto(cdc) +} diff --git a/wire/wire.go b/wire/wire.go index 6db81687f..9c366b6fb 100644 --- a/wire/wire.go +++ b/wire/wire.go @@ -1,16 +1,17 @@ package wire import ( - "bytes" - "reflect" - "github.com/tendermint/go-amino" + "github.com/tendermint/go-crypto" ) type Codec = amino.Codec func NewCodec() *Codec { cdc := amino.NewCodec() - RegisterAmino(cdc) return cdc } + +func RegisterCrypto(cdc *Codec) { + crypto.RegisterAmino(cdc) +} diff --git a/x/auth/ante.go b/x/auth/ante.go index a5ab83bcb..6801769a4 100644 --- a/x/auth/ante.go +++ b/x/auth/ante.go @@ -118,9 +118,9 @@ func processSig( // If pubkey is not known for account, // set it from the StdSignature. pubKey := acc.GetPubKey() - if pubKey.Empty() { + if pubKey == nil { pubKey = sig.PubKey - if pubKey.Empty() { + if pubKey == nil { return nil, sdk.ErrInvalidPubKey("PubKey not found").Result() } if !bytes.Equal(pubKey.Address(), addr) { diff --git a/x/auth/ante_test.go b/x/auth/ante_test.go index fd94145dd..fa545e32b 100644 --- a/x/auth/ante_test.go +++ b/x/auth/ante_test.go @@ -31,7 +31,7 @@ func newCoins() sdk.Coins { func privAndAddr() (crypto.PrivKey, sdk.Address) { priv := crypto.GenPrivKeyEd25519() addr := priv.PubKey().Address() - return priv.Wrap(), addr + return priv, addr } // run the tx through the anteHandler and ensure its valid @@ -310,16 +310,16 @@ func TestAnteHandlerSetPubKey(t *testing.T) { msg = newTestMsg(addr2) tx = newTestTx(ctx, msg, privs, seqs, fee) sigs := tx.GetSignatures() - sigs[0].PubKey = crypto.PubKey{} + sigs[0].PubKey = nil checkInvalidTx(t, anteHandler, ctx, tx, sdk.CodeInvalidPubKey) acc2 = mapper.GetAccount(ctx, addr2) - assert.True(t, acc2.GetPubKey().Empty()) + assert.Nil(t, acc2.GetPubKey()) // test invalid signature and public key tx = newTestTx(ctx, msg, privs, seqs, fee) checkInvalidTx(t, anteHandler, ctx, tx, sdk.CodeInvalidPubKey) acc2 = mapper.GetAccount(ctx, addr2) - assert.True(t, acc2.GetPubKey().Empty()) + assert.Nil(t, acc2.GetPubKey()) } diff --git a/x/auth/baseaccount.go b/x/auth/baseaccount.go index 23123f994..74d8625f0 100644 --- a/x/auth/baseaccount.go +++ b/x/auth/baseaccount.go @@ -61,7 +61,7 @@ func (acc BaseAccount) GetPubKey() crypto.PubKey { // Implements sdk.Account. func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error { - if !acc.PubKey.Empty() { + if acc.PubKey != nil { return errors.New("cannot override BaseAccount pubkey") } acc.PubKey = pubKey @@ -94,6 +94,5 @@ func (acc *BaseAccount) SetSequence(seq int64) error { // Wire func RegisterWireBaseAccount(cdc *wire.Codec) { - // Register crypto.[PubKey,PrivKey,Signature] types. wire.RegisterCrypto(cdc) } diff --git a/x/auth/baseaccount_test.go b/x/auth/baseaccount_test.go index b2f5b54ae..24b3e3673 100644 --- a/x/auth/baseaccount_test.go +++ b/x/auth/baseaccount_test.go @@ -15,7 +15,7 @@ func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.Address) { key := crypto.GenPrivKeyEd25519() pub := key.PubKey() addr := pub.Address() - return key.Wrap(), pub, addr + return key, pub, addr } func TestBaseAccountAddressPubKey(t *testing.T) { @@ -25,7 +25,7 @@ func TestBaseAccountAddressPubKey(t *testing.T) { // check the address (set) and pubkey (not set) assert.EqualValues(t, addr1, acc.GetAddress()) - assert.EqualValues(t, crypto.PubKey{}, acc.GetPubKey()) + assert.EqualValues(t, nil, acc.GetPubKey()) // can't override address err := acc.SetAddress(addr2) diff --git a/x/auth/mapper.go b/x/auth/mapper.go index 13fe9a844..e07e8fbaa 100644 --- a/x/auth/mapper.go +++ b/x/auth/mapper.go @@ -1,12 +1,9 @@ package auth import ( - "bytes" "fmt" "reflect" - oldwire "github.com/tendermint/go-wire" - sdk "github.com/cosmos/cosmos-sdk/types" wire "github.com/cosmos/cosmos-sdk/wire" ) @@ -16,7 +13,7 @@ var _ sdk.AccountMapper = (*sealedAccountMapper)(nil) // Implements sdk.AccountMapper. // This AccountMapper encodes/decodes accounts using the -// go-wire (binary) encoding/decoding library. +// go-amino (binary) encoding/decoding library. type accountMapper struct { // The (unexposed) key used to access the store from the Context. @@ -30,7 +27,7 @@ type accountMapper struct { } // NewAccountMapper returns a new sdk.AccountMapper that -// uses go-wire to (binary) encode and decode concrete sdk.Accounts. +// uses go-amino to (binary) encode and decode concrete sdk.Accounts. func NewAccountMapper(key sdk.StoreKey, proto sdk.Account) accountMapper { cdc := wire.NewCodec() return accountMapper{ @@ -54,7 +51,7 @@ func NewAccountMapperSealed(key sdk.StoreKey, proto sdk.Account) sealedAccountMa return am.Seal() } -// Returns the go-wire codec. You may need to register interfaces +// Returns the go-amino codec. You may need to register interfaces // and concrete types here, if your app's sdk.Account // implementation includes interface fields. // NOTE: It is not secure to expose the codec, so check out @@ -103,7 +100,7 @@ type sealedAccountMapper struct { } // There's no way for external modules to mutate the -// sam.accountMapper.ctx from here, even with reflection. +// sam.accountMapper.cdc from here, even with reflection. func (sam sealedAccountMapper) WireCodec() *wire.Codec { panic("accountMapper is sealed") } @@ -152,34 +149,17 @@ func (am accountMapper) clonePrototype() sdk.Account { } func (am accountMapper) encodeAccount(acc sdk.Account) []byte { - bz, err := am.cdc.MarshalBinary(acc) + bz, err := am.cdc.MarshalBinaryBare(acc) if err != nil { panic(err) } return bz } -func (am accountMapper) decodeAccount(bz []byte) sdk.Account { - // ... old go-wire ... - r, n, err := bytes.NewBuffer(bz), new(int), new(error) - accI := oldwire.ReadBinary(struct{ sdk.Account }{}, r, len(bz), n, err) - if *err != nil { - panic(*err) +func (am accountMapper) decodeAccount(bz []byte) (acc sdk.Account) { + err := am.cdc.UnmarshalBinaryBare(bz, &acc) + if err != nil { + panic(err) } - - acc := accI.(struct{ sdk.Account }).Account - return acc - - /* - accPtr := am.clonePrototypePtr() - err := am.cdc.UnmarshalBinary(bz, accPtr) - if err != nil { - panic(err) - } - if reflect.ValueOf(am.proto).Kind() == reflect.Ptr { - return reflect.ValueOf(accPtr).Interface().(sdk.Account) - } else { - return reflect.ValueOf(accPtr).Elem().Interface().(sdk.Account) - } - */ + return } diff --git a/x/auth/mapper_test.go b/x/auth/mapper_test.go index 4ac96c381..752c933cc 100644 --- a/x/auth/mapper_test.go +++ b/x/auth/mapper_test.go @@ -6,8 +6,6 @@ import ( "github.com/stretchr/testify/assert" abci "github.com/tendermint/abci/types" - crypto "github.com/tendermint/go-crypto" - oldwire "github.com/tendermint/go-wire" dbm "github.com/tendermint/tmlibs/db" "github.com/cosmos/cosmos-sdk/store" @@ -21,11 +19,13 @@ func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) { ms.MountStoreWithDB(capKey, sdk.StoreTypeIAVL, db) ms.LoadLatestVersion() + /* XXX // wire registration while we're at it ... TODO var _ = oldwire.RegisterInterface( struct{ sdk.Account }{}, oldwire.ConcreteType{&BaseAccount{}, 0x1}, ) + */ return ms, capKey } @@ -47,7 +47,7 @@ func TestAccountMapperGetSet(t *testing.T) { acc = mapper.NewAccountWithAddress(ctx, addr) assert.NotNil(t, acc) assert.Equal(t, addr, acc.GetAddress()) - assert.EqualValues(t, crypto.PubKey{}, acc.GetPubKey()) + assert.EqualValues(t, nil, acc.GetPubKey()) assert.EqualValues(t, 0, acc.GetSequence()) // NewAccount doesn't call Set, so it's still nil diff --git a/x/ibc/ibc_test.go b/x/ibc/ibc_test.go index 1e0431147..34f4f6678 100644 --- a/x/ibc/ibc_test.go +++ b/x/ibc/ibc_test.go @@ -7,7 +7,6 @@ import ( abci "github.com/tendermint/abci/types" "github.com/tendermint/go-crypto" - oldwire "github.com/tendermint/go-wire" dbm "github.com/tendermint/tmlibs/db" "github.com/cosmos/cosmos-sdk/store" @@ -37,35 +36,20 @@ func getCoins(ck bank.CoinKeeper, ctx sdk.Context, addr crypto.Address) (sdk.Coi return ck.AddCoins(ctx, addr, zero) } -// custom tx codec -// TODO: use new go-wire func makeCodec() *wire.Codec { + var cdc = wire.NewCodec() - const msgTypeSend = 0x1 - const msgTypeIssue = 0x2 - const msgTypeQuiz = 0x3 - const msgTypeSetTrend = 0x4 - const msgTypeIBCTransferMsg = 0x5 - const msgTypeIBCReceiveMsg = 0x6 - var _ = oldwire.RegisterInterface( - struct{ sdk.Msg }{}, - oldwire.ConcreteType{bank.SendMsg{}, msgTypeSend}, - oldwire.ConcreteType{bank.IssueMsg{}, msgTypeIssue}, - oldwire.ConcreteType{IBCTransferMsg{}, msgTypeIBCTransferMsg}, - oldwire.ConcreteType{IBCReceiveMsg{}, msgTypeIBCReceiveMsg}, - ) + // Register Msgs + cdc.RegisterInterface((*sdk.Msg)(nil), nil) + cdc.RegisterConcrete(bank.SendMsg{}, "test/ibc/Send", nil) + cdc.RegisterConcrete(bank.IssueMsg{}, "test/ibc/Issue", nil) + cdc.RegisterConcrete(IBCTransferMsg{}, "test/ibc/IBCTransferMsg", nil) + cdc.RegisterConcrete(IBCReceiveMsg{}, "test/ibc/IBCReceiveMsg", nil) - const accTypeApp = 0x1 - var _ = oldwire.RegisterInterface( - struct{ sdk.Account }{}, - oldwire.ConcreteType{&auth.BaseAccount{}, accTypeApp}, - ) - cdc := wire.NewCodec() + // Register AppAccount + cdc.RegisterInterface((*sdk.Account)(nil), nil) + cdc.RegisterConcrete(&auth.BaseAccount{}, "test/ibc/Account", nil) - // cdc.RegisterInterface((*sdk.Msg)(nil), nil) - // bank.RegisterWire(cdc) // Register bank.[SendMsg,IssueMsg] types. - // crypto.RegisterWire(cdc) // Register crypto.[PubKey,PrivKey,Signature] types. - // ibc.RegisterWire(cdc) // Register ibc.[IBCTransferMsg, IBCReceiveMsg] types. return cdc } diff --git a/x/simplestake/commands/commands.go b/x/simplestake/commands/commands.go index ce89801d8..b2a057bee 100644 --- a/x/simplestake/commands/commands.go +++ b/x/simplestake/commands/commands.go @@ -77,7 +77,7 @@ func (co commander) bondTxCmd(cmd *cobra.Command, args []string) error { var pubKeyEd crypto.PubKeyEd25519 copy(pubKeyEd[:], rawPubKey) - msg := simplestake.NewBondMsg(from, stake, pubKeyEd.Wrap()) + msg := simplestake.NewBondMsg(from, stake, pubKeyEd) return co.sendMsg(msg) } diff --git a/x/simplestake/keeper.go b/x/simplestake/keeper.go index e5892f3e2..2370a8db3 100644 --- a/x/simplestake/keeper.go +++ b/x/simplestake/keeper.go @@ -83,7 +83,7 @@ func (k Keeper) Bond(ctx sdk.Context, addr sdk.Address, pubKey crypto.PubKey, st func (k Keeper) Unbond(ctx sdk.Context, addr sdk.Address) (crypto.PubKey, int64, sdk.Error) { bi := k.getBondInfo(ctx, addr) if bi.isEmpty() { - return crypto.PubKey{}, 0, ErrInvalidUnbond() + return nil, 0, ErrInvalidUnbond() } k.deleteBondInfo(ctx, addr) @@ -121,7 +121,7 @@ func (k Keeper) bondWithoutCoins(ctx sdk.Context, addr sdk.Address, pubKey crypt func (k Keeper) unbondWithoutCoins(ctx sdk.Context, addr sdk.Address) (crypto.PubKey, int64, sdk.Error) { bi := k.getBondInfo(ctx, addr) if bi.isEmpty() { - return crypto.PubKey{}, 0, ErrInvalidUnbond() + return nil, 0, ErrInvalidUnbond() } k.deleteBondInfo(ctx, addr) diff --git a/x/simplestake/msgs.go b/x/simplestake/msgs.go index 2ab0e1bad..9f4133484 100644 --- a/x/simplestake/msgs.go +++ b/x/simplestake/msgs.go @@ -34,7 +34,7 @@ func (msg BondMsg) ValidateBasic() sdk.Error { return ErrEmptyStake() } - if msg.PubKey.Empty() { + if msg.PubKey == nil { return sdk.ErrInvalidPubKey("BondMsg.PubKey must not be empty") } diff --git a/x/stake/commands/tx.go b/x/stake/commands/tx.go index d1dec6dce..d1a399e19 100644 --- a/x/stake/commands/tx.go +++ b/x/stake/commands/tx.go @@ -250,6 +250,6 @@ func GetPubKey(pubKeyStr string) (pk crypto.PubKey, err error) { } var pkEd crypto.PubKeyEd25519 copy(pkEd[:], pkBytes[:]) - pk = pkEd.Wrap() + pk = pkEd return } diff --git a/x/stake/test_common.go b/x/stake/test_common.go index ceb2addb4..e116bf705 100644 --- a/x/stake/test_common.go +++ b/x/stake/test_common.go @@ -83,7 +83,7 @@ func subspace(prefix []byte) (start, end []byte) { return prefix, end } -func MakeCodec() *wire.Codec { +func makeTestCodec() *wire.Codec { var cdc = wire.NewCodec() // Register Msgs @@ -152,7 +152,7 @@ func newPubKey(pk string) (res crypto.PubKey) { //res, err = crypto.PubKeyFromBytes(pkBytes) var pkEd crypto.PubKeyEd25519 copy(pkEd[:], pkBytes[:]) - return pkEd.Wrap() + return pkEd } // for incode address generation