Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aminoification #814

Merged
merged 11 commits into from
Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP commit
  • Loading branch information
jaekwon committed Apr 7, 2018
commit 49fdf80d9d8d5f51c8f6c1b7ef662ff7c16e4e20
39 changes: 20 additions & 19 deletions Gopkg.lock

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

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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()

Expand Down
5 changes: 2 additions & 3 deletions client/rpc/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
17 changes: 17 additions & 0 deletions client/rpc/wire.go
Original file line number Diff line number Diff line change
@@ -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)
}
51 changes: 17 additions & 34 deletions examples/democoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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},
)

const accTypeApp = 0x1
var _ = oldwire.RegisterInterface(
struct{ sdk.Account }{},
oldwire.ConcreteType{&types.AppAccount{}, accTypeApp},
)
cdc := wire.NewCodec()
var 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
}

Expand Down
2 changes: 1 addition & 1 deletion examples/democoin/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
7 changes: 4 additions & 3 deletions server/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions server/tm_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions server/wire.go
Original file line number Diff line number Diff line change
@@ -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)
}
9 changes: 5 additions & 4 deletions wire/wire.go
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 2 additions & 2 deletions x/auth/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading