mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Add apitypes to avoid parsing from/to DB
This commit is contained in:
@@ -150,6 +150,15 @@ func (hdb *HistoryDB) addBatches(d meddler.DB, batches []common.Batch) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBatch return the batch with the given batchNum
|
||||
func (hdb *HistoryDB) GetBatch(batchNum common.BatchNum) (HistoryBatch, error) {
|
||||
var batch *common.Batch
|
||||
return batch, meddler.QueryRow(
|
||||
hdb.db, &batch,
|
||||
"SELECT * FROM batch WHERE batch_num == $1;", batchNum,
|
||||
)
|
||||
}
|
||||
|
||||
// GetBatches retrieve batches from the DB, given a range of batch numbers defined by from and to
|
||||
func (hdb *HistoryDB) GetBatches(from, to common.BatchNum) ([]common.Batch, error) {
|
||||
var batches []*common.Batch
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/db"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
"github.com/iden3/go-merkletree"
|
||||
)
|
||||
@@ -131,3 +132,24 @@ type HistoryCoordinator struct {
|
||||
FirstItem int `meddler:"first_item"`
|
||||
LastItem int `meddler:"last_item"`
|
||||
}
|
||||
|
||||
// HistoryBatch is a representation of a batch with additional information
|
||||
// required by the API, and extracted by joining block table
|
||||
type HistoryBatch struct {
|
||||
ItemID int `json:"itemId" meddler:"item_id"`
|
||||
BatchNum common.BatchNum `json:"batchNum" meddler:"batch_num"`
|
||||
EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"`
|
||||
EthBlockHash ethCommon.Hash `json:"ethereumBlockHash" meddler:"hash"`
|
||||
Timestamp time.Time `json:"timestamp" meddler:"timestamp,utctime"`
|
||||
ForgerAddr ethCommon.Address `json:"forgerAddr" meddler:"forger_addr"`
|
||||
CollectedFees map[common.TokenID]db.BigIntStr `json:"collectedFees" meddler:"fees_collected,json"`
|
||||
TotalFeesUSD float64 `json:"historicTotalCollectedFeesUSD" meddler:"total_fees_usd"`
|
||||
StateRoot db.BigIntStr `json:"stateRoot" meddler:"state_root"`
|
||||
NumAccounts int `json:"numAccounts" meddler:"num_accounts"`
|
||||
ExitRoot db.BigIntStr `json:"exitRoot" meddler:"exit_root"`
|
||||
ForgeL1TxsNum *int64 `json:"forgeL1TransactionsNum" meddler:"forge_l1_txs_num"`
|
||||
SlotNum int64 `json:"slotNum" meddler:"slot_num"`
|
||||
TotalItems int `json:"-" meddler:"total_items"`
|
||||
FirstItem int `json:"-" meddler:"first_item"`
|
||||
LastItem int `json:"-" meddler:"last_item"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user