Debug Flag, Run -> RunE

This commit is contained in:
Rigel Rozanski 2017-04-15 12:07:27 -04:00 committed by Ethan Buchman
parent 5ebdd964c5
commit c292d54e47
19 changed files with 178 additions and 155 deletions

View File

@ -1,9 +1,6 @@
package main package main
import ( import (
"fmt"
"os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/tendermint/basecoin/cmd/commands" "github.com/tendermint/basecoin/cmd/commands"
@ -28,8 +25,5 @@ func main() {
commands.VersionCmd, commands.VersionCmd,
) )
if err := RootCmd.Execute(); err != nil { commands.ExecuteWithDebug(RootCmd)
fmt.Println(err)
os.Exit(1)
}
} }

View File

@ -5,11 +5,11 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/tendermint/basecoin/plugins/ibc" "github.com/tendermint/basecoin/plugins/ibc"
cmn "github.com/tendermint/go-common"
"github.com/tendermint/go-merkle" "github.com/tendermint/go-merkle"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
tmtypes "github.com/tendermint/tendermint/types" tmtypes "github.com/tendermint/tendermint/types"
@ -30,13 +30,13 @@ var (
IBCRegisterTxCmd = &cobra.Command{ IBCRegisterTxCmd = &cobra.Command{
Use: "register", Use: "register",
Short: "Register a blockchain via IBC", Short: "Register a blockchain via IBC",
Run: ibcRegisterTxCmd, RunE: ibcRegisterTxCmd,
} }
IBCUpdateTxCmd = &cobra.Command{ IBCUpdateTxCmd = &cobra.Command{
Use: "update", Use: "update",
Short: "Update the latest state of a blockchain via IBC", Short: "Update the latest state of a blockchain via IBC",
Run: ibcUpdateTxCmd, RunE: ibcUpdateTxCmd,
} }
IBCPacketTxCmd = &cobra.Command{ IBCPacketTxCmd = &cobra.Command{
@ -47,13 +47,13 @@ var (
IBCPacketCreateTxCmd = &cobra.Command{ IBCPacketCreateTxCmd = &cobra.Command{
Use: "create", Use: "create",
Short: "Create an egress IBC packet", Short: "Create an egress IBC packet",
Run: ibcPacketCreateTxCmd, RunE: ibcPacketCreateTxCmd,
} }
IBCPacketPostTxCmd = &cobra.Command{ IBCPacketPostTxCmd = &cobra.Command{
Use: "post", Use: "post",
Short: "Deliver an IBC packet to another chain", Short: "Deliver an IBC packet to another chain",
Run: ibcPacketPostTxCmd, RunE: ibcPacketPostTxCmd,
} }
) )
@ -117,13 +117,13 @@ func init() {
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// ibc command implementations // ibc command implementations
func ibcRegisterTxCmd(cmd *cobra.Command, args []string) { func ibcRegisterTxCmd(cmd *cobra.Command, args []string) error {
chainID := ibcChainIDFlag chainID := ibcChainIDFlag
genesisFile := ibcGenesisFlag genesisFile := ibcGenesisFlag
genesisBytes, err := ioutil.ReadFile(genesisFile) genesisBytes, err := ioutil.ReadFile(genesisFile)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Error reading genesis file %v: %+v\n", genesisFile, err)) return errors.Errorf("Error reading genesis file %v: %v\n", genesisFile, err)
} }
ibcTx := ibc.IBCRegisterChainTx{ ibcTx := ibc.IBCRegisterChainTx{
@ -140,18 +140,18 @@ func ibcRegisterTxCmd(cmd *cobra.Command, args []string) {
}{ibcTx})) }{ibcTx}))
name := "IBC" name := "IBC"
AppTx(name, data) return AppTx(name, data)
} }
func ibcUpdateTxCmd(cmd *cobra.Command, args []string) { func ibcUpdateTxCmd(cmd *cobra.Command, args []string) error {
headerBytes, err := hex.DecodeString(StripHex(ibcHeaderFlag)) headerBytes, err := hex.DecodeString(StripHex(ibcHeaderFlag))
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Header (%v) is invalid hex: %+v\n", ibcHeaderFlag, err)) return errors.Errorf("Header (%v) is invalid hex: %v\n", ibcHeaderFlag, err)
} }
commitBytes, err := hex.DecodeString(StripHex(ibcCommitFlag)) commitBytes, err := hex.DecodeString(StripHex(ibcCommitFlag))
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Commit (%v) is invalid hex: %+v\n", ibcCommitFlag, err)) return errors.Errorf("Commit (%v) is invalid hex: %v\n", ibcCommitFlag, err)
} }
header := new(tmtypes.Header) header := new(tmtypes.Header)
@ -159,12 +159,12 @@ func ibcUpdateTxCmd(cmd *cobra.Command, args []string) {
err = wire.ReadBinaryBytes(headerBytes, &header) err = wire.ReadBinaryBytes(headerBytes, &header)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Error unmarshalling header: %+v\n", err)) return errors.Errorf("Error unmarshalling header: %v\n", err)
} }
err = wire.ReadBinaryBytes(commitBytes, &commit) err = wire.ReadBinaryBytes(commitBytes, &commit)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Error unmarshalling commit: %+v\n", err)) return errors.Errorf("Error unmarshalling commit: %v\n", err)
} }
ibcTx := ibc.IBCUpdateChainTx{ ibcTx := ibc.IBCUpdateChainTx{
@ -179,21 +179,21 @@ func ibcUpdateTxCmd(cmd *cobra.Command, args []string) {
}{ibcTx})) }{ibcTx}))
name := "IBC" name := "IBC"
AppTx(name, data) return AppTx(name, data)
} }
func ibcPacketCreateTxCmd(cmd *cobra.Command, args []string) { func ibcPacketCreateTxCmd(cmd *cobra.Command, args []string) error {
fromChain, toChain := ibcFromFlag, ibcToFlag fromChain, toChain := ibcFromFlag, ibcToFlag
packetType := ibcTypeFlag packetType := ibcTypeFlag
payloadBytes, err := hex.DecodeString(StripHex(ibcPayloadFlag)) payloadBytes, err := hex.DecodeString(StripHex(ibcPayloadFlag))
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Payload (%v) is invalid hex: %+v\n", ibcPayloadFlag, err)) return errors.Errorf("Payload (%v) is invalid hex: %v\n", ibcPayloadFlag, err)
} }
sequence, err := ibcSequenceCmd() sequence, err := ibcSequenceCmd()
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
ibcTx := ibc.IBCPacketCreateTx{ ibcTx := ibc.IBCPacketCreateTx{
@ -212,20 +212,20 @@ func ibcPacketCreateTxCmd(cmd *cobra.Command, args []string) {
ibc.IBCTx `json:"unwrap"` ibc.IBCTx `json:"unwrap"`
}{ibcTx})) }{ibcTx}))
AppTx("IBC", data) return AppTx("IBC", data)
} }
func ibcPacketPostTxCmd(cmd *cobra.Command, args []string) { func ibcPacketPostTxCmd(cmd *cobra.Command, args []string) error {
fromChain, fromHeight := ibcFromFlag, ibcHeightFlag fromChain, fromHeight := ibcFromFlag, ibcHeightFlag
packetBytes, err := hex.DecodeString(StripHex(ibcPacketFlag)) packetBytes, err := hex.DecodeString(StripHex(ibcPacketFlag))
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Packet (%v) is invalid hex: %+v\n", ibcPacketFlag, err)) return errors.Errorf("Packet (%v) is invalid hex: %v\n", ibcPacketFlag, err)
} }
proofBytes, err := hex.DecodeString(StripHex(ibcProofFlag)) proofBytes, err := hex.DecodeString(StripHex(ibcProofFlag))
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Proof (%v) is invalid hex: %+v\n", ibcProofFlag, err)) return errors.Errorf("Proof (%v) is invalid hex: %v\n", ibcProofFlag, err)
} }
var packet ibc.Packet var packet ibc.Packet
@ -233,12 +233,12 @@ func ibcPacketPostTxCmd(cmd *cobra.Command, args []string) {
err = wire.ReadBinaryBytes(packetBytes, &packet) err = wire.ReadBinaryBytes(packetBytes, &packet)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Error unmarshalling packet: %+v\n", err)) return errors.Errorf("Error unmarshalling packet: %v\n", err)
} }
err = wire.ReadBinaryBytes(proofBytes, &proof) err = wire.ReadBinaryBytes(proofBytes, &proof)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Error unmarshalling proof: %+v\n", err)) return errors.Errorf("Error unmarshalling proof: %v\n", err)
} }
ibcTx := ibc.IBCPacketPostTx{ ibcTx := ibc.IBCPacketPostTx{
@ -254,7 +254,7 @@ func ibcPacketPostTxCmd(cmd *cobra.Command, args []string) {
ibc.IBCTx `json:"unwrap"` ibc.IBCTx `json:"unwrap"`
}{ibcTx})) }{ibcTx}))
AppTx("IBC", data) return AppTx("IBC", data)
} }
func ibcSequenceCmd() (uint64, error) { func ibcSequenceCmd() (uint64, error) {

View File

@ -1,7 +1,6 @@
package commands package commands
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
@ -16,25 +15,25 @@ var (
InitCmd = &cobra.Command{ InitCmd = &cobra.Command{
Use: "init", Use: "init",
Short: "Initialize a basecoin blockchain", Short: "Initialize a basecoin blockchain",
Run: initCmd, RunE: initCmd,
} }
) )
// setupFile aborts on error... or should we return it?? // setupFile aborts on error... or should we return it??
// returns 1 iff it set a file, otherwise 0 (so we can add them) // returns 1 iff it set a file, otherwise 0 (so we can add them)
func setupFile(path, data string, perm os.FileMode) int { func setupFile(path, data string, perm os.FileMode) (int, error) {
_, err := os.Stat(path) _, err := os.Stat(path)
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
return 0 return 0, nil
} }
err = ioutil.WriteFile(path, []byte(data), perm) err = ioutil.WriteFile(path, []byte(data), perm)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return 0, err
} }
return 1 return 1, nil
} }
func initCmd(cmd *cobra.Command, args []string) { func initCmd(cmd *cobra.Command, args []string) error {
rootDir := BasecoinRoot("") rootDir := BasecoinRoot("")
cmn.EnsureDir(rootDir, 0777) cmn.EnsureDir(rootDir, 0777)
@ -45,16 +44,30 @@ func initCmd(cmd *cobra.Command, args []string) {
key1File := path.Join(rootDir, "key.json") key1File := path.Join(rootDir, "key.json")
key2File := path.Join(rootDir, "key2.json") key2File := path.Join(rootDir, "key2.json")
mod := setupFile(genesisFile, GenesisJSON, 0644) + mod1, err := setupFile(genesisFile, GenesisJSON, 0644)
setupFile(privValFile, PrivValJSON, 0400) + if err != nil {
setupFile(key1File, Key1JSON, 0400) + return err
setupFile(key2File, Key2JSON, 0400) }
mod2, err := setupFile(privValFile, PrivValJSON, 0400)
if err != nil {
return err
}
mod3, err := setupFile(key1File, Key1JSON, 0400)
if err != nil {
return err
}
mod4, err := setupFile(key2File, Key2JSON, 0400)
if err != nil {
return err
}
if mod > 0 { if (mod1 + mod2 + mod3 + mod4) > 0 {
log.Notice("Initialized Basecoin", "genesis", genesisFile, "key", key1File) log.Notice("Initialized Basecoin", "genesis", genesisFile, "key", key1File)
} else { } else {
log.Notice("Already initialized", "priv_validator", privValFile) log.Notice("Already initialized", "priv_validator", privValFile)
} }
return nil
} }
var PrivValJSON = `{ var PrivValJSON = `{

View File

@ -8,9 +8,9 @@ import (
"path" "path"
"strings" "strings"
//"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
cmn "github.com/tendermint/go-common"
"github.com/tendermint/go-crypto" "github.com/tendermint/go-crypto"
) )
@ -24,18 +24,19 @@ var (
NewKeyCmd = &cobra.Command{ NewKeyCmd = &cobra.Command{
Use: "new", Use: "new",
Short: "Create a new private key", Short: "Create a new private key",
Run: newKeyCmd, RunE: newKeyCmd,
} }
) )
func newKeyCmd(cmd *cobra.Command, args []string) { func newKeyCmd(cmd *cobra.Command, args []string) error {
key := genKey() key := genKey()
keyJSON, err := json.MarshalIndent(key, "", "\t") keyJSON, err := json.MarshalIndent(key, "", "\t")
fmt.Println(&key) fmt.Println(&key)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
fmt.Println(string(keyJSON)) fmt.Println(string(keyJSON))
return nil
} }
func init() { func init() {
@ -85,18 +86,18 @@ func genKey() *Key {
} }
} }
func LoadKey(keyFile string) *Key { func LoadKey(keyFile string) (*Key, error) {
filePath := path.Join(BasecoinRoot(""), keyFile) filePath := path.Join(BasecoinRoot(""), keyFile)
keyJSONBytes, err := ioutil.ReadFile(filePath) keyJSONBytes, err := ioutil.ReadFile(filePath)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return nil, err
} }
key := new(Key) key := new(Key)
err = json.Unmarshal(keyJSONBytes, key) err = json.Unmarshal(keyJSONBytes, key)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Error reading key from %v: %v\n", filePath, err)) return nil, fmt.Errorf("Error reading key from %v: %v\n", filePath, err) //never stack trace
} }
return key return key, nil
} }

