2020-07-14 02:26:45 -04:00
|
|
|
/* istanbul ignore file */
|
|
|
|
|
2019-05-14 18:25:46 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import { Network } from "@ethersproject/networks";
|
|
|
|
import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
|
|
|
|
|
2019-08-01 18:04:06 -04:00
|
|
|
import { Logger } from "@ethersproject/logger";
|
|
|
|
import { version } from "./_version";
|
|
|
|
const logger = new Logger(version);
|
2019-05-14 18:25:46 -04:00
|
|
|
|
|
|
|
// Special API key provided by Nodesmith for ethers.js
|
|
|
|
const defaultApiKey = "ETHERS_JS_SHARED";
|
|
|
|
|
|
|
|
export class NodesmithProvider extends UrlJsonRpcProvider {
|
|
|
|
|
2019-11-19 18:00:05 +09:00
|
|
|
static getApiKey(apiKey: any): any {
|
|
|
|
if (apiKey && typeof(apiKey) !== "string") {
|
|
|
|
logger.throwArgumentError("invalid apiKey", "apiKey", apiKey);
|
|
|
|
}
|
2019-05-14 18:25:46 -04:00
|
|
|
return apiKey || defaultApiKey;
|
|
|
|
}
|
|
|
|
|
2019-11-19 18:00:05 +09:00
|
|
|
static getUrl(network: Network, apiKey?: any): string {
|
2019-11-19 18:14:40 +09:00
|
|
|
logger.warn("NodeSmith will be discontinued on 2019-12-20; please migrate to another platform.");
|
|
|
|
|
2019-05-14 18:25:46 -04:00
|
|
|
let host = null;
|
|
|
|
switch (network.name) {
|
|
|
|
case "homestead":
|
|
|
|
host = "https://ethereum.api.nodesmith.io/v1/mainnet/jsonrpc";
|
|
|
|
break;
|
|
|
|
case "ropsten":
|
|
|
|
host = "https://ethereum.api.nodesmith.io/v1/ropsten/jsonrpc";
|
|
|
|
break;
|
|
|
|
case "rinkeby":
|
|
|
|
host = "https://ethereum.api.nodesmith.io/v1/rinkeby/jsonrpc";
|
|
|
|
break;
|
|
|
|
case "goerli":
|
|
|
|
host = "https://ethereum.api.nodesmith.io/v1/goerli/jsonrpc";
|
|
|
|
break;
|
|
|
|
case "kovan":
|
|
|
|
host = "https://ethereum.api.nodesmith.io/v1/kovan/jsonrpc";
|
|
|
|
break;
|
|
|
|
default:
|
2019-08-01 18:04:06 -04:00
|
|
|
logger.throwArgumentError("unsupported network", "network", arguments[0]);
|
2019-05-14 18:25:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (host + "?apiKey=" + apiKey);
|
|
|
|
}
|
|
|
|
}
|