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.1 KiB

  1. package common
  2. import (
  3. "math/big"
  4. ethCommon "github.com/ethereum/go-ethereum/common"
  5. "github.com/iden3/go-iden3-crypto/babyjub"
  6. )
  7. // TxID is the identifier of a Hermez network transaction
  8. type TxID Hash // Hash is a guess
  9. // TxType is a string that represents the type of a Hermez network transaction
  10. type TxType string
  11. const (
  12. // TxTypeExit represents L2->L1 token transfer. A leaf for this account appears in the exit tree of the block
  13. TxTypeExit TxType = "Exit"
  14. // TxTypeWithdrawn represents the balance that was moved from L2->L1 has been widthrawn from the smart contract
  15. TxTypeWithdrawn TxType = "Withdrawn"
  16. // TxTypeTransfer represents L2->L2 token transfer
  17. TxTypeTransfer TxType = "Transfer"
  18. // TxTypeDeposit represents L1->L2 transfer
  19. TxTypeDeposit TxType = "Deposit"
  20. // TxTypeCreateAccountDeposit represents creation of a new leaf in the state tree (newAcconut) + L1->L2 transfer
  21. TxTypeCreateAccountDeposit TxType = "CreateAccountDeposit"
  22. // TxTypeCreateAccountDepositTransfer represents L1->L2 transfer + L2->L2 transfer
  23. TxTypeCreateAccountDepositTransfer TxType = "CreateAccountDepositTransfer"
  24. // TxTypeDepositTransfer TBD
  25. TxTypeDepositTransfer TxType = "TxTypeDepositTransfer"
  26. // TxTypeForceTransfer TBD
  27. TxTypeForceTransfer TxType = "TxTypeForceTransfer"
  28. // TxTypeForceExit TBD
  29. TxTypeForceExit TxType = "TxTypeForceExit"
  30. // TxTypeTransferToEthAddr TBD
  31. TxTypeTransferToEthAddr TxType = "TxTypeTransferToEthAddr"
  32. // TxTypeTransferToBJJ TBD
  33. TxTypeTransferToBJJ TxType = "TxTypeTransferToBJJ"
  34. )
  35. // Tx is a struct used by the TxSelector & BatchBuilder as a generic type generated from L1Tx & PoolL2Tx
  36. type Tx struct {
  37. // Generic
  38. IsL1 bool `meddler:"is_l1"`
  39. TxID TxID `meddler:"id"`
  40. Type TxType `meddler:"type"`
  41. Position int `meddler:"position"`
  42. FromIdx Idx `meddler:"from_idx"`
  43. ToIdx Idx `meddler:"to_idx"`
  44. Amount *big.Int `meddler:"amount,bigint"`
  45. AmountFloat float64 `meddler:"amount_f"`
  46. TokenID TokenID `meddler:"token_id"`
  47. USD float64 `meddler:"amount_usd,zeroisnull"`
  48. BatchNum BatchNum `meddler:"batch_num,zeroisnull"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0
  49. EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
  50. // L1
  51. ToForgeL1TxsNum uint32 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
  52. UserOrigin bool `meddler:"user_origin"` // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
  53. FromEthAddr ethCommon.Address `meddler:"from_eth_addr"`
  54. FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
  55. LoadAmount *big.Int `meddler:"load_amount,bigintnull"`
  56. LoadAmountFloat float64 `meddler:"load_amount_f"`
  57. LoadAmountUSD float64 `meddler:"load_amount_usd,zeroisnull"`
  58. // L2
  59. Fee FeeSelector `meddler:"fee,zeroisnull"`
  60. FeeUSD float64 `meddler:"fee_usd,zeroisnull"`
  61. Nonce Nonce `meddler:"nonce,zeroisnull"`
  62. }