forked from ten-protocol/go-ten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction_injector_tracker.go
83 lines (70 loc) · 2.83 KB
/
transaction_injector_tracker.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
package simulation
import (
"sync"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ten-protocol/go-ten/go/ethadapter"
"github.com/ten-protocol/go-ten/go/wallet"
"github.com/ten-protocol/go-ten/go/common"
)
type txInjectorTracker struct {
gasTransactionsLock sync.RWMutex
l1TransactionsLock sync.RWMutex
L1Transactions []ethadapter.L1Transaction
l2TransactionsLock sync.RWMutex
TransferL2Transactions []*common.L2Tx
NativeValueTransferL2Transactions []*common.L2Tx
WithdrawalL2Transactions []*common.L2Tx
GasBridgeTransactions []GasBridgingRecord
}
type GasBridgingRecord struct {
L1BridgeTx *types.Transaction
ReceiverWallet wallet.Wallet
}
func newCounter() *txInjectorTracker {
return &txInjectorTracker{
l1TransactionsLock: sync.RWMutex{},
L1Transactions: []ethadapter.L1Transaction{},
l2TransactionsLock: sync.RWMutex{},
TransferL2Transactions: []*common.L2Tx{},
WithdrawalL2Transactions: []*common.L2Tx{},
NativeValueTransferL2Transactions: []*common.L2Tx{},
GasBridgeTransactions: []GasBridgingRecord{},
}
}
func (m *txInjectorTracker) trackGasBridgingTx(tx *types.Transaction, receiverWallet wallet.Wallet) {
m.gasTransactionsLock.Lock()
defer m.gasTransactionsLock.Unlock()
m.GasBridgeTransactions = append(m.GasBridgeTransactions, GasBridgingRecord{
L1BridgeTx: tx,
ReceiverWallet: receiverWallet,
})
}
// trackL1Tx adds an L1Tx to the internal list
func (m *txInjectorTracker) trackL1Tx(tx ethadapter.L1Transaction) {
m.l1TransactionsLock.Lock()
defer m.l1TransactionsLock.Unlock()
m.L1Transactions = append(m.L1Transactions, tx)
}
func (m *txInjectorTracker) trackTransferL2Tx(tx *common.L2Tx) {
m.l2TransactionsLock.Lock()
defer m.l2TransactionsLock.Unlock()
m.TransferL2Transactions = append(m.TransferL2Transactions, tx)
}
func (m *txInjectorTracker) trackWithdrawalFromL2(tx *common.L2Tx) {
m.l2TransactionsLock.Lock()
defer m.l2TransactionsLock.Unlock()
m.WithdrawalL2Transactions = append(m.WithdrawalL2Transactions, tx)
}
func (m *txInjectorTracker) trackNativeValueTransferL2Tx(tx *common.L2Tx) {
m.l2TransactionsLock.Lock()
defer m.l2TransactionsLock.Unlock()
m.NativeValueTransferL2Transactions = append(m.NativeValueTransferL2Transactions, tx)
}
// GetL1Transactions returns all generated L1 L2Txs
func (m *txInjectorTracker) GetL1Transactions() []ethadapter.L1Transaction {
return m.L1Transactions
}
// GetL2Transactions returns all generated non-WithdrawalTx transactions, excluding prefund and ERC20 deploy transactions.
func (m *txInjectorTracker) GetL2Transactions() ([]*common.L2Tx, []*common.L2Tx, []*common.L2Tx) {
return m.TransferL2Transactions, m.WithdrawalL2Transactions, m.NativeValueTransferL2Transactions
}