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

Feature/cli cleanup aka confuse rigel #176

Merged
merged 22 commits into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7b0934b
Ripped about cmd logic to make middleware modular
ethanfrey Jul 18, 2017
a060bde
Add more flags to help with multisig
ethanfrey Jul 18, 2017
f41aed4
Cleanup nonce parsing for multiple keys
ethanfrey Jul 18, 2017
a9e4a94
Moved all commands from light-client into basecoin
ethanfrey Jul 18, 2017
d9c39ff
Bring more cli tests from light-client
ethanfrey Jul 18, 2017
eb495e0
Move commands to client/commands
ethanfrey Jul 18, 2017
1005220
Moved cmd/basecli/commands into client/commands
ethanfrey Jul 18, 2017
b486ed3
Merge pull request #174 from tendermint/feature/train-wreck-light-client
ethanfrey Jul 18, 2017
942506c
basecli tx handles json input
ethanfrey Jul 18, 2017
0a9460d
auto-sequencing
rigelrozanski Jul 19, 2017
8617841
errors cleanup
rigelrozanski Jul 19, 2017
ac1ecc1
new library orders
rigelrozanski Jul 19, 2017
f7fb30f
final PR update
rigelrozanski Jul 19, 2017
d712d6f
Fixed imports in main.go
ethanfrey Jul 19, 2017
29273e5
Merge pull request #177 from tendermint/feature/104-autoseq
ethanfrey Jul 19, 2017
e7da4c2
Add support for --prepare to store tx for multisig
ethanfrey Jul 19, 2017
a12d866
--sequence=-1 broken if no sequence yet
ethanfrey Jul 19, 2017
737e374
rigel: Handle auto-sequence when nonce=0
ethanfrey Jul 19, 2017
911dd14
Add roles wrapper/tx/query command to basecoin
ethanfrey Jul 19, 2017
63fc25e
Add roles cli test, coin query supports multiple apps in actor
ethanfrey Jul 19, 2017
5f1d98b
Tested sending 1 sig from role
ethanfrey Jul 19, 2017
44f6696
Proper tests for accessing a multi-sig account
ethanfrey Jul 19, 2017
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
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ dist:
benchmark:
@go test -bench=. ./modules/...

test: test_unit test_cli test_tutorial
#test: test_unit test_cli test_tutorial
test: test_unit test_cli

test_unit:
@go test `glide novendor`
#go run tests/tendermint/*.go

test_cli: tests/cli/shunit2
# sudo apt-get install jq
./tests/cli/keys.sh
./tests/cli/rpc.sh
./tests/cli/init.sh
./tests/cli/basictx.sh
./tests/cli/roles.sh
./tests/cli/counter.sh
./tests/cli/restart.sh
# @./tests/cli/ibc.sh
Expand Down
17 changes: 13 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/tendermint/basecoin/modules/coin"
"github.com/tendermint/basecoin/modules/fee"
"github.com/tendermint/basecoin/modules/nonce"
"github.com/tendermint/basecoin/modules/roles"
"github.com/tendermint/basecoin/stack"
sm "github.com/tendermint/basecoin/state"
"github.com/tendermint/basecoin/version"
Expand Down Expand Up @@ -56,14 +57,19 @@ func NewBasecoin(handler basecoin.Handler, eyesCli *eyes.Client, logger log.Logg
// DefaultHandler - placeholder to just handle sendtx
func DefaultHandler(feeDenom string) basecoin.Handler {
// use the default stack
h := coin.NewHandler()
d := stack.NewDispatcher(stack.WrapHandler(h))
c := coin.NewHandler()
r := roles.NewHandler()
d := stack.NewDispatcher(
stack.WrapHandler(c),
stack.WrapHandler(r),
)
return stack.New(
base.Logger{},
stack.Recovery{},
auth.Signatures{},
base.Chain{},
nonce.ReplayCheck{},
roles.NewMiddleware(),
fee.NewSimpleFeeMiddleware(coin.Coin{feeDenom, 0}, fee.Bank),
).Use(d)
}
Expand Down Expand Up @@ -139,19 +145,22 @@ func (app *Basecoin) CheckTx(txBytes []byte) abci.Result {
return errors.Result(err)
}

// TODO: can we abstract this setup and commit logic??
// we also need to discard error changes, so we don't increment checktx
// sequence on error, but not delivertx
cache := app.cacheState.CacheWrap()
ctx := stack.NewContext(
app.state.GetChainID(),
app.height,
app.logger.With("call", "checktx"),
)
// checktx generally shouldn't touch the state, but we don't care
// here on the framework level, since the cacheState is thrown away next block
res, err := app.handler.CheckTx(ctx, app.cacheState, tx)
res, err := app.handler.CheckTx(ctx, cache, tx)

if err != nil {
return errors.Result(err)
}
cache.CacheSync()
return res.ToABCI()
}

