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.

120 lines
6.6 KiB

  1. package historydb
  2. import (
  3. "math/big"
  4. "time"
  5. ethCommon "github.com/ethereum/go-ethereum/common"
  6. "github.com/hermeznetwork/hermez-node/common"
  7. "github.com/iden3/go-iden3-crypto/babyjub"
  8. "github.com/iden3/go-merkletree"
  9. )
  10. // HistoryTx is a representation of a generic Tx with additional information
  11. // required by the API, and extracted by joining block and token tables
  12. type HistoryTx struct {
  13. // Generic
  14. IsL1 bool `meddler:"is_l1"`
  15. TxID common.TxID `meddler:"id"`
  16. ItemID int `meddler:"item_id"`
  17. Type common.TxType `meddler:"type"`
  18. Position int `meddler:"position"`
  19. FromIdx *common.Idx `meddler:"from_idx"`
  20. ToIdx common.Idx `meddler:"to_idx"`
  21. Amount *big.Int `meddler:"amount,bigint"`
  22. HistoricUSD *float64 `meddler:"amount_usd"`
  23. BatchNum *common.BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0
  24. EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
  25. // L1
  26. ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
  27. 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
  28. FromEthAddr *ethCommon.Address `meddler:"from_eth_addr"`
  29. FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
  30. LoadAmount *big.Int `meddler:"load_amount,bigintnull"`
  31. // LoadAmountFloat *float64 `meddler:"load_amount_f"`
  32. HistoricLoadAmountUSD *float64 `meddler:"load_amount_usd"`
  33. // L2
  34. Fee *common.FeeSelector `meddler:"fee"`
  35. HistoricFeeUSD *float64 `meddler:"fee_usd"`
  36. Nonce *common.Nonce `meddler:"nonce"`
  37. // API extras
  38. Timestamp time.Time `meddler:"timestamp,utctime"`
  39. TotalItems int `meddler:"total_items"`
  40. FirstItem int `meddler:"first_item"`
  41. LastItem int `meddler:"last_item"`
  42. TokenID common.TokenID `meddler:"token_id"`
  43. TokenEthBlockNum int64 `meddler:"token_block"`
  44. TokenEthAddr ethCommon.Address `meddler:"eth_addr"`
  45. TokenName string `meddler:"name"`
  46. TokenSymbol string `meddler:"symbol"`
  47. TokenDecimals uint64 `meddler:"decimals"`
  48. TokenUSD *float64 `meddler:"usd"`
  49. TokenUSDUpdate *time.Time `meddler:"usd_update"`
  50. }
  51. // txWrite is an representatiion that merges common.L1Tx and common.L2Tx
  52. // in order to perform inserts into tx table
  53. type txWrite struct {
  54. // Generic
  55. IsL1 bool `meddler:"is_l1"`
  56. TxID common.TxID `meddler:"id"`
  57. Type common.TxType `meddler:"type"`
  58. Position int `meddler:"position"`
  59. FromIdx *common.Idx `meddler:"from_idx"`
  60. ToIdx common.Idx `meddler:"to_idx"`
  61. Amount *big.Int `meddler:"amount,bigint"`
  62. AmountFloat float64 `meddler:"amount_f"`
  63. TokenID common.TokenID `meddler:"token_id"`
  64. BatchNum *common.BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0
  65. EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
  66. // L1
  67. ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
  68. 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
  69. FromEthAddr *ethCommon.Address `meddler:"from_eth_addr"`
  70. FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
  71. LoadAmount *big.Int `meddler:"load_amount,bigintnull"`
  72. LoadAmountFloat *float64 `meddler:"load_amount_f"`
  73. // L2
  74. Fee *common.FeeSelector `meddler:"fee"`
  75. Nonce *common.Nonce `meddler:"nonce"`
  76. }
  77. // TokenRead add USD info to common.Token
  78. type TokenRead struct {
  79. ItemID int `meddler:"item_id"`
  80. TokenID common.TokenID `meddler:"token_id"`
  81. EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum block number in which this token was registered
  82. EthAddr ethCommon.Address `meddler:"eth_addr"`
  83. Name string `meddler:"name"`
  84. Symbol string `meddler:"symbol"`
  85. Decimals uint64 `meddler:"decimals"`
  86. USD *float64 `meddler:"usd"`
  87. USDUpdate *time.Time `meddler:"usd_update,utctime"`
  88. TotalItems int `meddler:"total_items"`
  89. FirstItem int `meddler:"first_item"`
  90. LastItem int `meddler:"last_item"`
  91. }
  92. // HistoryExit is a representation of a exit with additional information
  93. // required by the API, and extracted by joining token table
  94. type HistoryExit struct {
  95. ItemID int `meddler:"item_id"`
  96. BatchNum common.BatchNum `meddler:"batch_num"`
  97. AccountIdx common.Idx `meddler:"account_idx"`
  98. MerkleProof *merkletree.CircomVerifierProof `meddler:"merkle_proof,json"`
  99. Balance *big.Int `meddler:"balance,bigint"`
  100. InstantWithdrawn *int64 `meddler:"instant_withdrawn"`
  101. DelayedWithdrawRequest *int64 `meddler:"delayed_withdraw_request"`
  102. DelayedWithdrawn *int64 `meddler:"delayed_withdrawn"`
  103. TotalItems int `meddler:"total_items"`
  104. FirstItem int `meddler:"first_item"`
  105. LastItem int `meddler:"last_item"`
  106. TokenID common.TokenID `meddler:"token_id"`
  107. TokenEthBlockNum int64 `meddler:"token_block"`
  108. TokenEthAddr ethCommon.Address `meddler:"eth_addr"`
  109. TokenName string `meddler:"name"`
  110. TokenSymbol string `meddler:"symbol"`
  111. TokenDecimals uint64 `meddler:"decimals"`
  112. TokenUSD *float64 `meddler:"usd"`
  113. TokenUSDUpdate *time.Time `meddler:"usd_update"`
  114. }