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.

64 lines
1.6 KiB

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