mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Feature/merge history l2 tables (#156)
* WIP rebase * Combine both SQL DBs * API and DB refactor
This commit is contained in:
@@ -29,7 +29,9 @@ type L1Tx struct {
|
||||
LoadAmount *big.Int
|
||||
EthBlockNum int64 // Ethereum Block Number in which this L1Tx was added to the queue
|
||||
Type TxType
|
||||
BatchNum BatchNum
|
||||
BatchNum *BatchNum
|
||||
USD *float64
|
||||
LoadAmountUSD *float64
|
||||
}
|
||||
|
||||
// Tx returns a *Tx from the L1Tx
|
||||
@@ -52,11 +54,13 @@ func (tx *L1Tx) Tx() *Tx {
|
||||
FromBJJ: tx.FromBJJ,
|
||||
LoadAmount: tx.LoadAmount,
|
||||
EthBlockNum: tx.EthBlockNum,
|
||||
USD: tx.USD,
|
||||
LoadAmountUSD: tx.LoadAmountUSD,
|
||||
}
|
||||
if tx.LoadAmount != nil {
|
||||
lf := new(big.Float).SetInt(tx.LoadAmount)
|
||||
loadAmountFloat, _ := lf.Float64()
|
||||
genericTx.LoadAmountFloat = loadAmountFloat
|
||||
genericTx.LoadAmountFloat = &loadAmountFloat
|
||||
}
|
||||
return genericTx
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ type L2Tx struct {
|
||||
FromIdx Idx
|
||||
ToIdx Idx
|
||||
Amount *big.Int
|
||||
USD *float64
|
||||
Fee FeeSelector
|
||||
FeeUSD *float64
|
||||
Nonce Nonce
|
||||
Type TxType
|
||||
EthBlockNum int64 // Ethereum Block Number in which this L2Tx was added to the queue
|
||||
@@ -23,6 +25,12 @@ type L2Tx struct {
|
||||
func (tx *L2Tx) Tx() *Tx {
|
||||
f := new(big.Float).SetInt(tx.Amount)
|
||||
amountFloat, _ := f.Float64()
|
||||
batchNum := new(BatchNum)
|
||||
*batchNum = tx.BatchNum
|
||||
fee := new(FeeSelector)
|
||||
*fee = tx.Fee
|
||||
nonce := new(Nonce)
|
||||
*nonce = tx.Nonce
|
||||
return &Tx{
|
||||
IsL1: false,
|
||||
TxID: tx.TxID,
|
||||
@@ -31,11 +39,13 @@ func (tx *L2Tx) Tx() *Tx {
|
||||
FromIdx: tx.FromIdx,
|
||||
ToIdx: tx.ToIdx,
|
||||
Amount: tx.Amount,
|
||||
USD: tx.USD,
|
||||
AmountFloat: amountFloat,
|
||||
BatchNum: tx.BatchNum,
|
||||
BatchNum: batchNum,
|
||||
EthBlockNum: tx.EthBlockNum,
|
||||
Fee: tx.Fee,
|
||||
Nonce: tx.Nonce,
|
||||
Fee: fee,
|
||||
FeeUSD: tx.FeeUSD,
|
||||
Nonce: nonce,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ type PoolL2Tx struct {
|
||||
TokenID TokenID `meddler:"token_id"`
|
||||
Amount *big.Int `meddler:"amount,bigint"` // TODO: change to float16
|
||||
AmountFloat float64 `meddler:"amount_f"` // TODO: change to float16
|
||||
USD float64 `meddler:"value_usd"` // TODO: change to float16
|
||||
USD *float64 `meddler:"value_usd"` // TODO: change to float16
|
||||
Fee FeeSelector `meddler:"fee"`
|
||||
Nonce Nonce `meddler:"nonce"` // effective 40 bits used
|
||||
State PoolL2TxState `meddler:"state"`
|
||||
@@ -37,11 +37,12 @@ type PoolL2Tx struct {
|
||||
RqAmount *big.Int `meddler:"rq_amount,bigintnull"` // TODO: change to float16
|
||||
RqFee FeeSelector `meddler:"rq_fee,zeroisnull"`
|
||||
RqNonce uint64 `meddler:"rq_nonce,zeroisnull"` // effective 48 bits used
|
||||
AbsoluteFee float64 `meddler:"fee_usd,zeroisnull"`
|
||||
AbsoluteFeeUpdate time.Time `meddler:"usd_update,utctimez"`
|
||||
AbsoluteFee *float64 `meddler:"fee_usd"`
|
||||
AbsoluteFeeUpdate *time.Time `meddler:"usd_update,utctime"`
|
||||
Type TxType `meddler:"tx_type"`
|
||||
// Extra metadata, may be uninitialized
|
||||
RqTxCompressedData []byte `meddler:"-"` // 253 bits, optional for atomic txs
|
||||
TokenSymbol string `meddler:"token_symbol"`
|
||||
}
|
||||
|
||||
// TxCompressedData spec:
|
||||
@@ -186,8 +187,8 @@ func (tx *PoolL2Tx) Tx() *Tx {
|
||||
FromIdx: tx.FromIdx,
|
||||
ToIdx: tx.ToIdx,
|
||||
Amount: tx.Amount,
|
||||
Nonce: tx.Nonce,
|
||||
Fee: tx.Fee,
|
||||
Nonce: &tx.Nonce,
|
||||
Fee: &tx.Fee,
|
||||
Type: tx.Type,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ const tokenIDBytesLen = 4
|
||||
|
||||
// Token is a struct that represents an Ethereum token that is supported in Hermez network
|
||||
type Token struct {
|
||||
TokenID TokenID `meddler:"token_id"`
|
||||
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum block number in which this token was registered
|
||||
EthAddr ethCommon.Address `meddler:"eth_addr"`
|
||||
Name string `meddler:"name"`
|
||||
Symbol string `meddler:"symbol"`
|
||||
Decimals uint64 `meddler:"decimals"`
|
||||
USD float64 `meddler:"usd,zeroisnull"`
|
||||
USDUpdate time.Time `meddler:"usd_update,utctimez"`
|
||||
TokenID TokenID `json:"id" meddler:"token_id"`
|
||||
EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"` // Ethereum block number in which this token was registered
|
||||
EthAddr ethCommon.Address `json:"ethereumAddress" meddler:"eth_addr"`
|
||||
Name string `json:"name" meddler:"name"`
|
||||
Symbol string `json:"symbol" meddler:"symbol"`
|
||||
Decimals uint64 `json:"decimals" meddler:"decimals"`
|
||||
USD *float64 `json:"USD" meddler:"usd"`
|
||||
USDUpdate *time.Time `json:"fiatUpdate" meddler:"usd_update,utctime"`
|
||||
}
|
||||
|
||||
// TokenInfo provides the price of the token in USD
|
||||
|
||||
34
common/tx.go
34
common/tx.go
@@ -41,30 +41,30 @@ const (
|
||||
// Tx is a struct used by the TxSelector & BatchBuilder as a generic type generated from L1Tx & PoolL2Tx
|
||||
type Tx struct {
|
||||
// Generic
|
||||
IsL1 bool `meddler:"is_l1"`
|
||||
TxID TxID `meddler:"id"`
|
||||
Type TxType `meddler:"type"`
|
||||
Position int `meddler:"position"`
|
||||
FromIdx Idx `meddler:"from_idx"`
|
||||
ToIdx Idx `meddler:"to_idx"`
|
||||
Amount *big.Int `meddler:"amount,bigint"`
|
||||
AmountFloat float64 `meddler:"amount_f"`
|
||||
TokenID TokenID `meddler:"token_id"`
|
||||
USD float64 `meddler:"amount_usd,zeroisnull"`
|
||||
BatchNum BatchNum `meddler:"batch_num,zeroisnull"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0
|
||||
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
|
||||
IsL1 bool `meddler:"is_l1"`
|
||||
TxID TxID `meddler:"id"`
|
||||
Type TxType `meddler:"type"`
|
||||
Position int `meddler:"position"`
|
||||
FromIdx Idx `meddler:"from_idx"`
|
||||
ToIdx Idx `meddler:"to_idx"`
|
||||
Amount *big.Int `meddler:"amount,bigint"`
|
||||
AmountFloat float64 `meddler:"amount_f"`
|
||||
TokenID TokenID `meddler:"token_id"`
|
||||
USD *float64 `meddler:"amount_usd"`
|
||||
BatchNum *BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged. If the tx is L2, this must be != 0
|
||||
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
|
||||
// L1
|
||||
ToForgeL1TxsNum int64 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
|
||||
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
|
||||
FromEthAddr ethCommon.Address `meddler:"from_eth_addr"`
|
||||
FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
|
||||
LoadAmount *big.Int `meddler:"load_amount,bigintnull"`
|
||||
LoadAmountFloat float64 `meddler:"load_amount_f"`
|
||||
LoadAmountUSD float64 `meddler:"load_amount_usd,zeroisnull"`
|
||||
LoadAmountFloat *float64 `meddler:"load_amount_f"`
|
||||
LoadAmountUSD *float64 `meddler:"load_amount_usd"`
|
||||
// L2
|
||||
Fee FeeSelector `meddler:"fee,zeroisnull"`
|
||||
FeeUSD float64 `meddler:"fee_usd,zeroisnull"`
|
||||
Nonce Nonce `meddler:"nonce,zeroisnull"`
|
||||
Fee *FeeSelector `meddler:"fee"`
|
||||
FeeUSD *float64 `meddler:"fee_usd"`
|
||||
Nonce *Nonce `meddler:"nonce"`
|
||||
}
|
||||
|
||||
// L1Tx returns a *L1Tx from the Tx
|
||||
|
||||
Reference in New Issue
Block a user