import { BigNumber } from '../utils/bignumber'; import { isType, setType } from '../utils/properties'; /////////////////////////////// // Imported Types import { Arrayish } from '../utils/bytes'; import { BigNumberish } from '../utils/bignumber'; import { Network } from '../utils/networks'; import { OnceBlockable } from '../utils/web'; import { Transaction } from '../utils/transaction'; /////////////////////////////// // Exported Types export interface Block { hash: string; parentHash: string; number: number; timestamp: number; nonce: string; difficulty: number; gasLimit: BigNumber; gasUsed: BigNumber; miner: string; extraData: string; transactions: Array; } export type BlockTag = string | number; export type Filter = { fromBlock?: BlockTag, toBlock?: BlockTag, address?: string, topics?: Array>, } export interface Log { blockNumber?: number; blockHash?: string; transactionIndex?: number; removed?: boolean; transactionLogIndex?: number, address: string; data: string; topics: Array; transactionHash?: string; logIndex?: number; } export interface TransactionReceipt { contractAddress?: string, transactionIndex?: number, root?: string, gasUsed?: BigNumber, logsBloom?: string, blockHash?: string, transactionHash?: string, logs?: Array, blockNumber?: number, confirmations?: number, cumulativeGasUsed?: BigNumber, byzantium: boolean, status?: number }; export type TransactionRequest = { to?: string | Promise, from?: string | Promise, nonce?: number | string | Promise, gasLimit?: BigNumberish | Promise, gasPrice?: BigNumberish | Promise, data?: Arrayish | Promise, value?: BigNumberish | Promise, chainId?: number | Promise, } export interface TransactionResponse extends Transaction { // Only if a transaction has been mined blockNumber?: number, blockHash?: string, timestamp?: number, confirmations: number, // Not optional (as it is in Transaction) from: string; // The raw transaction raw?: string, // This function waits until the transaction has been mined wait: (confirmations?: number) => Promise }; export type EventType = string | Array | Filter; export type Listener = (...args: Array) => void; /////////////////////////////// // Exported Abstracts export abstract class Provider implements OnceBlockable { abstract getNetwork(): Promise; abstract getBlockNumber(): Promise; abstract getGasPrice(): Promise; abstract getBalance(addressOrName: string | Promise, blockTag?: BlockTag | Promise): Promise; abstract getTransactionCount(addressOrName: string | Promise, blockTag?: BlockTag | Promise): Promise; abstract getCode(addressOrName: string | Promise, blockTag?: BlockTag | Promise): Promise ; abstract getStorageAt(addressOrName: string | Promise, position: BigNumberish | Promise, blockTag?: BlockTag | Promise): Promise; abstract sendTransaction(signedTransaction: string | Promise): Promise; abstract call(transaction: TransactionRequest, blockTag?: BlockTag | Promise): Promise; abstract estimateGas(transaction: TransactionRequest): Promise; abstract getBlock(blockHashOrBlockTag: BlockTag | string | Promise, includeTransactions?: boolean): Promise; abstract getTransaction(transactionHash: string): Promise; abstract getTransactionReceipt(transactionHash: string): Promise; abstract getLogs(filter: Filter): Promise>; abstract resolveName(name: string | Promise): Promise; abstract lookupAddress(address: string | Promise): Promise; abstract on(eventName: EventType, listener: Listener): Provider; abstract once(eventName: EventType, listener: Listener): Provider; abstract listenerCount(eventName?: EventType): number; abstract listeners(eventName: EventType): Array; abstract removeAllListeners(eventName: EventType): Provider; abstract removeListener(eventName: EventType, listener: Listener): Provider; // @TODO: This *could* be implemented here, but would pull in events... abstract waitForTransaction(transactionHash: string, timeout?: number): Promise; constructor() { setType(this, 'Provider'); } static isProvider(value: any): value is Provider { return isType(value, 'Provider'); } // readonly inherits: (child: any) => void; } //defineReadOnly(Signer, 'inherits', inheritable(Abstract));