4 log "github.com/sirupsen/logrus"
6 "github.com/vapor/errors"
7 "github.com/vapor/protocol/bc"
8 "github.com/vapor/protocol/bc/types"
9 "github.com/vapor/protocol/state"
10 "github.com/vapor/protocol/validation"
13 // ErrBadTx is returned for transactions failing validation
14 var ErrBadTx = errors.New("invalid transaction")
16 // GetTransactionStatus return the transaction status of give block
17 func (c *Chain) GetTransactionStatus(hash *bc.Hash) (*bc.TransactionStatus, error) {
18 return c.store.GetTransactionStatus(hash)
21 // GetTransactionsUtxo return all the utxos that related to the txs' inputs
22 func (c *Chain) GetTransactionsUtxo(view *state.UtxoViewpoint, txs []*bc.Tx) error {
23 return c.store.GetTransactionsUtxo(view, txs)
26 // ValidateTx validates the given transaction. A cache holds
27 // per-transaction validation results and is consulted before
28 // performing full validation.
29 func (c *Chain) ValidateTx(tx *types.Tx) (bool, error) {
30 if ok := c.txPool.HaveTransaction(&tx.ID); ok {
31 return false, c.txPool.GetErrCache(&tx.ID)
34 if c.txPool.IsDust(tx) {
35 c.txPool.AddErrCache(&tx.ID, ErrDustTx)
36 return false, ErrDustTx
39 bh := c.BestBlockHeader()
40 gasStatus, err := validation.ValidateTx(tx.Tx, types.MapBlock(&types.Block{BlockHeader: *bh}))
41 if !gasStatus.GasValid {
42 c.txPool.AddErrCache(&tx.ID, err)
47 log.WithFields(log.Fields{"module": logModule, "tx_id": tx.Tx.ID.String(), "error": err}).Info("transaction status fail")
50 return c.txPool.ProcessTransaction(tx, err != nil, bh.Height, gasStatus.BTMValue)