Initial support for EIP-234; filter by blockHash (#412).
This commit is contained in:
parent
41c2c8a729
commit
60b75c10d7
@ -41,6 +41,16 @@ export type Filter = {
|
|||||||
topics?: Array<string | Array<string>>,
|
topics?: Array<string | Array<string>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @TODO: This is not supported as an EventType yet, as it will
|
||||||
|
// need some additional work to adhere to the serialized
|
||||||
|
// format for events. But we want to allow it for getLogs
|
||||||
|
// for now.
|
||||||
|
export type FilterByBlock = {
|
||||||
|
blockHash?: string,
|
||||||
|
address?: string,
|
||||||
|
topics?: Array<string | Array<string>>,
|
||||||
|
}
|
||||||
|
|
||||||
export interface Log {
|
export interface Log {
|
||||||
blockNumber?: number;
|
blockNumber?: number;
|
||||||
blockHash?: string;
|
blockHash?: string;
|
||||||
@ -134,7 +144,7 @@ export abstract class Provider implements OnceBlockable {
|
|||||||
abstract getTransaction(transactionHash: string): Promise<TransactionResponse>;
|
abstract getTransaction(transactionHash: string): Promise<TransactionResponse>;
|
||||||
abstract getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
|
abstract getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
|
||||||
|
|
||||||
abstract getLogs(filter: Filter): Promise<Array<Log>>;
|
abstract getLogs(filter: Filter | FilterByBlock): Promise<Array<Log>>;
|
||||||
|
|
||||||
abstract resolveName(name: string | Promise<string>): Promise<string>;
|
abstract resolveName(name: string | Promise<string>): Promise<string>;
|
||||||
abstract lookupAddress(address: string | Promise<string>): Promise<string>;
|
abstract lookupAddress(address: string | Promise<string>): Promise<string>;
|
||||||
|
@ -23,7 +23,7 @@ import { Provider } from './abstract-provider';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
Block, BlockTag,
|
Block, BlockTag,
|
||||||
EventType, Filter,
|
EventType, Filter, FilterByBlock,
|
||||||
Listener,
|
Listener,
|
||||||
Log,
|
Log,
|
||||||
TransactionReceipt, TransactionRequest, TransactionResponse
|
TransactionReceipt, TransactionRequest, TransactionResponse
|
||||||
@ -366,7 +366,16 @@ const formatFilter = {
|
|||||||
topics: allowNull(checkTopics, undefined),
|
topics: allowNull(checkTopics, undefined),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const formatFilterByBlock = {
|
||||||
|
blockHash: allowNull(checkHash, undefined),
|
||||||
|
address: allowNull(getAddress, undefined),
|
||||||
|
topics: allowNull(checkTopics, undefined),
|
||||||
|
};
|
||||||
|
|
||||||
function checkFilter(filter: any): any {
|
function checkFilter(filter: any): any {
|
||||||
|
if (filter && filter.blockHash) {
|
||||||
|
return check(formatFilterByBlock, filter);
|
||||||
|
}
|
||||||
return check(formatFilter, filter);
|
return check(formatFilter, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1071,7 +1080,7 @@ export class BaseProvider extends Provider {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogs(filter: Filter): Promise<Array<Log>> {
|
getLogs(filter: Filter | FilterByBlock): Promise<Array<Log>> {
|
||||||
return this.ready.then(() => {
|
return this.ready.then(() => {
|
||||||
return resolveProperties(filter).then((filter) => {
|
return resolveProperties(filter).then((filter) => {
|
||||||
return this._resolveNames(filter, ['address']).then((filter) => {
|
return this._resolveNames(filter, ['address']).then((filter) => {
|
||||||
|
@ -237,6 +237,16 @@ export class EtherscanProvider extends BaseProvider{
|
|||||||
url += '&toBlock=' + checkLogTag(params.filter.toBlock);
|
url += '&toBlock=' + checkLogTag(params.filter.toBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params.filter.blockHash) {
|
||||||
|
try {
|
||||||
|
errors.throwError("Etherscan does not support blockHash filters", errors.UNSUPPORTED_OPERATION, {
|
||||||
|
operation: "getLogs(blockHash)"
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (params.filter.address) {
|
if (params.filter.address) {
|
||||||
url += '&address=' + params.filter.address;
|
url += '&address=' + params.filter.address;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user