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 {
|
2018-03-05 03:31:09 +03:00
|
|
|
defineProperty: require('../utils/properties.js').defineProperty
|
2017-02-25 09:23:48 +03:00
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
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'); }
|
|
|
|
|
2018-03-05 03:31:09 +03:00
|
|
|
network = Provider.getNetwork(network);
|
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
|
|
|
|
2017-12-30 04:41:16 +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;
|