Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Feat/stats optimization #584

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions packages/app-explorer/src/systems/Statistics/blocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use server';

import { z } from 'zod';
import { act } from '../../systems/Core/utils/act-server';
import { sdk } from '../../systems/Core/utils/sdk';

const schema = z.object({
timeFilter: z.string().optional().nullable(),
});

export const getNewBlocksStats = act(schema, async ({ timeFilter }) => {
const params = { timeFilter: timeFilter } as {
timeFilter?: string;
};
const data = await sdk.newBlockStatistics(params);
return data;
});

export const getBlockRewardStats = act(schema, async ({ timeFilter }) => {
const params = { timeFilter: timeFilter } as {
timeFilter?: string;
};
const data = await sdk.blockRewardStatistics(params);
return data;
});
47 changes: 47 additions & 0 deletions packages/app-explorer/src/systems/Statistics/transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use server';

import { z } from 'zod';
import { act } from '../../systems/Core/utils/act-server';
import { sdk } from '../../systems/Core/utils/sdk';

const schema = z.object({
timeFilter: z.string().optional().nullable(),
});

export const getTransactionStats = act(schema, async ({ timeFilter }) => {
const params = { timeFilter: timeFilter } as {
timeFilter?: string;
};
const data = await sdk.transactionsStatistics(params);
return data;
});

export const getTransactionFeeStats = act(schema, async ({ timeFilter }) => {
const params = { timeFilter: timeFilter } as {
timeFilter?: string;
};
const data = await sdk.transactionFeeStatistics(params);
return data;
});

export const getCumulativeTransactionFeeStats = act(
schema,
async ({ timeFilter }) => {
const params = { timeFilter: timeFilter } as {
timeFilter?: string;
};
const data = await sdk.cumulativeFeeStatistics(params);
return data;
},
);

export const getCumulativeTransactionStats = act(
schema,
async ({ timeFilter }) => {
const params = { timeFilter: timeFilter } as {
timeFilter?: string;
};
const data = await sdk.cumulativeTransactionStatistics(params);
return data;
},
);
11 changes: 11 additions & 0 deletions packages/graphql/database/2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE indexer.block_statistics (
id SERIAL PRIMARY KEY,
timestamp TIMESTAMP NOT NULL,
number_of_blocks INTEGER NOT NULL,
cumulative_block_reward NUMERIC NOT NULL,
start_block INTEGER NOT NULL,
end_block INTEGER NOT NULL
);

CREATE UNIQUE INDEX ON indexer.block_statistics(id);
CREATE INDEX ON indexer.block_statistics(timestamp);
15 changes: 15 additions & 0 deletions packages/graphql/database/3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE indexer.transaction_statistics (
id SERIAL PRIMARY KEY,
timestamp TIMESTAMP NOT NULL,
start_block INTEGER NOT NULL,
end_block INTEGER NOT NULL,
transaction_count INTEGER NOT NULL,
transaction_count_cumulative INTEGER NOT NULL,
gas_used INTEGER NOT NULL,
gas_used_cumulative INTEGER NOT NULL,
fee_spent INTEGER NOT NULL,
fee_spent_cumulative INTEGER NOT NULL,
);

