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