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