Add support for --fee in countercli

This commit is contained in:
Ethan Frey
2017-07-12 21:04:34 +02:00
parent c1fc5ae3c8
commit d6d1655ab1
7 changed files with 51 additions and 10 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ func main() {
}
// TODO: register the counter here
commands.Handler = counter.NewHandler()
commands.Handler = counter.NewHandler("mycoin")
RootCmd.AddCommand(
commands.InitCmd,
@@ -28,14 +28,15 @@ You must pass --valid for it to count and the countfee will be added to the coun
const (
FlagCountFee = "countfee"
FlagValid = "valid"
FlagSequence = "sequence" // FIXME: currently not supported...
)
func init() {
fs := CounterTxCmd.Flags()
fs.String(FlagCountFee, "", "Coins to send in the format <amt><coin>,<amt><coin>...")
fs.Bool(FlagValid, false, "Is count valid?")
fs.Int(FlagSequence, -1, "Sequence number for this transaction")
fs.String(bcmd.FlagFee, "0mycoin", "Coins for the transaction fee of the format <amt><coin>")
fs.Int(bcmd.FlagSequence, -1, "Sequence number for this transaction")
}
// TODO: counterTx is very similar to the sendtx one,
@@ -55,11 +56,15 @@ func counterTx(cmd *cobra.Command, args []string) error {
}
// TODO: make this more flexible for middleware
// add the chain info
tx, err = bcmd.WrapFeeTx(tx)
if err != nil {
return err
}
tx, err = bcmd.WrapChainTx(tx)
if err != nil {
return err
}
stx := auth.NewSig(tx)
// Sign if needed and post. This it the work-horse
@@ -78,6 +83,6 @@ func readCounterTxFlags() (tx basecoin.Tx, err error) {
return tx, err
}
tx = counter.NewTx(viper.GetBool(FlagValid), feeCoins, viper.GetInt(FlagSequence))
tx = counter.NewTx(viper.GetBool(FlagValid), feeCoins, viper.GetInt(bcmd.FlagSequence))
return tx, nil
}
@@ -11,6 +11,7 @@ import (
"github.com/tendermint/basecoin/modules/auth"
"github.com/tendermint/basecoin/modules/base"
"github.com/tendermint/basecoin/modules/coin"
"github.com/tendermint/basecoin/modules/fee"
"github.com/tendermint/basecoin/stack"
"github.com/tendermint/basecoin/state"
)
@@ -89,12 +90,12 @@ func ErrDecoding() error {
//--------------------------------------------------------------------------------
// NewHandler returns a new counter transaction processing handler
func NewHandler() basecoin.Handler {
func NewHandler(feeDenom string) basecoin.Handler {
// use the default stack
coin := coin.NewHandler()
ch := coin.NewHandler()
counter := Handler{}
dispatcher := stack.NewDispatcher(
stack.WrapHandler(coin),
stack.WrapHandler(ch),
counter,
)
return stack.New(
@@ -102,6 +103,7 @@ func NewHandler() basecoin.Handler {
stack.Recovery{},
auth.Signatures{},
base.Chain{},
fee.NewSimpleFeeMiddleware(coin.Coin{feeDenom, 0}, fee.Bank),
).Use(dispatcher)
}
@@ -27,7 +27,7 @@ func TestCounterPlugin(t *testing.T) {
logger := log.NewTMLogger(os.Stdout).With("module", "app")
// logger = log.NewTracingLogger(logger)
bcApp := app.NewBasecoin(
NewHandler(),
NewHandler("gold"),
eyesCli,
logger,
)