You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.9 KiB

  1. package coordinator
  2. import (
  3. "github.com/hermeznetwork/hermez-node/common"
  4. )
  5. type Proof struct {
  6. // TBD this type will be got from the proof server
  7. }
  8. // BatchInfo contans the Batch information
  9. type BatchInfo struct {
  10. batchNum uint64
  11. serverProof *ServerProofInfo
  12. zkInputs *common.ZKInputs
  13. proof *Proof
  14. L1UserTxsExtra []common.L1Tx
  15. L1OperatorTxs []common.L1Tx
  16. L2Txs []common.PoolL2Tx
  17. // FeesInfo
  18. }
  19. // NewBatchInfo creates a new BatchInfo with the given batchNum &
  20. // ServerProofInfo
  21. func NewBatchInfo(batchNum uint64, serverProof *ServerProofInfo) BatchInfo {
  22. return BatchInfo{
  23. batchNum: batchNum,
  24. serverProof: serverProof,
  25. }
  26. }
  27. // SetTxsInfo sets the l1UserTxs, l1OperatorTxs and l2Txs to the BatchInfo data
  28. // structure
  29. func (bi *BatchInfo) SetTxsInfo(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. // SetZKInputs sets the ZKInputs to the BatchInfo data structure
  36. func (bi *BatchInfo) SetZKInputs(zkInputs *common.ZKInputs) {
  37. bi.zkInputs = zkInputs
  38. }
  39. // SetServerProof sets the ServerProofInfo to the BatchInfo data structure
  40. func (bi *BatchInfo) SetServerProof(serverProof *ServerProofInfo) {
  41. bi.serverProof = serverProof
  42. }
  43. // SetProof sets the Proof to the BatchInfo data structure
  44. func (bi *BatchInfo) SetProof(proof *Proof) {
  45. bi.proof = proof
  46. }
  47. // BatchQueue implements a FIFO queue of BatchInfo
  48. type BatchQueue struct {
  49. queue []*BatchInfo
  50. }
  51. func NewBatchQueue() *BatchQueue {
  52. return &BatchQueue{
  53. queue: []*BatchInfo{},
  54. }
  55. }
  56. // Push adds the given BatchInfo to the BatchQueue
  57. func (bq *BatchQueue) Push(b *BatchInfo) {
  58. bq.queue = append(bq.queue, b)
  59. }
  60. // Pop pops the first BatchInfo from the BatchQueue
  61. func (bq *BatchQueue) Pop() *BatchInfo {
  62. if len(bq.queue) == 0 {
  63. return nil
  64. }
  65. b := bq.queue[0]
  66. bq.queue = bq.queue[1:]
  67. return b
  68. }