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
 7type Proof struct {
 8	// TBD this type will be got from the proof server
 9}
10
11// BatchInfo contans the Batch information
12type BatchInfo struct {
13	batchNum       uint64
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 uint64, 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
61func NewBatchQueue() *BatchQueue {
62	return &BatchQueue{
63		queue: []*BatchInfo{},
64	}
65}
66
67// Push adds the given BatchInfo to the BatchQueue
68func (bq *BatchQueue) Push(b *BatchInfo) {
69	bq.queue = append(bq.queue, b)
70}
71
72// Pop pops the first BatchInfo from the BatchQueue
73func (bq *BatchQueue) Pop() *BatchInfo {
74	if len(bq.queue) == 0 {
75		return nil
76	}
77	b := bq.queue[0]
78	bq.queue = bq.queue[1:]
79	return b
80}