Updated EtherscanProvider for new CommunityResource API throttling.
This commit is contained in:
parent
ea2d2453a5
commit
6bd13c312f
@ -45,7 +45,7 @@ function getResult(result: { status?: number, message?: string, result?: any }):
|
||||
return result.result;
|
||||
}
|
||||
|
||||
if (result.status != 1 || result.message != "OK") {
|
||||
if (result.status != 1 || typeof(result.message) !== "string" || !result.message.match(/^OK/)) {
|
||||
const error: any = new Error("invalid response");
|
||||
error.result = JSON.stringify(result);
|
||||
if ((result.result || "").toLowerCase().indexOf("rate limit") >= 0) {
|
||||
@ -93,8 +93,6 @@ function checkLogTag(blockTag: string): number | "latest" {
|
||||
}
|
||||
|
||||
|
||||
const defaultApiKey = "9D13ZE7XSBTJ94N9BNJ2MA33VMAY2YPIRB";
|
||||
|
||||
function checkError(method: string, error: any, transaction: any): any {
|
||||
// Undo the "convenience" some nodes are attempting to prevent backwards
|
||||
// incompatibility; maybe for v6 consider forwarding reverts as errors
|
||||
@ -160,13 +158,13 @@ function checkError(method: string, error: any, transaction: any): any {
|
||||
|
||||
export class EtherscanProvider extends BaseProvider{
|
||||
readonly baseUrl: string;
|
||||
readonly apiKey: string;
|
||||
readonly apiKey: string | null;
|
||||
|
||||
constructor(network?: Networkish, apiKey?: string) {
|
||||
super(network);
|
||||
|
||||
defineReadOnly(this, "baseUrl", this.getBaseUrl());
|
||||
defineReadOnly(this, "apiKey", apiKey || defaultApiKey);
|
||||
defineReadOnly(this, "apiKey", apiKey || null);
|
||||
}
|
||||
|
||||
getBaseUrl(): string {
|
||||
@ -447,6 +445,6 @@ export class EtherscanProvider extends BaseProvider{
|
||||
}
|
||||
|
||||
isCommunityResource(): boolean {
|
||||
return (this.apiKey === defaultApiKey);
|
||||
return (this.apiKey == null);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user