github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/evm/watcher/evmtx.go (about)

     1  package watcher
     2  
     3  import (
     4  	ethcmn "github.com/ethereum/go-ethereum/common"
     5  	"github.com/fibonacci-chain/fbc/x/evm/types"
     6  )
     7  
     8  type evmTx struct {
     9  	msgEvmTx  *types.MsgEthereumTx
    10  	txHash    ethcmn.Hash
    11  	blockHash ethcmn.Hash
    12  	height    uint64
    13  	index     uint64
    14  }
    15  
    16  func NewEvmTx(msgEvmTx *types.MsgEthereumTx, txHash ethcmn.Hash, blockHash ethcmn.Hash, height, index uint64) *evmTx {
    17  	return &evmTx{
    18  		msgEvmTx:  msgEvmTx,
    19  		txHash:    txHash,
    20  		blockHash: blockHash,
    21  		height:    height,
    22  		index:     index,
    23  	}
    24  }
    25  
    26  func (etx *evmTx) GetTxHash() ethcmn.Hash {
    27  	if etx == nil {
    28  		return ethcmn.Hash{}
    29  	}
    30  	return etx.txHash
    31  }
    32  
    33  func (etx *evmTx) GetTransaction() *Transaction {
    34  	if etx == nil || etx.msgEvmTx == nil {
    35  		return nil
    36  	}
    37  	ethTx, e := NewTransaction(etx.msgEvmTx, etx.txHash, etx.blockHash, etx.height, etx.index)
    38  	if e != nil {
    39  		return nil
    40  	}
    41  	return ethTx
    42  }
    43  
    44  func (etx *evmTx) GetFailedReceipts(cumulativeGas, gasUsed uint64) *TransactionReceipt {
    45  	if etx == nil {
    46  		return nil
    47  	}
    48  	tr := newTransactionReceipt(TransactionFailed, etx.msgEvmTx, etx.txHash, etx.blockHash, etx.index, etx.height, &types.ResultData{}, cumulativeGas, gasUsed)
    49  	return &tr
    50  }
    51  
    52  func (etx *evmTx) GetIndex() uint64 {
    53  	return etx.index
    54  }
    55  
    56  type MsgEthTx struct {
    57  	*Transaction
    58  	Key []byte
    59  }
    60  
    61  func (m MsgEthTx) GetType() uint32 {
    62  	return TypeOthers
    63  }
    64  
    65  func (m MsgEthTx) GetKey() []byte {
    66  	return append(prefixTx, m.Key...)
    67  }
    68  
    69  func (etx *evmTx) GetTxWatchMessage() WatchMessage {
    70  	if etx == nil || etx.msgEvmTx == nil {
    71  		return nil
    72  	}
    73  
    74  	return newMsgEthTx(etx.msgEvmTx, etx.txHash, etx.blockHash, etx.height, etx.index)
    75  }
    76  
    77  func newTransaction(tx *types.MsgEthereumTx, txHash, blockHash ethcmn.Hash, blockNumber, index uint64) *Transaction {
    78  	return &Transaction{
    79  		Hash:              txHash,
    80  		tx:                tx,
    81  		originBlockHash:   &blockHash,
    82  		originBlockNumber: blockNumber,
    83  		originIndex:       index,
    84  	}
    85  }
    86  
    87  func newMsgEthTx(tx *types.MsgEthereumTx, txHash, blockHash ethcmn.Hash, height, index uint64) *MsgEthTx {
    88  	ethTx := newTransaction(tx, txHash, blockHash, height, index)
    89  
    90  	return &MsgEthTx{
    91  		Transaction: ethTx,
    92  		Key:         txHash.Bytes(),
    93  	}
    94  }