diff --git a/docs/include_package-core.rst b/docs/include_package-core.rst index fcb0ea45ab9..57f6c62d4f7 100644 --- a/docs/include_package-core.rst +++ b/docs/include_package-core.rst @@ -206,82 +206,3 @@ Example ------------------------------------------------------------------------------ - -extend -===================== - -.. code-block:: javascript - - web3.extend(methods) - web3.eth.extend(methods) - web3.shh.extend(methods) - web3.bzz.extend(methods) - ... - -Allows extending the web3 modules. - -.. note:: You also have ``*.extend.formatters`` as additional formatter functions to be used for in and output formatting. Please see the `source file `_ for function details. - ----------- -Parameters ----------- - -1. ``methods`` - ``Object``: Extension object with array of methods description objects as follows: - - ``property`` - ``String``: (optional) The name of the property to add to the module. If no property is set it will be added to the module directly. - - ``methods`` - ``Array``: The array of method descriptions: - - ``name`` - ``String``: Name of the method to add. - - ``call`` - ``String``: The RPC method name. - - ``params`` - ``Number``: (optional) The number of parameters for that function. Default 0. - - ``inputFormatter`` - ``Array``: (optional) Array of inputformatter functions. Each array item responds to a function parameter, so if you want some parameters not to be formatted, add a ``null`` instead. - - ``outputFormatter - ``Function``: (optional) Can be used to format the output of the method. - - ----------- -Returns ----------- - -``Object``: The extended module. - -------- -Example -------- - -.. code-block:: javascript - - web3.extend({ - property: 'myModule', - methods: [{ - name: 'getBalance', - call: 'eth_getBalance', - params: 2, - inputFormatter: [web3.extend.formatters.inputAddressFormatter, web3.extend.formatters.inputDefaultBlockNumberFormatter], - outputFormatter: web3.utils.hexToNumberString - },{ - name: 'getGasPriceSuperFunction', - call: 'eth_gasPriceSuper', - params: 2, - inputFormatter: [null, web3.utils.numberToHex] - }] - }); - - web3.extend({ - methods: [{ - name: 'directCall', - call: 'eth_callForFun', - }] - }); - - console.log(web3); - > Web3 { - myModule: { - getBalance: function(){}, - getGasPriceSuperFunction: function(){} - }, - directCall: function(){}, - eth: Eth {...}, - bzz: Bzz {...}, - ... - } - - ------------------------------------------------------------------------------- diff --git a/docs/web3-eth.rst b/docs/web3-eth.rst index 01342f35379..b1fdcb1ed42 100644 --- a/docs/web3-eth.rst +++ b/docs/web3-eth.rst @@ -1178,7 +1178,7 @@ signTransaction .. code-block:: javascript - web3.eth.signTransaction(transactionObject, address [, callback]) + web3.eth.signTransaction(transactionObject [, address] [, callback]) Signs a transaction. This account needs to be unlocked. @@ -1188,7 +1188,7 @@ Parameters 1. ``Object`` - The transaction data to sign :ref:`web3.eth.sendTransaction() ` for more. -2. ``String`` - Address to sign transaction with. +2. ``String`` - (optional) Address to sign transaction with. 3. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. diff --git a/packages/web3-eth-accounts/types/index.d.ts b/packages/web3-eth-accounts/types/index.d.ts index ebe95299548..35f1868cd7e 100644 --- a/packages/web3-eth-accounts/types/index.d.ts +++ b/packages/web3-eth-accounts/types/index.d.ts @@ -83,14 +83,13 @@ export interface EncryptedKeystoreV3Json { } } -/** MOVE ALL BELOW TO WEB3-CORE !!! */ +/** MOVE ALL BELOW TO WEB3-CORE ONCE TYPES COMPLETE FOR CLEAR UP !!! */ export interface Transaction { from?: string | number; - to: string; + to?: string; gasPrice?: string; - gas: number; - // value: number | string | BN | BigNumber; should be this - value: number | string; + gas?: number | string; + value?: number | string; chainId?: number; data?: string; nonce?: number; diff --git a/packages/web3-eth/package.json b/packages/web3-eth/package.json index 759c31608ff..665f31406b3 100644 --- a/packages/web3-eth/package.json +++ b/packages/web3-eth/package.json @@ -11,8 +11,10 @@ "scripts": { "build": "rollup -c", "dev": "rollup -c -w", - "test": "jest" + "test": "jest", + "dtslint": "dtslint types" }, + "types": "types", "dependencies": { "web3-core": "1.0.0-beta.36", "web3-core-helpers": "1.0.0-beta.36", @@ -28,7 +30,11 @@ "web3-providers": "1.0.0-beta.36", "web3-utils": "1.0.0-beta.36" }, + "devDependencies": { + "dtslint": "^0.3.0" + }, "files": [ - "dist" + "dist", + "types/index.d.ts" ] } diff --git a/packages/web3-eth/types/index.d.ts b/packages/web3-eth/types/index.d.ts new file mode 100644 index 00000000000..f314477f544 --- /dev/null +++ b/packages/web3-eth/types/index.d.ts @@ -0,0 +1,259 @@ +/* + This file is part of web3.js. + web3.js is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + web3.js is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public License + along with web3.js. If not, see . +*/ +/** + * @file index.d.ts + * @author Josh Stevens + * @date 2018 + */ + +import * as net from 'net'; +import {AbstractProviderAdapter, provider, BatchRequest} from 'web3-providers'; +import {AbstractWeb3Module, Web3ModuleOptions, Providers} from 'web3-core'; +import {Contract} from 'web3-eth-contract'; +import {Iban} from 'web3-eth-iban'; +import {Accounts} from 'web3-eth-accounts'; +import {AbiCoder} from 'web3-eth-abi'; +import {Network} from 'web3-net'; + +export class Eth extends AbstractWeb3Module { + constructor( + provider: AbstractProviderAdapter | provider, + options?: Web3ModuleOptions + ); + Contract: Contract; + Iban: Iban; + personal: Personal; // change one personal types are written + accounts: Accounts; + ens: any; // change once ens types as written + abi: AbiCoder; + net: Network; + clearSubscriptions(): boolean + subscribe(type: 'logs', options?: Logs): Promise>; + subscribe(type: 'logs', callback?: (error: Error, result: Subscribe) => void): Promise> + subscribe(type: 'logs', options?: Logs, callback?: (error: Error, result: Subscribe) => void): Promise>; + subscribe(type: 'syncing', callback?: (error: Error, result: Subscribe) => void): Promise> + subscribe(type: 'newBlockHeaders', callback?: (error: Error, result: Subscribe) => void): Promise> + subscribe(type: 'pendingTransactions', callback?: (error: Error, result: Subscribe) => void): Promise> + setProvider(provider: AbstractProviderAdapter | provider, net?: net.Server): boolean; + readonly providers: Providers; + readonly givenProvider: provider | null; + BatchRequest(): BatchRequest; + getProtocolVersion(callback?: (error: Error, protocolVersion: string) => void): Promise; + isSyncing(callback?: (error: Error, syncing: Syncing) => void): Promise; + getCoinbase(callback?: (error: Error, coinbaseAddress: string) => void): Promise; + isMining(callback?: (error: Error, mining: boolean) => void): Promise; + getHashrate(callback?: (error: Error, hashes: number) => void): Promise; + getGasPrice(callback?: (error: Error, gasPrice: string) => void): Promise; + getAccounts(callback?: (error: Error, accounts: string[]) => void): Promise; + getBlockNumber(callback?: (error: Error, blockNumber: number) => void): Promise; + getBalance(address: string): Promise; + getBalance(address: string, defaultBlock: string | number): Promise; + getBalance(address: string, callback?: (error: Error, balance: string) => void): Promise; + getBalance(address: string, defaultBlock: string | number, callback?: (error: Error, balance: string) => void): Promise; + getStorageAt(address: string, position: number): Promise; + getStorageAt(address: string, position: number, defaultBlock: number | string): Promise; + getStorageAt(address: string, position: number, callback?: (error: Error, storageAt: string) => void): Promise; + getStorageAt(address: string, position: number, defaultBlock: number | string, callback?: (error: Error, storageAt: string) => void): Promise; + getCode(address: string): Promise; + getCode(address: string, defaultBlock: string | number): Promise; + getCode(address: string, callback?: (error: Error, code: string) => void): Promise; + getCode(address: string, defaultBlock: string | number, callback?: (error: Error, code: string) => void): Promise; + getBlock(blockHashOrBlockNumber: string | number): Promise; + getBlock(blockHashOrBlockNumber: string | number, returnTransactionObjects: boolean): Promise; + getBlock(blockHashOrBlockNumber: string | number, callback?: (error: Error, block: Block) => void): Promise; + getBlock(blockHashOrBlockNumber: string | number, returnTransactionObjects: boolean, callback?: (error: Error, block: Block) => void): Promise; + getBlockTransactionCount(blockHashOrBlockNumber: string | number, callback?: (error: Error, numberOfTransactions: number) => void): Promise; + getUncle(blockHashOrBlockNumber: string | number, uncleIndex: number): Promise + getUncle(blockHashOrBlockNumber: string | number, uncleIndex: number, returnTransactionObjects: boolean): Promise + getUncle(blockHashOrBlockNumber: string | number, uncleIndex: number, callback?: (error: Error, uncle: {}) => void): Promise + getUncle(blockHashOrBlockNumber: string | number, uncleIndex: number, returnTransactionObjects: boolean, callback?: (error: Error, uncle: {}) => void): Promise + getTransaction(transactionHash: string, callback?: (error: Error, transaction: Transaction) => void): Promise; + getTransactionFromBlock(hashStringOrNumber: string | number, indexNumber: number, callback?: (error: Error, transaction: Transaction) => void): Promise; + getTransactionReceipt(hash: string, callback?: (error: Error, transactionReceipt: TransactionReceipt) => void): Promise; + getTransactionCount(address: string): Promise; + getTransactionCount(address: string, defaultBlock: number | string): Promise; + getTransactionCount(address: string, callback?: (error: Error, count: number) => void): Promise; + getTransactionCount(address: string, defaultBlock: number | string, callback?: (error: Error, count: number) => void): Promise; + sendTransaction(transaction: Transaction, callback?: (error: Error, hash: string) => void): PromiEvent; + sendSignedTransaction(signedTransactionData: string, callback?: (error: Error, gas: string) => void): PromiEvent + sign(dataToSign: string, address: string | number, callback?: (error: Error, signature: string) => void): Promise; + signTransaction(transaction: Transaction, callback?: (error: Error, signedTransaction: SignedTransaction) => void): Promise; + signTransaction(transaction: Transaction, address: string): Promise; + signTransaction(transaction: Transaction, address: string, callback: (error: Error, signedTransaction: SignedTransaction) => void): Promise; + call(transaction: Transaction): Promise; + call(transaction: Transaction, defaultBlock?: number | string): Promise; + call(transaction: Transaction, callback?: (error: Error, data: string) => void): Promise; + call(transaction: Transaction, defaultBlock: number | string, callback: (error: Error, data: string) => void): Promise; + estimateGas(transaction: Transaction, callback?: (error: Error, gas: number) => void): Promise; + getPastLogs(options: PastLogsOptions, callback?: (error: Error, logs: Log[]) => void): Promise; + getWork(callback?: (error: Error, result: string[]) => void): Promise; + submitWork(data: [string, string, string], callback?: (error: Error, result: boolean) => void): Promise; +} + +export interface Methods { + property?: string; + methods: Method[]; +} + +export interface Method { + name: string; + call: string; + params?: number; + inputFormatter?: Array<(() => void) | null>; + outputFormatter?: () => void; +} + +export interface Syncing { + startingBlock: number; + currentBlock: number; + highestBlock: number; + knownStates: number; + pulledStates: number; +} + +export interface BlockHeader { + number: number + hash: string + parentHash: string + nonce: string + sha3Uncles: string + logsBloom: string + transactionRoot: string + stateRoot: string + receiptRoot: string + miner: string + extraData: string + gasLimit: number + gasUsed: number + timestamp: number +} + +export interface Block extends BlockHeader { + transactions: Transaction[]; + size: number + difficulty: number + totalDifficulty: number + uncles: string[]; +} + +export interface PastLogsOptions { + fromBlock?: number | string; + toBlock?: number | string; + address: string | string[]; + topics?: Array; +} + +export interface Logs { + fromBlock?: number + address?: string + topics?: Array +} + +export interface Log { + address: string; + data: string; + topics: Array; + logIndex: number; + transactionIndex: number; + transactionHash: string; + blockHash: string; + blockNumber: number; +} + +export interface Subscribe { + subscription: { + id: string + subscribe(callback?: (error: Error, result: Subscribe) => void): Subscribe + unsubscribe(callback?: (error: Error, result: boolean) => void): void | boolean + options: {} + } + on(type: 'data', handler: (data: T) => void): void + on(type: 'changed', handler: (data: T) => void): void + on(type: 'error', handler: (data: Error) => void): void +} + +/** DELETE ONCE personal is complete */ + +export class Personal { + newAccount(password: string, callback?: (error: Error, result: boolean) => void): Promise + getAccounts(callback?: (error: Error, result: string[]) => void): Promise +} +/** END */ + +/** MOVE ALL BELOW TO WEB3-CORE ONCE TYPES COMPLETE FOR CLEAR UP !!! */ + +export interface PromiEvent extends Promise { + once(type: 'transactionHash', handler: (receipt: string) => void): PromiEvent + once(type: 'receipt', handler: (receipt: TransactionReceipt) => void): PromiEvent + once(type: 'confirmation', handler: (confNumber: number, receipt: TransactionReceipt) => void): PromiEvent + once(type: 'error', handler: (error: Error) => void): PromiEvent + once(type: 'error' | 'confirmation' | 'receipt' | 'transactionHash', handler: (error: Error | TransactionReceipt | string) => void): PromiEvent + on(type: 'transactionHash', handler: (receipt: string) => void): PromiEvent + on(type: 'receipt', handler: (receipt: TransactionReceipt) => void): PromiEvent + on(type: 'confirmation', handler: (confNumber: number, receipt: TransactionReceipt) => void): PromiEvent + on(type: 'error', handler: (error: Error) => void): PromiEvent + on(type: 'error' | 'confirmation' | 'receipt' | 'transactionHash', handler: (error: Error | TransactionReceipt | string) => void): PromiEvent +} + +export interface Transaction { + from?: string | number; + to?: string; + gasPrice?: string; + gas?: number | string; + value?: number | string; + chainId?: number; + data?: string; + nonce?: number; + v?: string; + r?: string; + s?: string; + hash?: string; +} + +export interface SignedTransaction { + messageHash?: string; + r: string; + s: string; + v: string; + rawTransaction?: string; +} + +export interface TransactionReceipt { + transactionHash: string + transactionIndex: number + blockHash: string + blockNumber: number + from: string + to: string + contractAddress: string + cumulativeGasUsed: number + gasUsed: number + logs?: Log[] + events?: { + [eventName: string]: EventLog + } +} + +export interface EventLog { + event: string + address: string + returnValues: object + logIndex: number + transactionIndex: number + transactionHash: string + blockHash: string + blockNumber: number + raw?: { data: string, topics: any[] } +} +/** END !!! */ diff --git a/packages/web3-eth/types/tests/eth.tests.ts b/packages/web3-eth/types/tests/eth.tests.ts new file mode 100644 index 00000000000..943f1c478d2 --- /dev/null +++ b/packages/web3-eth/types/tests/eth.tests.ts @@ -0,0 +1,397 @@ +/* + This file is part of web3.js. + web3.js is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + web3.js is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public License + along with web3.js. If not, see . +*/ +/** + * @file eth-tests.ts + * @author Josh Stevens + * @date 2018 + */ + +import {Eth, Log, Subscribe, BlockHeader, Transaction, Syncing, Block, TransactionReceipt, SignedTransaction} from 'web3-eth'; + +const eth = new Eth('http://localhost:8545'); + +// $ExpectType Contract +eth.Contract; + +// $ExpectType Iban +eth.Iban; + +// $ExpectType Personal +eth.personal; + +// $ExpectType Accounts +eth.accounts; + +// $ExpectType any +eth.ens; + +// $ExpectType AbiCoder +eth.abi; + +// $ExpectType Network +eth.net; + +// $ExpectType boolean +eth.clearSubscriptions; + +// $ExpectType Promise> +eth.subscribe('logs'); +// $ExpectType Promise> +eth.subscribe('logs'); +// $ExpectType Promise> +eth.subscribe('logs', (error: Error, result: Subscribe) => {}); +// $ExpectType Promise> +eth.subscribe('logs', {}); +// $ExpectType Promise> +eth.subscribe('logs', {}, (error: Error, result: Subscribe) => {}); + +// $ExpectType Promise> +eth.subscribe('syncing'); +// $ExpectType Promise> +eth.subscribe('syncing', (error: Error, result: Subscribe) => {}); + +// $ExpectType Promise> +eth.subscribe('newBlockHeaders'); +// $ExpectType Promise> +eth.subscribe('newBlockHeaders', (error: Error, result: Subscribe) => {}); + +// $ExpectType Promise> +eth.subscribe('pendingTransactions'); +// $ExpectType Promise> +eth.subscribe('pendingTransactions', (error: Error, result: Subscribe) => {}); + +// $ExpectType Providers +eth.providers; + +// $ExpectType provider | null +eth.givenProvider; + +// $ExpectType BatchRequest +eth.BatchRequest(); + +// $ExpectType string | null +eth.defaultAccount + +// $ExpectType string | number +eth.defaultBlock + +// $ExpectType Promise +eth.getProtocolVersion(); +// $ExpectType Promise +eth.getProtocolVersion((error: Error, protocolVersion: string) => {}); + +// $ExpectType Promise +eth.isSyncing(); +// $ExpectType Promise +eth.isSyncing((error: Error, syncing: Syncing) => {}); + +// $ExpectType Promise +eth.getCoinbase(); +// $ExpectType Promise +eth.getCoinbase((error: Error, coinbaseAddress: string) => {}); + +// $ExpectType Promise +eth.isMining(); +// $ExpectType Promise +eth.isMining((error: Error, mining: boolean) => {}); + +// $ExpectType Promise +eth.getHashrate(); +// $ExpectType Promise +eth.getHashrate((error: Error, hashes: number) => {}); + +// $ExpectType Promise +eth.getGasPrice(); +// $ExpectType Promise +eth.getGasPrice((error: Error, gasPrice: string) => {}); + +// $ExpectType Promise +eth.getAccounts(); +// $ExpectType Promise +eth.getAccounts((error: Error, accounts: string[]) => {}); + +// $ExpectType Promise +eth.getBlockNumber(); +// $ExpectType Promise +eth.getBlockNumber((error: Error, blockNumber: number) => {}); + +// $ExpectType Promise +eth.getBalance('0x407d73d8a49eeb85d32cf465507dd71d507100c1'); +// $ExpectType Promise +eth.getBalance('0x407d73d8a49eeb85d32cf465507dd71d507100c1', '1000'); +// $ExpectType Promise +eth.getBalance('0x407d73d8a49eeb85d32cf465507dd71d507100c1', '1000', (error: Error, balance: string) => {}); +// $ExpectType Promise +eth.getBalance('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 1000); +// $ExpectType Promise +eth.getBalance('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 1000, (error: Error, balance: string) => {}); + +// $ExpectType Promise +eth.getStorageAt('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 2); +// $ExpectType Promise +eth.getStorageAt('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 2, '1000'); +// $ExpectType Promise +eth.getStorageAt('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 2, '1000', (error: Error, balance: string) => {}); +// $ExpectType Promise +eth.getStorageAt('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 2, 1000); +// $ExpectType Promise +eth.getStorageAt('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 2, 1000, (error: Error, balance: string) => {}); + +// $ExpectType Promise +eth.getCode('0x407d73d8a49eeb85d32cf465507dd71d507100c1'); +// $ExpectType Promise +eth.getCode('0x407d73d8a49eeb85d32cf465507dd71d507100c1', '1000'); +// $ExpectType Promise +eth.getCode('0x407d73d8a49eeb85d32cf465507dd71d507100c1', '1000', (error: Error, balance: string) => {}); +// $ExpectType Promise +eth.getCode('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 1000); +// $ExpectType Promise +eth.getCode('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 1000, (error: Error, balance: string) => {}); + +// $ExpectType Promise +eth.getBlock('0x407d73d8a49eeb85d32cf465507dd71d507100c1'); +// $ExpectType Promise +eth.getBlock(345); +// $ExpectType Promise +eth.getBlock('0x407d73d8a49eeb85d32cf465507dd71d507100c1', true); +// $ExpectType Promise +eth.getBlock('0x407d73d8a49eeb85d32cf465507dd71d507100c1', false); +// $ExpectType Promise +eth.getBlock(345); +// $ExpectType Promise +eth.getBlock(345, true); +// $ExpectType Promise +eth.getBlock(345, false); +// $ExpectType Promise +eth.getBlock('0x407d73d8a49eeb85d32cf465507dd71d507100c1', (error: Error, block: Block) => {}); +// $ExpectType Promise +eth.getBlock(345, (error: Error, block: Block) => {}); +// $ExpectType Promise +eth.getBlock(345, true, (error: Error, block: Block) => {}); +// $ExpectType Promise +eth.getBlock(345, false, (error: Error, block: Block) => {}); +// $ExpectType Promise +eth.getBlock('0x407d73d8a49eeb85d32cf465507dd71d507100c1', true, (error: Error, block: Block) => {}); +// $ExpectType Promise +eth.getBlock('0x407d73d8a49eeb85d32cf465507dd71d507100c1', false, (error: Error, block: Block) => {}); + +// $ExpectType Promise +eth.getBlockTransactionCount('0x407d73d8a49eeb85d32cf465507dd71d507100c1', (error: Error, numberOfTransactions: number) => {}); +// $ExpectType Promise +eth.getBlockTransactionCount(345); +// $ExpectType Promise +eth.getBlockTransactionCount('0x407d73d8a49eeb85d32cf465507dd71d507100c1', (error: Error, numberOfTransactions: number) => {}); +// $ExpectType Promise +eth.getBlockTransactionCount(345); + +// $ExpectType Promise +eth.getUncle('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 4); +// $ExpectType Promise +eth.getUncle(345, 4); +// $ExpectType Promise +eth.getUncle('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 4, true); +// $ExpectType Promise +eth.getUncle('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 4, false); +// $ExpectType Promise +eth.getUncle('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 4, (error: Error, uncle: {}) => {}); +// $ExpectType Promise +eth.getUncle(345, 4, (error: Error, uncle: {}) => {}); +// $ExpectType Promise +eth.getUncle(345, 4, true); +// $ExpectType Promise +eth.getUncle(345, 4, false); +// $ExpectType Promise +eth.getUncle('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 4, true, (error: Error, uncle: {}) => {}); +// $ExpectType Promise +eth.getUncle('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 4, false, (error: Error, uncle: {}) => {}); +// $ExpectType Promise +eth.getUncle(345, 4, true, (error: Error, uncle: {}) => {}); +// $ExpectType Promise +eth.getUncle(345, 4, false, (error: Error, uncle: {}) => {}); + +// $ExpectType Promise +eth.getTransaction('0x407d73d8a49eeb85d32cf465507dd71d507100c1'); +// $ExpectType Promise +eth.getTransaction('0x407d73d8a49eeb85d32cf465507dd71d507100c1', (error: Error, transaction: Transaction) => {}); + +// $ExpectType Promise +eth.getTransactionFromBlock('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 2); +// $ExpectType Promise +eth.getTransactionFromBlock(345, 2); +// $ExpectType Promise +eth.getTransactionFromBlock('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 2, (error: Error, transaction: Transaction) => {}); +// $ExpectType Promise +eth.getTransactionFromBlock(345, 2, (error: Error, transaction: Transaction) => {}); + +// $ExpectType Promise +eth.getTransactionReceipt('0x407d73d8a49eeb85d32cf465507dd71d507100c1'); +// $ExpectType Promise +eth.getTransactionReceipt('0x407d73d8a49eeb85d32cf465507dd71d507100c1', (error: Error, transactionReceipt: TransactionReceipt) => {}); + +// $ExpectType Promise +eth.getTransactionCount('0x407d73d8a49eeb85d32cf465507dd71d507100c1'); +// $ExpectType Promise +eth.getTransactionCount('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 1000); +// $ExpectType Promise +eth.getTransactionCount('0x407d73d8a49eeb85d32cf465507dd71d507100c1', '1000'); +// $ExpectType Promise +eth.getTransactionCount('0x407d73d8a49eeb85d32cf465507dd71d507100c1', (error: Error, count: number) => {}); +// $ExpectType Promise +eth.getTransactionCount('0x407d73d8a49eeb85d32cf465507dd71d507100c1', (error: Error, count: number) => {}); +// $ExpectType Promise +eth.getTransactionCount('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 1000, (error: Error, count: number) => {}); +// $ExpectType Promise +eth.getTransactionCount('0x407d73d8a49eeb85d32cf465507dd71d507100c1', '1000', (error: Error, count: number) => {}); + +const code = '603d80600c6000396000f3007c0'; + +// $ExpectType PromiEvent +eth.sendTransaction({ + from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe', + data: 'code' +}); +// $ExpectType PromiEvent +eth.sendTransaction({ + from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe', + data: 'code' +}, (error: Error, hash: string) => {}); + +// $ExpectType PromiEvent +eth.sendSignedTransaction('0xf889808609184e72a0008227109'); +// $ExpectType PromiEvent +eth.sendSignedTransaction('0xf889808609184e72a0008227109', (error: Error, gas: string) => {}); + +// $ExpectType Promise +eth.sign('Hello world', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'); +// $ExpectType Promise +eth.sign('Hello world', 3); +// $ExpectType Promise +eth.sign('Hello world', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', (error: Error, signature: string) => {}); +// $ExpectType Promise +eth.sign('Hello world', 3, (error: Error, signature: string) => {}); + +// $ExpectType Promise +eth.signTransaction({ + from: '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0', + gasPrice: '20000000000', + gas: '21000', + to: '0x3535353535353535353535353535353535353535', + value: '1000000000000000000', + data: '' +}); +// $ExpectType Promise +eth.signTransaction({ + from: '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0', + gasPrice: '20000000000', + gas: '21000', + to: '0x3535353535353535353535353535353535353535', + value: '1000000000000000000', + data: '' +}, '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0'); +// $ExpectType Promise +eth.signTransaction({ + from: '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0', + gasPrice: '20000000000', + gas: '21000', + to: '0x3535353535353535353535353535353535353535', + value: '1000000000000000000', + data: '' +}, (error: Error, signedTransaction: SignedTransaction) => {}); +// $ExpectType Promise +eth.signTransaction({ + from: '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0', + gasPrice: '20000000000', + gas: '21000', + to: '0x3535353535353535353535353535353535353535', + value: '1000000000000000000', + data: '' +}, '0xEB014f8c8B418Db6b45774c326A0E64C78914dC0', (error: Error, signedTransaction: SignedTransaction) => {}); + +// $ExpectType Promise +eth.call({ + to: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", // contract address + data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003" +}); +// $ExpectType Promise +eth.call({ + to: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", // contract address + data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003" +}, 100); +// $ExpectType Promise +eth.call({ + to: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", // contract address + data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003" +}, '100'); +// $ExpectType Promise +eth.call({ + to: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", // contract address + data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003" +}, (error: Error, data: string) => {}); +// $ExpectType Promise +eth.call({ + to: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", // contract address + data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003" +}, '100', (error: Error, data: string) => {}); +// $ExpectType Promise +eth.call({ + to: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", // contract address + data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003" +}, 100, (error: Error, data: string) => {}); + +// $ExpectType Promise +eth.call({ + to: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", // contract address + data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003" +}, 100, (error: Error, data: string) => {}); + +// $ExpectType Promise +eth.estimateGas({ + to: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", + data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003" +}); +// $ExpectType Promise +eth.estimateGas({ + to: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", + data: "0xc6888fa10000000000000000000000000000000000000000000000000000000000000003" +}, (error: Error, gas: number) => {}); + +// $ExpectType Promise +eth.getPastLogs({ + address: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", + topics: ["0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234"] +}); +// $ExpectType Promise +eth.getPastLogs({ + address: "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", + topics: ["0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234"] +}, (error: Error, logs: Log[]) => {}); + +// $ExpectType Promise +eth.getWork(); +// $ExpectType Promise +eth.getWork((error: Error, result: string[]) => {}); + +// $ExpectType Promise +eth.submitWork([ + "0x0000000000000001", + "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", + "0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000" +]); + +// $ExpectType Promise +eth.submitWork([ + "0x0000000000000001", + "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", + "0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000" +], (error: Error, result: boolean) => {}); diff --git a/packages/web3-eth/types/tsconfig.json b/packages/web3-eth/types/tsconfig.json new file mode 100644 index 00000000000..82c7ac530ee --- /dev/null +++ b/packages/web3-eth/types/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "noEmit": true, + "allowSyntheticDefaultImports": true, + "baseUrl": ".", + "paths": { + "web3-eth": ["."] + } + } +} diff --git a/packages/web3-eth/types/tslint.json b/packages/web3-eth/types/tslint.json new file mode 100644 index 00000000000..871d605704b --- /dev/null +++ b/packages/web3-eth/types/tslint.json @@ -0,0 +1,11 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + "semicolon": false, + "no-import-default-of-export-equals": false, + "file-name-casing": [true, "kebab-case"], + "whitespace": false, + "no-unnecessary-class": false, + "unified-signatures": false + } +}