Add support for --fee in countercli
This commit is contained in:
parent
c1fc5ae3c8
commit
d6d1655ab1
@ -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,
|
||||
)
|
||||
|
||||
@ -63,7 +63,7 @@ test02SendTxWithFee() {
|
||||
checkAccount $RECV "1082"
|
||||
|
||||
# Make sure tx is indexed
|
||||
# checkSendFeeTx $HASH $TX_HEIGHT $SENDER "90" "10"
|
||||
checkSendFeeTx $HASH $TX_HEIGHT $SENDER "90" "10"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -169,6 +169,30 @@ checkSendTx() {
|
||||
return $?
|
||||
}
|
||||
|
||||
# XXX Ex Usage: checkSendFeeTx $HASH $HEIGHT $SENDER $AMOUNT $FEE
|
||||
# Desc: This is like checkSendTx, but asserts a feetx wrapper with $FEE value.
|
||||
# This looks up the tx by hash, and makes sure the height and type match
|
||||
# and that the first input was from this sender for this amount
|
||||
checkSendFeeTx() {
|
||||
TX=$(${CLIENT_EXE} query tx $1)
|
||||
assertTrue "found tx" $?
|
||||
if [ -n "$DEBUG" ]; then echo $TX; echo; fi
|
||||
|
||||
assertEquals "proper height" $2 $(echo $TX | jq .height)
|
||||
assertEquals "type=sigs/one" '"sigs/one"' $(echo $TX | jq .data.type)
|
||||
CTX=$(echo $TX | jq .data.data.tx)
|
||||
assertEquals "type=chain/tx" '"chain/tx"' $(echo $CTX | jq .type)
|
||||
FTX=$(echo $CTX | jq .data.tx)
|
||||
assertEquals "type=fee/tx" '"fee/tx"' $(echo $FTX | jq .type)
|
||||
assertEquals "proper fee" "$5" $(echo $FTX | jq .data.fee.amount)
|
||||
STX=$(echo $FTX | jq .data.tx)
|
||||
assertEquals "type=coin/send" '"coin/send"' $(echo $STX | jq .type)
|
||||
assertEquals "proper sender" "\"$3\"" $(echo $STX | jq .data.inputs[0].address.addr)
|
||||
assertEquals "proper out amount" "$4" $(echo $STX | jq .data.outputs[0].coins[0].amount)
|
||||
return $?
|
||||
}
|
||||
|
||||
|
||||
# XXX Ex Usage: waitForBlock $port
|
||||
# Desc: Waits until the block height on that node increases by one
|
||||
waitForBlock() {
|
||||
|
||||
@ -89,6 +89,16 @@ test03AddCount() {
|
||||
assertEquals "type=cntr/count" '"cntr/count"' $(echo $CNTX | jq .type)
|
||||
assertEquals "proper fee" "10" $(echo $CNTX | jq .data.fee[0].amount)
|
||||
fi
|
||||
|
||||
# test again with fees...
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx counter --countfee=7mycoin --fee=4mycoin --sequence=3 --name=${RICH} --valid)
|
||||
txSucceeded $? "$TX" "counter"
|
||||
|
||||
# make sure the counter was updated, added 7
|
||||
checkCounter "2" "17"
|
||||
|
||||
# make sure the account was debited 11
|
||||
checkAccount $SENDER "9007199254739979"
|
||||
}
|
||||
|
||||
# Load common then run these tests with shunit2!
|
||||
|
||||
Loading…
Reference in New Issue
Block a user