Add non-coinbase txs count in the history endpoint#609
Add non-coinbase txs count in the history endpoint#609
Conversation
Those values are nice to have in order to see the real sent transactions over the coinbase one.
| "type": "array", | ||
| "items": { | ||
| "$ref": "#/components/schemas/TimedCount" | ||
| "$ref": "#/components/schemas/TimedTxCount" |
There was a problem hiding this comment.
TimedCount was originally meant to be a general case class that could be reused for any history data. But now that we introduce two count (total and non-coinbase), it's better to be explicit that it's for transactions count. It was only use there.
| "type": "array", | ||
| "items": { | ||
| "$ref": "#/components/schemas/PerChainTimedCount" | ||
| "$ref": "#/components/schemas/PerChainTimedTxCount" |
| """ | ||
| .asAS[(TimeStamp, Int, Int, Long)] | ||
| .map(_.map { case (ts, from, to, value) => | ||
| (ts, from, to, value, Some(value - 1)) |
There was a problem hiding this comment.
That's were we get the txsCount for each block, as a block as only 1 coinbase tx, we can simply remove 1.
| } | ||
| .foldLeft((0L, 0L)) { | ||
| case ((currentCount, currentNonCoinbaseCount), (_, _, _, count, nonCoinbaseCount)) => | ||
| (currentCount + count, currentNonCoinbaseCount + nonCoinbaseCount.getOrElse(0L)) |
There was a problem hiding this comment.
we use nonCoinbaseCount.getOrElse(0L) as the DB type is Optional, as we introduce it later with a migration.
But during the processing here, we are guarantee to have a value, as four hourly the txsCount is fetch from the blocks table here.
For daily we use the data stored in hourly so it will always have the freshly inserted data.
Those values are nice to have in order to see the real sent transactions over the coinbase ones.
Not really sure about the all
nonCoinbasenaming, but it's at least very explicit.No extra queries are needed and we keep the same performance of the previous optimization.
We'll just need to decide if we want to reset the past month of history to re trigger the computation and have the non-coinbase count.