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.

88 lines
4.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. )
  9. // HistoryTx is a representation of a generic Tx with additional information
  10. // required by the API, and extracted by joining block and token tables
  11. type HistoryTx struct {
  12. // Generic
  13. IsL1 bool `meddler:"is_l1"`
  14. TxID common.TxID `meddler:"id"`
  15. Type common.TxType `meddler:"type"`
  16. Position int `meddler:"position"`
  17. FromIdx *common.Idx `meddler:"from_idx"`
  18. ToIdx common.Idx `meddler:"to_idx"`
  19. Amount *big.Int `meddler:"amount,bigint"`
  20. HistoricUSD *float64 `meddler:"amount_usd"`
  21. BatchNum *common.BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0
  22. EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
  23. // L1
  24. ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
  25. 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
  26. FromEthAddr *ethCommon.Address `meddler:"from_eth_addr"`
  27. FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
  28. LoadAmount *big.Int `meddler:"load_amount,bigintnull"`
  29. // LoadAmountFloat *float64 `meddler:"load_amount_f"`
  30. HistoricLoadAmountUSD *float64 `meddler:"load_amount_usd"`
  31. // L2
  32. Fee *common.FeeSelector `meddler:"fee"`
  33. HistoricFeeUSD *float64 `meddler:"fee_usd"`
  34. Nonce *common.Nonce `meddler:"nonce"`
  35. // API extras
  36. Timestamp time.Time `meddler:"timestamp,utctime"`
  37. TotalItems int `meddler:"total_items"`
  38. TokenID common.TokenID `meddler:"token_id"`
  39. TokenEthBlockNum int64 `meddler:"token_block"`
  40. TokenEthAddr ethCommon.Address `meddler:"eth_addr"`
  41. TokenName string `meddler:"name"`
  42. TokenSymbol string `meddler:"symbol"`
  43. TokenDecimals uint64 `meddler:"decimals"`
  44. TokenUSD *float64 `meddler:"usd"`
  45. TokenUSDUpdate *time.Time `meddler:"usd_update"`
  46. }
  47. // txWrite is an representatiion that merges common.L1Tx and common.L2Tx
  48. // in order to perform inserts into tx table
  49. type txWrite struct {
  50. // Generic
  51. IsL1 bool `meddler:"is_l1"`
  52. TxID common.TxID `meddler:"id"`
  53. Type common.TxType `meddler:"type"`
  54. Position int `meddler:"position"`
  55. FromIdx *common.Idx `meddler:"from_idx"`
  56. ToIdx common.Idx `meddler:"to_idx"`
  57. Amount *big.Int `meddler:"amount,bigint"`
  58. AmountFloat float64 `meddler:"amount_f"`
  59. TokenID common.TokenID `meddler:"token_id"`
  60. BatchNum *common.BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0
  61. EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
  62. // L1
  63. ToForgeL1TxsNum *int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
  64. 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
  65. FromEthAddr *ethCommon.Address `meddler:"from_eth_addr"`
  66. FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
  67. LoadAmount *big.Int `meddler:"load_amount,bigintnull"`
  68. LoadAmountFloat *float64 `meddler:"load_amount_f"`
  69. // L2
  70. Fee *common.FeeSelector `meddler:"fee"`
  71. Nonce *common.Nonce `meddler:"nonce"`
  72. }
  73. // TokenRead add USD info to common.Token
  74. type TokenRead struct {
  75. TokenID common.TokenID `json:"id" meddler:"token_id"`
  76. EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"` // Ethereum block number in which this token was registered
  77. EthAddr ethCommon.Address `json:"ethereumAddress" meddler:"eth_addr"`
  78. Name string `json:"name" meddler:"name"`
  79. Symbol string `json:"symbol" meddler:"symbol"`
  80. Decimals uint64 `json:"decimals" meddler:"decimals"`
  81. USD *float64 `json:"USD" meddler:"usd"`
  82. USDUpdate *time.Time `json:"fiatUpdate" meddler:"usd_update,utctime"`
  83. }