Skip to content

Commit

Permalink
Merge branch 'master' into pxrl/tokenRolesEnum
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl committed Sep 29, 2023
2 parents bfa95b5 + f655e95 commit b296de1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
28 changes: 4 additions & 24 deletions src/utils/ProviderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,13 @@ export async function getProvider(chainId: number, logger?: winston.Logger, useC
return provider;
}

export function getNodeUrlList(chainId: number, quorum: number): string[] {
export function getNodeUrlList(chainId: number, quorum = 1): string[] {
const resolveUrls = (): string[] => {
const providers = process.env[`RPC_PROVIDERS_${chainId}`] ?? process.env["RPC_PROVIDERS"];
if (providers === undefined) {
throw new Error(`No RPC providers defined for chainId ${chainId}`);
}

const nodeUrls = providers.split(",").map((provider) => {
const envVar = `RPC_PROVIDER_${provider}_${chainId}`;
const url = process.env[envVar];
Expand All @@ -591,29 +592,8 @@ export function getNodeUrlList(chainId: number, quorum: number): string[] {
return nodeUrls;
};

const retryConfigKey = `NODE_URLS_${chainId}`;
const nodeUrlKey = `NODE_URL_${chainId}`;
let nodeUrls: string[] = [];

try {
nodeUrls = resolveUrls();
} catch {
// Fallback to existing config scheme.
if (process.env[retryConfigKey]) {
nodeUrls = JSON.parse(process.env[retryConfigKey]) || [];
if (nodeUrls?.length === 0) {
throw new Error(`Provided ${retryConfigKey}, but parsing it as json did not result in an array of urls.`);
}
} else {
if (process.env[nodeUrlKey]) {
nodeUrls = [process.env[nodeUrlKey]];
}
}
}

if (nodeUrls.length === 0) {
throw new Error(`Can't get ${chainId} node url(s) because neither ${retryConfigKey} or ${nodeUrlKey} are defined.`);
} else if (nodeUrls.length < quorum) {
const nodeUrls = resolveUrls();
if (nodeUrls.length < quorum) {
throw new Error(`Insufficient RPC providers for chainId ${chainId} to meet quorum (minimum ${quorum} required)`);
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/SignerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type SignerOptions = {
* The type of wallet to use.
* @note If using a GCKMS wallet, the gckmsKeys parameter must be set.
*/
keyType: "mnemonic" | "privateKey" | "gckms";
keyType: string;
/**
* Whether or not to clear the mnemonic/private key from the env after retrieving the signer.
* @note Not including this parameter or setting it to false will not clear the mnemonic/private key from the env.
Expand Down Expand Up @@ -42,7 +42,7 @@ export async function getSigner({ keyType, gckmsKeys, cleanEnv }: SignerOptions)
wallet = await getGckmsSigner(gckmsKeys);
break;
default:
throw new Error("Must define mnemonic, privatekey or gckms for wallet");
throw new Error(`getSigner: Unsupported key type (${keyType})`);
}
if (!wallet) {
throw new Error("Must define mnemonic, privatekey or gckms for wallet");
Expand Down

0 comments on commit b296de1

Please sign in to comment.