Update SQL schemas

This commit is contained in:
a_bennassar
2020-08-13 12:53:42 +02:00
committed by arnaucube
parent bf1a648091
commit cb1b820256
12 changed files with 418 additions and 108 deletions

View File

@@ -9,15 +9,19 @@ import (
// L1Tx is a struct that represents a L1 tx
type L1Tx struct {
Tx
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
PublicKey babyjub.PublicKey
LoadAmount *big.Int // amount transfered from L1 -> L2
EthBlockNum uint64 // Ethereum Block Number in which this L1Tx was added to the queue
EthTxHash eth.Hash // TxHash that added this L1Tx to the queue
Position int // Position among all the L1Txs in that batch
ToForgeL1TxsNum uint32 // toForgeL1TxsNum in which the tx was forged / will be forged
FromBJJ babyjub.PublicKey
CreateAccount bool // "from" + token ID is a new account
FromEthAddr eth.Address
// 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 eth.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
// Extra metadata, may be uninitialized
Type TxType `meddler:"-"` // optional, descrives which kind of tx it's
}

View File

@@ -1,7 +1,20 @@
package common
import (
"math/big"
)
// L2Tx is a struct that represents an already forged L2 tx
type L2Tx struct {
Tx
Position int // Position among all the L1Txs in that batch
// 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 uint64 `meddler:"nonce"`
// Extra metadata, may be uninitialized
Type TxType `meddler:"-"` // optional, descrives which kind of tx it's
}

View File

@@ -10,37 +10,46 @@ import (
// PoolL2Tx is a struct that represents a L2Tx sent by an account to the coordinator hat is waiting to be forged
type PoolL2Tx struct {
Tx
ToBJJ babyjub.PublicKey
Status PoolL2TxStatus
RqTxCompressedData []byte // 253 bits, optional for atomic txs
RqTx RqTx
Timestamp time.Time // time when added to the tx pool
Signature babyjub.Signature // tx signature
ToEthAddr eth.Address
AbsoluteFee float64 // TODO add methods to calculate this value from Tx.Fee tables + priceupdater tables
// Stored in DB: mandatory fileds
TxID TxID `meddler:"tx_id"`
FromIdx Idx `meddler:"from_idx"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
ToIdx Idx `meddler:"to_idx"` // ToIdx is ignored in L1Tx/Deposit, but used in the L1Tx/DepositAndTransfer
ToEthAddr eth.Address `meddler:"to_eth_addr"`
ToBJJ *babyjub.PublicKey `meddler:"to_bjj"` // TODO: stop using json, use scanner/valuer
TokenID TokenID `meddler:"token_id"`
Amount *big.Int `meddler:"amount,bigint"` // TODO: change to float16
Fee FeeSelector `meddler:"fee"`
Nonce uint64 `meddler:"nonce"` // effective 48 bits used
State PoolL2TxState `meddler:"state"`
Signature babyjub.Signature `meddler:"signature"` // tx signature
Timestamp time.Time `meddler:"timestamp,utctime"` // time when added to the tx pool
// Stored in DB: optional fileds, may be uninitialized
BatchNum BatchNum `meddler:"batch_num,zeroisnull"` // batchNum in which this tx was forged. Presence indicates "forged" state.
RqFromIdx Idx `meddler:"rq_from_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
RqToIdx Idx `meddler:"rq_to_idx,zeroisnull"` // FromIdx is used by L1Tx/Deposit to indicate the Idx receiver of the L1Tx.LoadAmount (deposit)
RqToEthAddr eth.Address `meddler:"rq_to_eth_addr"`
RqToBJJ *babyjub.PublicKey `meddler:"rq_to_bjj"` // TODO: stop using json, use scanner/valuer
RqTokenID TokenID `meddler:"rq_token_id,zeroisnull"`
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:"absolute_fee,zeroisnull"`
AbsoluteFeeUpdate time.Time `meddler:"absolute_fee_update,utctimez"`
// Extra metadata, may be uninitialized
Type TxType `meddler:"-"` // optional, descrives which kind of tx it's
RqTxCompressedData []byte `meddler:"-"` // 253 bits, optional for atomic txs
}
// RqTx Transaction Data used to indicate that a transaction depends on another transaction
type RqTx struct {
FromEthAddr eth.Address
ToEthAddr eth.Address
TokenID TokenID
Amount *big.Int
FeeSelector FeeSelector
Nonce uint64 // effective 48 bits used
}
// PoolL2TxStatus is a struct that represents the status of a L2 transaction
type PoolL2TxStatus string
// PoolL2TxState is a struct that represents the status of a L2 transaction
type PoolL2TxState string
const (
// PoolL2TxStatusPending represents a valid L2Tx that hasn't started the forging process
PoolL2TxStatusPending PoolL2TxStatus = "Pending"
// PoolL2TxStatusForging represents a valid L2Tx that has started the forging process
PoolL2TxStatusForging PoolL2TxStatus = "Forging"
// PoolL2TxStatusForged represents a L2Tx that has already been forged
PoolL2TxStatusForged PoolL2TxStatus = "Forged"
// PoolL2TxStatusInvalid represents a L2Tx that has been invalidated
PoolL2TxStatusInvalid PoolL2TxStatus = "Invalid"
// PoolL2TxStatePending represents a valid L2Tx that hasn't started the forging process
PoolL2TxStatePending PoolL2TxState = "pend"
// PoolL2TxStateForging represents a valid L2Tx that has started the forging process
PoolL2TxStateForging PoolL2TxState = "fing"
// PoolL2TxStateForged represents a L2Tx that has already been forged
PoolL2TxStateForged PoolL2TxState = "fged"
// PoolL2TxStateInvalid represents a L2Tx that has been invalidated
PoolL2TxStateInvalid PoolL2TxState = "invl"
)

View File

@@ -28,19 +28,6 @@ func IdxFromBigInt(b *big.Int) (Idx, error) {
return Idx(uint32(b.Int64())), nil
}
// Tx is a struct that represents a Hermez network transaction
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/DepositAndTransfer
TokenID TokenID
Amount *big.Int
Nonce uint64 // effective 48 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.
}
// TxID is the identifier of a Hermez network transaction
type TxID Hash // Hash is a guess