Expand Down
4 changes: 3 additions & 1 deletion app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/basecoin/modules/coin"

eyescli "github.com/tendermint/merkleeyes/client"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"

"github.com/tendermint/basecoin/modules/coin"
)

const genesisFilepath = "./testdata/genesis.json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package auto

import (
"os"
Expand Down
141 changes: 141 additions & 0 deletions client/commands/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
Package commands contains any general setup/helpers valid for all subcommands
*/
package commands

import (
"encoding/hex"
"strings"

"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/tendermint/light-client/certifiers"
"github.com/tendermint/light-client/certifiers/client"
"github.com/tendermint/light-client/certifiers/files"
"github.com/tendermint/tmlibs/cli"
cmn "github.com/tendermint/tmlibs/common"

rpcclient "github.com/tendermint/tendermint/rpc/client"

"github.com/tendermint/basecoin"
"github.com/tendermint/basecoin/modules/auth"
)

var (
trustedProv certifiers.Provider
sourceProv certifiers.Provider
)

const (
ChainFlag = "chain-id"
NodeFlag = "node"
)

// AddBasicFlags adds --node and --chain-id, which we need for everything
func AddBasicFlags(cmd *cobra.Command) {
cmd.PersistentFlags().String(ChainFlag, "", "Chain ID of tendermint node")
cmd.PersistentFlags().String(NodeFlag, "", "<host>:<port> to tendermint rpc interface for this chain")
}

// GetChainID reads ChainID from the flags
func GetChainID() string {
return viper.GetString(ChainFlag)
}

// GetNode prepares a simple rpc.Client from the flags
func GetNode() rpcclient.Client {
return rpcclient.NewHTTP(viper.GetString(NodeFlag), "/websocket")
}

// GetProviders creates a trusted (local) seed provider and a remote
// provider based on configuration.
func GetProviders() (trusted certifiers.Provider, source certifiers.Provider) {
if trustedProv == nil || sourceProv == nil {
// initialize provider with files stored in homedir
rootDir := viper.GetString(cli.HomeFlag)
trustedProv = certifiers.NewCacheProvider(
certifiers.NewMemStoreProvider(),
files.NewProvider(rootDir),
)
node := viper.GetString(NodeFlag)
sourceProv = client.NewHTTP(node)
}
return trustedProv, sourceProv
}

// GetCertifier constructs a dynamic certifier from the config info
func GetCertifier() (*certifiers.InquiringCertifier, error) {
// load up the latest store....
trust, source := GetProviders()

// this gets the most recent verified seed
seed, err := certifiers.LatestSeed(trust)
if certifiers.IsSeedNotFoundErr(err) {
return nil, errors.New("Please run init first to establish a root of trust")
}
if err != nil {
return nil, err
}
cert := certifiers.NewInquiring(
viper.GetString(ChainFlag), seed.Validators, trust, source)
return cert, nil
}

// ParseActor parses an address of form:
// [<chain>:][<app>:]<hex address>
// into a basecoin.Actor.
// If app is not specified or "", then assume auth.NameSigs
func ParseActor(input string) (res basecoin.Actor, err error) {
chain, app := "", auth.NameSigs
input = strings.TrimSpace(input)
spl := strings.SplitN(input, ":", 3)

if len(spl) == 3 {
chain = spl[0]
spl = spl[1:]
}
if len(spl) == 2 {
if spl[0] != "" {
app = spl[0]
}
spl = spl[1:]
}

addr, err := hex.DecodeString(cmn.StripHex(spl[0]))
if err != nil {
return res, errors.Errorf("Address is invalid hex: %v\n", err)
}
res = basecoin.Actor{
ChainID: chain,
App: app,
Address: addr,
}
return
}

// ParseActors takes a comma-separated list of actors and parses them into
// a slice
func ParseActors(key string) (signers []basecoin.Actor, err error) {
var act basecoin.Actor
for _, k := range strings.Split(key, ",") {
act, err = ParseActor(k)
if err != nil {
return
}
signers = append(signers, act)
}
return
}

// GetOneArg makes sure there is exactly one positional argument
func GetOneArg(args []string, argname string) (string, error) {
if len(args) == 0 {
return "", errors.Errorf("Missing required argument [%s]", argname)
}
if len(args) > 1 {
return "", errors.Errorf("Only accepts one argument [%s]", argname)
}
return args[0], nil
}
Loading