Skip to content

Commit 321bee2

Browse files
use network enable epochs
1 parent 2fddce2 commit 321bee2

5 files changed

Lines changed: 41 additions & 3 deletions

File tree

src/common/gateway/entities/gateway.component.request.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export enum GatewayComponentRequest {
22
networkConfig = 'networkConfig',
3+
networkEnableEpochs = 'networkEnableEpochs',
4+
networkEnableEpochsV2 = 'networkEnableEpochsV2',
35
networkStatus = 'networkStatus',
46
networkEsdt = 'networkEsdt',
57
networkEconomics = 'networkEconomics',

src/common/gateway/gateway.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ export class GatewayService {
9191
});
9292
}
9393

94+
async getNetworkEnableEpochs(): Promise<Record<string,number>> {
95+
const result = await this.get(`network/enable-epochs`, GatewayComponentRequest.networkEnableEpochs);
96+
return result.enableEpochs;
97+
}
98+
99+
async getNetworkEnableEpochsV2(): Promise<Record<string,number>> {
100+
const result = await this.get(`network/enable-epochs-v2`, GatewayComponentRequest.networkEnableEpochsV2);
101+
return result.enableEpochs;
102+
}
103+
94104
async getAddressDetails(address: string): Promise<Account> {
95105
const result = await this.get(`address/${address}`, GatewayComponentRequest.addressDetails);
96106
return result;

src/endpoints/blocks/block.service.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { IdentitiesService } from "../identities/identities.service";
1212
import { ApiConfigService } from "../../common/api-config/api.config.service";
1313
import { ConcurrencyUtils } from "src/utils/concurrency.utils";
1414
import { ApiUtils } from "@multiversx/sdk-nestjs-http";
15+
import { GatewayService } from "../../common/gateway/gateway.service";
1516

1617
@Injectable()
1718
export class BlockService {
@@ -24,6 +25,7 @@ export class BlockService {
2425
@Inject(forwardRef(() => IdentitiesService))
2526
private readonly identitiesService: IdentitiesService,
2627
private readonly apiConfigService: ApiConfigService,
28+
private readonly gatewayService: GatewayService,
2729
) { }
2830

2931
async getBlocksCount(filter: BlockFilter): Promise<number> {
@@ -115,7 +117,8 @@ export class BlockService {
115117
const isChainAndromedaEnabled = this.apiConfigService.isChainAndromedaEnabled()
116118
&& result.epoch >= this.apiConfigService.getChainAndromedaActivationEpoch();
117119

118-
const isSupernovaEnabled = result.epoch >= await this.getSupernovaEnableEpoch();
120+
const supernovaEnableEpoch = await this.getSupernovaEnableEpoch();
121+
const isSupernovaEnabled = supernovaEnableEpoch !== -1 && result.epoch >= supernovaEnableEpoch;
119122
if (isSupernovaEnabled) {
120123
const executionResults = await this.indexerService.getExecutionResults(hash);
121124
if (executionResults) {
@@ -172,7 +175,15 @@ export class BlockService {
172175
}
173176

174177
async getSupernovaEnableEpoch(): Promise<number> {
175-
// TODO: fetch it from proxy /network/enable-epochs -> erd_supernova_enable_epoch
176-
return await Promise.resolve(2);
178+
const enableEpochs = await this.getNetworkEnableEpochs();
179+
return enableEpochs["erd_supernova_enable_epoch"] ?? -1;
180+
}
181+
182+
async getNetworkEnableEpochs(): Promise<Record<string, number>> {
183+
return await this.cachingService.getOrSet(
184+
CacheInfo.NetworkEnableEpochs.key,
185+
async () => this.gatewayService.getNetworkEnableEpochs(),
186+
CacheInfo.NetworkEnableEpochs.ttl,
187+
)
177188
}
178189
}

src/endpoints/proxy/gateway.proxy.controller.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ export class GatewayProxyController {
233233
return await this.gatewayGet('network/config', GatewayComponentRequest.networkConfig);
234234
}
235235

236+
@Get('/network/enable-epochs')
237+
async getNetworkEnableEpochs() {
238+
return await this.gatewayGet('network/enable-epochs', GatewayComponentRequest.networkEnableEpochs);
239+
}
240+
241+
@Get('/network/enable-epochs-v2')
242+
async getNetworkEnabledEpochsV2() {
243+
return await this.gatewayGet('network/enable-epochs-v2', GatewayComponentRequest.networkEnableEpochsV2);
244+
}
245+
236246
@Get('/network/economics')
237247
async getNetworkEconomics() {
238248
return await this.gatewayGet('network/economics', GatewayComponentRequest.networkEconomics);

src/utils/cache.info.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,11 @@ export class CacheInfo {
418418
ttl: Constants.oneMinute() * 10,
419419
};
420420

421+
static NetworkEnableEpochs: CacheInfo = {
422+
key: "networkEnableEpochs",
423+
ttl: Constants.oneHour() * 10,
424+
};
425+
421426
static MexPairs: CacheInfo = {
422427
key: "mexPairs",
423428
ttl: Constants.oneMinute() * 10,

0 commit comments

Comments
 (0)