diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 06581836c9..5cc20185d4 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -327,8 +327,8 @@ func (tx testUpdatePowerTx) Get(key interface{}) (value interface{}) { return ni func (tx testUpdatePowerTx) GetMsg() sdk.Msg { return tx } func (tx testUpdatePowerTx) GetSignBytes() []byte { return nil } func (tx testUpdatePowerTx) ValidateBasic() sdk.Error { return nil } -func (tx testUpdatePowerTx) GetSigners() []sdk.Address { return nil } -func (tx testUpdatePowerTx) GetFeePayer() sdk.Address { return nil } +func (tx testUpdatePowerTx) GetSigners() []sdk.Address { return nil } +func (tx testUpdatePowerTx) GetFeePayer() sdk.Address { return nil } func (tx testUpdatePowerTx) GetSignatures() []sdk.StdSignature { return nil } func TestValidatorChange(t *testing.T) { @@ -430,7 +430,7 @@ func makePubKey(secret string) crypto.PubKey { func makePrivKey(secret string) crypto.PrivKey { privKey := crypto.GenPrivKeyEd25519FromSecret([]byte(secret)) - return privKey + return privKey.Wrap() } func secret(index int) string { diff --git a/client/keys/wire.go b/client/keys/wire.go index 5f7c15344e..225e60ae71 100644 --- a/client/keys/wire.go +++ b/client/keys/wire.go @@ -1,15 +1,14 @@ package keys import ( - crypto "github.com/tendermint/go-crypto" - wire "github.com/tendermint/go-wire" + "github.com/cosmos/cosmos-sdk/wire" ) var cdc *wire.Codec func init() { cdc = wire.NewCodec() - crypto.RegisterWire(cdc) + wire.RegisterCrypto(cdc) } func MarshalJSON(o interface{}) ([]byte, error) { diff --git a/client/tx/root.go b/client/tx/root.go index 2099fb2112..829a35b19c 100644 --- a/client/tx/root.go +++ b/client/tx/root.go @@ -2,7 +2,8 @@ package tx import ( "github.com/spf13/cobra" - wire "github.com/tendermint/go-wire" + + "github.com/cosmos/cosmos-sdk/wire" ) // type used to pass around the provided cdc diff --git a/client/tx/search.go b/client/tx/search.go index ffe0ca323d..8356f99ca6 100644 --- a/client/tx/search.go +++ b/client/tx/search.go @@ -8,9 +8,10 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/cosmos/cosmos-sdk/client" - wire "github.com/tendermint/go-wire" ctypes "github.com/tendermint/tendermint/rpc/core/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/wire" ) const ( diff --git a/client/tx/tx.go b/client/tx/tx.go index f9ac0631bf..183efef1dc 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -9,11 +9,12 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + abci "github.com/tendermint/abci/types" + ctypes "github.com/tendermint/tendermint/rpc/core/types" + "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" - abci "github.com/tendermint/abci/types" - wire "github.com/tendermint/go-wire" - ctypes "github.com/tendermint/tendermint/rpc/core/types" + "github.com/cosmos/cosmos-sdk/wire" ) // Get the default command for a tx query diff --git a/examples/basecoin/app/app.go b/examples/basecoin/app/app.go index 34778456b2..420e0632f9 100644 --- a/examples/basecoin/app/app.go +++ b/examples/basecoin/app/app.go @@ -4,14 +4,14 @@ import ( "encoding/json" abci "github.com/tendermint/abci/types" - crypto "github.com/tendermint/go-crypto" - "github.com/tendermint/go-wire" + oldwire "github.com/tendermint/go-wire" cmn "github.com/tendermint/tmlibs/common" dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/tmlibs/log" bam "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" @@ -74,11 +74,33 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB) *BasecoinApp { // custom tx codec func MakeCodec() *wire.Codec { + + // XXX: Using old wire for now :) + const ( + msgTypeSend = 0x1 + msgTypeIssue = 0x2 + ) + var _ = oldwire.RegisterInterface( + struct{ sdk.Msg }{}, + oldwire.ConcreteType{bank.SendMsg{}, msgTypeSend}, + oldwire.ConcreteType{bank.IssueMsg{}, msgTypeIssue}, + ) + + const ( + accTypeApp = 0x1 + ) + var _ = oldwire.RegisterInterface( + struct{ sdk.Account }{}, + oldwire.ConcreteType{&types.AppAccount{}, accTypeApp}, + ) + cdc := wire.NewCodec() - cdc.RegisterInterface((*sdk.Msg)(nil), nil) - bank.RegisterWire(cdc) // Register bank.[SendMsg,IssueMsg] types. - crypto.RegisterWire(cdc) // Register crypto.[PubKey,PrivKey,Signature] types. + // TODO: use new go-wire + // cdc.RegisterInterface((*sdk.Msg)(nil), nil) + // bank.RegisterWire(cdc) // Register bank.[SendMsg,IssueMsg] types. + // crypto.RegisterWire(cdc) // Register crypto.[PubKey,PrivKey,Signature] types. return cdc + } // custom logic for transaction decoding diff --git a/examples/basecoin/types/account.go b/examples/basecoin/types/account.go index 90bb0d5130..30dc1dbf4e 100644 --- a/examples/basecoin/types/account.go +++ b/examples/basecoin/types/account.go @@ -2,8 +2,8 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" - wire "github.com/tendermint/go-wire" ) var _ sdk.Account = (*AppAccount)(nil) diff --git a/glide.lock b/glide.lock index 9ff8dde612..ab784f16be 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: fa45c8a4f5512ed730f793b93d4876bdc604a1333a5a1f938c98a0f7dd55f22e -updated: 2018-03-01T00:41:12.97082395-05:00 +hash: bb3fc7a1729189d36ebf8e7b47bfecdcbc3450c911d9966e665b8c6b01b9df80 +updated: 2018-03-02T04:23:04.095993751-05:00 imports: - name: github.com/bgentry/speakeasy version: 4aabc24848ce5fd31929f7d1e4ea74d3709c14cd @@ -7,10 +7,6 @@ imports: version: 50de9da05b50eb15658bb350f6ea24368a111ab7 subpackages: - btcec -- name: github.com/davecgh/go-spew - version: 346938d642f2ec3594ed81d874461961cd0faa76 - subpackages: - - spew - name: github.com/ebuchman/fail-test version: 95f809107225be108efcf10a3509e4ea6ceef3c4 - name: github.com/fsnotify/fsnotify @@ -109,11 +105,11 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: 68592f4d8ee34e97db94b7a7976b1309efdb7eb9 + version: 9e0e00bef42aebf6b402f66bf0f3dc607de8a6f3 subpackages: - client - example/code - - example/dummy + - example/kvstore - server - types - name: github.com/tendermint/ed25519 @@ -122,18 +118,20 @@ imports: - edwards25519 - extra25519 - name: github.com/tendermint/go-crypto - version: 4fc3055dbd17aa1203d0abc64b9293f378da22ec + version: 6c6d01b51c56f8b155cf9712e79de8fb12a82803 subpackages: - keys - keys/bcrypt - keys/words - keys/words/wordlist - name: github.com/tendermint/go-wire - version: 5d7845f24b843c914cf571dad2ca13c91cf70f0d + version: 67ee274c5f9da166622f3b6e6747003b563e3742 + subpackages: + - data - name: github.com/tendermint/iavl - version: 1a59ec0c82dc940c25339dd7c834df5cb76a95cb + version: 39de8f0b4ee758fdd5bb3a9afc6dd9bf42c04785 - name: github.com/tendermint/tendermint - version: c330b9e43c93351a5c3040333d7d0c7c27859a20 + version: c394eef7b8f4b71f3e077c22f697040694eb6c74 subpackages: - blockchain - cmd/tendermint/commands @@ -167,6 +165,7 @@ imports: - state/txindex/kv - state/txindex/null - types + - types/priv_validator - version - wire - name: github.com/tendermint/tmlibs @@ -204,6 +203,7 @@ imports: - idna - internal/timeseries - lex/httplex + - netutil - trace - name: golang.org/x/sys version: 37707fdb30a5b38865cfb95e5aab41707daec7fd @@ -242,6 +242,10 @@ imports: - name: gopkg.in/yaml.v2 version: d670f9405373e636a5a2765eea47fac0c9bc91a4 testImports: +- name: github.com/davecgh/go-spew + version: 346938d642f2ec3594ed81d874461961cd0faa76 + subpackages: + - spew - name: github.com/pmezard/go-difflib version: 792786c7400a136282c1664665ae0a8db921c6c2 subpackages: diff --git a/glide.yaml b/glide.yaml index 086cd0c25c..bc675cfd7c 100644 --- a/glide.yaml +++ b/glide.yaml @@ -17,11 +17,11 @@ import: - server - types - package: github.com/tendermint/go-crypto - version: develop + version: develop-pre-wire - package: github.com/tendermint/go-wire - version: develop + version: bucky/new-go-wire-api - package: github.com/tendermint/iavl - version: develop + version: develop-pre-wire - package: github.com/tendermint/tmlibs version: develop subpackages: @@ -30,7 +30,7 @@ import: - log - merkle - package: github.com/tendermint/tendermint - version: breaking/wire-sdk2 + version: bucky/new-wire-api subpackages: - cmd/tendermint/commands - config diff --git a/mock/app.go b/mock/app.go index 3e9a3ad5f5..6cb339a3c3 100644 --- a/mock/app.go +++ b/mock/app.go @@ -88,6 +88,7 @@ func InitChainer(key sdk.StoreKey) func(sdk.Context, abci.RequestInitChain) abci stateJSON := req.AppStateBytes genesisState := new(GenesisJSON) + fmt.Println("STASTE JSON", string(stateJSON)) err := json.Unmarshal(stateJSON, genesisState) if err != nil { panic(err) // TODO https://github.com/cosmos/cosmos-sdk/issues/468 diff --git a/store/wire.go b/store/wire.go index 22536ff09e..7befbdfcd9 100644 --- a/store/wire.go +++ b/store/wire.go @@ -1,7 +1,7 @@ package store import ( - "github.com/tendermint/go-wire" + "github.com/cosmos/cosmos-sdk/wire" ) var cdc = wire.NewCodec() diff --git a/wire/wire.go b/wire/wire.go new file mode 100644 index 0000000000..e53d5e195b --- /dev/null +++ b/wire/wire.go @@ -0,0 +1,55 @@ +package wire + +import ( + "bytes" + "reflect" + + "github.com/tendermint/go-wire" +) + +type Codec struct{} + +func NewCodec() *Codec { + return &Codec{} +} + +func (cdc *Codec) MarshalBinary(o interface{}) ([]byte, error) { + w, n, err := new(bytes.Buffer), new(int), new(error) + wire.WriteBinary(o, w, n, err) + return w.Bytes(), *err +} + +func (cdc *Codec) UnmarshalBinary(bz []byte, o interface{}) error { + r, n, err := bytes.NewBuffer(bz), new(int), new(error) + + rv := reflect.ValueOf(o) + if rv.Kind() == reflect.Ptr { + wire.ReadBinaryPtr(o, r, len(bz), n, err) + } else { + wire.ReadBinary(o, r, len(bz), n, err) + } + return *err +} + +func (cdc *Codec) MarshalJSON(o interface{}) ([]byte, error) { + w, n, err := new(bytes.Buffer), new(int), new(error) + wire.WriteJSON(o, w, n, err) + return w.Bytes(), *err +} + +func (cdc *Codec) UnmarshalJSON(bz []byte, o interface{}) (err error) { + + rv := reflect.ValueOf(o) + if rv.Kind() == reflect.Ptr { + wire.ReadJSONPtr(o, bz, &err) + } else { + wire.ReadJSON(o, bz, &err) + } + return err +} + +//---------------------------------------------- + +func RegisterCrypto(cdc *Codec) { + // TODO +} diff --git a/x/auth/ante.go b/x/auth/ante.go index 28785c8096..11aa03c0d7 100644 --- a/x/auth/ante.go +++ b/x/auth/ante.go @@ -55,7 +55,7 @@ func NewAnteHandler(accountMapper sdk.AccountMapper) sdk.AnteHandler { signerAccs[i] = signerAcc // If no pubkey, set pubkey. - if signerAcc.GetPubKey() == nil { + if signerAcc.GetPubKey().Empty() { err := signerAcc.SetPubKey(sig.PubKey) if err != nil { return ctx, diff --git a/x/auth/baseaccount.go b/x/auth/baseaccount.go index 9c826333b0..23123f9949 100644 --- a/x/auth/baseaccount.go +++ b/x/auth/baseaccount.go @@ -3,9 +3,10 @@ package auth import ( "errors" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/go-crypto" - "github.com/tendermint/go-wire" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/wire" ) //----------------------------------------------------------- @@ -17,10 +18,10 @@ var _ sdk.Account = (*BaseAccount)(nil) // Extend this by embedding this in your AppAccount. // See the examples/basecoin/types/account.go for an example. type BaseAccount struct { - Address sdk.Address `json:"address"` - Coins sdk.Coins `json:"coins"` - PubKey crypto.PubKey `json:"public_key"` - Sequence int64 `json:"sequence"` + Address sdk.Address `json:"address"` + Coins sdk.Coins `json:"coins"` + PubKey crypto.PubKey `json:"public_key"` + Sequence int64 `json:"sequence"` } func NewBaseAccountWithAddress(addr sdk.Address) BaseAccount { @@ -60,7 +61,7 @@ func (acc BaseAccount) GetPubKey() crypto.PubKey { // Implements sdk.Account. func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error { - if acc.PubKey != nil { + if !acc.PubKey.Empty() { return errors.New("cannot override BaseAccount pubkey") } acc.PubKey = pubKey @@ -94,5 +95,5 @@ func (acc *BaseAccount) SetSequence(seq int64) error { func RegisterWireBaseAccount(cdc *wire.Codec) { // Register crypto.[PubKey,PrivKey,Signature] types. - crypto.RegisterWire(cdc) + wire.RegisterCrypto(cdc) } diff --git a/x/auth/baseaccount_test.go b/x/auth/baseaccount_test.go index a7397dc453..85674af18b 100644 --- a/x/auth/baseaccount_test.go +++ b/x/auth/baseaccount_test.go @@ -3,10 +3,12 @@ package auth import ( "testing" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" + crypto "github.com/tendermint/go-crypto" - wire "github.com/tendermint/go-wire" + + sdk "github.com/cosmos/cosmos-sdk/types" + wire "github.com/cosmos/cosmos-sdk/wire" ) func TestBaseAccount(t *testing.T) { @@ -20,13 +22,13 @@ func TestBaseAccount(t *testing.T) { // need a codec for marshaling codec := wire.NewCodec() - crypto.RegisterWire(codec) + wire.RegisterCrypto(codec) err := acc.SetPubKey(pub) assert.Nil(t, err) assert.Equal(t, pub, acc.GetPubKey()) - assert.Equal(t, addr, acc.GetAddress()) + assert.EqualValues(t, addr, acc.GetAddress()) err = acc.SetCoins(someCoins) assert.Nil(t, err) diff --git a/x/auth/commands/account.go b/x/auth/commands/account.go index c8a9fe0b3f..86df60a389 100644 --- a/x/auth/commands/account.go +++ b/x/auth/commands/account.go @@ -8,10 +8,9 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" - wire "github.com/tendermint/go-wire" - "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" ) diff --git a/x/auth/mapper.go b/x/auth/mapper.go index 0de0d17197..b50e4405fd 100644 --- a/x/auth/mapper.go +++ b/x/auth/mapper.go @@ -1,12 +1,14 @@ package auth import ( + "bytes" "fmt" "reflect" - wire "github.com/tendermint/go-wire" + oldwire "github.com/tendermint/go-wire" sdk "github.com/cosmos/cosmos-sdk/types" + wire "github.com/cosmos/cosmos-sdk/wire" ) // Implements sdk.AccountMapper. @@ -154,14 +156,27 @@ func (am accountMapper) encodeAccount(acc sdk.Account) []byte { } func (am accountMapper) decodeAccount(bz []byte) sdk.Account { - 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) + // ... 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) + } + + 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) + } + */ } diff --git a/x/bank/commands/sendtx.go b/x/bank/commands/sendtx.go index 45ca03abb8..af171fb726 100644 --- a/x/bank/commands/sendtx.go +++ b/x/bank/commands/sendtx.go @@ -8,11 +8,10 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - wire "github.com/tendermint/go-wire" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/keys" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/bank" ) diff --git a/x/bank/wire.go b/x/bank/wire.go index 7162a416aa..a69398ea3d 100644 --- a/x/bank/wire.go +++ b/x/bank/wire.go @@ -1,11 +1,14 @@ package bank import ( - "github.com/tendermint/go-wire" + "github.com/cosmos/cosmos-sdk/wire" ) func RegisterWire(cdc *wire.Codec) { - // TODO include option to always include prefix bytes. - cdc.RegisterConcrete(SendMsg{}, "cosmos-sdk/SendMsg", nil) - cdc.RegisterConcrete(IssueMsg{}, "cosmos-sdk/IssueMsg", nil) + // TODO: bring this back ... + /* + // TODO include option to always include prefix bytes. + cdc.RegisterConcrete(SendMsg{}, "cosmos-sdk/SendMsg", nil) + cdc.RegisterConcrete(IssueMsg{}, "cosmos-sdk/IssueMsg", nil) + */ }