ethers.js/providers/infura-provider.js

85 lines
3.6 KiB
JavaScript
Raw Permalink Normal View History

2018-06-13 15:39:39 -04:00
'use strict';
var __extends = (this && this.__extends) || (function () {
var 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 function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var json_rpc_provider_1 = require("./json-rpc-provider");
2019-01-23 16:30:12 -05:00
var bytes_1 = require("../utils/bytes");
2018-07-16 00:55:34 -04:00
var networks_1 = require("../utils/networks");
2018-06-18 05:42:41 -04:00
var properties_1 = require("../utils/properties");
2018-09-24 16:07:14 -04:00
var errors = __importStar(require("../errors"));
2019-01-23 16:30:12 -05:00
var defaultProjectId = "7d0d81d0919f4f05b9ab6634be01ee73";
2018-06-13 15:39:39 -04:00
var InfuraProvider = /** @class */ (function (_super) {
__extends(InfuraProvider, _super);
2019-01-23 16:30:12 -05:00
function InfuraProvider(network, projectId) {
2018-06-13 15:39:39 -04:00
var _this = this;
2019-01-23 16:30:12 -05:00
var standard = networks_1.getNetwork((network == null) ? 'homestead' : network);
if (projectId == null) {
projectId = defaultProjectId;
}
2018-06-13 15:39:39 -04:00
var host = null;
2019-01-23 16:30:12 -05:00
switch (standard.name) {
2018-06-13 15:39:39 -04:00
case 'homestead':
host = 'mainnet.infura.io';
break;
case 'ropsten':
host = 'ropsten.infura.io';
break;
case 'rinkeby':
host = 'rinkeby.infura.io';
break;
2019-03-08 14:29:59 -05:00
case 'goerli':
host = 'goerli.infura.io';
break;
2018-06-13 15:39:39 -04:00
case 'kovan':
host = 'kovan.infura.io';
break;
default:
2019-01-23 16:30:12 -05:00
errors.throwError('unsupported network', errors.INVALID_ARGUMENT, {
argument: "network",
value: network
});
}
// New-style Project ID
if (bytes_1.isHexString("0x" + projectId, 16)) {
_this = _super.call(this, 'https://' + host + '/v3/' + projectId, standard) || this;
properties_1.defineReadOnly(_this, 'apiAccessToken', null);
properties_1.defineReadOnly(_this, 'projectId', projectId);
// Legacy API Access Token
}
else {
2019-05-24 19:41:38 -04:00
errors.warn("The legacy INFURA apiAccesToken API is deprecated; please upgrade to a Project ID instead (see INFURA dshboard; https://infura.io)");
2019-01-23 16:30:12 -05:00
_this = _super.call(this, 'https://' + host + '/' + projectId, standard) || this;
properties_1.defineReadOnly(_this, 'apiAccessToken', projectId);
properties_1.defineReadOnly(_this, 'projectId', null);
2018-06-13 15:39:39 -04:00
}
errors.checkNew(_this, InfuraProvider);
2018-06-13 15:39:39 -04:00
return _this;
}
InfuraProvider.prototype._startPending = function () {
2018-12-27 15:53:00 -05:00
errors.warn('WARNING: INFURA does not support pending filters');
2018-06-13 15:39:39 -04:00
};
InfuraProvider.prototype.getSigner = function (address) {
2019-01-23 16:30:12 -05:00
return errors.throwError('INFURA does not support signing', errors.UNSUPPORTED_OPERATION, { operation: 'getSigner' });
2018-06-13 15:39:39 -04:00
};
InfuraProvider.prototype.listAccounts = function () {
return Promise.resolve([]);
};
return InfuraProvider;
}(json_rpc_provider_1.JsonRpcProvider));
exports.InfuraProvider = InfuraProvider;