mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Add forged txs in batch endpoints response
This commit is contained in:
@@ -27,6 +27,7 @@ type testBatch struct {
|
|||||||
ExitRoot string `json:"exitRoot"`
|
ExitRoot string `json:"exitRoot"`
|
||||||
ForgeL1TxsNum *int64 `json:"forgeL1TransactionsNum"`
|
ForgeL1TxsNum *int64 `json:"forgeL1TransactionsNum"`
|
||||||
SlotNum int64 `json:"slotNum"`
|
SlotNum int64 `json:"slotNum"`
|
||||||
|
ForgedTxs int `json:"forgedTransactions"`
|
||||||
}
|
}
|
||||||
type testBatchesResponse struct {
|
type testBatchesResponse struct {
|
||||||
Batches []testBatch `json:"batches"`
|
Batches []testBatch `json:"batches"`
|
||||||
@@ -73,6 +74,12 @@ func genTestBatches(
|
|||||||
for k, v := range cBatches[i].CollectedFees {
|
for k, v := range cBatches[i].CollectedFees {
|
||||||
collectedFees[k] = v.String()
|
collectedFees[k] = v.String()
|
||||||
}
|
}
|
||||||
|
forgedTxs := 0
|
||||||
|
for _, tx := range txs {
|
||||||
|
if tx.BatchNum != nil && *tx.BatchNum == cBatches[i].BatchNum {
|
||||||
|
forgedTxs++
|
||||||
|
}
|
||||||
|
}
|
||||||
tBatch := testBatch{
|
tBatch := testBatch{
|
||||||
BatchNum: cBatches[i].BatchNum,
|
BatchNum: cBatches[i].BatchNum,
|
||||||
EthBlockNum: cBatches[i].EthBlockNum,
|
EthBlockNum: cBatches[i].EthBlockNum,
|
||||||
@@ -86,6 +93,7 @@ func genTestBatches(
|
|||||||
ExitRoot: cBatches[i].ExitRoot.String(),
|
ExitRoot: cBatches[i].ExitRoot.String(),
|
||||||
ForgeL1TxsNum: cBatches[i].ForgeL1TxsNum,
|
ForgeL1TxsNum: cBatches[i].ForgeL1TxsNum,
|
||||||
SlotNum: cBatches[i].SlotNum,
|
SlotNum: cBatches[i].SlotNum,
|
||||||
|
ForgedTxs: forgedTxs,
|
||||||
}
|
}
|
||||||
tBatches = append(tBatches, tBatch)
|
tBatches = append(tBatches, tBatch)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2113,6 +2113,10 @@ components:
|
|||||||
nullable: true
|
nullable: true
|
||||||
slotNum:
|
slotNum:
|
||||||
$ref: '#/components/schemas/SlotNum'
|
$ref: '#/components/schemas/SlotNum'
|
||||||
|
forgedTransactions:
|
||||||
|
type: integer
|
||||||
|
description: Amount of forged transactions in this batch.
|
||||||
|
example: 318
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
required:
|
required:
|
||||||
- itemId
|
- itemId
|
||||||
@@ -2128,6 +2132,7 @@ components:
|
|||||||
- exitRoot
|
- exitRoot
|
||||||
- forgeL1TransactionsNum
|
- forgeL1TransactionsNum
|
||||||
- slotNum
|
- slotNum
|
||||||
|
- forgedTransactions
|
||||||
FullBatch:
|
FullBatch:
|
||||||
type: object
|
type: object
|
||||||
description: Group of transactions forged in a coordinator and sent and validated in Ethereum.
|
description: Group of transactions forged in a coordinator and sent and validated in Ethereum.
|
||||||
|
|||||||
@@ -171,8 +171,9 @@ func (hdb *HistoryDB) GetBatchAPI(batchNum common.BatchNum) (*BatchAPI, error) {
|
|||||||
batch := &BatchAPI{}
|
batch := &BatchAPI{}
|
||||||
return batch, tracerr.Wrap(meddler.QueryRow(
|
return batch, tracerr.Wrap(meddler.QueryRow(
|
||||||
hdb.db, batch,
|
hdb.db, batch,
|
||||||
`SELECT batch.*, block.timestamp, block.hash
|
`SELECT batch.*, block.timestamp, block.hash,
|
||||||
FROM batch INNER JOIN block ON batch.eth_block_num = block.eth_block_num
|
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,
|
WHERE batch_num = $1;`, batchNum,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -186,6 +187,7 @@ func (hdb *HistoryDB) GetBatchesAPI(
|
|||||||
var query string
|
var query string
|
||||||
var args []interface{}
|
var args []interface{}
|
||||||
queryStr := `SELECT batch.*, block.timestamp, block.hash,
|
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
|
count(*) OVER() AS total_items
|
||||||
FROM batch INNER JOIN block ON batch.eth_block_num = block.eth_block_num `
|
FROM batch INNER JOIN block ON batch.eth_block_num = block.eth_block_num `
|
||||||
// Apply filters
|
// Apply filters
|
||||||
|
|||||||
@@ -291,6 +291,7 @@ type BatchAPI struct {
|
|||||||
ExitRoot apitypes.BigIntStr `json:"exitRoot" meddler:"exit_root"`
|
ExitRoot apitypes.BigIntStr `json:"exitRoot" meddler:"exit_root"`
|
||||||
ForgeL1TxsNum *int64 `json:"forgeL1TransactionsNum" meddler:"forge_l1_txs_num"`
|
ForgeL1TxsNum *int64 `json:"forgeL1TransactionsNum" meddler:"forge_l1_txs_num"`
|
||||||
SlotNum int64 `json:"slotNum" meddler:"slot_num"`
|
SlotNum int64 `json:"slotNum" meddler:"slot_num"`
|
||||||
|
ForgedTxs int `json:"forgedTransactions" meddler:"forged_txs"`
|
||||||
TotalItems uint64 `json:"-" meddler:"total_items"`
|
TotalItems uint64 `json:"-" meddler:"total_items"`
|
||||||
FirstItem uint64 `json:"-" meddler:"first_item"`
|
FirstItem uint64 `json:"-" meddler:"first_item"`
|
||||||
LastItem uint64 `json:"-" meddler:"last_item"`
|
LastItem uint64 `json:"-" meddler:"last_item"`
|
||||||
|
|||||||
Reference in New Issue
Block a user