OSDN Git Service

update master (#487)
[bytom/bytom-spv.git] / protocol / tx.go
index 00721ba..75e1c1a 100644 (file)
@@ -3,7 +3,7 @@ package protocol
 import (
        "github.com/bytom/errors"
        "github.com/bytom/protocol/bc"
-       "github.com/bytom/protocol/bc/legacy"
+       "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/validation"
 )
 
@@ -13,9 +13,9 @@ var ErrBadTx = errors.New("invalid transaction")
 // ValidateTx validates the given transaction. A cache holds
 // per-transaction validation results and is consulted before
 // performing full validation.
-func (c *Chain) ValidateTx(tx *legacy.Tx) error {
+func (c *Chain) ValidateTx(tx *types.Tx) error {
        newTx := tx.Tx
-       block := legacy.MapBlock(c.BestBlock())
+       block := types.MapBlock(c.BestBlock())
        if ok := c.txPool.HaveTransaction(&newTx.ID); ok {
                return c.txPool.GetErrCache(&newTx.ID)
        }
@@ -33,15 +33,15 @@ func (c *Chain) ValidateTx(tx *legacy.Tx) error {
 
        // validate the BVM contract
        gasOnlyTx := false
-       fee, gasVaild, err := validation.ValidateTx(newTx, block)
+       gasStatus, err := validation.ValidateTx(newTx, block)
        if err != nil {
-               if !gasVaild {
+               if gasStatus == nil || !gasStatus.GasVaild {
                        c.txPool.AddErrCache(&newTx.ID, err)
                        return err
                }
                gasOnlyTx = true
        }
 
-       _, err = c.txPool.AddTransaction(tx, gasOnlyTx, block.BlockHeader.Height, fee)
+       _, err = c.txPool.AddTransaction(tx, gasOnlyTx, block.BlockHeader.Height, gasStatus.BTMValue)
        return err
 }