Refactor Provider.
This commit is contained in:
parent
cf79190175
commit
336df72e04
@ -1,5 +1,5 @@
|
||||
|
||||
import { checkTransactionResponse, Provider, TransactionRequest } from './provider';
|
||||
import { BlockTag, checkTransactionResponse, Provider, TransactionRequest, TransactionResponse } from './provider';
|
||||
import { Networkish } from './networks';
|
||||
|
||||
import { hexlify, hexStripZeros } from '../utils/bytes';
|
||||
@ -251,32 +251,33 @@ export class EtherscanProvider extends Provider{
|
||||
return super.perform(method, params);
|
||||
}
|
||||
|
||||
getHistory(addressOrName, startBlock, endBlock) {
|
||||
// @TODO: Allow startBlock and endBlock to be Promises
|
||||
getHistory(addressOrName: string | Promise<string>, startBlock?: BlockTag, endBlock?: BlockTag): Promise<Array<TransactionResponse>> {
|
||||
|
||||
var url = this.baseUrl;
|
||||
let url = this.baseUrl;
|
||||
|
||||
var apiKey = '';
|
||||
let apiKey = '';
|
||||
if (this.apiKey) { apiKey += '&apikey=' + this.apiKey; }
|
||||
|
||||
if (startBlock == null) { startBlock = 0; }
|
||||
if (endBlock == null) { endBlock = 99999999; }
|
||||
|
||||
return this.resolveName(addressOrName).then(function(address) {
|
||||
return this.resolveName(addressOrName).then((address) => {
|
||||
url += '/api?module=account&action=txlist&address=' + address;
|
||||
url += '&startblock=' + startBlock;
|
||||
url += '&endblock=' + endBlock;
|
||||
url += '&sort=asc' + apiKey;
|
||||
|
||||
return fetchJson(url, null, getResult).then(function(result) {
|
||||
var output = [];
|
||||
result.forEach(function(tx) {
|
||||
return fetchJson(url, null, getResult).then((result) => {
|
||||
var output: Array<TransactionResponse> = [];
|
||||
result.forEach((tx) => {
|
||||
['contractAddress', 'to'].forEach(function(key) {
|
||||
if (tx[key] == '') { delete tx[key]; }
|
||||
});
|
||||
if (tx.creates == null && tx.contractAddress != null) {
|
||||
tx.creates = tx.contractAddress;
|
||||
}
|
||||
var item = checkTransactionResponse(tx);
|
||||
let item = checkTransactionResponse(tx);
|
||||
if (tx.timeStamp) { item.timestamp = parseInt(tx.timeStamp); }
|
||||
output.push(item);
|
||||
});
|
||||
|
@ -65,7 +65,7 @@ function getLowerCase(value: string): string {
|
||||
|
||||
export class JsonRpcSigner extends Signer {
|
||||
readonly provider: JsonRpcProvider;
|
||||
readonly _address: string;
|
||||
private _address: string;
|
||||
|
||||
constructor(provider: JsonRpcProvider, address?: string) {
|
||||
super();
|
||||
|
@ -630,26 +630,6 @@ export class ProviderSigner extends Signer {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
estimateGas(transaction: TransactionRequest): Promise<BigNumber> {
|
||||
transaction = shallowCopy(transaction);
|
||||
|
||||
if (transaction.from == null) {
|
||||
transaction.from = this.getAddress();
|
||||
}
|
||||
|
||||
return this.provider.estimateGas(transaction);
|
||||
}
|
||||
|
||||
call(transaction: TransactionRequest): Promise<string> {
|
||||
transaction = shallowCopy(transaction);
|
||||
|
||||
if (transaction.from == null) {
|
||||
transaction.from = this.getAddress();
|
||||
}
|
||||
|
||||
return this.provider.call(transaction);
|
||||
}
|
||||
}
|
||||
|
||||
export class Provider {
|
||||
@ -1349,13 +1329,3 @@ function(child) {
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
//defineProperty(Provider, 'networks', networks);
|
||||
|
||||
/*
|
||||
defineProperty(Provider, '_formatters', {
|
||||
checkTransactionResponse: checkTransaction
|
||||
});
|
||||
|
||||
module.exports = Provider;
|
||||
*/
|
||||
|
4
src/providers/etherscan-provider.d.ts
vendored
4
src/providers/etherscan-provider.d.ts
vendored
@ -1,9 +1,9 @@
|
||||
import { Provider } from './provider';
|
||||
import { BlockTag, Provider, TransactionResponse } from './provider';
|
||||
import { Networkish } from './networks';
|
||||
export declare class EtherscanProvider extends Provider {
|
||||
readonly baseUrl: string;
|
||||
readonly apiKey: string;
|
||||
constructor(network?: Networkish, apiKey?: string);
|
||||
perform(method: string, params: any): Promise<any>;
|
||||
getHistory(addressOrName: any, startBlock: any, endBlock: any): Promise<any[]>;
|
||||
getHistory(addressOrName: string | Promise<string>, startBlock?: BlockTag, endBlock?: BlockTag): Promise<Array<TransactionResponse>>;
|
||||
}
|
||||
|
@ -243,6 +243,7 @@ var EtherscanProvider = /** @class */ (function (_super) {
|
||||
}
|
||||
return _super.prototype.perform.call(this, method, params);
|
||||
};
|
||||
// @TODO: Allow startBlock and endBlock to be Promises
|
||||
EtherscanProvider.prototype.getHistory = function (addressOrName, startBlock, endBlock) {
|
||||
var url = this.baseUrl;
|
||||
var apiKey = '';
|
||||
|
2
src/providers/json-rpc-provider.d.ts
vendored
2
src/providers/json-rpc-provider.d.ts
vendored
@ -7,7 +7,7 @@ import { ConnectionInfo } from '../utils/web';
|
||||
export declare function hexlifyTransaction(transaction: TransactionRequest): any;
|
||||
export declare class JsonRpcSigner extends Signer {
|
||||
readonly provider: JsonRpcProvider;
|
||||
readonly _address: string;
|
||||
private _address;
|
||||
constructor(provider: JsonRpcProvider, address?: string);
|
||||
readonly address: string;
|
||||
getAddress(): Promise<string>;
|
||||
|
2
src/providers/provider.d.ts
vendored
2
src/providers/provider.d.ts
vendored
@ -73,8 +73,6 @@ export declare class ProviderSigner extends Signer {
|
||||
getAddress(): Promise<string>;
|
||||
signMessage(message: Arrayish | string): Promise<string>;
|
||||
sendTransaction(transaction: TransactionRequest): Promise<TransactionResponse>;
|
||||
estimateGas(transaction: TransactionRequest): Promise<BigNumber>;
|
||||
call(transaction: TransactionRequest): Promise<string>;
|
||||
}
|
||||
export declare class Provider {
|
||||
private _network;
|
||||
|
@ -492,20 +492,6 @@ var ProviderSigner = /** @class */ (function (_super) {
|
||||
});
|
||||
});
|
||||
};
|
||||
ProviderSigner.prototype.estimateGas = function (transaction) {
|
||||
transaction = properties_1.shallowCopy(transaction);
|
||||
if (transaction.from == null) {
|
||||
transaction.from = this.getAddress();
|
||||
}
|
||||
return this.provider.estimateGas(transaction);
|
||||
};
|
||||
ProviderSigner.prototype.call = function (transaction) {
|
||||
transaction = properties_1.shallowCopy(transaction);
|
||||
if (transaction.from == null) {
|
||||
transaction.from = this.getAddress();
|
||||
}
|
||||
return this.provider.call(transaction);
|
||||
};
|
||||
return ProviderSigner;
|
||||
}(wallet_1.Signer));
|
||||
exports.ProviderSigner = ProviderSigner;
|
||||
|
Loading…
Reference in New Issue
Block a user