Skip to content

Commit

Permalink
revert to old go-wire
Browse files Browse the repository at this point in the history
  • Loading branch information
ebuchman committed Mar 2, 2018
1 parent 62d6a5d commit 630a5fe
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 66 deletions.
6 changes: 3 additions & 3 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions client/keys/wire.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion client/tx/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions client/tx/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
7 changes: 4 additions & 3 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"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/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
)

// Get the default command for a tx query
Expand Down
32 changes: 27 additions & 5 deletions examples/basecoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/basecoin/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 16 additions & 12 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion store/wire.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package store

import (
"github.com/tendermint/go-wire"
"github.com/cosmos/cosmos-sdk/wire"
)

var cdc = wire.NewCodec()
55 changes: 55 additions & 0 deletions wire/wire.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion x/auth/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 9 additions & 8 deletions x/auth/baseaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

//-----------------------------------------------------------
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Loading

0 comments on commit 630a5fe

Please sign in to comment.