add providerType() getter to AbstractProvider

This commit is contained in:
Andre Staltz 2023-08-15 10:42:55 +03:00
parent 32915634be
commit 6344644197
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
4 changed files with 25 additions and 0 deletions

View File

@ -428,6 +428,8 @@ type CcipArgs = {
errorArgs: Array<any>
};
type ProviderType = "jsonrpc" | "etherscan" | "fallback" | "";
/**
* An **AbstractProvider** provides a base class for other sub-classes to
* implement the [[Provider]] API by normalizing input arguments and
@ -504,6 +506,17 @@ export class AbstractProvider implements Provider {
*/
get provider(): this { return this; }
/**
* Returns a string that identifies the AbstractProvider subclass, for
* better duck typing.
*/
get providerType(): ProviderType {
assert(false, "not implemented yet", "NOT_IMPLEMENTED", {
operation: "providerType"
});
return "";
}
/**
* Returns all the registered plug-ins.
*/

View File

@ -142,6 +142,10 @@ export class EtherscanProvider extends AbstractProvider {
this.getBaseUrl();
}
get providerType() {
return 'etherscan' as const;
}
/**
* Returns the base URL.
*

View File

@ -414,6 +414,10 @@ export class FallbackProvider extends AbstractProvider {
"quorum exceed provider wieght", "quorum", this.quorum);
}
get providerType() {
return 'fallback' as const;
}
get providerConfigs(): Array<FallbackProviderState> {
return this.#configs.map((c) => {
const result: any = Object.assign({ }, c);

View File

@ -572,6 +572,10 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
}
}
get providerType() {
return 'jsonrpc' as const;
}
/**
* Returns the value associated with the option %%key%%.
*