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.

57 lines
1.4 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 `meddler:"tx_id"`
  9. BatchNum BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged.
  10. Position int `meddler:"position"`
  11. FromIdx Idx `meddler:"from_idx"`
  12. ToIdx Idx `meddler:"to_idx"`
  13. Amount *big.Int `meddler:"amount,bigint"`
  14. Fee FeeSelector `meddler:"fee"`
  15. Nonce Nonce `meddler:"nonce"`
  16. Type TxType `meddler:"tx_type"`
  17. }
  18. // Tx returns a *Tx from the L2Tx
  19. func (tx *L2Tx) Tx() *Tx {
  20. return &Tx{
  21. TxID: tx.TxID,
  22. FromIdx: tx.FromIdx,
  23. ToIdx: tx.ToIdx,
  24. Amount: tx.Amount,
  25. Nonce: tx.Nonce,
  26. Fee: tx.Fee,
  27. Type: tx.Type,
  28. }
  29. }
  30. // PoolL2Tx returns the data structure of PoolL2Tx with the parameters of a
  31. // L2Tx filled
  32. func (tx *L2Tx) PoolL2Tx() *PoolL2Tx {
  33. return &PoolL2Tx{
  34. TxID: tx.TxID,
  35. BatchNum: tx.BatchNum,
  36. FromIdx: tx.FromIdx,
  37. ToIdx: tx.ToIdx,
  38. Amount: tx.Amount,
  39. Fee: tx.Fee,
  40. Nonce: tx.Nonce,
  41. Type: tx.Type,
  42. }
  43. }
  44. // L2TxsToPoolL2Txs returns an array of []*PoolL2Tx from an array of []*L2Tx,
  45. // where the PoolL2Tx only have the parameters of a L2Tx filled.
  46. func L2TxsToPoolL2Txs(txs []*L2Tx) []*PoolL2Tx {
  47. var r []*PoolL2Tx
  48. for _, tx := range txs {
  49. r = append(r, tx.PoolL2Tx())
  50. }
  51. return r
  52. }