View File

@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
cmn "github.com/tendermint/go-common"
"github.com/tendermint/go-merkle" "github.com/tendermint/go-merkle"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
tmtypes "github.com/tendermint/tendermint/types" tmtypes "github.com/tendermint/tendermint/types"
@ -18,25 +18,25 @@ var (
QueryCmd = &cobra.Command{ QueryCmd = &cobra.Command{
Use: "query [key]", Use: "query [key]",
Short: "Query the merkle tree", Short: "Query the merkle tree",
Run: queryCmd, RunE: queryCmd,
} }
AccountCmd = &cobra.Command{ AccountCmd = &cobra.Command{
Use: "account [address]", Use: "account [address]",
Short: "Get details of an account", Short: "Get details of an account",
Run: accountCmd, RunE: accountCmd,
} }
BlockCmd = &cobra.Command{ BlockCmd = &cobra.Command{
Use: "block [height]", Use: "block [height]",
Short: "Get the header and commit of a block", Short: "Get the header and commit of a block",
Run: blockCmd, RunE: blockCmd,
} }
VerifyCmd = &cobra.Command{ VerifyCmd = &cobra.Command{
Use: "verify", Use: "verify",
Short: "Verify the IAVL proof", Short: "Verify the IAVL proof",
Run: verifyCmd, RunE: verifyCmd,
} }
) )
@ -68,10 +68,10 @@ func init() {
RegisterFlags(VerifyCmd, verifyFlags) RegisterFlags(VerifyCmd, verifyFlags)
} }
func queryCmd(cmd *cobra.Command, args []string) { func queryCmd(cmd *cobra.Command, args []string) error {
if len(args) != 1 { if len(args) != 1 {
cmn.Exit("query command requires an argument ([key])") return fmt.Errorf("query command requires an argument ([key])") //never stack trace
} }
keyString := args[0] keyString := args[0]
@ -81,17 +81,17 @@ func queryCmd(cmd *cobra.Command, args []string) {
var err error var err error
key, err = hex.DecodeString(StripHex(keyString)) key, err = hex.DecodeString(StripHex(keyString))
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Query key (%v) is invalid hex: %+v\n", keyString, err)) return errors.Errorf("Query key (%v) is invalid hex: %v\n", keyString, err)
} }
} }
resp, err := Query(nodeFlag, key) resp, err := Query(nodeFlag, key)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Query returns error: %+v\n", err)) return errors.Errorf("Query returns error: %v\n", err)
} }
if !resp.Code.IsOK() { if !resp.Code.IsOK() {
cmn.Exit(fmt.Sprintf("Query for key (%v) returned non-zero code (%v): %v", keyString, resp.Code, resp.Log)) return errors.Errorf("Query for key (%v) returned non-zero code (%v): %v", keyString, resp.Code, resp.Log)
} }
val := resp.Value val := resp.Value
@ -103,12 +103,13 @@ func queryCmd(cmd *cobra.Command, args []string) {
Proof []byte `json:"proof"` Proof []byte `json:"proof"`
Height uint64 `json:"height"` Height uint64 `json:"height"`
}{val, proof, height}))) }{val, proof, height})))
return nil
} }
func accountCmd(cmd *cobra.Command, args []string) { func accountCmd(cmd *cobra.Command, args []string) error {
if len(args) != 1 { if len(args) != 1 {
cmn.Exit("account command requires an argument ([address])") return fmt.Errorf("account command requires an argument ([address])") //never stack trace
} }
addrHex := StripHex(args[0]) addrHex := StripHex(args[0])
@ -116,31 +117,32 @@ func accountCmd(cmd *cobra.Command, args []string) {
// convert destination address to bytes // convert destination address to bytes
addr, err := hex.DecodeString(addrHex) addr, err := hex.DecodeString(addrHex)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Account address (%v) is invalid hex: %+v\n", addrHex, err)) return errors.Errorf("Account address (%v) is invalid hex: %v\n", addrHex, err)
} }
acc, err := getAcc(nodeFlag, addr) acc, err := getAcc(nodeFlag, addr)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
fmt.Println(string(wire.JSONBytes(acc))) fmt.Println(string(wire.JSONBytes(acc)))
return nil
} }
func blockCmd(cmd *cobra.Command, args []string) { func blockCmd(cmd *cobra.Command, args []string) error {
if len(args) != 1 { if len(args) != 1 {
cmn.Exit("block command requires an argument ([height])") return fmt.Errorf("block command requires an argument ([height])") //never stack trace
} }
heightString := args[0] heightString := args[0]
height, err := strconv.Atoi(heightString) height, err := strconv.Atoi(heightString)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Height must be an int, got %v: %+v\n", heightString, err)) return errors.Errorf("Height must be an int, got %v: %v\n", heightString, err)
} }
header, commit, err := getHeaderAndCommit(nodeFlag, height) header, commit, err := getHeaderAndCommit(nodeFlag, height)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
fmt.Println(string(wire.JSONBytes(struct { fmt.Println(string(wire.JSONBytes(struct {
@ -156,6 +158,7 @@ func blockCmd(cmd *cobra.Command, args []string) {
Commit: commit, Commit: commit,
}, },
}))) })))
return nil
} }
type BlockHex struct { type BlockHex struct {
@ -168,7 +171,7 @@ type BlockJSON struct {
Commit *tmtypes.Commit `json:"commit"` Commit *tmtypes.Commit `json:"commit"`
} }
func verifyCmd(cmd *cobra.Command, args []string) { func verifyCmd(cmd *cobra.Command, args []string) error {
keyString, valueString := keyFlag, valueFlag keyString, valueString := keyFlag, valueFlag
@ -177,7 +180,7 @@ func verifyCmd(cmd *cobra.Command, args []string) {
if isHex(keyString) { if isHex(keyString) {
key, err = hex.DecodeString(StripHex(keyString)) key, err = hex.DecodeString(StripHex(keyString))
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Key (%v) is invalid hex: %+v\n", keyString, err)) return errors.Errorf("Key (%v) is invalid hex: %v\n", keyString, err)
} }
} }
@ -185,25 +188,26 @@ func verifyCmd(cmd *cobra.Command, args []string) {
if isHex(valueString) { if isHex(valueString) {
value, err = hex.DecodeString(StripHex(valueString)) value, err = hex.DecodeString(StripHex(valueString))
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Value (%v) is invalid hex: %+v\n", valueString, err)) return errors.Errorf("Value (%v) is invalid hex: %v\n", valueString, err)
} }
} }
root, err := hex.DecodeString(StripHex(rootFlag)) root, err := hex.DecodeString(StripHex(rootFlag))
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Root (%v) is invalid hex: %+v\n", rootFlag, err)) return errors.Errorf("Root (%v) is invalid hex: %v\n", rootFlag, err)
} }
proofBytes, err := hex.DecodeString(StripHex(proofFlag)) proofBytes, err := hex.DecodeString(StripHex(proofFlag))
proof, err := merkle.ReadProof(proofBytes) proof, err := merkle.ReadProof(proofBytes)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Error unmarshalling proof: %+v\n", err)) return errors.Errorf("Error unmarshalling proof: %v\n", err)
} }
if proof.Verify(key, value, root) { if proof.Verify(key, value, root) {
fmt.Println("OK") fmt.Println("OK")
} else { } else {
cmn.Exit(fmt.Sprintf("Proof does not verify")) return errors.New("Proof does not verify")
} }
return nil
} }

