hermez-node/coordinator/batch.go
coordinator/batch.goRaw
1package coordinator
2
3import (
4 "github.com/hermeznetwork/hermez-node/common"
5)
6
7// BatchInfo contans the Batch information
8type BatchInfo struct {
9 batchNum uint64
10 serverProof *ServerProofInfo
11 zkInputs *common.ZKInputs
12 L1UserTxsExtra []common.L1Tx
13 L1OperatorTxs []common.L1Tx
14 L2Txs []common.PoolL2Tx
15 // FeesInfo
16}
17
18// NewBatchInfo creates a new BatchInfo with the given batchNum &
19// ServerProofInfo
20func NewBatchInfo(batchNum uint64, serverProof *ServerProofInfo) BatchInfo {
21 return BatchInfo{
22 batchNum: batchNum,
23 serverProof: serverProof,
24 }
25}
26
27// AddTxsInfo adds the l1UserTxs, l1OperatorTxs and l2Txs to the BatchInfo data
28// structure
29func (bi *BatchInfo) AddTxsInfo(l1UserTxsExtra, l1OperatorTxs []common.L1Tx, l2Txs []common.PoolL2Tx) {
30 // TBD parameter: feesInfo
31 bi.L1UserTxsExtra = l1UserTxsExtra
32 bi.L1OperatorTxs = l1OperatorTxs
33 bi.L2Txs = l2Txs
34}
35
36// AddTxsInfo adds the ZKInputs to the BatchInfo data structure
37func (bi *BatchInfo) AddZKInputs(zkInputs *common.ZKInputs) {
38 bi.zkInputs = zkInputs
39}
40
41// AddTxsInfo adds the ServerProofInfo to the BatchInfo data structure
42func (bi *BatchInfo) AddServerProof(serverProof *ServerProofInfo) {
43 bi.serverProof = serverProof
44}
45
46// BatchQueue implements a FIFO queue of BatchInfo
47type BatchQueue struct {
48 queue []*BatchInfo
49}
50
51// Push adds the given BatchInfo to the BatchQueue
52func (bq *BatchQueue) Push(b *BatchInfo) {
53 bq.queue = append(bq.queue, b)
54}
55
56// Pop pops the first BatchInfo from the BatchQueue
57func (bq *BatchQueue) Pop() *BatchInfo {
58 if len(bq.queue) == 0 {
59 return nil
60 }
61 b := bq.queue[0]
62 bq.queue = bq.queue[1:]
63 return b
64}