From 61db7726b6572c0bcc496740f786650beca55f45 Mon Sep 17 00:00:00 2001 From: Alejo Acosta Date: Sat, 13 Apr 2024 19:54:56 -0300 Subject: [PATCH] implement quai_getProtocolExpansionNumber --- src.ts/providers/abstract-provider.ts | 8 ++++++++ src.ts/providers/provider-fallback.ts | 2 ++ src.ts/providers/provider-jsonrpc.ts | 10 +++++++++- src.ts/providers/provider.ts | 5 +++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src.ts/providers/abstract-provider.ts b/src.ts/providers/abstract-provider.ts index bb5bcb33..9bbf9db0 100644 --- a/src.ts/providers/abstract-provider.ts +++ b/src.ts/providers/abstract-provider.ts @@ -426,6 +426,8 @@ export type PerformActionRequest = { blockTag: BlockTag, amt: number, shard: string +} | { + method: "getProtocolExpansionNumber", }; @@ -601,6 +603,12 @@ export class AbstractProvider implements Provider { }); } + async getProtocolExpansionNumber(): Promise { + return await this.#perform({ + method: "getProtocolExpansionNumber" + }); + } + async getLatestQiRate(shard: string, amt: number = 1): Promise { const blockNumber = await this.getBlockNumber(shard); return this.getQiRateAtBlock(shard, blockNumber, amt); diff --git a/src.ts/providers/provider-fallback.ts b/src.ts/providers/provider-fallback.ts index 22cd135d..b9456442 100644 --- a/src.ts/providers/provider-fallback.ts +++ b/src.ts/providers/provider-fallback.ts @@ -472,6 +472,8 @@ export class FallbackProvider extends AbstractProvider { return await provider.getTransactionReceipt(req.hash); case "getTransactionResult": return await provider.getTransactionResult(req.hash); + case "getProtocolExpansionNumber": + return await provider.getProtocolExpansionNumber(); } } diff --git a/src.ts/providers/provider-jsonrpc.ts b/src.ts/providers/provider-jsonrpc.ts index a0b445a3..4ee203f0 100644 --- a/src.ts/providers/provider-jsonrpc.ts +++ b/src.ts/providers/provider-jsonrpc.ts @@ -676,7 +676,8 @@ export abstract class JsonRpcApiProvider extends AbstractProvider { const request = this.getRpcRequest(req); if (request != null) { - return await this.send(request.method, request.args, req.shard); + const shard = 'shard' in req ? req.shard : undefined; + return await this.send(request.method, request.args, shard); } return super._perform(req); @@ -958,6 +959,13 @@ export abstract class JsonRpcApiProvider extends AbstractProvider { } } + case "getProtocolExpansionNumber": { + return { + method: "quai_getProtocolExpansionNumber", + args: [] + } + } + case "getQiRateAtBlock": { return { method: "quai_qiRateAtBlock", diff --git a/src.ts/providers/provider.ts b/src.ts/providers/provider.ts index fd02d133..0e790858 100644 --- a/src.ts/providers/provider.ts +++ b/src.ts/providers/provider.ts @@ -2049,4 +2049,9 @@ export interface Provider extends ContractRunner, EventEmitterable; + + /** + * Resolves to the number indicating the size of the network + */ + getProtocolExpansionNumber(): Promise; }