Add TokenID to L2Tx

L2Tx.TokenID is not on the data obtained by the Synchronizer from the
blockchain, but is set by the TxProcessor when processing the
transactions in the StateDB.
This commit is contained in:
arnaucube
2021-01-27 12:40:09 +01:00
parent f3678e8cb8
commit a899f43914
5 changed files with 25 additions and 13 deletions

View File

@@ -205,6 +205,7 @@ func (tx L1Tx) TxCompressedData(chainID uint16) (*big.Int, error) {
}
// BytesDataAvailability encodes a L1Tx into []byte for the Data Availability
// [ fromIdx | toIdx | amountFloat16 | Fee ]
func (tx *L1Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) {
idxLen := nLevels / 8 //nolint:gomnd

View File

@@ -10,16 +10,19 @@ import (
// L2Tx is a struct that represents an already forged L2 tx
type L2Tx struct {
// Stored in DB: mandatory fileds
TxID TxID `meddler:"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:"type"`
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L2Tx was added to the queue
TxID TxID `meddler:"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"`
// TokenID is filled by the TxProcessor
TokenID TokenID `meddler:"token_id"`
Amount *big.Int `meddler:"amount,bigint"`
Fee FeeSelector `meddler:"fee"`
// Nonce is filled by the TxProcessor
Nonce Nonce `meddler:"nonce"`
Type TxType `meddler:"type"`
EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum Block Number in which this L2Tx was added to the queue
}
// NewL2Tx returns the given L2Tx with the TxId & Type parameters calculated
@@ -92,6 +95,7 @@ func (tx *L2Tx) Tx() *Tx {
Position: tx.Position,
FromIdx: tx.FromIdx,
ToIdx: tx.ToIdx,
TokenID: tx.TokenID,
Amount: tx.Amount,
BatchNum: batchNum,
EthBlockNum: tx.EthBlockNum,
@@ -107,6 +111,7 @@ func (tx L2Tx) PoolL2Tx() *PoolL2Tx {
TxID: tx.TxID,
FromIdx: tx.FromIdx,
ToIdx: tx.ToIdx,
TokenID: tx.TokenID,
Amount: tx.Amount,
Fee: tx.Fee,
Nonce: tx.Nonce,
@@ -134,6 +139,7 @@ func TxIDsFromL2Txs(txs []L2Tx) []TxID {
}
// BytesDataAvailability encodes a L2Tx into []byte for the Data Availability
// [ fromIdx | toIdx | amountFloat16 | Fee ]
func (tx L2Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) {
idxLen := nLevels / 8 //nolint:gomnd

View File

@@ -281,7 +281,8 @@ func (tx *PoolL2Tx) RqTxCompressedDataV2() (*big.Int, error) {
return bi, nil
}
// HashToSign returns the computed Poseidon hash from the *PoolL2Tx that will be signed by the sender.
// HashToSign returns the computed Poseidon hash from the *PoolL2Tx that will
// be signed by the sender.
func (tx *PoolL2Tx) HashToSign(chainID uint16) (*big.Int, error) {
toCompressedData, err := tx.TxCompressedData(chainID)
if err != nil {
@@ -331,6 +332,7 @@ func (tx PoolL2Tx) L2Tx() L2Tx {
TxID: tx.TxID,
FromIdx: tx.FromIdx,
ToIdx: toIdx,
TokenID: tx.TokenID,
Amount: tx.Amount,
Fee: tx.Fee,
Nonce: tx.Nonce,