Merge pull request #411 from hermeznetwork/feature/forged-txs-in-batchesapi

Add forged txs in batch endpoints response
This commit is contained in:
Eduard S
2020-12-23 12:07:45 +01:00
committed by GitHub
4 changed files with 18 additions and 2 deletions

View File

@@ -171,8 +171,9 @@ func (hdb *HistoryDB) GetBatchAPI(batchNum common.BatchNum) (*BatchAPI, error) {
batch := &BatchAPI{}
return batch, tracerr.Wrap(meddler.QueryRow(
hdb.db, batch,
`SELECT batch.*, block.timestamp, block.hash
FROM batch INNER JOIN block ON batch.eth_block_num = block.eth_block_num
`SELECT batch.*, block.timestamp, block.hash,
COALESCE ((SELECT COUNT(*) FROM tx WHERE batch_num = batch.batch_num), 0) AS forged_txs
FROM batch INNER JOIN block ON batch.eth_block_num = block.eth_block_num
WHERE batch_num = $1;`, batchNum,
))
}
@@ -186,6 +187,7 @@ func (hdb *HistoryDB) GetBatchesAPI(
var query string
var args []interface{}
queryStr := `SELECT batch.*, block.timestamp, block.hash,
COALESCE ((SELECT COUNT(*) FROM tx WHERE batch_num = batch.batch_num), 0) AS forged_txs,
count(*) OVER() AS total_items
FROM batch INNER JOIN block ON batch.eth_block_num = block.eth_block_num `
// Apply filters

View File

@@ -291,6 +291,7 @@ type BatchAPI struct {
ExitRoot apitypes.BigIntStr `json:"exitRoot" meddler:"exit_root"`
ForgeL1TxsNum *int64 `json:"forgeL1TransactionsNum" meddler:"forge_l1_txs_num"`
SlotNum int64 `json:"slotNum" meddler:"slot_num"`
ForgedTxs int `json:"forgedTransactions" meddler:"forged_txs"`
TotalItems uint64 `json:"-" meddler:"total_items"`
FirstItem uint64 `json:"-" meddler:"first_item"`
LastItem uint64 `json:"-" meddler:"last_item"`