View File

@ -5,20 +5,21 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/tendermint/tendermint/cmd/tendermint/commands" tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
tmcfg "github.com/tendermint/tendermint/config/tendermint" tmcfg "github.com/tendermint/tendermint/config/tendermint"
) )
var UnsafeResetAllCmd = &cobra.Command{ var UnsafeResetAllCmd = &cobra.Command{
Use: "unsafe_reset_all", Use: "unsafe_reset_all",
Short: "Reset all blockchain data", Short: "Reset all blockchain data",
Run: unsafeResetAllCmd, RunE: unsafeResetAllCmd,
} }
func unsafeResetAllCmd(cmd *cobra.Command, args []string) { func unsafeResetAllCmd(cmd *cobra.Command, args []string) error {
basecoinDir := BasecoinRoot("") basecoinDir := BasecoinRoot("")
tmDir := path.Join(basecoinDir) tmDir := path.Join(basecoinDir)
tmConfig := tmcfg.GetConfig(tmDir) tmConfig := tmcfg.GetConfig(tmDir)
commands.ResetAll(tmConfig, log) tmcmd.ResetAll(tmConfig, log)
return nil
} }

View File

@ -5,6 +5,7 @@ import (
"os" "os"
"path" "path"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/tendermint/abci/server" "github.com/tendermint/abci/server"
@ -22,7 +23,7 @@ import (
var StartCmd = &cobra.Command{ var StartCmd = &cobra.Command{
Use: "start", Use: "start",
Short: "Start basecoin", Short: "Start basecoin",
Run: startCmd, RunE: startCmd,
} }
//flags //flags
@ -42,7 +43,7 @@ func init() {
{&addrFlag, "address", "tcp://0.0.0.0:46658", "Listen address"}, {&addrFlag, "address", "tcp://0.0.0.0:46658", "Listen address"},
{&eyesFlag, "eyes", "local", "MerkleEyes address, or 'local' for embedded"}, {&eyesFlag, "eyes", "local", "MerkleEyes address, or 'local' for embedded"},
{&dirFlag, "dir", ".", "Root directory"}, {&dirFlag, "dir", ".", "Root directory"},
{&withoutTendermintFlag, "without-tendermint", false, "Run Tendermint in-process with the App"}, {&withoutTendermintFlag, "without-tendermint", false, "RunE Tendermint in-process with the App"},
} }
RegisterFlags(StartCmd, flags) RegisterFlags(StartCmd, flags)
@ -50,7 +51,7 @@ func init() {
// eyesCacheSizePtr := flag.Int("eyes-cache-size", 10000, "MerkleEyes db cache size, for embedded") // eyesCacheSizePtr := flag.Int("eyes-cache-size", 10000, "MerkleEyes db cache size, for embedded")
} }
func startCmd(cmd *cobra.Command, args []string) { func startCmd(cmd *cobra.Command, args []string) error {
basecoinDir := BasecoinRoot("") basecoinDir := BasecoinRoot("")
// Connect to MerkleEyes // Connect to MerkleEyes
@ -61,7 +62,7 @@ func startCmd(cmd *cobra.Command, args []string) {
var err error var err error
eyesCli, err = eyes.NewClient(eyesFlag) eyesCli, err = eyes.NewClient(eyesFlag)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Error connecting to MerkleEyes: %+v\n", err)) return errors.Errorf("Error connecting to MerkleEyes: %v\n", err)
} }
} }
@ -84,7 +85,7 @@ func startCmd(cmd *cobra.Command, args []string) {
if _, err := os.Stat(genesisFile); err == nil { if _, err := os.Stat(genesisFile); err == nil {
err := basecoinApp.LoadGenesis(genesisFile) err := basecoinApp.LoadGenesis(genesisFile)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Error in LoadGenesis: %+v\n", err)) return errors.Errorf("Error in LoadGenesis: %v\n", err)
} }
} else { } else {
fmt.Printf("No genesis file at %s, skipping...\n", genesisFile) fmt.Printf("No genesis file at %s, skipping...\n", genesisFile)
@ -95,20 +96,20 @@ func startCmd(cmd *cobra.Command, args []string) {
if withoutTendermintFlag { if withoutTendermintFlag {
log.Notice("Starting Basecoin without Tendermint", "chain_id", chainID) log.Notice("Starting Basecoin without Tendermint", "chain_id", chainID)
// run just the abci app/server // run just the abci app/server
startBasecoinABCI(basecoinApp) return startBasecoinABCI(basecoinApp)
} else { } else {
log.Notice("Starting Basecoin with Tendermint", "chain_id", chainID) log.Notice("Starting Basecoin with Tendermint", "chain_id", chainID)
// start the app with tendermint in-process // start the app with tendermint in-process
startTendermint(basecoinDir, basecoinApp) return startTendermint(basecoinDir, basecoinApp)
} }
} }
func startBasecoinABCI(basecoinApp *app.Basecoin) { func startBasecoinABCI(basecoinApp *app.Basecoin) error {
// Start the ABCI listener // Start the ABCI listener
svr, err := server.NewServer(addrFlag, "socket", basecoinApp) svr, err := server.NewServer(addrFlag, "socket", basecoinApp)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("Error creating listener: %+v\n", err)) return errors.Errorf("Error creating listener: %v\n", err)
} }
// Wait forever // Wait forever
@ -116,9 +117,10 @@ func startBasecoinABCI(basecoinApp *app.Basecoin) {
// Cleanup // Cleanup
svr.Stop() svr.Stop()
}) })
return nil
} }
func startTendermint(dir string, basecoinApp *app.Basecoin) { func startTendermint(dir string, basecoinApp *app.Basecoin) error {
// Get configuration // Get configuration
tmConfig := tmcfg.GetConfig(dir) tmConfig := tmcfg.GetConfig(dir)
@ -132,7 +134,7 @@ func startTendermint(dir string, basecoinApp *app.Basecoin) {
_, err := n.Start() _, err := n.Start()
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return errors.Errorf("%v\n", err)
} }
// Wait forever // Wait forever
@ -140,4 +142,5 @@ func startTendermint(dir string, basecoinApp *app.Basecoin) {
// Cleanup // Cleanup
n.Stop() n.Stop()
}) })
return nil
} }

