mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Add HistoryDB SQL triggers (#125)
This commit is contained in:
@@ -65,11 +65,13 @@ func IdxFromBigInt(b *big.Int) (Idx, error) {
|
||||
|
||||
// Account is a struct that gives information of the holdings of an address and a specific token. Is the data structure that generates the Value stored in the leaf of the MerkleTree
|
||||
type Account struct {
|
||||
TokenID TokenID
|
||||
Nonce Nonce // max of 40 bits used
|
||||
Balance *big.Int // max of 192 bits used
|
||||
PublicKey *babyjub.PublicKey
|
||||
EthAddr ethCommon.Address
|
||||
Idx Idx `meddler:"idx"`
|
||||
TokenID TokenID `meddler:"token_id"`
|
||||
BatchNum BatchNum `meddler:"batch_num"`
|
||||
PublicKey *babyjub.PublicKey `meddler:"bjj"`
|
||||
EthAddr ethCommon.Address `meddler:"eth_addr"`
|
||||
Nonce Nonce `meddler:"-"` // max of 40 bits used
|
||||
Balance *big.Int `meddler:"-"` // max of 192 bits used
|
||||
}
|
||||
|
||||
func (a *Account) String() string {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
// Block represents of an Ethereum block
|
||||
type Block struct {
|
||||
EthBlockNum int64 `meddler:"eth_block_num"`
|
||||
Timestamp time.Time `meddler:"timestamp"`
|
||||
Timestamp time.Time `meddler:"timestamp,utctime"`
|
||||
Hash ethCommon.Hash `meddler:"hash"`
|
||||
ParentHash ethCommon.Hash `meddler:"-"`
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
// Coordinator represents a Hermez network coordinator who wins an auction for an specific slot
|
||||
// WARNING: this is strongly based on the previous implementation, once the new spec is done, this may change a lot.
|
||||
type Coordinator struct {
|
||||
EthBlockNum int64 // block in which the coordinator was registered
|
||||
Forger ethCommon.Address // address of the forger
|
||||
Beneficiary ethCommon.Address // address of the beneficiary
|
||||
Withdraw ethCommon.Address // address of the withdraw
|
||||
URL string // URL of the coordinators API
|
||||
}
|
||||
|
||||
@@ -18,31 +18,49 @@ const (
|
||||
// L1Tx is a struct that represents a L1 tx
|
||||
type L1Tx struct {
|
||||
// Stored in DB: mandatory fileds
|
||||
TxID TxID `meddler:"tx_id"`
|
||||
ToForgeL1TxsNum uint32 `meddler:"to_forge_l1_txs_num"` // toForgeL1TxsNum in which the tx was forged / will be forged
|
||||
Position int `meddler:"position"`
|
||||
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
|
||||
FromIdx Idx `meddler:"from_idx"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
|
||||
FromEthAddr ethCommon.Address `meddler:"from_eth_addr"`
|
||||
FromBJJ *babyjub.PublicKey `meddler:"from_bjj"`
|
||||
ToIdx Idx `meddler:"to_idx"` // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositAndTransfer
|
||||
TokenID TokenID `meddler:"token_id"`
|
||||
Amount *big.Int `meddler:"amount,bigint"`
|
||||
LoadAmount *big.Int `meddler:"load_amount,bigint"`
|
||||
EthBlockNum uint64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L1Tx was added to the queue
|
||||
Type TxType `meddler:"tx_type"`
|
||||
BatchNum BatchNum `meddler:"-"`
|
||||
TxID TxID
|
||||
ToForgeL1TxsNum uint32 // toForgeL1TxsNum in which the tx was forged / will be forged
|
||||
Position int
|
||||
UserOrigin bool // 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
|
||||
FromIdx Idx // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
|
||||
FromEthAddr ethCommon.Address
|
||||
FromBJJ *babyjub.PublicKey
|
||||
ToIdx Idx // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositAndTransfer
|
||||
TokenID TokenID
|
||||
Amount *big.Int
|
||||
LoadAmount *big.Int
|
||||
EthBlockNum int64 // Ethereum Block Number in which this L1Tx was added to the queue
|
||||
Type TxType
|
||||
BatchNum BatchNum
|
||||
}
|
||||
|
||||
// Tx returns a *Tx from the L1Tx
|
||||
func (tx *L1Tx) Tx() *Tx {
|
||||
return &Tx{
|
||||
TxID: tx.TxID,
|
||||
FromIdx: tx.FromIdx,
|
||||
ToIdx: tx.ToIdx,
|
||||
Amount: tx.Amount,
|
||||
Type: tx.Type,
|
||||
f := new(big.Float).SetInt(tx.Amount)
|
||||
amountFloat, _ := f.Float64()
|
||||
genericTx := &Tx{
|
||||
IsL1: true,
|
||||
TxID: tx.TxID,
|
||||
Type: tx.Type,
|
||||
Position: tx.Position,
|
||||
FromIdx: tx.FromIdx,
|
||||
ToIdx: tx.ToIdx,
|
||||
Amount: tx.Amount,
|
||||
AmountFloat: amountFloat,
|
||||
TokenID: tx.TokenID,
|
||||
ToForgeL1TxsNum: tx.ToForgeL1TxsNum,
|
||||
UserOrigin: tx.UserOrigin,
|
||||
FromEthAddr: tx.FromEthAddr,
|
||||
FromBJJ: tx.FromBJJ,
|
||||
LoadAmount: tx.LoadAmount,
|
||||
EthBlockNum: tx.EthBlockNum,
|
||||
}
|
||||
if tx.LoadAmount != nil {
|
||||
lf := new(big.Float).SetInt(tx.LoadAmount)
|
||||
loadAmountFloat, _ := lf.Float64()
|
||||
genericTx.LoadAmountFloat = loadAmountFloat
|
||||
}
|
||||
return genericTx
|
||||
}
|
||||
|
||||
// Bytes encodes a L1Tx into []byte
|
||||
|
||||
@@ -7,27 +7,35 @@ import (
|
||||
// L2Tx is a struct that represents an already forged L2 tx
|
||||
type L2Tx struct {
|
||||
// Stored in DB: mandatory fileds
|
||||
TxID TxID `meddler:"tx_id"`
|
||||
BatchNum BatchNum `meddler:"batch_num"` // batchNum in which this tx was forged.
|
||||
Position int `meddler:"position"`
|
||||
FromIdx Idx `meddler:"from_idx"`
|
||||
ToIdx Idx `meddler:"to_idx"`
|
||||
Amount *big.Int `meddler:"amount,bigint"`
|
||||
Fee FeeSelector `meddler:"fee"`
|
||||
Nonce Nonce `meddler:"nonce"`
|
||||
Type TxType `meddler:"tx_type"`
|
||||
TxID TxID
|
||||
BatchNum BatchNum // batchNum in which this tx was forged.
|
||||
Position int
|
||||
FromIdx Idx
|
||||
ToIdx Idx
|
||||
Amount *big.Int
|
||||
Fee FeeSelector
|
||||
Nonce Nonce
|
||||
Type TxType
|
||||
EthBlockNum int64 // Ethereum Block Number in which this L2Tx was added to the queue
|
||||
}
|
||||
|
||||
// Tx returns a *Tx from the L2Tx
|
||||
func (tx *L2Tx) Tx() *Tx {
|
||||
f := new(big.Float).SetInt(tx.Amount)
|
||||
amountFloat, _ := f.Float64()
|
||||
return &Tx{
|
||||
TxID: tx.TxID,
|
||||
FromIdx: tx.FromIdx,
|
||||
ToIdx: tx.ToIdx,
|
||||
Amount: tx.Amount,
|
||||
Nonce: tx.Nonce,
|
||||
Fee: tx.Fee,
|
||||
Type: tx.Type,
|
||||
IsL1: false,
|
||||
TxID: tx.TxID,
|
||||
Type: tx.Type,
|
||||
Position: tx.Position,
|
||||
FromIdx: tx.FromIdx,
|
||||
ToIdx: tx.ToIdx,
|
||||
Amount: tx.Amount,
|
||||
AmountFloat: amountFloat,
|
||||
BatchNum: tx.BatchNum,
|
||||
EthBlockNum: tx.EthBlockNum,
|
||||
Fee: tx.Fee,
|
||||
Nonce: tx.Nonce,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,14 @@ import (
|
||||
|
||||
// Token is a struct that represents an Ethereum token that is supported in Hermez network
|
||||
type Token struct {
|
||||
TokenID TokenID
|
||||
EthAddr ethCommon.Address
|
||||
Name string
|
||||
Symbol string
|
||||
Decimals uint64
|
||||
EthTxHash ethCommon.Hash // Ethereum TxHash in which this token was registered
|
||||
EthBlockNum uint64 // Ethereum block number in which this token was registered
|
||||
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 float32 `meddler:"usd,zeroisnull"`
|
||||
USDUpdate time.Time `meddler:"usd_update,utctimez"`
|
||||
}
|
||||
|
||||
// TokenInfo provides the price of the token in USD
|
||||
|
||||
36
common/tx.go
36
common/tx.go
@@ -2,6 +2,9 @@ package common
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
)
|
||||
|
||||
// TxID is the identifier of a Hermez network transaction
|
||||
@@ -37,12 +40,29 @@ const (
|
||||
|
||||
// Tx is a struct used by the TxSelector & BatchBuilder as a generic type generated from L1Tx & PoolL2Tx
|
||||
type Tx struct {
|
||||
TxID TxID
|
||||
FromIdx Idx // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
|
||||
ToIdx Idx // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositTransfer
|
||||
Amount *big.Int
|
||||
Nonce Nonce // effective 40 bits used
|
||||
Fee FeeSelector
|
||||
Type TxType // optional, descrives which kind of tx it's
|
||||
BatchNum BatchNum // batchNum in which this tx was forged. Presence indicates "forged" state.
|
||||
// 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
|
||||
// L1
|
||||
ToForgeL1TxsNum uint32 `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"`
|
||||
// L2
|
||||
Fee FeeSelector `meddler:"fee,zeroisnull"`
|
||||
FeeUSD float64 `meddler:"fee_usd,zeroisnull"`
|
||||
Nonce Nonce `meddler:"nonce,zeroisnull"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user