ethers.js/packages/providers/lib/url-json-rpc-provider.js

66 lines
3.0 KiB
JavaScript
Raw Normal View History

2019-05-15 01:48:48 +03:00
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var properties_1 = require("@ethersproject/properties");
2019-08-02 09:10:58 +03:00
var logger_1 = require("@ethersproject/logger");
var _version_1 = require("./_version");
var logger = new logger_1.Logger(_version_1.version);
2019-05-15 01:48:48 +03:00
var json_rpc_provider_1 = require("./json-rpc-provider");
var UrlJsonRpcProvider = /** @class */ (function (_super) {
__extends(UrlJsonRpcProvider, _super);
function UrlJsonRpcProvider(network, apiKey) {
var _newTarget = this.constructor;
var _this = this;
2019-08-02 09:10:58 +03:00
logger.checkAbstract(_newTarget, UrlJsonRpcProvider);
2019-05-24 02:13:44 +03:00
// Normalize the Network and API Key
2019-08-21 08:52:13 +03:00
network = properties_1.getStatic((_newTarget), "getNetwork")(network);
apiKey = properties_1.getStatic((_newTarget), "getApiKey")(apiKey);
2019-11-20 12:57:38 +03:00
var connection = properties_1.getStatic((_newTarget), "getUrl")(network, apiKey);
_this = _super.call(this, connection, network) || this;
if (typeof (apiKey) === "string") {
properties_1.defineReadOnly(_this, "apiKey", apiKey);
}
else if (apiKey != null) {
Object.keys(apiKey).forEach(function (key) {
properties_1.defineReadOnly(_this, key, apiKey[key]);
});
}
2019-05-15 01:48:48 +03:00
return _this;
}
UrlJsonRpcProvider.prototype._startPending = function () {
2019-08-02 09:10:58 +03:00
logger.warn("WARNING: API provider does not support pending filters");
2019-05-15 01:48:48 +03:00
};
UrlJsonRpcProvider.prototype.getSigner = function (address) {
2019-11-20 12:57:38 +03:00
return logger.throwError("API provider does not support signing", logger_1.Logger.errors.UNSUPPORTED_OPERATION, { operation: "getSigner" });
2019-05-15 01:48:48 +03:00
};
UrlJsonRpcProvider.prototype.listAccounts = function () {
return Promise.resolve([]);
};
// Return a defaultApiKey if null, otherwise validate the API key
UrlJsonRpcProvider.getApiKey = function (apiKey) {
return apiKey;
};
2019-11-20 12:57:38 +03:00
// Returns the url or connection for the given network and API key. The
// API key will have been sanitized by the getApiKey first, so any validation
// or transformations can be done there.
2019-05-15 01:48:48 +03:00
UrlJsonRpcProvider.getUrl = function (network, apiKey) {
2019-08-02 09:10:58 +03:00
return logger.throwError("not implemented; sub-classes must override getUrl", logger_1.Logger.errors.NOT_IMPLEMENTED, {
2019-05-15 01:48:48 +03:00
operation: "getUrl"
});
};
return UrlJsonRpcProvider;
}(json_rpc_provider_1.JsonRpcProvider));
exports.UrlJsonRpcProvider = UrlJsonRpcProvider;