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.

68 lines
3.4 KiB

  1. package common
  2. import (
  3. "math/big"
  4. "time"
  5. eth "github.com/ethereum/go-ethereum/common"
  6. "github.com/iden3/go-iden3-crypto/babyjub"
  7. )
  8. // PoolL2Tx is a struct that represents a L2Tx sent by an account to the coordinator hat is waiting to be forged
  9. type PoolL2Tx struct {
  10. // Stored in DB: mandatory fileds
  11. TxID TxID `meddler:"tx_id"`
  12. FromIdx Idx `meddler:"from_idx"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
  13. ToIdx Idx `meddler:"to_idx"` // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositAndTransfer
  14. ToEthAddr eth.Address `meddler:"to_eth_addr"`
  15. ToBJJ *babyjub.PublicKey `meddler:"to_bjj"` // TODO: stop using json, use scanner/valuer
  16. TokenID TokenID `meddler:"token_id"`
  17. Amount *big.Int `meddler:"amount,bigint"` // TODO: change to float16
  18. Fee FeeSelector `meddler:"fee"`
  19. Nonce uint64 `meddler:"nonce"` // effective 48 bits used
  20. State PoolL2TxState `meddler:"state"`
  21. Signature babyjub.Signature `meddler:"signature"` // tx signature
  22. Timestamp time.Time `meddler:"timestamp,utctime"` // time when added to the tx pool
  23. // Stored in DB: optional fileds, may be uninitialized
  24. BatchNum BatchNum `meddler:"batch_num,zeroisnull"` // batchNum in which this tx was forged. Presence indicates "forged" state.
  25. RqFromIdx Idx `meddler:"rq_from_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
  26. RqToIdx Idx `meddler:"rq_to_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
  27. RqToEthAddr eth.Address `meddler:"rq_to_eth_addr"`
  28. RqToBJJ *babyjub.PublicKey `meddler:"rq_to_bjj"` // TODO: stop using json, use scanner/valuer
  29. RqTokenID TokenID `meddler:"rq_token_id,zeroisnull"`
  30. RqAmount *big.Int `meddler:"rq_amount,bigintnull"` // TODO: change to float16
  31. RqFee FeeSelector `meddler:"rq_fee,zeroisnull"`
  32. RqNonce uint64 `meddler:"rq_nonce,zeroisnull"` // effective 48 bits used
  33. AbsoluteFee float64 `meddler:"absolute_fee,zeroisnull"`
  34. AbsoluteFeeUpdate time.Time `meddler:"absolute_fee_update,utctimez"`
  35. // Extra metadata, may be uninitialized
  36. Type TxType `meddler:"-"` // optional, descrives which kind of tx it's
  37. RqTxCompressedData []byte `meddler:"-"` // 253 bits, optional for atomic txs
  38. }
  39. func (tx *PoolL2Tx) Tx() *Tx {
  40. return &Tx{
  41. TxID: tx.TxID,
  42. FromIdx: tx.FromIdx,
  43. ToIdx: tx.ToIdx,
  44. TokenID: tx.TokenID,
  45. Amount: tx.Amount,
  46. Nonce: tx.Nonce,
  47. Fee: tx.Fee,
  48. Type: tx.Type,
  49. }
  50. }
  51. // PoolL2TxState is a struct that represents the status of a L2 transaction
  52. type PoolL2TxState string
  53. const (
  54. // PoolL2TxStatePending represents a valid L2Tx that hasn't started the forging process
  55. PoolL2TxStatePending PoolL2TxState = "pend"
  56. // PoolL2TxStateForging represents a valid L2Tx that has started the forging process
  57. PoolL2TxStateForging PoolL2TxState = "fing"
  58. // PoolL2TxStateForged represents a L2Tx that has already been forged
  59. PoolL2TxStateForged PoolL2TxState = "fged"
  60. // PoolL2TxStateInvalid represents a L2Tx that has been invalidated
  61. PoolL2TxStateInvalid PoolL2TxState = "invl"
  62. )