arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Merge pull request #411 from hermeznetwork/feature/forged-txs-in-batchesapi

Add forged txs in batch endpoints response
Eduard S eduard@iden3.io
Wed, 23 Dec 2020 12:07:45 +0100
commit

fb48ca4e588a20e03b63fa9727960fac679842a5

parent

4793a20727faffb45eee89698d106eee5b9bc98f

4 files changed, 18 insertions(+), 2 deletions(-)

jump to
M api/batch_test.go → api/batch_test.go

@@ -27,6 +27,7 @@ NumAccounts int `json:"numAccounts"`

ExitRoot string `json:"exitRoot"` ForgeL1TxsNum *int64 `json:"forgeL1TransactionsNum"` SlotNum int64 `json:"slotNum"` + ForgedTxs int `json:"forgedTransactions"` } type testBatchesResponse struct { Batches []testBatch `json:"batches"`

@@ -73,6 +74,12 @@ collectedFees := make(map[common.TokenID]string)

for k, v := range cBatches[i].CollectedFees { collectedFees[k] = v.String() } + forgedTxs := 0 + for _, tx := range txs { + if tx.BatchNum != nil && *tx.BatchNum == cBatches[i].BatchNum { + forgedTxs++ + } + } tBatch := testBatch{ BatchNum: cBatches[i].BatchNum, EthBlockNum: cBatches[i].EthBlockNum,

@@ -86,6 +93,7 @@ NumAccounts: cBatches[i].NumAccounts,

ExitRoot: cBatches[i].ExitRoot.String(), ForgeL1TxsNum: cBatches[i].ForgeL1TxsNum, SlotNum: cBatches[i].SlotNum, + ForgedTxs: forgedTxs, } tBatches = append(tBatches, tBatch) }
M api/swagger.yml → api/swagger.yml

@@ -2086,6 +2086,10 @@ example: 5

nullable: true slotNum: $ref: '#/components/schemas/SlotNum' + forgedTransactions: + type: integer + description: Amount of forged transactions in this batch. + example: 318 additionalProperties: false required: - itemId

@@ -2101,6 +2105,7 @@ - numAccounts

- exitRoot - forgeL1TransactionsNum - slotNum + - forgedTransactions FullBatch: type: object description: Group of transactions forged in a coordinator and sent and validated in Ethereum.
M db/historydb/historydb.go → db/historydb/historydb.go

@@ -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 @@ ) ([]BatchAPI, uint64, error) {

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
M db/historydb/views.go → db/historydb/views.go

@@ -291,6 +291,7 @@ NumAccounts int `json:"numAccounts" meddler:"num_accounts"`

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"`