mirror of
https://github.com/mempool/mempool.git
synced 2026-08-13 12:33:11 +02:00
fix fee and reward graphs on networks without price indexing
This commit is contained in:
parent
29afce710d
commit
49ca1856ee
7 changed files with 36 additions and 21 deletions
|
|
@ -902,6 +902,15 @@ export class Common {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// must match the conditions under which the indexer runs the 'blocksPrices' task,
|
||||||
|
// otherwise queries will join against a blocks_prices table that is never populated
|
||||||
|
static blockPricesIndexingEnabled(): boolean {
|
||||||
|
return (
|
||||||
|
!['testnet', 'signet', 'testnet4', 'regtest'].includes(config.MEMPOOL.NETWORK) &&
|
||||||
|
config.FIAT_PRICE.ENABLED === true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static setDateMidnight(date: Date): void {
|
static setDateMidnight(date: Date): void {
|
||||||
date.setUTCHours(0);
|
date.setUTCHours(0);
|
||||||
date.setUTCMinutes(0);
|
date.setUTCMinutes(0);
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ class Indexer {
|
||||||
|
|
||||||
switch (task) {
|
switch (task) {
|
||||||
case 'blocksPrices': {
|
case 'blocksPrices': {
|
||||||
if (!['testnet', 'signet', 'testnet4', 'regtest'].includes(config.MEMPOOL.NETWORK) && config.FIAT_PRICE.ENABLED) {
|
if (Common.blockPricesIndexingEnabled()) {
|
||||||
let latestPriceId;
|
let latestPriceId;
|
||||||
try {
|
try {
|
||||||
latestPriceId = await PricesRepository.$getLatestPriceId();
|
latestPriceId = await PricesRepository.$getLatestPriceId();
|
||||||
|
|
|
||||||
|
|
@ -773,14 +773,16 @@ class BlocksRepository {
|
||||||
*/
|
*/
|
||||||
public async $getHistoricalBlockFees(div: number, interval: string | null, timespan?: {from: number, to: number}): Promise<any> {
|
public async $getHistoricalBlockFees(div: number, interval: string | null, timespan?: {from: number, to: number}): Promise<any> {
|
||||||
try {
|
try {
|
||||||
|
const withPrices = Common.blockPricesIndexingEnabled();
|
||||||
|
|
||||||
let query = `SELECT
|
let query = `SELECT
|
||||||
CAST(AVG(blocks.height) as INT) as avgHeight,
|
CAST(AVG(blocks.height) as INT) as avgHeight,
|
||||||
CAST(AVG(UNIX_TIMESTAMP(blockTimestamp)) as INT) as timestamp,
|
CAST(AVG(UNIX_TIMESTAMP(blockTimestamp)) as INT) as timestamp,
|
||||||
CAST(AVG(fees) as INT) as avgFees,
|
CAST(AVG(fees) as INT) as avgFees${withPrices ? `,
|
||||||
prices.USD
|
prices.USD` : ''}
|
||||||
FROM blocks
|
FROM blocks${withPrices ? `
|
||||||
JOIN blocks_prices on blocks_prices.height = blocks.height
|
JOIN blocks_prices on blocks_prices.height = blocks.height
|
||||||
JOIN prices on prices.id = blocks_prices.price_id
|
JOIN prices on prices.id = blocks_prices.price_id` : ''}
|
||||||
WHERE stale = 0
|
WHERE stale = 0
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
@ -806,14 +808,16 @@ class BlocksRepository {
|
||||||
*/
|
*/
|
||||||
public async $getHistoricalBlockRewards(div: number, interval: string | null): Promise<any> {
|
public async $getHistoricalBlockRewards(div: number, interval: string | null): Promise<any> {
|
||||||
try {
|
try {
|
||||||
|
const withPrices = Common.blockPricesIndexingEnabled();
|
||||||
|
|
||||||
let query = `SELECT
|
let query = `SELECT
|
||||||
CAST(AVG(blocks.height) as INT) as avgHeight,
|
CAST(AVG(blocks.height) as INT) as avgHeight,
|
||||||
CAST(AVG(UNIX_TIMESTAMP(blockTimestamp)) as INT) as timestamp,
|
CAST(AVG(UNIX_TIMESTAMP(blockTimestamp)) as INT) as timestamp,
|
||||||
CAST(AVG(reward) as INT) as avgRewards,
|
CAST(AVG(reward) as INT) as avgRewards${withPrices ? `,
|
||||||
prices.USD
|
prices.USD` : ''}
|
||||||
FROM blocks
|
FROM blocks${withPrices ? `
|
||||||
JOIN blocks_prices on blocks_prices.height = blocks.height
|
JOIN blocks_prices on blocks_prices.height = blocks.height
|
||||||
JOIN prices on prices.id = blocks_prices.price_id
|
JOIN prices on prices.id = blocks_prices.price_id` : ''}
|
||||||
WHERE stale = 0
|
WHERE stale = 0
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ export class BlockFeesGraphComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareChartOptions(data) {
|
prepareChartOptions(data) {
|
||||||
|
const showFiat = !this.stateService.isAnyTestnet();
|
||||||
const feesBtcLabel = $localize`:@@graphs.blockFees.feesBtc:Fees BTC`;
|
const feesBtcLabel = $localize`:@@graphs.blockFees.feesBtc:Fees BTC`;
|
||||||
const feesFiatLabel = $localize`:@@graphs.blockFees.feesFiat:Fees ${this.currency}:currency:`;
|
const feesFiatLabel = $localize`:@@graphs.blockFees.feesFiat:Fees ${this.currency}:currency:`;
|
||||||
|
|
||||||
|
|
@ -186,7 +187,7 @@ export class BlockFeesGraphComponent implements OnInit {
|
||||||
hideOverlap: true,
|
hideOverlap: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
legend: data.blockFees.length === 0 ? undefined : {
|
legend: (data.blockFees.length === 0 || !showFiat) ? undefined : {
|
||||||
top: 'top',
|
top: 'top',
|
||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
|
|
@ -224,7 +225,7 @@ export class BlockFeesGraphComponent implements OnInit {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
...(showFiat ? [{
|
||||||
type: 'value',
|
type: 'value',
|
||||||
position: 'right',
|
position: 'right',
|
||||||
axisLabel: {
|
axisLabel: {
|
||||||
|
|
@ -236,7 +237,7 @@ export class BlockFeesGraphComponent implements OnInit {
|
||||||
splitLine: {
|
splitLine: {
|
||||||
show: false,
|
show: false,
|
||||||
},
|
},
|
||||||
},
|
}] : []),
|
||||||
],
|
],
|
||||||
series: data.blockFees.length === 0 ? undefined : [
|
series: data.blockFees.length === 0 ? undefined : [
|
||||||
{
|
{
|
||||||
|
|
@ -253,7 +254,7 @@ export class BlockFeesGraphComponent implements OnInit {
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
...(showFiat ? [{
|
||||||
legendHoverLink: false,
|
legendHoverLink: false,
|
||||||
zlevel: 1,
|
zlevel: 1,
|
||||||
yAxisIndex: 1,
|
yAxisIndex: 1,
|
||||||
|
|
@ -266,7 +267,7 @@ export class BlockFeesGraphComponent implements OnInit {
|
||||||
width: 2,
|
width: 2,
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
}
|
}
|
||||||
},
|
}] : []),
|
||||||
],
|
],
|
||||||
dataZoom: data.blockFees.length === 0 ? undefined : [{
|
dataZoom: data.blockFees.length === 0 ? undefined : [{
|
||||||
type: 'inside',
|
type: 'inside',
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,7 @@ export class BlockRewardsGraphComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareChartOptions(data) {
|
prepareChartOptions(data) {
|
||||||
|
const showFiat = !this.stateService.isAnyTestnet();
|
||||||
let title: object;
|
let title: object;
|
||||||
if (data.blockRewards.length === 0) {
|
if (data.blockRewards.length === 0) {
|
||||||
title = {
|
title = {
|
||||||
|
|
@ -182,7 +183,7 @@ export class BlockRewardsGraphComponent implements OnInit {
|
||||||
hideOverlap: true,
|
hideOverlap: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
legend: data.blockRewards.length === 0 ? undefined : {
|
legend: (data.blockRewards.length === 0 || !showFiat) ? undefined : {
|
||||||
top: 'top',
|
top: 'top',
|
||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
|
|
@ -226,7 +227,7 @@ export class BlockRewardsGraphComponent implements OnInit {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
...(showFiat ? [{
|
||||||
min: (value) => {
|
min: (value) => {
|
||||||
return Math.round(value.min * (1.0 - scaleFactor) * 10) / 10;
|
return Math.round(value.min * (1.0 - scaleFactor) * 10) / 10;
|
||||||
},
|
},
|
||||||
|
|
@ -244,7 +245,7 @@ export class BlockRewardsGraphComponent implements OnInit {
|
||||||
splitLine: {
|
splitLine: {
|
||||||
show: false,
|
show: false,
|
||||||
},
|
},
|
||||||
},
|
}] : []),
|
||||||
],
|
],
|
||||||
series: data.blockRewards.length === 0 ? undefined : [
|
series: data.blockRewards.length === 0 ? undefined : [
|
||||||
{
|
{
|
||||||
|
|
@ -257,7 +258,7 @@ export class BlockRewardsGraphComponent implements OnInit {
|
||||||
smooth: 0.25,
|
smooth: 0.25,
|
||||||
symbol: 'none',
|
symbol: 'none',
|
||||||
},
|
},
|
||||||
{
|
...(showFiat ? [{
|
||||||
legendHoverLink: false,
|
legendHoverLink: false,
|
||||||
zlevel: 1,
|
zlevel: 1,
|
||||||
yAxisIndex: 1,
|
yAxisIndex: 1,
|
||||||
|
|
@ -273,7 +274,7 @@ export class BlockRewardsGraphComponent implements OnInit {
|
||||||
areaStyle: {
|
areaStyle: {
|
||||||
opacity: 0.05,
|
opacity: 0.05,
|
||||||
}
|
}
|
||||||
},
|
}] : []),
|
||||||
],
|
],
|
||||||
dataZoom: data.blockRewards.length === 0 ? undefined : [{
|
dataZoom: data.blockRewards.length === 0 ? undefined : [{
|
||||||
type: 'inside',
|
type: 'inside',
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
i18n="mining.block-fee-rates">Block Fee Rates</a>
|
i18n="mining.block-fee-rates">Block Fee Rates</a>
|
||||||
<a class="dropdown-item" routerLinkActive="active" [routerLink]="['/graphs/mining/block-fees' | relativeUrl]"
|
<a class="dropdown-item" routerLinkActive="active" [routerLink]="['/graphs/mining/block-fees' | relativeUrl]"
|
||||||
i18n="mining.block-fees">Block Fees</a>
|
i18n="mining.block-fees">Block Fees</a>
|
||||||
<a class="dropdown-item" routerLinkActive="active" [routerLink]="['/graphs/mining/block-fees-subsidy' | relativeUrl]"
|
<a *ngIf="isMainnet" class="dropdown-item" routerLinkActive="active" [routerLink]="['/graphs/mining/block-fees-subsidy' | relativeUrl]"
|
||||||
i18n="mining.block-fees-subsidy-subsidy">Block Fees Vs Subsidy</a>
|
i18n="mining.block-fees-subsidy-subsidy">Block Fees Vs Subsidy</a>
|
||||||
<a class="dropdown-item" routerLinkActive="active" [routerLink]="['/graphs/mining/block-rewards' | relativeUrl]"
|
<a class="dropdown-item" routerLinkActive="active" [routerLink]="['/graphs/mining/block-rewards' | relativeUrl]"
|
||||||
i18n="mining.block-rewards">Block Rewards</a>
|
i18n="mining.block-rewards">Block Rewards</a>
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ const routes: Routes = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'mining/block-fees-subsidy',
|
path: 'mining/block-fees-subsidy',
|
||||||
data: { networks: ['bitcoin'] },
|
data: { networks: ['bitcoin'], networkSpecific: true, onlySubnet: [''] },
|
||||||
component: BlockFeesSubsidyGraphComponent,
|
component: BlockFeesSubsidyGraphComponent,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue