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.

116 lines
6.5 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. TokenID common.TokenID `json:"id" meddler:"token_id"`
  80. EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"` // Ethereum block number in which this token was registered
  81. EthAddr ethCommon.Address `json:"ethereumAddress" meddler:"eth_addr"`
  82. Name string `json:"name" meddler:"name"`
  83. Symbol string `json:"symbol" meddler:"symbol"`
  84. Decimals uint64 `json:"decimals" meddler:"decimals"`
  85. USD *float64 `json:"USD" meddler:"usd"`
  86. USDUpdate *time.Time `json:"fiatUpdate" meddler:"usd_update,utctime"`
  87. }
  88. // HistoryExit is a representation of a exit with additional information
  89. // required by the API, and extracted by joining token table
  90. type HistoryExit struct {
  91. ItemID int `meddler:"item_id"`
  92. BatchNum common.BatchNum `meddler:"batch_num"`
  93. AccountIdx common.Idx `meddler:"account_idx"`
  94. MerkleProof *merkletree.CircomVerifierProof `meddler:"merkle_proof,json"`
  95. Balance *big.Int `meddler:"balance,bigint"`
  96. InstantWithdrawn *int64 `meddler:"instant_withdrawn"`
  97. DelayedWithdrawRequest *int64 `meddler:"delayed_withdraw_request"`
  98. DelayedWithdrawn *int64 `meddler:"delayed_withdrawn"`
  99. TotalItems int `meddler:"total_items"`
  100. FirstItem int `meddler:"first_item"`
  101. LastItem int `meddler:"last_item"`
  102. TokenID common.TokenID `meddler:"token_id"`
  103. TokenEthBlockNum int64 `meddler:"token_block"`
  104. TokenEthAddr ethCommon.Address `meddler:"eth_addr"`
  105. TokenName string `meddler:"name"`
  106. TokenSymbol string `meddler:"symbol"`
  107. TokenDecimals uint64 `meddler:"decimals"`
  108. TokenUSD *float64 `meddler:"usd"`
  109. TokenUSDUpdate *time.Time `meddler:"usd_update"`
  110. }