From 935c74d9708fa5bacfa78c47496bbeae125b6044 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 30 May 2017 17:51:35 +0200 Subject: [PATCH 1/3] Make sure cmd uses encoding/json not wire.JSONBytes --- cmd/commands/ibc.go | 26 ++++++++++++++++++++++---- cmd/commands/query.go | 25 ++++++++++++++++++++----- cmd/commands/tx.go | 15 +++++++++++++-- cmd/counter/cmd.go | 7 ++++++- 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/cmd/commands/ibc.go b/cmd/commands/ibc.go index 4297bba422..01996d6076 100644 --- a/cmd/commands/ibc.go +++ b/cmd/commands/ibc.go @@ -2,6 +2,7 @@ package commands import ( "encoding/hex" + "encoding/json" "fmt" "io/ioutil" @@ -133,7 +134,12 @@ func ibcRegisterTxCmd(cmd *cobra.Command, args []string) error { }, } - fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx))) + out, err := json.Marshal(ibcTx) + if err != nil { + return err + } + + fmt.Println("IBCTx:", string(out)) data := []byte(wire.BinaryBytes(struct { ibc.IBCTx `json:"unwrap"` @@ -172,7 +178,11 @@ func ibcUpdateTxCmd(cmd *cobra.Command, args []string) error { Commit: *commit, } - fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx))) + out, err := json.Marshal(ibcTx) + if err != nil { + return err + } + fmt.Println("IBCTx:", string(out)) data := []byte(wire.BinaryBytes(struct { ibc.IBCTx `json:"unwrap"` @@ -211,7 +221,11 @@ func ibcPacketCreateTxCmd(cmd *cobra.Command, args []string) error { }, } - fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx))) + out, err := json.Marshal(ibcTx) + if err != nil { + return err + } + fmt.Println("IBCTx:", string(out)) data := []byte(wire.BinaryBytes(struct { ibc.IBCTx `json:"unwrap"` @@ -253,7 +267,11 @@ func ibcPacketPostTxCmd(cmd *cobra.Command, args []string) error { Proof: proof, } - fmt.Println("IBCTx:", string(wire.JSONBytes(ibcTx))) + out, err := json.Marshal(ibcTx) + if err != nil { + return err + } + fmt.Println("IBCTx:", string(out)) data := []byte(wire.BinaryBytes(struct { ibc.IBCTx `json:"unwrap"` diff --git a/cmd/commands/query.go b/cmd/commands/query.go index 330ba1514e..05bd4f93ca 100644 --- a/cmd/commands/query.go +++ b/cmd/commands/query.go @@ -2,6 +2,7 @@ package commands import ( "encoding/hex" + "encoding/json" "fmt" "strconv" @@ -99,11 +100,16 @@ func queryCmd(cmd *cobra.Command, args []string) error { proof := resp.Proof height := resp.Height - fmt.Println(string(wire.JSONBytes(struct { + out, err := json.Marshal(struct { Value []byte `json:"value"` Proof []byte `json:"proof"` Height uint64 `json:"height"` - }{val, proof, height}))) + }{val, proof, height}) + if err != nil { + return err + } + + fmt.Println(string(out)) return nil } @@ -126,7 +132,11 @@ func accountCmd(cmd *cobra.Command, args []string) error { if err != nil { return err } - fmt.Println(string(wire.JSONBytes(acc))) + out, err := json.Marshal(acc) + if err != nil { + return err + } + fmt.Println(string(out)) return nil } @@ -147,7 +157,7 @@ func blockCmd(cmd *cobra.Command, args []string) error { return err } - fmt.Println(string(wire.JSONBytes(struct { + out, err := json.Marshal(struct { Hex BlockHex `json:"hex"` JSON BlockJSON `json:"json"` }{ @@ -159,7 +169,12 @@ func blockCmd(cmd *cobra.Command, args []string) error { Header: header, Commit: commit, }, - }))) + }) + if err != nil { + return err + } + + fmt.Println(string(out)) return nil } diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index d13411bf04..81e304c9a9 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -2,6 +2,7 @@ package commands import ( "encoding/hex" + "encoding/json" "fmt" "strings" @@ -141,8 +142,13 @@ func sendTxCmd(cmd *cobra.Command, args []string) error { signBytes := tx.SignBytes(chainIDFlag) tx.Inputs[0].Signature = privKey.Sign(signBytes) + out, err := json.Marshal(tx) + if err != nil { + return err + } + fmt.Println("Signed SendTx:") - fmt.Println(string(wire.JSONBytes(tx))) + fmt.Println(string(out)) // broadcast the transaction to tendermint data, log, err := broadcastTx(tx) @@ -197,8 +203,13 @@ func AppTx(name string, data []byte) error { tx.Input.Signature = privKey.Sign(tx.SignBytes(chainIDFlag)) + out, err := json.Marshal(tx) + if err != nil { + return err + } + fmt.Println("Signed AppTx:") - fmt.Println(string(wire.JSONBytes(tx))) + fmt.Println(string(out)) data, log, err := broadcastTx(tx) if err != nil { diff --git a/cmd/counter/cmd.go b/cmd/counter/cmd.go index 451f42a482..e83430498a 100644 --- a/cmd/counter/cmd.go +++ b/cmd/counter/cmd.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "fmt" "github.com/spf13/cobra" @@ -45,7 +46,11 @@ func counterTxCmd(cmd *cobra.Command, args []string) error { Fee: countFee, } - fmt.Println("CounterTx:", string(wire.JSONBytes(counterTx))) + out, err := json.Marshal(counterTx) + if err != nil { + return err + } + fmt.Println("CounterTx:", string(out)) data := wire.BinaryBytes(counterTx) name := "counter" From bcf3212462360277bf15f8c39ded1a5e19647e13 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 30 May 2017 18:11:10 +0200 Subject: [PATCH 2/3] Fix up tendermint cli flags to 0.10.0-rc2 in demo --- cmd/commands/ibc.go | 8 ++++---- demo/clean.sh | 4 ++-- demo/start.sh | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/commands/ibc.go b/cmd/commands/ibc.go index 01996d6076..8f1bdb4f56 100644 --- a/cmd/commands/ibc.go +++ b/cmd/commands/ibc.go @@ -139,7 +139,7 @@ func ibcRegisterTxCmd(cmd *cobra.Command, args []string) error { return err } - fmt.Println("IBCTx:", string(out)) + fmt.Printf("IBCTx: %s\n", string(out)) data := []byte(wire.BinaryBytes(struct { ibc.IBCTx `json:"unwrap"` @@ -182,7 +182,7 @@ func ibcUpdateTxCmd(cmd *cobra.Command, args []string) error { if err != nil { return err } - fmt.Println("IBCTx:", string(out)) + fmt.Printf("IBCTx: %s\n", string(out)) data := []byte(wire.BinaryBytes(struct { ibc.IBCTx `json:"unwrap"` @@ -225,7 +225,7 @@ func ibcPacketCreateTxCmd(cmd *cobra.Command, args []string) error { if err != nil { return err } - fmt.Println("IBCTx:", string(out)) + fmt.Printf("IBCTx: %s\n", string(out)) data := []byte(wire.BinaryBytes(struct { ibc.IBCTx `json:"unwrap"` @@ -271,7 +271,7 @@ func ibcPacketPostTxCmd(cmd *cobra.Command, args []string) error { if err != nil { return err } - fmt.Println("IBCTx:", string(out)) + fmt.Printf("IBCTx: %s\n", string(out)) data := []byte(wire.BinaryBytes(struct { ibc.IBCTx `json:"unwrap"` diff --git a/demo/clean.sh b/demo/clean.sh index e39f090eec..bffdefdb84 100644 --- a/demo/clean.sh +++ b/demo/clean.sh @@ -1,8 +1,8 @@ #! /bin/bash killall -9 basecoin tendermint -TMROOT=./data/chain1 tendermint unsafe_reset_all -TMROOT=./data/chain2 tendermint unsafe_reset_all +TMHOME=./data/chain1 tendermint unsafe_reset_all +TMHOME=./data/chain2 tendermint unsafe_reset_all rm ./*.log diff --git a/demo/start.sh b/demo/start.sh index 490806fd62..d42e5ae11a 100644 --- a/demo/start.sh +++ b/demo/start.sh @@ -91,13 +91,13 @@ echo "" echo "... starting chains" echo "" # start the first node -TMROOT=$BCHOME1 tendermint node --p2p.skip_upnp --log_level=info &> $LOG_DIR/chain1_tendermint.log & +TMHOME=$BCHOME1 tendermint node --p2p.skip_upnp --log_level=info &> $LOG_DIR/chain1_tendermint.log & ifExit BCHOME=$BCHOME1 basecoin start --without-tendermint &> $LOG_DIR/chain1_basecoin.log & ifExit # start the second node -TMROOT=$BCHOME2 tendermint node --p2p.skip_upnp --log_level=info --p2p.laddr tcp://localhost:36656 --rpc_laddr tcp://localhost:36657 --proxy_app tcp://localhost:36658 &> $LOG_DIR/chain2_tendermint.log & +TMHOME=$BCHOME2 tendermint node --p2p.skip_upnp --log_level=info --p2p.laddr tcp://localhost:36656 --rpc.laddr tcp://localhost:36657 --proxy_app tcp://localhost:36658 &> $LOG_DIR/chain2_tendermint.log & ifExit BCHOME=$BCHOME2 basecoin start --address tcp://localhost:36658 --without-tendermint &> $LOG_DIR/chain2_basecoin.log & ifExit @@ -124,7 +124,7 @@ echo "... creating egress packet on chain1" echo "" # send coins from chain1 to an address on chain2 # TODO: dont hardcode the address -basecoin tx send --amount 10mycoin $CHAIN_FLAGS1 --to $CHAIN_ID2/053BA0F19616AFF975C8756A2CBFF04F408B4D47 +basecoin tx send --amount 10mycoin $CHAIN_FLAGS1 --to $CHAIN_ID2/053BA0F19616AFF975C8756A2CBFF04F408B4D47 ifExit # alternative way to create packets (for testing) From 9444427d7e171dcd6b3ae890410aa7dece07b400 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Tue, 30 May 2017 18:28:25 +0200 Subject: [PATCH 3/3] Make sure we export hex not base64 for byte slices --- cmd/commands/query.go | 11 ++++++----- cmd/commands/tx.go | 17 ++++------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/cmd/commands/query.go b/cmd/commands/query.go index 05bd4f93ca..e31d625491 100644 --- a/cmd/commands/query.go +++ b/cmd/commands/query.go @@ -10,6 +10,7 @@ import ( "github.com/spf13/cobra" "github.com/tendermint/go-wire" + "github.com/tendermint/go-wire/data" "github.com/tendermint/merkleeyes/iavl" "github.com/tendermint/tendermint/rpc/client" tmtypes "github.com/tendermint/tendermint/types" @@ -101,9 +102,9 @@ func queryCmd(cmd *cobra.Command, args []string) error { height := resp.Height out, err := json.Marshal(struct { - Value []byte `json:"value"` - Proof []byte `json:"proof"` - Height uint64 `json:"height"` + Value data.Bytes `json:"value"` + Proof data.Bytes `json:"proof"` + Height uint64 `json:"height"` }{val, proof, height}) if err != nil { return err @@ -179,8 +180,8 @@ func blockCmd(cmd *cobra.Command, args []string) error { } type BlockHex struct { - Header []byte `json:"header"` - Commit []byte `json:"commit"` + Header data.Bytes `json:"header"` + Commit data.Bytes `json:"commit"` } type BlockJSON struct { diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index 81e304c9a9..70bc8e626b 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -2,7 +2,6 @@ package commands import ( "encoding/hex" - "encoding/json" "fmt" "strings" @@ -142,13 +141,9 @@ func sendTxCmd(cmd *cobra.Command, args []string) error { signBytes := tx.SignBytes(chainIDFlag) tx.Inputs[0].Signature = privKey.Sign(signBytes) - out, err := json.Marshal(tx) - if err != nil { - return err - } - + out := wire.BinaryBytes(tx) fmt.Println("Signed SendTx:") - fmt.Println(string(out)) + fmt.Printf("%X\n", out) // broadcast the transaction to tendermint data, log, err := broadcastTx(tx) @@ -203,13 +198,9 @@ func AppTx(name string, data []byte) error { tx.Input.Signature = privKey.Sign(tx.SignBytes(chainIDFlag)) - out, err := json.Marshal(tx) - if err != nil { - return err - } - + out := wire.BinaryBytes(tx) fmt.Println("Signed AppTx:") - fmt.Println(string(out)) + fmt.Printf("%X\n", out) data, log, err := broadcastTx(tx) if err != nil {