Skip to content

Commit

Permalink
implement quai_getProtocolExpansionNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoacosta74 authored and rileystephens28 committed Apr 15, 2024
1 parent 6c66869 commit 61db772
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src.ts/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ export type PerformActionRequest = {
blockTag: BlockTag,
amt: number,
shard: string
} | {
method: "getProtocolExpansionNumber",
};


Expand Down Expand Up @@ -601,6 +603,12 @@ export class AbstractProvider implements Provider {
});
}

async getProtocolExpansionNumber(): Promise<number> {
return await this.#perform({
method: "getProtocolExpansionNumber"
});
}

async getLatestQiRate(shard: string, amt: number = 1): Promise<bigint> {
const blockNumber = await this.getBlockNumber(shard);
return this.getQiRateAtBlock(shard, blockNumber, amt);
Expand Down
2 changes: 2 additions & 0 deletions src.ts/providers/provider-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
10 changes: 9 additions & 1 deletion src.ts/providers/provider-jsonrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -958,6 +959,13 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
}
}

case "getProtocolExpansionNumber": {
return {
method: "quai_getProtocolExpansionNumber",
args: []
}
}

case "getQiRateAtBlock": {
return {
method: "quai_qiRateAtBlock",
Expand Down
5 changes: 5 additions & 0 deletions src.ts/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2049,4 +2049,9 @@ export interface Provider extends ContractRunner, EventEmitterable<ProviderEvent
* the ``currentBlockNumber + N``.
*/
waitForBlock(shard: string, blockTag?: BlockTag): Promise<Block>;

/**
* Resolves to the number indicating the size of the network
*/
getProtocolExpansionNumber(): Promise<number>;
}

0 comments on commit 61db772

Please sign in to comment.