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