Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,15 @@ GET /validator/F60A6BF9EC0794BB0CFD1E0F2217933F4B33EDE6FE810692BC275CA18148AEF0/
{
"timestamp": "2024-06-23T13:51:44.154Z",
"data": {
"reward": 34000000
"reward": 34000000,
"runningTotal": 34000000
}
},
{
"timestamp": "2024-06-23T13:53:44.154Z",
"data": {
"reward": 34000000,
"runningTotal": 68000000
}
},...
]
Expand All @@ -611,7 +619,15 @@ GET /validator/F60A6BF9EC0794BB0CFD1E0F2217933F4B33EDE6FE810692BC275CA18148AEF0/
{
"timestamp": "2024-06-23T13:51:44.154Z",
"data": {
"blocksCount": 2
"blocksCount": 2,
"runningTotal": 2
}
},
{
"timestamp": "2024-06-23T13:53:44.154Z",
"data": {
"blocksCount": 2,
"runningTotal": 4
}
},...
]
Expand Down Expand Up @@ -1744,7 +1760,8 @@ GET /transactions/history?timestamp_start=2024-01-01T00:00:00&timestamp_end=2025
{
"timestamp": "2024-04-22T08:45:20.911Z",
"data": {
"txs": 5
"txs": 5,
"runningTotal": 5,
"blockHeight": 2,
"blockHash": "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF"
}
Expand All @@ -1753,6 +1770,7 @@ GET /transactions/history?timestamp_start=2024-01-01T00:00:00&timestamp_end=2025
"timestamp": "2024-04-22T08:50:20.911Z",
"data": {
"txs": 13,
"runningTotal": 18,
"blockHeight": 7,
"blockHash": "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF"
}
Expand Down Expand Up @@ -1780,6 +1798,7 @@ GET /transactions/gas/history?timestamp_start=2024-01-01T00:00:00&timestamp_end=
"timestamp": "2024-04-22T08:45:20.911Z",
"data": {
"gas": 772831320,
"runningTotal": 772831320,
"blockHeight": 64060,
"blockHash": "4A1F6B5238032DDAC55009A28797D909DB4288D5B5EC14B86DEC6EA8F25EC71A"
}
Expand All @@ -1788,6 +1807,7 @@ GET /transactions/gas/history?timestamp_start=2024-01-01T00:00:00&timestamp_end=
"timestamp": "2024-04-22T08:50:20.911Z",
"data": {
"gas": 14108752440,
"runningTotal": 14881583760,
"blockHeight": 64333,
"blockHash": "507659D9BE2FF76A031F4219061F3D2D39475A7FA4B24F25AEFDB34CD4DF2A57"
}
Expand Down
12 changes: 10 additions & 2 deletions packages/api/src/dao/TransactionsDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ module.exports = class TransactionsDAO {

const rows = await this.knex(heightSubquery)
.select('tx_count', 'block_height', 'hash as block_hash', 'date_from')
.select(
this.knex.raw('SUM(tx_count) OVER (ORDER BY date_from) AS running_total')
)
.leftJoin('blocks', function () {
this.on('blocks.height', '=', 'block_height').andOnNotNull('block_height')
})
Expand All @@ -222,7 +225,8 @@ module.exports = class TransactionsDAO {
.map(row => ({
timestamp: new Date(row.date_from).toISOString(),
data: {
txs: parseInt(row.tx_count ?? 0),
txs: Number(row.tx_count ?? 0),
runningTotal: Number(row.running_total ?? 0),
blockHeight: row.block_height,
blockHash: row.block_hash
}
Expand Down Expand Up @@ -277,6 +281,9 @@ module.exports = class TransactionsDAO {

const rows = await this.knex(heightSubquery)
.select('gas', 'block_height', 'hash as block_hash', 'date_from')
.select(
this.knex.raw('SUM(gas) OVER (ORDER BY date_from) AS running_total')
)
.leftJoin('blocks', function () {
this.on('blocks.height', '=', 'block_height').andOnNotNull('block_height')
})
Expand All @@ -285,7 +292,8 @@ module.exports = class TransactionsDAO {
.map(row => ({
timestamp: new Date(row.date_from).toISOString(),
data: {
gas: parseInt(row.gas ?? 0),
gas: Number(row.gas ?? 0),
runningTotal: Number(row.running_total ?? 0),
blockHeight: row.block_height,
blockHash: row.block_hash
}
Expand Down
26 changes: 22 additions & 4 deletions packages/api/src/dao/ValidatorsDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ module.exports = class ValidatorsDAO {
.from(this.knex.raw(`generate_series(${startSql}, ${endSql}, '${interval}'::interval) date_to`))
.select('date_to', this.knex.raw(`LAG(date_to, 1, '${start.toISOString()}'::timestamptz) over (order by date_to asc) date_from`))

const rows = await this.knex.with('ranges', ranges)
const subquery = this.knex.with('ranges', ranges)
.select('date_from')
.select(
this.knex('blocks')
Expand All @@ -263,11 +263,20 @@ module.exports = class ValidatorsDAO {
)
.from('ranges')

const rows = await this.knex
.with('subquery', subquery)
.select('date_from', 'blocks_count')
.select(
this.knex.raw('SUM(blocks_count) OVER (ORDER BY date_from) AS running_total')
)
.from('subquery')

return rows
.map(row => ({
timestamp: row.date_from,
data: {
blocksCount: parseInt(row.blocks_count)
blocksCount: Number(row.blocks_count),
runningTotal: Number(row.running_total ?? 0)
}
}))
.map(({ timestamp, data }) => new SeriesData(timestamp, data))
Expand All @@ -282,7 +291,7 @@ module.exports = class ValidatorsDAO {
.from(this.knex.raw(`generate_series(${startSql}, ${endSql}, '${interval}'::interval) date_to`))
.select('date_to', this.knex.raw(`LAG(date_to, 1, '${start.toISOString()}'::timestamptz) over (order by date_to asc) date_from`))

const rows = await this.knex.with('ranges', ranges)
const subquery = this.knex.with('ranges', ranges)
.select('date_from')
.select(
this.knex('blocks')
Expand All @@ -294,12 +303,21 @@ module.exports = class ValidatorsDAO {
)
.from('ranges')

const rows = await this.knex
.with('subquery', subquery)
.select('date_from', 'gas_used')
.select(
this.knex.raw('SUM(gas_used) OVER (ORDER BY date_from) AS running_total')
)
.from('subquery')

return rows
.slice(1)
.map(row => ({
timestamp: row.date_from,
data: {
reward: parseInt(row.gas_used ?? 0)
reward: Number(row.gas_used ?? 0),
runningTotal: Number(row.running_total ?? 0)
}
}))
.map(({ timestamp, data }) => new SeriesData(timestamp, data))
Expand Down
Loading