Added v3 INFURA end-points to InfuraProvider (#286).
This commit is contained in:
parent
5f013216c5
commit
f2dd977de4
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { JsonRpcProvider, JsonRpcSigner } from './json-rpc-provider';
|
import { JsonRpcProvider, JsonRpcSigner } from './json-rpc-provider';
|
||||||
|
|
||||||
|
import { isHexString } from "../utils/bytes";
|
||||||
import { getNetwork } from '../utils/networks';
|
import { getNetwork } from '../utils/networks';
|
||||||
import { defineReadOnly } from '../utils/properties';
|
import { defineReadOnly } from '../utils/properties';
|
||||||
|
|
||||||
@ -10,14 +11,18 @@ import { Networkish } from '../utils/networks';
|
|||||||
|
|
||||||
import * as errors from '../errors';
|
import * as errors from '../errors';
|
||||||
|
|
||||||
|
const defaultProjectId = "7d0d81d0919f4f05b9ab6634be01ee73";
|
||||||
|
|
||||||
export class InfuraProvider extends JsonRpcProvider {
|
export class InfuraProvider extends JsonRpcProvider {
|
||||||
readonly apiAccessToken: string;
|
readonly apiAccessToken: string;
|
||||||
|
readonly projectId: string;
|
||||||
|
|
||||||
constructor(network?: Networkish, apiAccessToken?: string) {
|
constructor(network?: Networkish, projectId?: string) {
|
||||||
network = getNetwork((network == null) ? 'homestead': network);
|
let standard = getNetwork((network == null) ? 'homestead': network);
|
||||||
|
if (projectId == null) { projectId = defaultProjectId; }
|
||||||
|
|
||||||
var host = null;
|
let host = null;
|
||||||
switch(network.name) {
|
switch(standard.name) {
|
||||||
case 'homestead':
|
case 'homestead':
|
||||||
host = 'mainnet.infura.io';
|
host = 'mainnet.infura.io';
|
||||||
break;
|
break;
|
||||||
@ -31,13 +36,26 @@ export class InfuraProvider extends JsonRpcProvider {
|
|||||||
host = 'kovan.infura.io';
|
host = 'kovan.infura.io';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error('unsupported network');
|
errors.throwError('unsupported network', errors.INVALID_ARGUMENT, {
|
||||||
|
argument: "network",
|
||||||
|
value: network
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
super('https://' + host + '/' + (apiAccessToken || ''), network);
|
// New-style Project ID
|
||||||
errors.checkNew(this, InfuraProvider);
|
if (isHexString("0x" + projectId, 16)) {
|
||||||
|
super('https://' + host + '/v3/' + projectId, standard);
|
||||||
|
defineReadOnly(this, 'apiAccessToken', null);
|
||||||
|
defineReadOnly(this, 'projectId', projectId);
|
||||||
|
|
||||||
defineReadOnly(this, 'apiAccessToken', apiAccessToken || null);
|
// Legacy API Access Token
|
||||||
|
} else {
|
||||||
|
super('https://' + host + '/' + projectId, standard);
|
||||||
|
defineReadOnly(this, 'apiAccessToken', projectId);
|
||||||
|
defineReadOnly(this, 'projectId', null);
|
||||||
|
}
|
||||||
|
|
||||||
|
errors.checkNew(this, InfuraProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _startPending(): void {
|
protected _startPending(): void {
|
||||||
@ -45,12 +63,11 @@ export class InfuraProvider extends JsonRpcProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSigner(address?: string): JsonRpcSigner {
|
getSigner(address?: string): JsonRpcSigner {
|
||||||
errors.throwError(
|
return errors.throwError(
|
||||||
'INFURA does not support signing',
|
'INFURA does not support signing',
|
||||||
errors.UNSUPPORTED_OPERATION,
|
errors.UNSUPPORTED_OPERATION,
|
||||||
{ operation: 'getSigner' }
|
{ operation: 'getSigner' }
|
||||||
);
|
);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
listAccounts(): Promise<Array<string>> {
|
listAccounts(): Promise<Array<string>> {
|
||||||
|
Loading…
Reference in New Issue
Block a user