|
| 1 | +// Type definitions for ethereum-block-by-date 1.4 |
| 2 | +// Project: https://github.com/monosux/ethereum-block-by-date |
| 3 | +// Definitions by: Alexandre ABRIOUX <https://github.com/alexandre-abrioux> |
| 4 | +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
| 5 | + |
| 6 | +import { DurationInputObject, MomentInput } from 'moment'; |
| 7 | +import { providers as EthersProviders } from 'ethers'; |
| 8 | +import Web3 from 'web3'; |
| 9 | + |
| 10 | +export = EthDater; |
| 11 | +export as namespace EthDater; |
| 12 | + |
| 13 | +declare namespace EthDater { |
| 14 | + interface BlockResult { |
| 15 | + block: number; |
| 16 | + timestamp: number; |
| 17 | + date: string; |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +declare class EthDater { |
| 22 | + constructor(provider: EthersProviders.Provider | Web3); |
| 23 | + |
| 24 | + /** |
| 25 | + * Search for the closest block on the chain corresponding to the input date. |
| 26 | + * @param date Date, required. Any valid moment.js value: string, milliseconds, Date() object, moment() object. |
| 27 | + * @param blockAfter Block after, optional. Search for the nearest block before or after the given date. By default, true. |
| 28 | + */ |
| 29 | + getDate(date: MomentInput, blockAfter?: boolean): EthDater.BlockResult; |
| 30 | + |
| 31 | + /** |
| 32 | + * Returns an array of blocks corresponding to periods. |
| 33 | + * For example: every first block of Monday's noons of October 2019. |
| 34 | + * @param period Period, required. Valid value: years, quarters, months, weeks, days, hours, minutes. |
| 35 | + * @param startDate Start date, required. Any valid moment.js value: string, milliseconds, Date() object, moment() object. |
| 36 | + * @param endDate End date, required. Any valid moment.js value: string, milliseconds, Date() object, moment() object. |
| 37 | + * @param every Duration, optional, integer. By default, 1. |
| 38 | + * @param blockAfter Block after, optional. Search for the nearest block before or after the given date. By default, true. |
| 39 | + */ |
| 40 | + getEvery( |
| 41 | + period: keyof DurationInputObject, |
| 42 | + startDate: MomentInput, |
| 43 | + endDate: MomentInput, |
| 44 | + every?: number, |
| 45 | + blockAfter?: boolean, |
| 46 | + ): EthDater.BlockResult[]; |
| 47 | +} |
0 commit comments