4 log "github.com/sirupsen/logrus"
6 "github.com/vapor/protocol/bc"
7 "github.com/vapor/protocol/bc/types"
8 "github.com/vapor/protocol/state"
9 "github.com/vapor/protocol/validation"
12 // GetTransactionStatus return the transaction status of give block
13 func (c *Chain) GetTransactionStatus(hash *bc.Hash) (*bc.TransactionStatus, error) {
14 return c.store.GetTransactionStatus(hash)
17 // GetTransactionsUtxo return all the utxos that related to the txs' inputs
18 func (c *Chain) GetTransactionsUtxo(view *state.UtxoViewpoint, txs []*bc.Tx) error {
19 return c.store.GetTransactionsUtxo(view, txs)
22 // ValidateTx validates the given transaction. A cache holds
23 // per-transaction validation results and is consulted before
24 // performing full validation.
25 func (c *Chain) ValidateTx(tx *types.Tx) (bool, error) {
30 c.markTransactions(tx)
32 return c.validateTx(tx)
35 // validateTx validates the given transaction without checking duplication.
36 func (c *Chain) validateTx(tx *types.Tx) (bool, error) {
37 if ok := c.txPool.HaveTransaction(&tx.ID); ok {
38 return false, c.txPool.GetErrCache(&tx.ID)
41 if c.txPool.IsDust(tx) {
42 c.txPool.AddErrCache(&tx.ID, ErrDustTx)
43 return false, ErrDustTx
46 bh := c.BestBlockHeader()
47 gasStatus, err := validation.ValidateTx(tx.Tx, types.MapBlock(&types.Block{BlockHeader: *bh}))
48 if !gasStatus.GasValid {
49 c.txPool.AddErrCache(&tx.ID, err)
54 log.WithFields(log.Fields{"module": logModule, "tx_id": tx.Tx.ID.String(), "error": err}).Info("transaction status fail")
57 return c.txPool.ProcessTransaction(tx, err != nil, bh.Height, gasStatus.BTMValue)