View File

@ -10,7 +10,6 @@ import (
"github.com/tendermint/basecoin/types" "github.com/tendermint/basecoin/types"
crypto "github.com/tendermint/go-crypto" crypto "github.com/tendermint/go-crypto"
cmn "github.com/tendermint/go-common"
client "github.com/tendermint/go-rpc/client" client "github.com/tendermint/go-rpc/client"
wire "github.com/tendermint/go-wire" wire "github.com/tendermint/go-wire"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
@ -26,13 +25,13 @@ var (
SendTxCmd = &cobra.Command{ SendTxCmd = &cobra.Command{
Use: "send", Use: "send",
Short: "A SendTx transaction, for sending tokens around", Short: "A SendTx transaction, for sending tokens around",
Run: sendTxCmd, RunE: sendTxCmd,
} }
AppTxCmd = &cobra.Command{ AppTxCmd = &cobra.Command{
Use: "app", Use: "app",
Short: "An AppTx transaction, for sending raw data to plugins", Short: "An AppTx transaction, for sending raw data to plugins",
Run: appTxCmd, RunE: appTxCmd,
} }
) )
@ -82,31 +81,34 @@ func init() {
TxCmd.AddCommand(SendTxCmd, AppTxCmd) TxCmd.AddCommand(SendTxCmd, AppTxCmd)
} }
func sendTxCmd(cmd *cobra.Command, args []string) { func sendTxCmd(cmd *cobra.Command, args []string) error {
// convert destination address to bytes // convert destination address to bytes
to, err := hex.DecodeString(StripHex(toFlag)) to, err := hex.DecodeString(StripHex(toFlag))
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("To address is invalid hex: %+v\n", err)) return errors.Errorf("To address is invalid hex: %v\n", err)
} }
// load the priv key // load the priv key
privKey := LoadKey(fromFlag) privKey, err := LoadKey(fromFlag)
if err != nil {
return err
}
// get the sequence number for the tx // get the sequence number for the tx
sequence, err := getSeq(privKey.Address[:]) sequence, err := getSeq(privKey.Address[:])
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
//parse the fee and amounts into coin types //parse the fee and amounts into coin types
feeCoin, err := types.ParseCoin(feeFlag) feeCoin, err := types.ParseCoin(feeFlag)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
amountCoins, err := types.ParseCoins(amountFlag) amountCoins, err := types.ParseCoins(amountFlag)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
// craft the tx // craft the tx
@ -129,39 +131,43 @@ func sendTxCmd(cmd *cobra.Command, args []string) {
// broadcast the transaction to tendermint // broadcast the transaction to tendermint
data, log, err := broadcastTx(tx) data, log, err := broadcastTx(tx)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
fmt.Printf("Response: %X ; %s\n", data, log) fmt.Printf("Response: %X ; %s\n", data, log)
return nil
} }
func appTxCmd(cmd *cobra.Command, args []string) { func appTxCmd(cmd *cobra.Command, args []string) error {
// convert data to bytes // convert data to bytes
data := []byte(dataFlag) data := []byte(dataFlag)
if isHex(dataFlag) { if isHex(dataFlag) {
data, _ = hex.DecodeString(dataFlag) data, _ = hex.DecodeString(dataFlag)
} }
name := nameFlag name := nameFlag
AppTx(name, data) return AppTx(name, data)
} }
func AppTx(name string, data []byte) { func AppTx(name string, data []byte) error {
privKey := LoadKey(fromFlag) privKey, err := LoadKey(fromFlag)
if err != nil {
return err
}
sequence, err := getSeq(privKey.Address[:]) sequence, err := getSeq(privKey.Address[:])
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
//parse the fee and amounts into coin types //parse the fee and amounts into coin types
feeCoin, err := types.ParseCoin(feeFlag) feeCoin, err := types.ParseCoin(feeFlag)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
amountCoins, err := types.ParseCoins(amountFlag) amountCoins, err := types.ParseCoins(amountFlag)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
input := types.NewTxInput(privKey.PubKey, amountCoins, sequence) input := types.NewTxInput(privKey.PubKey, amountCoins, sequence)
@ -180,9 +186,10 @@ func AppTx(name string, data []byte) {
data, log, err := broadcastTx(tx) data, log, err := broadcastTx(tx)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
fmt.Printf("Response: %X ; %s\n", data, log) fmt.Printf("Response: %X ; %s\n", data, log)
return nil
} }
// broadcast the transaction to tendermint // broadcast the transaction to tendermint
@ -199,7 +206,7 @@ func broadcastTx(tx types.Tx) ([]byte, string, error) {
_, err := uriClient.Call("broadcast_tx_commit", map[string]interface{}{"tx": txBytes}, tmResult) _, err := uriClient.Call("broadcast_tx_commit", map[string]interface{}{"tx": txBytes}, tmResult)
if err != nil { if err != nil {
return nil, "", errors.New(cmn.Fmt("Error on broadcast tx: %v", err)) return nil, "", errors.Errorf("Error on broadcast tx: %v", err)
} }
res := (*tmResult).(*ctypes.ResultBroadcastTxCommit) res := (*tmResult).(*ctypes.ResultBroadcastTxCommit)
@ -207,12 +214,12 @@ func broadcastTx(tx types.Tx) ([]byte, string, error) {
// if it fails check, we don't even get a delivertx back! // if it fails check, we don't even get a delivertx back!
if !res.CheckTx.Code.IsOK() { if !res.CheckTx.Code.IsOK() {
r := res.CheckTx r := res.CheckTx
return nil, "", errors.New(cmn.Fmt("BroadcastTxCommit got non-zero exit code: %v. %X; %s", r.Code, r.Data, r.Log)) return nil, "", errors.Errorf("BroadcastTxCommit got non-zero exit code: %v. %X; %s", r.Code, r.Data, r.Log)
} }
if !res.DeliverTx.Code.IsOK() { if !res.DeliverTx.Code.IsOK() {
r := res.DeliverTx r := res.DeliverTx
return nil, "", errors.New(cmn.Fmt("BroadcastTxCommit got non-zero exit code: %v. %X; %s", r.Code, r.Data, r.Log)) return nil, "", errors.Errorf("BroadcastTxCommit got non-zero exit code: %v. %X; %s", r.Code, r.Data, r.Log)
} }
return res.DeliverTx.Data, res.DeliverTx.Log, nil return res.DeliverTx.Data, res.DeliverTx.Log, nil

View File

@ -13,6 +13,7 @@ import (
"github.com/tendermint/basecoin/types" "github.com/tendermint/basecoin/types"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
cmn "github.com/tendermint/go-common"
client "github.com/tendermint/go-rpc/client" client "github.com/tendermint/go-rpc/client"
wire "github.com/tendermint/go-wire" wire "github.com/tendermint/go-wire"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
@ -33,6 +34,19 @@ func BasecoinRoot(rootDir string) string {
return rootDir return rootDir
} }
//Add debugging flag and execute the root command
func ExecuteWithDebug(RootCmd *cobra.Command) {
var debug bool
RootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enables stack trace error messages")
//note that Execute() prints the error if encountered, so no need to reprint the error,
// only if we want the full stack trace
if err := RootCmd.Execute(); err != nil && debug {
cmn.Exit(fmt.Sprintf("%+v\n", err))
}
}
type Flag2Register struct { type Flag2Register struct {
Pointer interface{} Pointer interface{}
Use string Use string
@ -117,11 +131,11 @@ func Query(tmAddr string, key []byte) (*abci.ResponseQuery, error) {
} }
_, err := uriClient.Call("abci_query", params, tmResult) _, err := uriClient.Call("abci_query", params, tmResult)
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Error calling /abci_query: %v", err)) return nil, errors.Errorf("Error calling /abci_query: %v", err)
} }
res := (*tmResult).(*ctypes.ResultABCIQuery) res := (*tmResult).(*ctypes.ResultABCIQuery)
if !res.Response.Code.IsOK() { if !res.Response.Code.IsOK() {
return nil, errors.New(fmt.Sprintf("Query got non-zero exit code: %v. %s", res.Response.Code, res.Response.Log)) return nil, errors.Errorf("Query got non-zero exit code: %v. %s", res.Response.Code, res.Response.Log)
} }
return &res.Response, nil return &res.Response, nil
} }
@ -138,14 +152,14 @@ func getAcc(tmAddr string, address []byte) (*types.Account, error) {
accountBytes := response.Value accountBytes := response.Value
if len(accountBytes) == 0 { if len(accountBytes) == 0 {
return nil, errors.New(fmt.Sprintf("Account bytes are empty for address: %X ", address)) return nil, fmt.Errorf("Account bytes are empty for address: %X ", address) //never stack trace
} }
var acc *types.Account var acc *types.Account
err = wire.ReadBinaryBytes(accountBytes, &acc) err = wire.ReadBinaryBytes(accountBytes, &acc)
if err != nil { if err != nil {
return nil, errors.New(fmt.Sprintf("Error reading account %X error: %v", return nil, errors.Errorf("Error reading account %X error: %v",
accountBytes, err.Error())) accountBytes, err.Error())
} }
return acc, nil return acc, nil
@ -158,7 +172,7 @@ func getHeaderAndCommit(tmAddr string, height int) (*tmtypes.Header, *tmtypes.Co
method := "commit" method := "commit"
_, err := uriClient.Call(method, map[string]interface{}{"height": height}, tmResult) _, err := uriClient.Call(method, map[string]interface{}{"height": height}, tmResult)
if err != nil { if err != nil {
return nil, nil, errors.New(fmt.Sprintf("Error on %s: %v", method, err)) return nil, nil, errors.Errorf("Error on %s: %v", method, err)
} }
resCommit := (*tmResult).(*ctypes.ResultCommit) resCommit := (*tmResult).(*ctypes.ResultCommit)
header := resCommit.Header header := resCommit.Header

View File

@ -9,14 +9,13 @@ import (
"github.com/tendermint/basecoin/cmd/commands" "github.com/tendermint/basecoin/cmd/commands"
"github.com/tendermint/basecoin/plugins/counter" "github.com/tendermint/basecoin/plugins/counter"
"github.com/tendermint/basecoin/types" "github.com/tendermint/basecoin/types"
cmn "github.com/tendermint/go-common"
) )
//commands //commands
var CounterTxCmd = &cobra.Command{ var CounterTxCmd = &cobra.Command{
Use: "counter", Use: "counter",
Short: "Create, sign, and broadcast a transaction to the counter plugin", Short: "Create, sign, and broadcast a transaction to the counter plugin",
Run: counterTxCmd, RunE: counterTxCmd,
} }
//flags //flags
@ -34,11 +33,11 @@ func init() {
commands.RegisterStartPlugin("counter", func() types.Plugin { return counter.New() }) commands.RegisterStartPlugin("counter", func() types.Plugin { return counter.New() })
} }
func counterTxCmd(cmd *cobra.Command, args []string) { func counterTxCmd(cmd *cobra.Command, args []string) error {
countFee, err := commands.ParseCoins(countFeeFlag) countFee, err := commands.ParseCoins(countFeeFlag)
if err != nil { if err != nil {
cmn.Exit(fmt.Sprintf("%+v\n", err)) return err
} }
counterTx := counter.CounterTx{ counterTx := counter.CounterTx{
@ -51,5 +50,5 @@ func counterTxCmd(cmd *cobra.Command, args []string) {
data := wire.BinaryBytes(counterTx) data := wire.BinaryBytes(counterTx)
name := "counter" name := "counter"
commands.AppTx(name, data) return commands.AppTx(name, data)
} }

View File

@ -1,9 +1,6 @@
package main package main
import ( import (
"fmt"
"os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/tendermint/basecoin/cmd/commands" "github.com/tendermint/basecoin/cmd/commands"
@ -27,8 +24,5 @@ func main() {
commands.QuickVersionCmd("0.1.0"), commands.QuickVersionCmd("0.1.0"),
) )
if err := RootCmd.Execute(); err != nil { commands.ExecuteWithDebug(RootCmd)
fmt.Println(err)
os.Exit(1)
}
} }

View File

@ -46,10 +46,7 @@ func main() {
) )
//Run the root command //Run the root command
if err := RootCmd.Execute(); err != nil { commands.ExecuteWithDebug(RootCmd)
fmt.Println(err)
os.Exit(1)
}
} }
``` ```
@ -71,7 +68,7 @@ var (
ExamplePluginTxCmd = &cobra.Command{ ExamplePluginTxCmd = &cobra.Command{
Use: "example", Use: "example",
Short: "Create, sign, and broadcast a transaction to the example plugin", Short: "Create, sign, and broadcast a transaction to the example plugin",
Run: examplePluginTxCmd, RunE: examplePluginTxCmd,
} }
) )
``` ```
@ -98,10 +95,10 @@ func init() {
We now define the actual function which is called by our CLI command. We now define the actual function which is called by our CLI command.
```golang ```golang
func examplePluginTxCmd(cmd *cobra.Command, args []string) { func examplePluginTxCmd(cmd *cobra.Command, args []string) error {
exampleTx := ExamplePluginTx{validFlag} exampleTx := ExamplePluginTx{validFlag}
exampleTxBytes := wire.BinaryBytes(exampleTx) exampleTxBytes := wire.BinaryBytes(exampleTx)
commands.AppTx("example-plugin", exampleTxBytes) return commands.AppTx("example-plugin", exampleTxBytes)
} }
``` ```

View File

@ -13,7 +13,8 @@ You may also want to see the tutorials on [a simple example plugin](example-plug
and the list of [more advanced plugins](more-examples.md). and the list of [more advanced plugins](more-examples.md).
The IBC plugin defines a new set of transactions as subtypes of the `AppTx`. The IBC plugin defines a new set of transactions as subtypes of the `AppTx`.
The plugin's functionality is accessed by setting the `AppTx.Name` field to `"IBC"`, and setting the `Data` field to the serialized IBC transaction type. The plugin's functionality is accessed by setting the `AppTx.Name` field to `"IBC"`,
and setting the `Data` field to the serialized IBC transaction type.
We'll demonstrate exactly how this works below. We'll demonstrate exactly how this works below.
@ -33,7 +34,8 @@ contains the votes responsible for committing the previous block, and a field
in the block header called `AppHash`, which refers to the Merkle root hash of in the block header called `AppHash`, which refers to the Merkle root hash of
the application after processing the transactions from the previous block. So, the application after processing the transactions from the previous block. So,
if we want to verify the `AppHash` from height H, we need the signatures from `LastCommit` if we want to verify the `AppHash` from height H, we need the signatures from `LastCommit`
at height H+1. (And remember that this `AppHash` only contains the results from all transactions up to and including block H-1) at height H+1. (And remember that this `AppHash` only contains the results from all
transactions up to and including block H-1)
Unlike Proof-of-Work, the light-client protocol does not need to download and Unlike Proof-of-Work, the light-client protocol does not need to download and
check all the headers in the blockchain - the client can always jump straight check all the headers in the blockchain - the client can always jump straight

View File

@ -17,7 +17,7 @@ var (
ExamplePluginTxCmd = &cobra.Command{ ExamplePluginTxCmd = &cobra.Command{
Use: "example", Use: "example",
Short: "Create, sign, and broadcast a transaction to the example plugin", Short: "Create, sign, and broadcast a transaction to the example plugin",
Run: examplePluginTxCmd, RunE: examplePluginTxCmd,
} }
) )
@ -35,7 +35,7 @@ func init() {
} }
//Send a transaction //Send a transaction
func examplePluginTxCmd(cmd *cobra.Command, args []string) { func examplePluginTxCmd(cmd *cobra.Command, args []string) error {
// Create a transaction using the flag. // Create a transaction using the flag.
// The tx passes on custom information to the plugin // The tx passes on custom information to the plugin
@ -58,5 +58,5 @@ func examplePluginTxCmd(cmd *cobra.Command, args []string) {
// - Once deserialized, the tx is passed to `state.ExecTx` (state/execution.go) // - Once deserialized, the tx is passed to `state.ExecTx` (state/execution.go)
// - If the tx passes various checks, the `tx.Data` is forwarded as `txBytes` to `plugin.RunTx` (docs/guide/src/example-plugin/plugin.go) // - If the tx passes various checks, the `tx.Data` is forwarded as `txBytes` to `plugin.RunTx` (docs/guide/src/example-plugin/plugin.go)
// - Finally, it deserialized back to the ExamplePluginTx // - Finally, it deserialized back to the ExamplePluginTx
commands.AppTx("example-plugin", exampleTxBytes) return commands.AppTx("example-plugin", exampleTxBytes)
} }

View File

@ -1,9 +1,6 @@
package main package main
import ( import (
"fmt"
"os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/tendermint/basecoin/cmd/commands" "github.com/tendermint/basecoin/cmd/commands"
@ -31,8 +28,5 @@ func main() {
) )
//Run the root command //Run the root command
if err := RootCmd.Execute(); err != nil { commands.ExecuteWithDebug(RootCmd)
fmt.Println(err)
os.Exit(1)
}
} }

