2018-07-31 01:59:52 +03:00
|
|
|
|
|
|
|
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<string>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type BlockTag = string | number;
|
|
|
|
|
|
|
|
export type Filter = {
|
|
|
|
fromBlock?: BlockTag,
|
|
|
|
toBlock?: BlockTag,
|
|
|
|
address?: string,
|
|
|
|
topics?: Array<string | Array<string>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Log {
|
|
|
|
blockNumber?: number;
|
|
|
|
blockHash?: string;
|
|
|
|
transactionIndex?: number;
|
|
|
|
|
|
|
|
removed?: boolean;
|
|
|
|
|
|
|
|
transactionLogIndex?: number,
|
|
|
|
|
|
|
|
address: string;
|
|
|
|
data: string;
|
|
|
|
|
|
|
|
topics: Array<string>;
|
|
|
|
|
|
|
|
transactionHash?: string;
|
|
|
|
logIndex?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TransactionReceipt {
|
|
|
|
contractAddress?: string,
|
|
|
|
transactionIndex?: number,
|
|
|
|
root?: string,
|
|
|
|
gasUsed?: BigNumber,
|
|
|
|
logsBloom?: string,
|
|
|
|
blockHash?: string,
|
|
|
|
transactionHash?: string,
|
|
|
|
logs?: Array<Log>,
|
|
|
|
blockNumber?: number,
|
2018-10-05 00:27:42 +03:00
|
|
|
confirmations?: number,
|
2018-07-31 01:59:52 +03:00
|
|
|
cumulativeGasUsed?: BigNumber,
|
|
|
|
byzantium: boolean,
|
|
|
|
status?: number
|
|
|
|
};
|
|
|
|
|
|
|
|
export type TransactionRequest = {
|
|
|
|
to?: string | Promise<string>,
|
|
|
|
from?: string | Promise<string>,
|
2018-12-13 00:56:50 +03:00
|
|
|
nonce?: BigNumberish | Promise<BigNumberish>,
|
2018-07-31 01:59:52 +03:00
|
|
|
|
|
|
|
gasLimit?: BigNumberish | Promise<BigNumberish>,
|
|
|
|
gasPrice?: BigNumberish | Promise<BigNumberish>,
|
|
|
|
|
|
|
|
data?: Arrayish | Promise<Arrayish>,
|
|
|
|
value?: BigNumberish | Promise<BigNumberish>,
|
|
|
|
chainId?: number | Promise<number>,
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TransactionResponse extends Transaction {
|
|
|
|
// Only if a transaction has been mined
|
|
|
|
blockNumber?: number,
|
|
|
|
blockHash?: string,
|
|
|
|
timestamp?: number,
|
|
|
|
|
2018-10-04 23:24:31 +03:00
|
|
|
confirmations: number,
|
|
|
|
|
2018-07-31 01:59:52 +03:00
|
|
|
// Not optional (as it is in Transaction)
|
|
|
|
from: string;
|
|
|
|
|
|
|
|
// The raw transaction
|
|
|
|
raw?: string,
|
|
|
|
|
|
|
|
// This function waits until the transaction has been mined
|
2018-10-05 02:54:15 +03:00
|
|
|
wait: (confirmations?: number) => Promise<TransactionReceipt>
|
2018-07-31 01:59:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export type EventType = string | Array<string> | Filter;
|
|
|
|
|
|
|
|
export type Listener = (...args: Array<any>) => void;
|
|
|
|
|
|
|
|
///////////////////////////////
|
|
|
|
// Exported Abstracts
|
|
|
|
|
|
|
|
export abstract class Provider implements OnceBlockable {
|
|
|
|
abstract getNetwork(): Promise<Network>;
|
|
|
|
|
|
|
|
abstract getBlockNumber(): Promise<number>;
|
|
|
|
abstract getGasPrice(): Promise<BigNumber>;
|
|
|
|
|
|
|
|
abstract getBalance(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<BigNumber>;
|
|
|
|
abstract getTransactionCount(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<number>;
|
|
|
|
abstract getCode(addressOrName: string | Promise<string>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string> ;
|
|
|
|
abstract getStorageAt(addressOrName: string | Promise<string>, position: BigNumberish | Promise<BigNumberish>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string>;
|
|
|
|
|
|
|
|
abstract sendTransaction(signedTransaction: string | Promise<string>): Promise<TransactionResponse>;
|
2018-10-11 23:03:18 +03:00
|
|
|
abstract call(transaction: TransactionRequest, blockTag?: BlockTag | Promise<BlockTag>): Promise<string>;
|
2018-07-31 01:59:52 +03:00
|
|
|
abstract estimateGas(transaction: TransactionRequest): Promise<BigNumber>;
|
|
|
|
|
2018-09-04 17:08:50 +03:00
|
|
|
abstract getBlock(blockHashOrBlockTag: BlockTag | string | Promise<BlockTag | string>, includeTransactions?: boolean): Promise<Block>;
|
2018-07-31 01:59:52 +03:00
|
|
|
abstract getTransaction(transactionHash: string): Promise<TransactionResponse>;
|
|
|
|
abstract getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
|
|
|
|
|
|
|
|
abstract getLogs(filter: Filter): Promise<Array<Log>>;
|
|
|
|
|
|
|
|
abstract resolveName(name: string | Promise<string>): Promise<string>;
|
|
|
|
abstract lookupAddress(address: string | Promise<string>): Promise<string>;
|
|
|
|
abstract on(eventName: EventType, listener: Listener): Provider;
|
|
|
|
abstract once(eventName: EventType, listener: Listener): Provider;
|
|
|
|
abstract listenerCount(eventName?: EventType): number;
|
|
|
|
abstract listeners(eventName: EventType): Array<Listener>;
|
|
|
|
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<TransactionReceipt>;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|