-
Notifications
You must be signed in to change notification settings - Fork 198
/
processPending.go
140 lines (123 loc) · 4.02 KB
/
processPending.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package process
import (
"github.com/ElrondNetwork/elrond-go-logger"
"github.com/ElrondNetwork/elrond-go/core"
"github.com/ElrondNetwork/elrond-go/core/check"
"github.com/ElrondNetwork/elrond-go/data/block"
"github.com/ElrondNetwork/elrond-go/data/rewardTx"
"github.com/ElrondNetwork/elrond-go/data/smartContractResult"
"github.com/ElrondNetwork/elrond-go/data/state"
"github.com/ElrondNetwork/elrond-go/data/transaction"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/sharding"
"github.com/ElrondNetwork/elrond-go/update"
)
var log = logger.GetOrCreate("update/process/")
// ArgsPendingTransactionProcessor defines the arguments structure
type ArgsPendingTransactionProcessor struct {
Accounts state.AccountsAdapter
TxProcessor process.TransactionProcessor
RwdTxProcessor process.RewardTransactionProcessor
ScrTxProcessor process.SmartContractResultProcessor
PubKeyConv core.PubkeyConverter
ShardCoordinator sharding.Coordinator
}
type pendingProcessor struct {
accounts state.AccountsAdapter
txProcessor process.TransactionProcessor
rwdTxProcessor process.RewardTransactionProcessor
scrTxProcessor process.SmartContractResultProcessor
pubKeyConv core.PubkeyConverter
shardCoordinator sharding.Coordinator
}
// NewPendingTransactionProcessor creates a pending transaction processor to be used after hardfork import
func NewPendingTransactionProcessor(args ArgsPendingTransactionProcessor) (*pendingProcessor, error) {
if check.IfNil(args.Accounts) {
return nil, update.ErrNilAccounts
}
if check.IfNil(args.TxProcessor) {
return nil, update.ErrNilTxProcessor
}
if check.IfNil(args.ScrTxProcessor) {
return nil, update.ErrNilSCRProcessor
}
if check.IfNil(args.RwdTxProcessor) {
return nil, update.ErrNilRwdTxProcessor
}
if check.IfNil(args.PubKeyConv) {
return nil, update.ErrNilPubKeyConverter
}
if check.IfNil(args.ShardCoordinator) {
return nil, update.ErrNilShardCoordinator
}
return &pendingProcessor{
accounts: args.Accounts,
txProcessor: args.TxProcessor,
rwdTxProcessor: args.RwdTxProcessor,
scrTxProcessor: args.ScrTxProcessor,
pubKeyConv: args.PubKeyConv,
shardCoordinator: args.ShardCoordinator,
}, nil
}
// ProcessTransactionsDstMe processes all the transactions in which destination is the current shard
func (p *pendingProcessor) ProcessTransactionsDstMe(mbInfo *update.MbInfo) (*block.MiniBlock, error) {
miniBlock := &block.MiniBlock{
TxHashes: make([][]byte, 0),
ReceiverShardID: mbInfo.ReceiverShardID,
SenderShardID: mbInfo.SenderShardID,
Type: mbInfo.Type,
}
for _, txInfo := range mbInfo.TxsInfo {
err := p.processSingleTransaction(txInfo)
if err != nil {
log.Debug("could not process transaction",
"err", err,
"snd", txInfo.Tx.GetSndAddr(),
"rcv", txInfo.Tx.GetRcvAddr(),
"value", txInfo.Tx.GetValue().String(),
"data", txInfo.Tx.GetData())
continue
}
miniBlock.TxHashes = append(miniBlock.TxHashes, txInfo.TxHash)
}
return miniBlock, nil
}
func (p *pendingProcessor) processSingleTransaction(txInfo *update.TxInfo) error {
rwdTx, ok := txInfo.Tx.(*rewardTx.RewardTx)
if ok {
err := p.rwdTxProcessor.ProcessRewardTransaction(rwdTx)
if err != nil {
return err
}
return nil
}
scrTx, ok := txInfo.Tx.(*smartContractResult.SmartContractResult)
if ok {
_, err := p.scrTxProcessor.ProcessSmartContractResult(scrTx)
if err != nil {
return err
}
return nil
}
tx, ok := txInfo.Tx.(*transaction.Transaction)
if ok {
_, err := p.txProcessor.ProcessTransaction(tx)
if err != nil {
return err
}
return nil
}
return nil
}
// RootHash returns the roothash of the accounts
func (p *pendingProcessor) RootHash() ([]byte, error) {
return p.accounts.RootHash()
}
// Commit commits the changes of the accounts
func (p *pendingProcessor) Commit() ([]byte, error) {
return p.accounts.Commit()
}
// IsInterfaceNil returns true if underlying object is nil
func (p *pendingProcessor) IsInterfaceNil() bool {
return p == nil
}