arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/coordinator/batch.go
coordinator/batch.goRaw
 1package coordinator
 2
 3import (
 4	"github.com/hermeznetwork/hermez-node/common"
 5)
 6
 7// Proof TBD this type will be got from the proof server
 8type Proof struct {
 9}
10
11// BatchInfo contans the Batch information
12type BatchInfo struct {
13	batchNum       common.BatchNum
14	serverProof    *ServerProofInfo
15	zkInputs       *common.ZKInputs
16	proof          *Proof
17	L1UserTxsExtra []*common.L1Tx
18	L1OperatorTxs  []*common.L1Tx
19	L2Txs          []*common.PoolL2Tx
20	// FeesInfo
21}
22
23// NewBatchInfo creates a new BatchInfo with the given batchNum &
24// ServerProofInfo
25func NewBatchInfo(batchNum common.BatchNum, serverProof *ServerProofInfo) BatchInfo {
26	return BatchInfo{
27		batchNum:    batchNum,
28		serverProof: serverProof,
29	}
30}
31
32// SetTxsInfo sets the l1UserTxs, l1OperatorTxs and l2Txs to the BatchInfo data
33// structure
34func (bi *BatchInfo) SetTxsInfo(l1UserTxsExtra, l1OperatorTxs []*common.L1Tx, l2Txs []*common.PoolL2Tx) {
35	// TBD parameter: feesInfo
36	bi.L1UserTxsExtra = l1UserTxsExtra
37	bi.L1OperatorTxs = l1OperatorTxs
38	bi.L2Txs = l2Txs
39}
40
41// SetZKInputs sets the ZKInputs to the BatchInfo data structure
42func (bi *BatchInfo) SetZKInputs(zkInputs *common.ZKInputs) {
43	bi.zkInputs = zkInputs
44}
45
46// SetServerProof sets the ServerProofInfo to the BatchInfo data structure
47func (bi *BatchInfo) SetServerProof(serverProof *ServerProofInfo) {
48	bi.serverProof = serverProof
49}
50
51// SetProof sets the Proof to the BatchInfo data structure
52func (bi *BatchInfo) SetProof(proof *Proof) {
53	bi.proof = proof
54}
55
56// BatchQueue implements a FIFO queue of BatchInfo
57type BatchQueue struct {
58	queue []*BatchInfo
59}
60
61// NewBatchQueue returns a new *BatchQueue
62func NewBatchQueue() *BatchQueue {
63	return &BatchQueue{
64		queue: []*BatchInfo{},
65	}
66}
67
68// Push adds the given BatchInfo to the BatchQueue
69func (bq *BatchQueue) Push(b *BatchInfo) {
70	bq.queue = append(bq.queue, b)
71}
72
73// Pop pops the first BatchInfo from the BatchQueue
74func (bq *BatchQueue) Pop() *BatchInfo {
75	if len(bq.queue) == 0 {
76		return nil
77	}
78	b := bq.queue[0]
79	bq.queue = bq.queue[1:]
80	return b
81}