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

Add new methods for getting active regions and zones #312

Merged
merged 1 commit into from
Oct 10, 2024
Merged
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
41 changes: 38 additions & 3 deletions src/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,44 @@ export class AbstractProvider<C = FetchRequest> implements Provider {
* @returns {Promise<number>} A promise that resolves to the protocol expansion number.
*/
async getProtocolExpansionNumber(): Promise<number> {
return await this.#perform({
method: 'getProtocolExpansionNumber',
});
return getNumber(await this.#perform({ method: 'getProtocolExpansionNumber' }));
}

/**
* Get the active region shards based on the protocol expansion number.
*
* @returns {Promise<Shard[]>} A promise that resolves to the active shards.
*/
async getActiveRegions(): Promise<Shard[]> {
const protocolExpansionNumber = await this.getProtocolExpansionNumber();
const shards = [Shard.Cyprus];
if (protocolExpansionNumber >= 1) {
shards.push(Shard.Paxos);
}
if (protocolExpansionNumber >= 3) {
shards.push(Shard.Hydra);
}
return shards.sort((a: Shard, b: Shard) => a.localeCompare(b));
}

/**
* Get the active zones for a shard based on the protocol expansion number.
*
* @returns {Promise<Zone[]>} A promise that resolves to the active zones.
*/
async getActiveZones(): Promise<Zone[]> {
const protocolExpansionNumber = await this.getProtocolExpansionNumber();
const zones = [Zone.Cyprus1];
if (protocolExpansionNumber >= 1) {
zones.push(Zone.Cyprus2);
}
if (protocolExpansionNumber >= 2) {
zones.push(Zone.Paxos1, Zone.Paxos2);
}
if (protocolExpansionNumber >= 3) {
zones.push(Zone.Cyprus3, Zone.Paxos3, Zone.Hydra1, Zone.Hydra2, Zone.Hydra3);
}
return zones.sort((a: Zone, b: Zone) => a.localeCompare(b));
}

/**
Expand Down
Loading