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.

65 lines
1.5 KiB

  1. package common
  2. import (
  3. "math/big"
  4. )
  5. // L2Tx is a struct that represents an already forged L2 tx
  6. type L2Tx struct {
  7. // Stored in DB: mandatory fileds
  8. TxID TxID
  9. BatchNum BatchNum // batchNum in which this tx was forged.
  10. Position int
  11. FromIdx Idx
  12. ToIdx Idx
  13. Amount *big.Int
  14. Fee FeeSelector
  15. Nonce Nonce
  16. Type TxType
  17. EthBlockNum int64 // Ethereum Block Number in which this L2Tx was added to the queue
  18. }
  19. // Tx returns a *Tx from the L2Tx
  20. func (tx *L2Tx) Tx() *Tx {
  21. f := new(big.Float).SetInt(tx.Amount)
  22. amountFloat, _ := f.Float64()
  23. return &Tx{
  24. IsL1: false,
  25. TxID: tx.TxID,
  26. Type: tx.Type,
  27. Position: tx.Position,
  28. FromIdx: tx.FromIdx,
  29. ToIdx: tx.ToIdx,
  30. Amount: tx.Amount,
  31. AmountFloat: amountFloat,
  32. BatchNum: tx.BatchNum,
  33. EthBlockNum: tx.EthBlockNum,
  34. Fee: tx.Fee,
  35. Nonce: tx.Nonce,
  36. }
  37. }
  38. // PoolL2Tx returns the data structure of PoolL2Tx with the parameters of a
  39. // L2Tx filled
  40. func (tx *L2Tx) PoolL2Tx() *PoolL2Tx {
  41. return &PoolL2Tx{
  42. TxID: tx.TxID,
  43. BatchNum: tx.BatchNum,
  44. FromIdx: tx.FromIdx,
  45. ToIdx: tx.ToIdx,
  46. Amount: tx.Amount,
  47. Fee: tx.Fee,
  48. Nonce: tx.Nonce,
  49. Type: tx.Type,
  50. }
  51. }
  52. // L2TxsToPoolL2Txs returns an array of []*PoolL2Tx from an array of []*L2Tx,
  53. // where the PoolL2Tx only have the parameters of a L2Tx filled.
  54. func L2TxsToPoolL2Txs(txs []*L2Tx) []*PoolL2Tx {
  55. var r []*PoolL2Tx
  56. for _, tx := range txs {
  57. r = append(r, tx.PoolL2Tx())
  58. }
  59. return r
  60. }