CREATE UNIQUE INDEX ON indexer.transaction_statistics(id);
CREATE INDEX ON indexer.transaction_statistics(timestamp);
12 changes: 12 additions & 0 deletions packages/graphql/src/core/Date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ export class DateHelper {
static dateToTai64(date: Date) {
return TAI64.fromUnix(Math.floor(date.getTime() / 1000)).toString(10);
}

static addHours(date: string | Date, hours: number): string {
const dateObj = typeof date === 'string' ? new Date(date) : date;
const newDate = new Date(dateObj.getTime() + hours * 60 * 60 * 1000);
return newDate.toISOString();
}

static floorToHour(date: string | Date): string {
const flooredDate = typeof date === 'string' ? new Date(date) : date;
flooredDate.setMinutes(0, 0, 0); // Set minutes, seconds, and milliseconds to 0
return flooredDate.toISOString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query blockRewardStatistics($timeFilter: String){
blockRewardStatistics(timeFilter: $timeFilter){
nodes{
block_reward
time
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query cumulativeFeeStatistics($timeFilter: String){
cumulativeFeeStatistics(timeFilter: $timeFilter){
nodes{
time
fee_spent_cumulative
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query cumulativeTransactionStatistics($timeFilter: String){
cumulativeTransactionStatistics(timeFilter: $timeFilter){
nodes{
time
transaction_count_cumulative
}
}
}
169 changes: 140 additions & 29 deletions packages/graphql/src/graphql/generated/fuelcore/queries/index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,143 @@
const fs = require('fs');
const path = require('path');

module.exports.balance = fs.readFileSync(path.join(__dirname, 'balance.graphql'), 'utf8');
module.exports.balances = fs.readFileSync(path.join(__dirname, 'balances.graphql'), 'utf8');
module.exports.block = fs.readFileSync(path.join(__dirname, 'block.graphql'), 'utf8');
module.exports.blocks = fs.readFileSync(path.join(__dirname, 'blocks.graphql'), 'utf8');
module.exports.chain = fs.readFileSync(path.join(__dirname, 'chain.graphql'), 'utf8');
module.exports.coin = fs.readFileSync(path.join(__dirname, 'coin.graphql'), 'utf8');
module.exports.coins = fs.readFileSync(path.join(__dirname, 'coins.graphql'), 'utf8');
module.exports.coinsToSpend = fs.readFileSync(path.join(__dirname, 'coinsToSpend.graphql'), 'utf8');
module.exports.contract = fs.readFileSync(path.join(__dirname, 'contract.graphql'), 'utf8');
module.exports.contractBalance = fs.readFileSync(path.join(__dirname, 'contractBalance.graphql'), 'utf8');
module.exports.contractBalances = fs.readFileSync(path.join(__dirname, 'contractBalances.graphql'), 'utf8');
module.exports.estimateGasPrice = fs.readFileSync(path.join(__dirname, 'estimateGasPrice.graphql'), 'utf8');
module.exports.estimatePredicates = fs.readFileSync(path.join(__dirname, 'estimatePredicates.graphql'), 'utf8');
module.exports.health = fs.readFileSync(path.join(__dirname, 'health.graphql'), 'utf8');
module.exports.latestGasPrice = fs.readFileSync(path.join(__dirname, 'latestGasPrice.graphql'), 'utf8');
module.exports.memory = fs.readFileSync(path.join(__dirname, 'memory.graphql'), 'utf8');
module.exports.message = fs.readFileSync(path.join(__dirname, 'message.graphql'), 'utf8');
module.exports.messageProof = fs.readFileSync(path.join(__dirname, 'messageProof.graphql'), 'utf8');
module.exports.messageStatus = fs.readFileSync(path.join(__dirname, 'messageStatus.graphql'), 'utf8');
module.exports.messages = fs.readFileSync(path.join(__dirname, 'messages.graphql'), 'utf8');
module.exports.nodeInfo = fs.readFileSync(path.join(__dirname, 'nodeInfo.graphql'), 'utf8');
module.exports.register = fs.readFileSync(path.join(__dirname, 'register.graphql'), 'utf8');
module.exports.relayedTransactionStatus = fs.readFileSync(path.join(__dirname, 'relayedTransactionStatus.graphql'), 'utf8');
module.exports.transaction = fs.readFileSync(path.join(__dirname, 'transaction.graphql'), 'utf8');
module.exports.transactions = fs.readFileSync(path.join(__dirname, 'transactions.graphql'), 'utf8');
module.exports.transactionsByOwner = fs.readFileSync(path.join(__dirname, 'transactionsByOwner.graphql'), 'utf8');
module.exports.transactionsByBlockId = fs.readFileSync(path.join(__dirname, 'transactionsByBlockId.graphql'), 'utf8');
module.exports.tps = fs.readFileSync(path.join(__dirname, 'tps.graphql'), 'utf8');
module.exports.getBlocksDashboard = fs.readFileSync(path.join(__dirname, 'getBlocksDashboard.graphql'), 'utf8');
module.exports.balance = fs.readFileSync(
path.join(__dirname, 'balance.graphql'),
'utf8',
);
module.exports.balances = fs.readFileSync(
path.join(__dirname, 'balances.graphql'),
'utf8',
);
module.exports.block = fs.readFileSync(
path.join(__dirname, 'block.graphql'),
'utf8',
);
module.exports.blocks = fs.readFileSync(
path.join(__dirname, 'blocks.graphql'),
'utf8',
);
module.exports.chain = fs.readFileSync(
path.join(__dirname, 'chain.graphql'),
'utf8',
);
module.exports.coin = fs.readFileSync(
path.join(__dirname, 'coin.graphql'),
'utf8',
);
module.exports.coins = fs.readFileSync(
path.join(__dirname, 'coins.graphql'),
'utf8',
);
module.exports.coinsToSpend = fs.readFileSync(
path.join(__dirname, 'coinsToSpend.graphql'),
'utf8',
);
module.exports.contract = fs.readFileSync(
path.join(__dirname, 'contract.graphql'),
'utf8',
);
module.exports.contractBalance = fs.readFileSync(
path.join(__dirname, 'contractBalance.graphql'),
'utf8',
);
module.exports.contractBalances = fs.readFileSync(
path.join(__dirname, 'contractBalances.graphql'),
'utf8',
);
module.exports.estimateGasPrice = fs.readFileSync(
path.join(__dirname, 'estimateGasPrice.graphql'),
'utf8',
);
module.exports.estimatePredicates = fs.readFileSync(
path.join(__dirname, 'estimatePredicates.graphql'),
'utf8',
);
module.exports.health = fs.readFileSync(
path.join(__dirname, 'health.graphql'),
'utf8',
);
module.exports.latestGasPrice = fs.readFileSync(
path.join(__dirname, 'latestGasPrice.graphql'),
'utf8',
);
module.exports.memory = fs.readFileSync(
path.join(__dirname, 'memory.graphql'),
'utf8',
);
module.exports.message = fs.readFileSync(
path.join(__dirname, 'message.graphql'),
'utf8',
);
module.exports.messageProof = fs.readFileSync(
path.join(__dirname, 'messageProof.graphql'),
'utf8',
);
module.exports.messageStatus = fs.readFileSync(
path.join(__dirname, 'messageStatus.graphql'),
'utf8',
);
module.exports.messages = fs.readFileSync(
path.join(__dirname, 'messages.graphql'),
'utf8',
);
module.exports.nodeInfo = fs.readFileSync(
path.join(__dirname, 'nodeInfo.graphql'),
'utf8',
);
module.exports.register = fs.readFileSync(
path.join(__dirname, 'register.graphql'),
'utf8',
);
module.exports.relayedTransactionStatus = fs.readFileSync(
path.join(__dirname, 'relayedTransactionStatus.graphql'),
'utf8',
);
module.exports.transaction = fs.readFileSync(
path.join(__dirname, 'transaction.graphql'),
'utf8',
);
module.exports.transactions = fs.readFileSync(
path.join(__dirname, 'transactions.graphql'),
'utf8',
);
module.exports.transactionsByOwner = fs.readFileSync(
path.join(__dirname, 'transactionsByOwner.graphql'),
'utf8',
);
module.exports.transactionsByBlockId = fs.readFileSync(
path.join(__dirname, 'transactionsByBlockId.graphql'),
'utf8',
);
module.exports.tps = fs.readFileSync(
path.join(__dirname, 'tps.graphql'),
'utf8',
);
module.exports.getBlocksDashboard = fs.readFileSync(
path.join(__dirname, 'getBlocksDashboard.graphql'),
'utf8',
);
module.exports.newBlockStatistics = fs.readFileSync(
path.join(__dirname, 'newBlockStatistics.graphql'),
'utf8',
);
module.exports.blockRewardStatistics = fs.readFileSync(
path.join(__dirname, 'blockRewardStatistics.graphql'),
'utf8',
);
module.exports.transactionFeeStatistics = fs.readFileSync(
path.join(__dirname, 'transactionFeeStatistics.graphql'),
'utf8',
);
module.exports.transactionsStatistics = fs.readFileSync(
path.join(__dirname, 'transactionsStatistics.graphql'),
'utf8',
);
module.exports.cumulativeFeeStatistics = fs.readFileSync(
path.join(__dirname, 'cumulativeFeeStatistics.graphql'),
'utf8',
);
module.exports.cumulativeTransactionStatistics = fs.readFileSync(
path.join(__dirname, 'cumulativeTransactionStatistics.graphql'),
'utf8',
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query newBlockStatistics($timeFilter: String){
newBlockStatistics(timeFilter: $timeFilter){
nodes{
new_blocks
time
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query transactionFeeStatistics($timeFilter: String){
transactionFeeStatistics(timeFilter: $timeFilter){
nodes{
tx_count
fee_spent
time
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
query transactionsStatistics($timeFilter: String){
transactionsStatistics(timeFilter: $timeFilter){
nodes{
tx_count
time
}
}
}
Loading
Loading