2019-08-21 08:45:06 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import { Network } from "@ethersproject/networks";
|
|
|
|
import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
|
|
|
|
|
|
|
|
import { Logger } from "@ethersproject/logger";
|
|
|
|
import { version } from "./_version";
|
|
|
|
const logger = new Logger(version);
|
|
|
|
|
|
|
|
export class CloudflareProvider extends UrlJsonRpcProvider {
|
|
|
|
|
2019-11-19 12:00:05 +03:00
|
|
|
static getApiKey(apiKey: any): any {
|
2019-08-21 08:45:06 +03:00
|
|
|
if (apiKey != null) {
|
|
|
|
logger.throwArgumentError("apiKey not supported for cloudflare", "apiKey", apiKey);
|
|
|
|
}
|
2019-11-19 12:00:05 +03:00
|
|
|
return null;
|
|
|
|
}
|
2019-08-21 08:45:06 +03:00
|
|
|
|
2019-11-19 12:00:05 +03:00
|
|
|
static getUrl(network: Network, apiKey?: any): string {
|
2019-08-21 08:45:06 +03:00
|
|
|
let host = null;
|
|
|
|
switch (network.name) {
|
|
|
|
case "homestead":
|
|
|
|
host = "https://cloudflare-eth.com/";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
logger.throwArgumentError("unsupported network", "network", arguments[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return host;
|
|
|
|
}
|
2020-04-23 15:13:53 +03:00
|
|
|
|
|
|
|
async perform(method: string, params: any): Promise<any> {
|
|
|
|
// The Cloudflare provider does not support eth_blockNumber,
|
|
|
|
// so we get the latest block and pull it from that
|
|
|
|
if (method === "getBlockNumber") {
|
|
|
|
const block = await super.perform("getBlock", { blockTag: "latest" });
|
|
|
|
return block.number;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.perform(method, params);
|
|
|
|
}
|
2019-08-21 08:45:06 +03:00
|
|
|
}
|