ethers.js/providers/infura-provider.js

53 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-10-26 02:58:21 +03:00
'use strict';
var Provider = require('./provider');
var JsonRpcProvider = require('./json-rpc-provider');
2017-02-25 09:23:48 +03:00
var utils = (function() {
return {
defineProperty: require('ethers-utils/properties.js').defineProperty
}
})();
2017-10-26 02:58:21 +03:00
function InfuraProvider(network, apiAccessToken) {
2017-02-25 09:23:48 +03:00
if (!(this instanceof InfuraProvider)) { throw new Error('missing new'); }
// Legacy constructor (testnet, apiAccessToken)
2017-10-26 02:58:21 +03:00
// @TODO: Remove this in the next major release
network = Provider._legacyConstructor(network, 1, arguments[0]);
2017-10-26 02:58:21 +03:00
var host = null;
switch(network.name) {
case 'homestead':
host = 'mainnet.infura.io';
break;
case 'ropsten':
host = 'ropsten.infura.io';
break;
case 'rinkeby':
host = 'rinkeby.infura.io';
break;
case 'kovan':
host = 'kovan.infura.io';
break;
default:
throw new Error('unsupported network');
}
2017-02-25 09:23:48 +03:00
var url = 'https://' + host + '/' + (apiAccessToken || '');
2017-10-26 02:58:21 +03:00
JsonRpcProvider.call(this, url, network);
2017-02-25 09:23:48 +03:00
utils.defineProperty(this, 'apiAccessToken', apiAccessToken || null);
}
2017-03-01 10:31:11 +03:00
JsonRpcProvider.inherits(InfuraProvider);
2017-02-25 09:23:48 +03:00
utils.defineProperty(InfuraProvider.prototype, '_startPending', function() {
console.log('WARNING: INFURA does not support pending filters');
});
utils.defineProperty(InfuraProvider.prototype, '_stopPending', function() {
});
2017-02-25 09:23:48 +03:00
module.exports = InfuraProvider;