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