diff --git a/app/app_test.go b/app/app_test.go index e98b8a5a2..7889a31b0 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -44,7 +44,7 @@ func (at *appTest) getTx(seq int, coins coin.Coins) basecoin.Tx { in := []coin.TxInput{{Address: at.acctIn.Actor(), Coins: coins, Sequence: seq}} out := []coin.TxOutput{{Address: at.acctOut.Actor(), Coins: coins}} tx := coin.NewSendTx(in, out) - tx = base.NewChainTx(at.chainID, tx) + tx = base.NewChainTx(at.chainID, 0, tx) stx := auth.NewMulti(tx) auth.Sign(stx, at.acctIn.Key) return stx.Wrap() diff --git a/cmd/basecli/commands/cmds.go b/cmd/basecli/commands/cmds.go index b3c9ede91..e5fff3634 100644 --- a/cmd/basecli/commands/cmds.go +++ b/cmd/basecli/commands/cmds.go @@ -34,6 +34,7 @@ const ( FlagAmount = "amount" FlagFee = "fee" FlagGas = "gas" + FlagExpires = "expires" FlagSequence = "sequence" ) @@ -42,7 +43,8 @@ func init() { flags.String(FlagTo, "", "Destination address for the bits") flags.String(FlagAmount, "", "Coins to send in the format ,...") flags.String(FlagFee, "0mycoin", "Coins for the transaction fee of the format ") - flags.Int64(FlagGas, 0, "Amount of gas for this transaction") + flags.Uint64(FlagGas, 0, "Amount of gas for this transaction") + flags.Int64(FlagExpires, 0, "Block height at which this tx expires") flags.Int(FlagSequence, -1, "Sequence number for this transaction") } @@ -63,7 +65,12 @@ func doSendTx(cmd *cobra.Command, args []string) error { // TODO: make this more flexible for middleware // add the chain info - tx = base.NewChainTx(commands.GetChainID(), tx) + tx, err = WrapChainTx(tx) + if err != nil { + return err + } + + // Note: this is single sig (no multi sig yet) stx := auth.NewSig(tx) // Sign if needed and post. This it the work-horse @@ -76,6 +83,16 @@ func doSendTx(cmd *cobra.Command, args []string) error { return txcmd.OutputTx(bres) } +// WrapChainTx will wrap the tx with a ChainTx from the standard flags +func WrapChainTx(tx basecoin.Tx) (res basecoin.Tx, err error) { + expires := viper.GetInt64(FlagExpires) + if expires < 0 { + return res, errors.New("expires must be >= 0") + } + res = base.NewChainTx(commands.GetChainID(), uint64(expires), tx) + return res, nil +} + func readSendTxFlags() (tx basecoin.Tx, err error) { // parse to address chain, to, err := parseChainAddress(viper.GetString(FlagTo)) diff --git a/docs/guide/counter/cmd/countercli/commands/counter.go b/docs/guide/counter/cmd/countercli/commands/counter.go index 255a2f65e..326b62b19 100644 --- a/docs/guide/counter/cmd/countercli/commands/counter.go +++ b/docs/guide/counter/cmd/countercli/commands/counter.go @@ -4,13 +4,12 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/tendermint/basecoin" - "github.com/tendermint/light-client/commands" txcmd "github.com/tendermint/light-client/commands/txs" + "github.com/tendermint/basecoin" + bcmd "github.com/tendermint/basecoin/cmd/basecli/commands" "github.com/tendermint/basecoin/docs/guide/counter/plugins/counter" "github.com/tendermint/basecoin/modules/auth" - "github.com/tendermint/basecoin/modules/base" "github.com/tendermint/basecoin/modules/coin" ) @@ -57,7 +56,10 @@ func counterTx(cmd *cobra.Command, args []string) error { // TODO: make this more flexible for middleware // add the chain info - tx = base.NewChainTx(commands.GetChainID(), tx) + tx, err = bcmd.WrapChainTx(tx) + if err != nil { + return err + } stx := auth.NewSig(tx) // Sign if needed and post. This it the work-horse diff --git a/docs/guide/counter/plugins/counter/counter_test.go b/docs/guide/counter/plugins/counter/counter_test.go index 522d6a721..2de91d62a 100644 --- a/docs/guide/counter/plugins/counter/counter_test.go +++ b/docs/guide/counter/plugins/counter/counter_test.go @@ -42,7 +42,7 @@ func TestCounterPlugin(t *testing.T) { // Deliver a CounterTx DeliverCounterTx := func(valid bool, counterFee coin.Coins, inputSequence int) abci.Result { tx := NewTx(valid, counterFee, inputSequence) - tx = base.NewChainTx(chainID, tx) + tx = base.NewChainTx(chainID, 0, tx) stx := auth.NewSig(tx) auth.Sign(stx, acct.Key) txBytes := wire.BinaryBytes(stx.Wrap()) diff --git a/modules/base/chain.go b/modules/base/chain.go index a36226766..4fc7071e6 100644 --- a/modules/base/chain.go +++ b/modules/base/chain.go @@ -44,10 +44,19 @@ func (c Chain) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin. // checkChain makes sure the tx is a Chain Tx and is on the proper chain func (c Chain) checkChain(chainID string, tx basecoin.Tx) (basecoin.Tx, error) { + // make sure it is a chaintx ctx, ok := tx.Unwrap().(ChainTx) if !ok { return tx, errors.ErrNoChain() } + + // basic validation + err := ctx.ValidateBasic() + if err != nil { + return tx, err + } + + // compare against state if ctx.ChainID != chainID { return tx, errors.ErrWrongChain(ctx.ChainID) }