2018-06-13 22:39:39 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import { JsonRpcProvider, JsonRpcSigner } from './json-rpc-provider';
|
2018-06-18 12:42:41 +03:00
|
|
|
import { getNetwork, Networkish } from './networks';
|
|
|
|
|
|
|
|
import { defineReadOnly } from '../utils/properties';
|
2018-06-13 22:39:39 +03:00
|
|
|
|
|
|
|
import * as errors from '../utils/errors';
|
|
|
|
|
|
|
|
export class InfuraProvider extends JsonRpcProvider {
|
|
|
|
readonly apiAccessToken: string;
|
|
|
|
|
2018-06-18 12:42:41 +03:00
|
|
|
constructor(network?: Networkish, apiAccessToken?: string) {
|
|
|
|
network = getNetwork((network == null) ? 'homestead': network);
|
2018-06-13 22:39:39 +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');
|
|
|
|
}
|
|
|
|
|
|
|
|
super('https://' + host + '/' + (apiAccessToken || ''), network);
|
2018-06-14 04:10:41 +03:00
|
|
|
errors.checkNew(this, InfuraProvider);
|
|
|
|
|
2018-06-18 12:42:41 +03:00
|
|
|
defineReadOnly(this, 'apiAccessToken', apiAccessToken || null);
|
2018-06-13 22:39:39 +03:00
|
|
|
}
|
|
|
|
|
2018-06-15 11:18:17 +03:00
|
|
|
_startPending(): void {
|
2018-06-13 22:39:39 +03:00
|
|
|
console.log('WARNING: INFURA does not support pending filters');
|
|
|
|
}
|
|
|
|
|
|
|
|
getSigner(address?: string): JsonRpcSigner {
|
|
|
|
errors.throwError(
|
|
|
|
'INFURA does not support signing',
|
|
|
|
errors.UNSUPPORTED_OPERATION,
|
|
|
|
{ operation: 'getSigner' }
|
|
|
|
);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-06-15 11:18:17 +03:00
|
|
|
listAccounts(): Promise<Array<string>> {
|
2018-06-13 22:39:39 +03:00
|
|
|
return Promise.resolve([]);
|
|
|
|
}
|
|
|
|
}
|