2019-08-25 02:39:20 -04:00
|
|
|
"use strict";
|
2020-04-23 23:35:39 -04:00
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
});
|
|
|
|
};
|
2019-08-25 02:39:20 -04:00
|
|
|
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-20 18:57:38 +09:00
|
|
|
static getApiKey(apiKey) {
|
2019-08-25 02:39:20 -04:00
|
|
|
if (apiKey != null) {
|
|
|
|
logger.throwArgumentError("apiKey not supported for cloudflare", "apiKey", apiKey);
|
|
|
|
}
|
2019-11-20 18:57:38 +09:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
static getUrl(network, apiKey) {
|
2019-08-25 02:39:20 -04: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 23:35:39 -04:00
|
|
|
perform(method, params) {
|
|
|
|
const _super = Object.create(null, {
|
|
|
|
perform: { get: () => super.perform }
|
|
|
|
});
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
// The Cloudflare provider does not support eth_blockNumber,
|
|
|
|
// so we get the latest block and pull it from that
|
|
|
|
if (method === "getBlockNumber") {
|
|
|
|
const block = yield _super.perform.call(this, "getBlock", { blockTag: "latest" });
|
|
|
|
return block.number;
|
|
|
|
}
|
|
|
|
return _super.perform.call(this, method, params);
|
|
|
|
});
|
|
|
|
}
|
2019-08-25 02:39:20 -04:00
|
|
|
}
|
2020-07-13 08:03:56 -04:00
|
|
|
//# sourceMappingURL=cloudflare-provider.js.map
|