diff --git a/cmd/basecli/commands/cmds.go b/cmd/basecli/commands/cmds.go index e5fff36342..4c5a90640e 100644 --- a/cmd/basecli/commands/cmds.go +++ b/cmd/basecli/commands/cmds.go @@ -44,7 +44,7 @@ func init() { flags.String(FlagAmount, "", "Coins to send in the format ,...") flags.String(FlagFee, "0mycoin", "Coins for the transaction fee of the format ") flags.Uint64(FlagGas, 0, "Amount of gas for this transaction") - flags.Int64(FlagExpires, 0, "Block height at which this tx expires") + flags.Uint64(FlagExpires, 0, "Block height at which this tx expires") flags.Int(FlagSequence, -1, "Sequence number for this transaction") } @@ -86,10 +86,11 @@ func doSendTx(cmd *cobra.Command, args []string) error { // 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") + chain := commands.GetChainID() + if chain == "" { + return res, errors.New("No chain-id provided") } - res = base.NewChainTx(commands.GetChainID(), uint64(expires), tx) + res = base.NewChainTx(chain, uint64(expires), tx) return res, nil } diff --git a/modules/base/chain.go b/modules/base/chain.go index 8161f8802e..65513679de 100644 --- a/modules/base/chain.go +++ b/modules/base/chain.go @@ -26,7 +26,7 @@ var _ stack.Middleware = Chain{} // CheckTx makes sure we are on the proper chain - fulfills Middlware interface func (c Chain) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { - stx, err := c.checkChain(ctx.ChainID(), ctx.BlockHeight(), tx) + stx, err := c.checkChainTx(ctx.ChainID(), ctx.BlockHeight(), tx) if err != nil { return res, err } @@ -35,15 +35,16 @@ func (c Chain) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx // DeliverTx makes sure we are on the proper chain - fulfills Middlware interface func (c Chain) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { - stx, err := c.checkChain(ctx.ChainID(), ctx.BlockHeight(), tx) + stx, err := c.checkChainTx(ctx.ChainID(), ctx.BlockHeight(), tx) if err != nil { return res, err } return next.DeliverTx(ctx, store, stx) } -// checkChain makes sure the tx is a Chain Tx and is on the proper chain -func (c Chain) checkChain(chainID string, height uint64, tx basecoin.Tx) (basecoin.Tx, error) { +// checkChainTx makes sure the tx is a Chain Tx, it is on the proper chain, +// and it has not expired. +func (c Chain) checkChainTx(chainID string, height uint64, tx basecoin.Tx) (basecoin.Tx, error) { // make sure it is a chaintx ctx, ok := tx.Unwrap().(ChainTx) if !ok { diff --git a/modules/base/tx.go b/modules/base/tx.go index 819811ef6c..fd66fad884 100644 --- a/modules/base/tx.go +++ b/modules/base/tx.go @@ -56,8 +56,10 @@ func (mt MultiTx) ValidateBasic() error { // ChainTx locks this tx to one chainTx, wrap with this before signing type ChainTx struct { - ChainID string `json:"chain_id"` // name of chain, must be [A-Za-z0-9_-]+ - ExpiresAt uint64 `json:"expires_at"` // block height at which it is no longer valid + // name of chain, must be [A-Za-z0-9_-]+ + ChainID string `json:"chain_id"` + // block height at which it is no longer valid, 0 means no expiration + ExpiresAt uint64 `json:"expires_at"` Tx basecoin.Tx `json:"tx"` } @@ -67,7 +69,8 @@ var ( chainPattern = regexp.MustCompile("^[A-Za-z0-9_-]+$") ) -//nolint - TxInner Functions +// NewChainTx wraps a particular tx with the ChainTx wrapper, +// to enforce chain and height func NewChainTx(chainID string, expires uint64, tx basecoin.Tx) basecoin.Tx { c := ChainTx{ ChainID: chainID, @@ -76,6 +79,8 @@ func NewChainTx(chainID string, expires uint64, tx basecoin.Tx) basecoin.Tx { } return c.Wrap() } + +//nolint - TxInner Functions func (c ChainTx) Wrap() basecoin.Tx { return basecoin.Tx{c} }