2
glide.lock generated
View File

@ -89,7 +89,7 @@ imports:
subpackages: subpackages:
- upnp - upnp
- name: github.com/tendermint/go-rpc - name: github.com/tendermint/go-rpc
version: fcea0cda21f64889be00a0f4b6d13266b1a76ee7 version: c3295f4878019ff3fdfcac37a4c0e4bcf4bb02a7
subpackages: subpackages:
- client - client
- server - server

View File

@ -11,7 +11,7 @@ import:
- package: github.com/tendermint/go-data - package: github.com/tendermint/go-data
version: master version: master
- package: github.com/tendermint/go-rpc - package: github.com/tendermint/go-rpc
version: master version: develop
- package: github.com/tendermint/go-wire - package: github.com/tendermint/go-wire
version: master version: master
- package: github.com/tendermint/merkleeyes - package: github.com/tendermint/merkleeyes

View File

@ -9,7 +9,7 @@ import (
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
. "github.com/tendermint/go-common" cmn "github.com/tendermint/go-common"
"github.com/tendermint/go-rpc/client" "github.com/tendermint/go-rpc/client"
"github.com/tendermint/go-rpc/types" "github.com/tendermint/go-rpc/types"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
@ -21,7 +21,7 @@ func main() {
_, err := ws.Start() _, err := ws.Start()
if err != nil { if err != nil {
Exit(err.Error()) cmn.Exit(err.Error())
} }
// Read a bunch of responses // Read a bunch of responses
@ -50,7 +50,7 @@ func main() {
reqBytes := wire.JSONBytes(request) reqBytes := wire.JSONBytes(request)
err = ws.WriteMessage(websocket.TextMessage, reqBytes) err = ws.WriteMessage(websocket.TextMessage, reqBytes)
if err != nil { if err != nil {
Exit("writing websocket request: " + err.Error()) cmn.Exit("writing websocket request: " + err.Error())
} }
} }

View File

@ -72,7 +72,7 @@ func main() {
// Write request // Write request
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx}) txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx_sync", cmn.Arr(txBytes)) request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx_sync", map[string]interface{}{"tx": txBytes})
//request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx_sync", map[string]interface{}{"tx": txBytes}) //request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx_sync", map[string]interface{}{"tx": txBytes})
reqBytes := wire.JSONBytes(request) reqBytes := wire.JSONBytes(request)
//fmt.Print(".") //fmt.Print(".")
@ -123,7 +123,7 @@ func main() {
// Write request // Write request
txBytes := wire.BinaryBytes(struct{ types.Tx }{tx}) txBytes := wire.BinaryBytes(struct{ types.Tx }{tx})
request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx_sync", cmn.Arr(txBytes)) request := rpctypes.NewRPCRequest("fakeid", "broadcast_tx_sync", map[string]interface{}{"tx": txBytes})
reqBytes := wire.JSONBytes(request) reqBytes := wire.JSONBytes(request)
//fmt.Print(".") //fmt.Print(".")
err := ws.WriteMessage(websocket.TextMessage, reqBytes) err := ws.WriteMessage(websocket.TextMessage, reqBytes)