Fixes as per Rigels comments on PR

This commit is contained in:
Ethan Frey
2017-07-11 13:44:44 +02:00
parent 765f52e402
commit 64f2c63e21
3 changed files with 18 additions and 11 deletions
+5 -4
View File
@@ -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 {
+8 -3
View File
@@ -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}
}