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.

81 lines
2.0 KiB

  1. package coordinator
  2. import (
  3. "github.com/hermeznetwork/hermez-node/common"
  4. )
  5. // Proof TBD this type will be received from the proof server
  6. type Proof struct {
  7. }
  8. // BatchInfo contans the Batch information
  9. type BatchInfo struct {
  10. batchNum common.BatchNum
  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 common.BatchNum, 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. // NewBatchQueue returns a new *BatchQueue
  52. func NewBatchQueue() *BatchQueue {
  53. return &BatchQueue{
  54. queue: []*BatchInfo{},
  55. }
  56. }
  57. // Push adds the given BatchInfo to the BatchQueue
  58. func (bq *BatchQueue) Push(b *BatchInfo) {
  59. bq.queue = append(bq.queue, b)
  60. }
  61. // Pop pops the first BatchInfo from the BatchQueue
  62. func (bq *BatchQueue) Pop() *BatchInfo {
  63. if len(bq.queue) == 0 {
  64. return nil
  65. }
  66. b := bq.queue[0]
  67. bq.queue = bq.queue[1:]
  68. return b
  69. }