Create new command, countercli, removed counter from basecli
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
package counter
|
||||
|
||||
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
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package counter
|
||||
|
||||
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())
|
||||
}
|
||||
+2
-9
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/tendermint/tmlibs/cli"
|
||||
|
||||
bcmd "github.com/tendermint/basecoin/cmd/basecli/commands"
|
||||
bcount "github.com/tendermint/basecoin/cmd/basecli/counter"
|
||||
)
|
||||
|
||||
// BaseCli represents the base command when called without any subcommands
|
||||
@@ -34,21 +33,15 @@ func main() {
|
||||
|
||||
// Prepare queries
|
||||
pr := proofs.RootCmd
|
||||
// These are default parsers, but you optional in your app
|
||||
// These are default parsers, but optional in your app (you can remove key)
|
||||
pr.AddCommand(proofs.TxCmd)
|
||||
pr.AddCommand(proofs.KeyCmd)
|
||||
pr.AddCommand(bcmd.AccountQueryCmd)
|
||||
pr.AddCommand(bcount.CounterQueryCmd)
|
||||
|
||||
// Here is how you add custom txs... but don't really add counter in your app
|
||||
// you will always want this for the base send command
|
||||
proofs.TxPresenters.Register("base", bcmd.BaseTxPresenter{})
|
||||
tr := txs.RootCmd
|
||||
tr.AddCommand(bcmd.SendTxCmd)
|
||||
tr.AddCommand(bcount.CounterTxCmd)
|
||||
|
||||
// TODO
|
||||
// txs.Register("send", bcmd.SendTxMaker{})
|
||||
// txs.Register("counter", bcount.CounterTxMaker{})
|
||||
|
||||
// Set up the various commands to use
|
||||
BaseCli.AddCommand(
|
||||
|
||||
Reference in New Issue
Block a user