update docs, move counter

int

int

int
This commit is contained in:
rigel rozanski
2017-06-18 19:01:54 -04:00
parent 7dad89b152
commit 24bd0f5ed6
15 changed files with 395 additions and 354 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ func (a *AppTx) AddSigner(pk crypto.PubKey) {
// but that code is too ugly now, needs refactor..
func (a *AppTx) ValidateBasic() error {
if a.chainID == "" {
return errors.New("No chainId specified")
return errors.New("No chain-id specified")
}
in := a.Tx.Input
if len(in.Address) != 20 {
+1 -1
View File
@@ -80,7 +80,7 @@ func (s *SendTx) AddSigner(pk crypto.PubKey) {
// but that code is too ugly now, needs refactor..
func (s *SendTx) ValidateBasic() error {
if s.chainID == "" {
return errors.New("No chainId specified")
return errors.New("No chain-id specified")
}
for _, in := range s.Tx.Inputs {
if len(in.Address) != 20 {
-11
View File
@@ -1,11 +0,0 @@
package main
import (
"github.com/tendermint/basecoin/cmd/commands"
"github.com/tendermint/basecoin/plugins/counter"
"github.com/tendermint/basecoin/types"
)
func init() {
commands.RegisterStartPlugin("counter", func() types.Plugin { return counter.New() })
}
-27
View File
@@ -1,27 +0,0 @@
package main
import (
"os"
"github.com/spf13/cobra"
"github.com/tendermint/basecoin/cmd/commands"
"github.com/tendermint/tmlibs/cli"
)
func main() {
var RootCmd = &cobra.Command{
Use: "counter",
Short: "demo plugin for basecoin",
}
RootCmd.AddCommand(
commands.InitCmd,
commands.StartCmd,
commands.UnsafeResetAllCmd,
commands.VersionCmd,
)
cmd := cli.PrepareMainCmd(RootCmd, "BC", os.ExpandEnv("$HOME/.basecoin"))
cmd.Execute()
}
-83
View File
@@ -1,83 +0,0 @@
package commands
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
wire "github.com/tendermint/go-wire"
txcmd "github.com/tendermint/light-client/commands/txs"
bcmd "github.com/tendermint/basecoin/cmd/basecli/commands"
"github.com/tendermint/basecoin/plugins/counter"
btypes "github.com/tendermint/basecoin/types"
)
//CounterTxCmd is the CLI command to execute the counter
// through the appTx Command
var CounterTxCmd = &cobra.Command{
Use: "counter",
Short: "add a vote to the counter",
Long: `Add a vote to the counter.
You must pass --valid for it to count and the countfee will be added to the counter.`,
RunE: counterTxCmd,
}
const (
flagCountFee = "countfee"
flagValid = "valid"
)
func init() {
fs := CounterTxCmd.Flags()
bcmd.AddAppTxFlags(fs)
fs.String(flagCountFee, "", "Coins to send in the format <amt><coin>,<amt><coin>...")
fs.Bool(flagValid, false, "Is count valid?")
}
func counterTxCmd(cmd *cobra.Command, args []string) error {
// Note: we don't support loading apptx from json currently, so skip that
// Read the app-specific flags
name, data, err := getAppData()
if err != nil {
return err
}
// Read the standard app-tx flags
gas, fee, txInput, err := bcmd.ReadAppTxFlags()
if err != nil {
return err
}
// Create AppTx and broadcast
tx := &btypes.AppTx{
Gas: gas,
Fee: fee,
Name: name,
Input: txInput,
Data: data,
}
res, err := bcmd.BroadcastAppTx(tx)
if err != nil {
return err
}
// Output result
return txcmd.OutputTx(res)
}
func getAppData() (name string, data []byte, err error) {
countFee, err := btypes.ParseCoins(viper.GetString(flagCountFee))
if err != nil {
return
}
ctx := counter.CounterTx{
Valid: viper.GetBool(flagValid),
Fee: countFee,
}
name = counter.New().Name()
data = wire.BinaryBytes(ctx)
return
}
-28
View File
@@ -1,28 +0,0 @@
package commands
import (
"github.com/spf13/cobra"
proofcmd "github.com/tendermint/light-client/commands/proofs"
"github.com/tendermint/basecoin/plugins/counter"
)
//CounterQueryCmd CLI command to query the counter state
var CounterQueryCmd = &cobra.Command{
Use: "counter",
Short: "Query counter state, with proof",
RunE: counterQueryCmd,
}
func counterQueryCmd(cmd *cobra.Command, args []string) error {
key := counter.New().StateKey()
var cp counter.CounterPluginState
proof, err := proofcmd.GetAndParseAppProof(key, &cp)
if err != nil {
return err
}
return proofcmd.OutputProof(cp, proof.BlockHeight())
}
-64
View File
@@ -1,64 +0,0 @@
package main
import (
"os"
"github.com/spf13/cobra"
keycmd "github.com/tendermint/go-crypto/cmd"
"github.com/tendermint/light-client/commands"
"github.com/tendermint/light-client/commands/proofs"
"github.com/tendermint/light-client/commands/proxy"
"github.com/tendermint/light-client/commands/seeds"
"github.com/tendermint/light-client/commands/txs"
"github.com/tendermint/tmlibs/cli"
bcmd "github.com/tendermint/basecoin/cmd/basecli/commands"
bcount "github.com/tendermint/basecoin/cmd/countercli/commands"
)
// BaseCli represents the base command when called without any subcommands
var BaseCli = &cobra.Command{
Use: "basecli",
Short: "Light client for tendermint",
Long: `Basecli is an version of tmcli including custom logic to
present a nice (not raw hex) interface to the basecoin blockchain structure.
This is a useful tool, but also serves to demonstrate how one can configure
tmcli to work for any custom abci app.
`,
}
func main() {
commands.AddBasicFlags(BaseCli)
// Prepare queries
pr := proofs.RootCmd
// These are default parsers, but you optional in your app
pr.AddCommand(proofs.TxCmd)
pr.AddCommand(proofs.KeyCmd)
pr.AddCommand(bcmd.AccountQueryCmd)
// IMPORTANT: here is how you add custom query commands in your app
pr.AddCommand(bcount.CounterQueryCmd)
proofs.TxPresenters.Register("base", bcmd.BaseTxPresenter{})
tr := txs.RootCmd
tr.AddCommand(bcmd.SendTxCmd)
// IMPORTANT: here is how you add custom tx construction for your app
tr.AddCommand(bcount.CounterTxCmd)
// Set up the various commands to use
BaseCli.AddCommand(
commands.InitCmd,
commands.ResetCmd,
keycmd.RootCmd,
seeds.RootCmd,
pr,
tr,
proxy.RootCmd)
cmd := cli.PrepareMainCmd(BaseCli, "BC", os.ExpandEnv("$HOME/.basecli"))
cmd.Execute()
}