Allow getDefaultProvider to accept a URL as a network.
This commit is contained in:
parent
987b5354cc
commit
8c1ff4c862
@ -42,6 +42,25 @@ const logger = new Logger(version);
|
|||||||
|
|
||||||
function getDefaultProvider(network?: Network | string, options?: any): BaseProvider {
|
function getDefaultProvider(network?: Network | string, options?: any): BaseProvider {
|
||||||
if (network == null) { network = "homestead"; }
|
if (network == null) { network = "homestead"; }
|
||||||
|
|
||||||
|
// If passed a URL, figure out the right type of provider based on the scheme
|
||||||
|
if (typeof(network) === "string") {
|
||||||
|
// @TODO: Add support for IpcProvider; maybe if it ends in ".ipc"?
|
||||||
|
|
||||||
|
// Handle http and ws (and their secure variants)
|
||||||
|
const match = network.match(/^(ws|http)s?:/i);
|
||||||
|
if (match) {
|
||||||
|
switch (match[1]) {
|
||||||
|
case "http":
|
||||||
|
return new JsonRpcProvider(network);
|
||||||
|
case "ws":
|
||||||
|
return new WebSocketProvider(network);
|
||||||
|
default:
|
||||||
|
logger.throwArgumentError("unsupported URL scheme", "network", network);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const n = getNetwork(network);
|
const n = getNetwork(network);
|
||||||
if (!n || !n._defaultProvider) {
|
if (!n || !n._defaultProvider) {
|
||||||
logger.throwError("unsupported getDefaultProvider network", Logger.errors.NETWORK_ERROR, {
|
logger.throwError("unsupported getDefaultProvider network", Logger.errors.NETWORK_ERROR, {
|
||||||
|
Loading…
Reference in New Issue
Block a user