Fix basecoin cli to newest tendermint develop (0.10)
This commit is contained in:
parent
354ea8ffd7
commit
73435303af
@ -1,9 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/tendermint/basecoin/cmd/commands"
|
||||
"github.com/tendermint/tmlibs/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -25,5 +28,6 @@ func main() {
|
||||
commands.VersionCmd,
|
||||
)
|
||||
|
||||
commands.ExecuteWithDebug(RootCmd)
|
||||
cmd := cli.PrepareMainCmd(RootCmd, "BC", os.ExpandEnv("$HOME/.basecoin"))
|
||||
cmd.Execute()
|
||||
}
|
||||
|
||||
@ -6,7 +6,9 @@ import (
|
||||
"path"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/tendermint/tmlibs/cli"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
)
|
||||
|
||||
@ -33,8 +35,7 @@ func setupFile(path, data string, perm os.FileMode) (int, error) {
|
||||
}
|
||||
|
||||
func initCmd(cmd *cobra.Command, args []string) error {
|
||||
rootDir := BasecoinRoot("")
|
||||
|
||||
rootDir := viper.GetString(cli.HomeFlag)
|
||||
cmn.EnsureDir(rootDir, 0777)
|
||||
|
||||
// initalize basecoin
|
||||
|
||||
@ -10,8 +10,10 @@ import (
|
||||
|
||||
//"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/tendermint/go-crypto"
|
||||
"github.com/tendermint/tmlibs/cli"
|
||||
)
|
||||
|
||||
//commands
|
||||
@ -87,7 +89,8 @@ func genKey() *Key {
|
||||
}
|
||||
|
||||
func LoadKey(keyFile string) (*Key, error) {
|
||||
filePath := path.Join(BasecoinRoot(""), keyFile)
|
||||
rootDir := viper.GetString(cli.HomeFlag)
|
||||
filePath := path.Join(rootDir, keyFile)
|
||||
keyJSONBytes, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
|
||||
tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||
tmcfg "github.com/tendermint/tendermint/config/tendermint"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tmlibs/cli"
|
||||
)
|
||||
|
||||
var UnsafeResetAllCmd = &cobra.Command{
|
||||
@ -14,8 +17,9 @@ var UnsafeResetAllCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func unsafeResetAllCmd(cmd *cobra.Command, args []string) error {
|
||||
basecoinDir := BasecoinRoot("")
|
||||
tmConfig := tmcfg.GetConfig(basecoinDir)
|
||||
tmcmd.ResetAll(tmConfig, log)
|
||||
rootDir := viper.GetString(cli.HomeFlag)
|
||||
// wipe out rootdir if it exists before recreating it
|
||||
os.RemoveAll(rootDir)
|
||||
config.EnsureRoot(rootDir)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -7,12 +7,15 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/tendermint/abci/server"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
eyes "github.com/tendermint/merkleeyes/client"
|
||||
"github.com/tendermint/tmlibs/cli"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
"github.com/tendermint/tmlibs/logger"
|
||||
|
||||
tmcfg "github.com/tendermint/tendermint/config/tendermint"
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/node"
|
||||
"github.com/tendermint/tendermint/proxy"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
@ -49,12 +52,12 @@ func init() {
|
||||
}
|
||||
|
||||
func startCmd(cmd *cobra.Command, args []string) error {
|
||||
basecoinDir := BasecoinRoot("")
|
||||
rootDir := viper.GetString(cli.HomeFlag)
|
||||
|
||||
// Connect to MerkleEyes
|
||||
var eyesCli *eyes.Client
|
||||
if eyesFlag == "local" {
|
||||
eyesCli = eyes.NewLocalClient(path.Join(basecoinDir, "data", "merkleeyes.db"), EyesCacheSize)
|
||||
eyesCli = eyes.NewLocalClient(path.Join(rootDir, "data", "merkleeyes.db"), EyesCacheSize)
|
||||
} else {
|
||||
var err error
|
||||
eyesCli, err = eyes.NewClient(eyesFlag)
|
||||
@ -78,7 +81,7 @@ func startCmd(cmd *cobra.Command, args []string) error {
|
||||
// else, assume it's been loaded
|
||||
if basecoinApp.GetState().GetChainID() == "" {
|
||||
// If genesis file exists, set key-value options
|
||||
genesisFile := path.Join(basecoinDir, "genesis.json")
|
||||
genesisFile := path.Join(rootDir, "genesis.json")
|
||||
if _, err := os.Stat(genesisFile); err == nil {
|
||||
err := basecoinApp.LoadGenesis(genesisFile)
|
||||
if err != nil {
|
||||
@ -97,12 +100,11 @@ func startCmd(cmd *cobra.Command, args []string) error {
|
||||
} else {
|
||||
log.Notice("Starting Basecoin with Tendermint", "chain_id", chainID)
|
||||
// start the app with tendermint in-process
|
||||
return startTendermint(basecoinDir, basecoinApp)
|
||||
return startTendermint(rootDir, basecoinApp)
|
||||
}
|
||||
}
|
||||
|
||||
func startBasecoinABCI(basecoinApp *app.Basecoin) error {
|
||||
|
||||
// Start the ABCI listener
|
||||
svr, err := server.NewServer(addrFlag, "socket", basecoinApp)
|
||||
if err != nil {
|
||||
@ -118,18 +120,20 @@ func startBasecoinABCI(basecoinApp *app.Basecoin) error {
|
||||
}
|
||||
|
||||
func startTendermint(dir string, basecoinApp *app.Basecoin) error {
|
||||
|
||||
// Get configuration
|
||||
tmConfig := tmcfg.GetConfig(dir)
|
||||
// logger.SetLogLevel("notice") //config.GetString("log_level"))
|
||||
// parseFlags(config, args[1:]) // Command line overrides
|
||||
cfg := config.DefaultConfig()
|
||||
err := viper.Unmarshal(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.SetRoot(cfg.RootDir)
|
||||
config.EnsureRoot(cfg.RootDir)
|
||||
logger.SetLogLevel(cfg.LogLevel)
|
||||
|
||||
// Create & start tendermint node
|
||||
privValidatorFile := tmConfig.GetString("priv_validator_file")
|
||||
privValidator := tmtypes.LoadOrGenPrivValidator(privValidatorFile)
|
||||
n := node.NewNode(tmConfig, privValidator, proxy.NewLocalClientCreator(basecoinApp))
|
||||
privValidator := tmtypes.LoadOrGenPrivValidator(cfg.PrivValidator)
|
||||
n := node.NewNode(cfg, privValidator, proxy.NewLocalClientCreator(basecoinApp))
|
||||
|
||||
_, err := n.Start()
|
||||
_, err = n.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -9,9 +9,8 @@ import (
|
||||
|
||||
"github.com/tendermint/basecoin/types"
|
||||
|
||||
client "github.com/tendermint/tendermint/rpc/lib/client"
|
||||
wire "github.com/tendermint/go-wire"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
"github.com/tendermint/tendermint/rpc/client"
|
||||
)
|
||||
|
||||
//commands
|
||||
@ -193,23 +192,17 @@ func AppTx(name string, data []byte) error {
|
||||
|
||||
// broadcast the transaction to tendermint
|
||||
func broadcastTx(tx types.Tx) ([]byte, string, error) {
|
||||
|
||||
tmResult := new(ctypes.TMResult)
|
||||
uriClient := client.NewURIClient(txNodeFlag)
|
||||
|
||||
httpClient := client.NewHTTP(txNodeFlag, "/websocket")
|
||||
// Don't you hate having to do this?
|
||||
// How many times have I lost an hour over this trick?!
|
||||
txBytes := []byte(wire.BinaryBytes(struct {
|
||||
types.Tx `json:"unwrap"`
|
||||
}{tx}))
|
||||
|
||||
_, err := uriClient.Call("broadcast_tx_commit", map[string]interface{}{"tx": txBytes}, tmResult)
|
||||
res, err := httpClient.BroadcastTxCommit(txBytes)
|
||||
if err != nil {
|
||||
return nil, "", errors.Errorf("Error on broadcast tx: %v", err)
|
||||
}
|
||||
|
||||
res := (*tmResult).(*ctypes.ResultBroadcastTxCommit)
|
||||
|
||||
// if it fails check, we don't even get a delivertx back!
|
||||
if !res.CheckTx.Code.IsOK() {
|
||||
r := res.CheckTx
|
||||
|
||||
@ -3,8 +3,6 @@ package commands
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
@ -14,41 +12,11 @@ import (
|
||||
"github.com/tendermint/basecoin/types"
|
||||
|
||||
abci "github.com/tendermint/abci/types"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
client "github.com/tendermint/tendermint/rpc/lib/client"
|
||||
wire "github.com/tendermint/go-wire"
|
||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||
"github.com/tendermint/tendermint/rpc/client"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
//This variable can be overwritten by plugin applications
|
||||
// if they require a different working directory
|
||||
var DefaultHome = ".basecoin"
|
||||
|
||||
func BasecoinRoot(rootDir string) string {
|
||||
if rootDir == "" {
|
||||
rootDir = os.Getenv("BCHOME")
|
||||
}
|
||||
if rootDir == "" {
|
||||
rootDir = path.Join(os.Getenv("HOME"), DefaultHome)
|
||||
}
|
||||
return rootDir
|
||||
}
|
||||
|
||||
//Add debugging flag and execute the root command
|
||||
func ExecuteWithDebug(RootCmd *cobra.Command) {
|
||||
|
||||
var debug bool
|
||||
RootCmd.SilenceUsage = true
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
//Quickly registering flags can be quickly achieved through using the utility functions
|
||||
//RegisterFlags, and RegisterPersistentFlags. Ex:
|
||||
// flags := []Flag2Register{
|
||||
@ -130,24 +98,16 @@ func StripHex(s string) string {
|
||||
return s
|
||||
}
|
||||
|
||||
func Query(tmAddr string, key []byte) (*abci.ResponseQuery, error) {
|
||||
uriClient := client.NewURIClient(tmAddr)
|
||||
tmResult := new(ctypes.TMResult)
|
||||
|
||||
params := map[string]interface{}{
|
||||
"path": "/key",
|
||||
"data": key,
|
||||
"prove": true,
|
||||
}
|
||||
_, err := uriClient.Call("abci_query", params, tmResult)
|
||||
func Query(tmAddr string, key []byte) (*abci.ResultQuery, error) {
|
||||
httpClient := client.NewHTTP(tmAddr, "/websocket")
|
||||
res, err := httpClient.ABCIQuery("/key", key, true)
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("Error calling /abci_query: %v", err)
|
||||
}
|
||||
res := (*tmResult).(*ctypes.ResultABCIQuery)
|
||||
if !res.Response.Code.IsOK() {
|
||||
return nil, errors.Errorf("Query got non-zero exit code: %v. %s", res.Response.Code, res.Response.Log)
|
||||
if !res.Code.IsOK() {
|
||||
return nil, errors.Errorf("Query got non-zero exit code: %v. %s", res.Code, res.Log)
|
||||
}
|
||||
return &res.Response, nil
|
||||
return res.ResultQuery, nil
|
||||
}
|
||||
|
||||
// fetch the account by querying the app
|
||||
@ -176,17 +136,13 @@ func getAcc(tmAddr string, address []byte) (*types.Account, error) {
|
||||
}
|
||||
|
||||
func getHeaderAndCommit(tmAddr string, height int) (*tmtypes.Header, *tmtypes.Commit, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
||||
uriClient := client.NewURIClient(tmAddr)
|
||||
|
||||
method := "commit"
|
||||
_, err := uriClient.Call(method, map[string]interface{}{"height": height}, tmResult)
|
||||
httpClient := client.NewHTTP(tmAddr, "/websocket")
|
||||
res, err := httpClient.Commit(height)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Errorf("Error on %s: %v", method, err)
|
||||
return nil, nil, errors.Errorf("Error on commit: %v", err)
|
||||
}
|
||||
resCommit := (*tmResult).(*ctypes.ResultCommit)
|
||||
header := resCommit.Header
|
||||
commit := resCommit.Commit
|
||||
header := res.Header
|
||||
commit := res.Commit
|
||||
|
||||
return header, commit, nil
|
||||
}
|
||||
|
||||
69
glide.lock
generated
69
glide.lock
generated
@ -1,5 +1,5 @@
|
||||
hash: f4077fecc95e11f007adea022a38441a2e1c5d51d75ebab0fc9a296052ee5a6b
|
||||
updated: 2017-04-27T23:14:26.934716255+02:00
|
||||
hash: c887040d9aa1545d4d2c45db78032ab5e132c4eebed14e757573e7f7103fc162
|
||||
updated: 2017-04-27T20:02:48.730032774-04:00
|
||||
imports:
|
||||
- name: github.com/bgentry/speakeasy
|
||||
version: 4aabc24848ce5fd31929f7d1e4ea74d3709c14cd
|
||||
@ -7,6 +7,12 @@ imports:
|
||||
version: 4b348c1d33373d672edd83fc576892d0e46686d2
|
||||
subpackages:
|
||||
- btcec
|
||||
- name: github.com/BurntSushi/toml
|
||||
version: b26d9c308763d68093482582cea63d69be07a0f0
|
||||
- name: github.com/davecgh/go-spew
|
||||
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
|
||||
subpackages:
|
||||
- spew
|
||||
- name: github.com/ebuchman/fail-test
|
||||
version: 95f809107225be108efcf10a3509e4ea6ceef3c4
|
||||
- name: github.com/fsnotify/fsnotify
|
||||
@ -63,6 +69,10 @@ imports:
|
||||
version: 13d49d4606eb801b8f01ae542b4afc4c6ee3d84a
|
||||
- name: github.com/pkg/errors
|
||||
version: 645ef00459ed84a119197bfb8d8205042c6df63d
|
||||
- name: github.com/pmezard/go-difflib
|
||||
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
|
||||
subpackages:
|
||||
- difflib
|
||||
- name: github.com/spf13/afero
|
||||
version: 9be650865eab0c12963d8753212f4f9c66cdcf12
|
||||
subpackages:
|
||||
@ -77,6 +87,11 @@ imports:
|
||||
version: 2300d0f8576fe575f71aaa5b9bbe4e1b0dc2eb51
|
||||
- name: github.com/spf13/viper
|
||||
version: 5d46e70da8c0b6f812e0b170b7a985753b5c63cb
|
||||
- name: github.com/stretchr/testify
|
||||
version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0
|
||||
subpackages:
|
||||
- assert
|
||||
- require
|
||||
- name: github.com/syndtr/goleveldb
|
||||
version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4
|
||||
subpackages:
|
||||
@ -93,7 +108,7 @@ imports:
|
||||
- leveldb/table
|
||||
- leveldb/util
|
||||
- name: github.com/tendermint/abci
|
||||
version: c709d3cc857929a8dd36a90da3640122d7e75770
|
||||
version: 8d8e35ae537538c9cf6808be3ca9dd7dab81b7f6
|
||||
subpackages:
|
||||
- client
|
||||
- example/dummy
|
||||
@ -104,10 +119,8 @@ imports:
|
||||
subpackages:
|
||||
- edwards25519
|
||||
- extra25519
|
||||
- name: github.com/tendermint/go-common
|
||||
version: f9e3db037330c8a8d61d3966de8473eaf01154fa
|
||||
- name: github.com/tendermint/go-crypto
|
||||
version: 197a2b270fd94ee03824b158e738fce62862d0b8
|
||||
version: e71bbb2509b586f0b24f120b6ba57f32aefa1579
|
||||
subpackages:
|
||||
- cmd
|
||||
- keys
|
||||
@ -117,43 +130,29 @@ imports:
|
||||
- keys/server/types
|
||||
- keys/storage/filestorage
|
||||
- keys/storage/memstorage
|
||||
- name: github.com/tendermint/go-db
|
||||
version: 9643f60bc2578693844aacf380a7c32e4c029fee
|
||||
- name: github.com/tendermint/go-merkle
|
||||
version: 714d4d04557fd068a7c2a1748241ce8428015a96
|
||||
- name: github.com/tendermint/go-wire
|
||||
version: 334005c236d19c632fb5f073f9de3b0fab6a522b
|
||||
version: b53add0b622662731985485f3a19be7f684660b8
|
||||
subpackages:
|
||||
- data
|
||||
- data/base58
|
||||
- name: github.com/tendermint/light-client
|
||||
version: d13e97e756e914fe9c6c1b23ea639b51f1d5bf40
|
||||
subpackages:
|
||||
- certifiers
|
||||
- certifiers/client
|
||||
- certifiers/files
|
||||
- commands
|
||||
- commands/proofs
|
||||
- commands/seeds
|
||||
- commands/tx
|
||||
- commands/txs
|
||||
- proofs
|
||||
version: e55dc347586218ba5691267d3dc959c6f4943836
|
||||
- name: github.com/tendermint/log15
|
||||
version: ae0f3d6450da9eac7074b439c8e1c3cabf0d5ce6
|
||||
subpackages:
|
||||
- term
|
||||
- name: github.com/tendermint/merkleeyes
|
||||
version: d0aa363fd4e015e509038c3a0ec493bc62ee0b8a
|
||||
version: c722818b460381bc5b82e38c73ff6e22a9df624d
|
||||
subpackages:
|
||||
- app
|
||||
- client
|
||||
- iavl
|
||||
- testutil
|
||||
- name: github.com/tendermint/tendermint
|
||||
version: 1310c7264750efa8939680536098ded9f9e8df74
|
||||
version: d2ae7e164af0bb9eb3dbeec3e0b54bbee440f537
|
||||
subpackages:
|
||||
- blockchain
|
||||
- cmd/tendermint/commands
|
||||
- config/tendermint
|
||||
- config/tendermint_test
|
||||
- consensus
|
||||
- mempool
|
||||
- node
|
||||
@ -168,6 +167,7 @@ imports:
|
||||
- rpc/lib/client
|
||||
- rpc/lib/server
|
||||
- rpc/lib/types
|
||||
- rpc/test
|
||||
- state
|
||||
- state/txindex
|
||||
- state/txindex/kv
|
||||
@ -175,7 +175,7 @@ imports:
|
||||
- types
|
||||
- version
|
||||
- name: github.com/tendermint/tmlibs
|
||||
version: df250b69416a35a943a6e2a92118667e9ef031d4
|
||||
version: 706b9fbd671d5d49ecf1b2ea3bb34e51d61ff091
|
||||
subpackages:
|
||||
- autofile
|
||||
- clist
|
||||
@ -240,17 +240,4 @@ imports:
|
||||
version: 6d8c18553ea1ac493d049edd6f102f52e618f085
|
||||
- name: gopkg.in/yaml.v2
|
||||
version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b
|
||||
testImports:
|
||||
- name: github.com/davecgh/go-spew
|
||||
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
|
||||
subpackages:
|
||||
- spew
|
||||
- name: github.com/pmezard/go-difflib
|
||||
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
|
||||
subpackages:
|
||||
- difflib
|
||||
- name: github.com/stretchr/testify
|
||||
version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0
|
||||
subpackages:
|
||||
- assert
|
||||
- require
|
||||
testImports: []
|
||||
|
||||
Loading…
Reference in New Issue
Block a user