mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Add TxID calculation & New{Layer}Tx Type
Add TxID calculation & New{Layer}Tx Type
New{Layer}Tx methods that compute the `TxID` & `TxType` values from the
transaction values:
- NewL1Tx
- NewL2Tx
- NewPoolL2Tx
Add TxID Scanner & Valuer for database/sql
HistoryDB & L2DB & API packages tests will need to be addapted to the
TestTransaction generation once is done.
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
@@ -357,7 +356,10 @@ func (s *Synchronizer) rollupSync(blockNum int64) (*rollupData, error) {
|
||||
// }
|
||||
|
||||
// Get L1UserTX
|
||||
rollupData.l1Txs = getL1UserTx(rollupEvents.L1UserTx, blockNum)
|
||||
rollupData.l1Txs, err = getL1UserTx(rollupEvents.L1UserTx, blockNum)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get ForgeBatch events to get the L1CoordinatorTxs
|
||||
for _, fbEvent := range rollupEvents.ForgeBatch {
|
||||
@@ -394,12 +396,15 @@ func (s *Synchronizer) rollupSync(blockNum int64) (*rollupData, error) {
|
||||
for _, l1CoordinatorTx := range forgeBatchArgs.L1CoordinatorTxs {
|
||||
l1CoordinatorTx.Position = position
|
||||
l1CoordinatorTx.ToForgeL1TxsNum = nextForgeL1TxsNum
|
||||
l1CoordinatorTx.TxID = common.TxID(common.Hash([]byte("0x01" + strconv.FormatInt(int64(nextForgeL1TxsNum), 10) + strconv.FormatInt(int64(l1CoordinatorTx.Position), 10) + "00")))
|
||||
l1CoordinatorTx.UserOrigin = false
|
||||
l1CoordinatorTx.EthBlockNum = blockNum
|
||||
bn := new(common.BatchNum)
|
||||
*bn = common.BatchNum(fbEvent.BatchNum)
|
||||
l1CoordinatorTx.BatchNum = bn
|
||||
l1CoordinatorTx, err = common.NewL1Tx(l1CoordinatorTx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
batchData.l1CoordinatorTxs = append(batchData.l1CoordinatorTxs, l1CoordinatorTx)
|
||||
|
||||
@@ -563,18 +568,22 @@ func (s *Synchronizer) wdelayerSync(blockNum int64) (*common.WithdrawalDelayerVa
|
||||
// return forgeBatchArgs.NewLastIdx + 1, nil
|
||||
// }
|
||||
|
||||
func getL1UserTx(l1UserTxEvents []eth.RollupEventL1UserTx, blockNum int64) []*common.L1Tx {
|
||||
func getL1UserTx(l1UserTxEvents []eth.RollupEventL1UserTx, blockNum int64) ([]*common.L1Tx, error) {
|
||||
l1Txs := make([]*common.L1Tx, 0)
|
||||
|
||||
for _, eL1UserTx := range l1UserTxEvents {
|
||||
// Fill aditional Tx fields
|
||||
eL1UserTx.L1Tx.TxID = common.TxID(common.Hash([]byte("0x00" + strconv.FormatInt(int64(eL1UserTx.ToForgeL1TxsNum), 10) + strconv.FormatInt(int64(eL1UserTx.Position), 10) + "00")))
|
||||
eL1UserTx.L1Tx.ToForgeL1TxsNum = eL1UserTx.ToForgeL1TxsNum
|
||||
eL1UserTx.L1Tx.Position = eL1UserTx.Position
|
||||
eL1UserTx.L1Tx.UserOrigin = true
|
||||
eL1UserTx.L1Tx.EthBlockNum = blockNum
|
||||
nL1Tx, err := common.NewL1Tx(&eL1UserTx.L1Tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
eL1UserTx.L1Tx = *nL1Tx
|
||||
|
||||
l1Txs = append(l1Txs, &eL1UserTx.L1Tx)
|
||||
}
|
||||
return l1Txs
|
||||
return l1Txs, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user