ethers.js/providers/infura-provider.js

61 lines
1.6 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('../utils/properties').defineProperty
2017-02-25 09:23:48 +03:00
}
})();
var errors = require('../utils/errors');
2017-10-26 02:58:21 +03:00
function InfuraProvider(network, apiAccessToken) {
errors.checkNew(this, InfuraProvider);
2017-02-25 09:23:48 +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
utils.defineProperty(InfuraProvider.prototype, '_startPending', function() {
console.log('WARNING: INFURA does not support pending filters');
});
utils.defineProperty(InfuraProvider.prototype, '_stopPending', function() {
});
utils.defineProperty(InfuraProvider.prototype, 'getSigner', function(address) {
errors.throwError('INFURA does not support signing', errors.UNSUPPORTED_OPERATION, { operation: 'getSigner' });
});
utils.defineProperty(InfuraProvider.prototype, 'listAccounts', function() {
return Promise.resolve([]);
});
2017-02-25 09:23:48 +03:00
module.exports = InfuraProvider;