Merge pull request #135 from hermeznetwork/feature/synchronizer-sc

Smart Contracts Data Synchronization
This commit is contained in:
Eduard S
2020-09-21 14:40:10 +02:00
committed by GitHub
13 changed files with 437 additions and 94 deletions

View File

@@ -14,6 +14,8 @@ import (
"github.com/russross/meddler"
)
// TODO(Edu): Document here how HistoryDB is kept consistent
// HistoryDB persist the historic of the rollup
type HistoryDB struct {
db *sqlx.DB
@@ -127,10 +129,11 @@ func (hdb *HistoryDB) GetLastBatchNum() (common.BatchNum, error) {
return batchNum, row.Scan(&batchNum)
}
// GetLastL1TxsNum returns the greatest ForgeL1TxsNum in the DB
func (hdb *HistoryDB) GetLastL1TxsNum() (uint32, error) {
// GetLastL1TxsNum returns the greatest ForgeL1TxsNum in the DB. If there's no
// batch in the DB (nil, nil) is returned.
func (hdb *HistoryDB) GetLastL1TxsNum() (*int64, error) {
row := hdb.db.QueryRow("SELECT MAX(forge_l1_txs_num) FROM batch;")
var lastL1TxsNum uint32
lastL1TxsNum := new(int64)
return lastL1TxsNum, row.Scan(&lastL1TxsNum)
}