From 84a563d1bc58efdad81415b5741788fe0d4893f1 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Sat, 30 Mar 2019 11:55:54 +0000 Subject: [PATCH 1/8] feat: update ENS docs --- docs/web3-eth-ens.rst | 62 ++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/docs/web3-eth-ens.rst b/docs/web3-eth-ens.rst index 10572f0046e..17bd89b5370 100644 --- a/docs/web3-eth-ens.rst +++ b/docs/web3-eth-ens.rst @@ -54,9 +54,11 @@ Example web3.eth.ens.registry; > { ens: Ens, - contract: Contract, - owner: Function(name), - resolve: Function(name) + resolverContract: Contract | null, + setProvider(provider: provider, net?: net.Socket): boolean, + owner(name: string, callback?: (error: Error, address: string) => void): Promise, + resolver(name: string): Promise, + checkNetwork(): Promise, } ------------------------------------------------------------------------------ @@ -94,7 +96,7 @@ supportsInterface .. code-block:: javascript - web3.eth.ens.supportsInterface(ENSName, interfaceId); + web3.eth.ens.supportsInterface(ENSName, interfaceId, [callback]); Checks if the current resolver does support the desired interface. @@ -104,12 +106,13 @@ Parameters 1. ``ENSName`` - ``String``: The Ens name to resolve. 2. ``interfaceId`` - ``String``: A defined ENS interfaceId. +3. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. ------- Returns ------- -``Boolean`` - Returns true if the given interfaceId is supported by the resolver. +``Promise`` - Returns true if the given interfaceId is supported by the resolver. ------- Example @@ -129,7 +132,7 @@ getAddress .. code-block:: javascript - web3.eth.ens.getAddress(ENSName); + web3.eth.ens.getAddress(ENSName, [callback]); Resolves an Ens name to an Ethereum address. @@ -138,12 +141,13 @@ Parameters ---------- 1. ``ENSName`` - ``String``: The Ens name to resolve. +2. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. ------- Returns ------- -``String`` - The Ethereum address of the given name. +``Promise`` - The Ethereum address of the given name. ------- Example @@ -163,7 +167,7 @@ setAddress .. code-block:: javascript - web3.eth.ens.setAddress(ENSName, address, options); + web3.eth.ens.setAddress(ENSName, address, options, [callback]); Sets the address of an Ens name in his resolver. @@ -177,6 +181,7 @@ Parameters * ``from`` - ``String``: The address the transaction should be sent from. * ``gasPrice`` - ``String`` (optional): The gas price in wei to use for this transaction. * ``gas`` - ``Number`` (optional): The maximum gas provided for this transaction (gas limit). +4. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. Emits an ``AddrChanged`` event. @@ -242,7 +247,7 @@ getPubkey .. code-block:: javascript - web3.eth.ens.getPubkey(ENSName); + web3.eth.ens.getPubkey(ENSName, [callback]); Returns the X and Y coordinates of the curve point for the public key. @@ -251,6 +256,7 @@ Parameters ---------- 1. ``ENSName`` - ``String``: The Ens name. +2. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. ------- Returns @@ -281,7 +287,7 @@ setPubkey .. code-block:: javascript - web3.eth.ens.setPubkey(ENSName, x, y, options); + web3.eth.ens.setPubkey(ENSName, x, y, options, [callback]); Sets the SECP256k1 public key associated with an Ens node @@ -296,6 +302,7 @@ Parameters * ``from`` - ``String``: The address the transaction should be sent from. * ``gasPrice`` - ``String`` (optional): The gas price in wei to use for this transaction. * ``gas`` - ``Number`` (optional): The maximum gas provided for this transaction (gas limit). +5. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. Emits an ``PubkeyChanged`` event. @@ -364,7 +371,7 @@ getText .. code-block:: javascript - web3.eth.ens.getText(ENSName, key); + web3.eth.ens.getText(ENSName, key, [callback]); Returns the text by the given key. @@ -373,14 +380,14 @@ Parameters ---------- 1. ``ENSName`` - ``String``: The Ens name. -1. ``key`` - ``String``: The key of the array. +2. ``key`` - ``String``: The key of the array. +3. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. ------- Returns ------- -``String`` - The ENS name. -``String`` - The key. +``Promise`` ------- Example @@ -400,7 +407,7 @@ setText .. code-block:: javascript - web3.eth.ens.setText(ENSName, key, value, options); + web3.eth.ens.setText(ENSName, key, value, options, [callback]); Sets the content hash associated with an Ens node. @@ -415,6 +422,7 @@ Parameters * ``from`` - ``String``: The address the transaction should be sent from. * ``gasPrice`` - ``String`` (optional): The gas price in wei to use for this transaction. * ``gas`` - ``Number`` (optional): The maximum gas provided for this transaction (gas limit). +4. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. Emits an ``TextChanged`` event. @@ -483,7 +491,7 @@ getContent .. code-block:: javascript - web3.eth.ens.getContent(ENSName); + web3.eth.ens.getContent(ENSName, [callback]); Returns the content hash associated with an Ens node. @@ -492,12 +500,13 @@ Parameters ---------- 1. ``ENSName`` - ``String``: The Ens name. +2. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. ------- Returns ------- -``String`` - The content hash associated with an Ens node. +``Promise`` - The content hash associated with an Ens node. ------- Example @@ -517,7 +526,7 @@ setContent .. code-block:: javascript - web3.eth.ens.setContent(ENSName, hash, options); + web3.eth.ens.setContent(ENSName, hash, options, [callback]); Sets the content hash associated with an Ens node. @@ -531,6 +540,7 @@ Parameters * ``from`` - ``String``: The address the transaction should be sent from. * ``gasPrice`` - ``String`` (optional): The gas price in wei to use for this transaction. * ``gas`` - ``Number`` (optional): The maximum gas provided for this transaction (gas limit). +4. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. Emits an ``ContentChanged`` event. @@ -597,7 +607,7 @@ getMultihash .. code-block:: javascript - web3.eth.ens.getMultihash(ENSName); + web3.eth.ens.getMultihash(ENSName, [callback]); Returns the multihash associated with an Ens node. @@ -606,12 +616,13 @@ Parameters ---------- 1. ``ENSName`` - ``String``: The Ens name. +2. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. ------- Returns ------- -``String`` - The associated multihash. +``Promise`` - The associated multihash. ------- Example @@ -631,7 +642,7 @@ setMultihash .. code-block:: javascript - web3.eth.ens.setMultihash(ENSName, hash, options); + web3.eth.ens.setMultihash(ENSName, hash, options, [callback]); Sets the multihash associated with an Ens node. @@ -645,6 +656,7 @@ Parameters * ``from`` - ``String``: The address the transaction should be sent from. * ``gasPrice`` - ``String`` (optional): The gas price in wei to use for this transaction. * ``gas`` - ``Number`` (optional): The maximum gas provided for this transaction (gas limit). +4. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. Emits an ``MultihashChanged``event. @@ -696,7 +708,7 @@ getContenthash .. code-block:: javascript - web3.eth.ens.getContenthash(ENSName); + web3.eth.ens.getContenthash(ENSName, [callback]); Returns the contenthash associated with an Ens node. @@ -705,12 +717,13 @@ Parameters ---------- 1. ``ENSName`` - ``String``: The Ens name. +2. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. ------- Returns ------- -``String`` - The associated contenthash. +``Promise`` - The associated contenthash. ------- Example @@ -730,7 +743,7 @@ setContenthash .. code-block:: javascript - web3.eth.ens.setContenthash(ENSName, hash, options); + web3.eth.ens.setContenthash(ENSName, hash, options, [callback]); Sets the contenthash associated with an Ens node. @@ -744,6 +757,7 @@ Parameters * ``from`` - ``String``: The address the transaction should be sent from. * ``gasPrice`` - ``String`` (optional): The gas price in wei to use for this transaction. * ``gas`` - ``Number`` (optional): The maximum gas provided for this transaction (gas limit). +4. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second. Emits an ``ContenthashChanged``event. From 8134640ff72a6fea44bfcf3110e40cacb998372a Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Sat, 30 Mar 2019 11:56:15 +0000 Subject: [PATCH 2/8] feat: `web.eth.ens` export typings --- packages/web3-eth/types/index.d.ts | 198 ++++++++++++++++++++--------- 1 file changed, 138 insertions(+), 60 deletions(-) diff --git a/packages/web3-eth/types/index.d.ts b/packages/web3-eth/types/index.d.ts index 1e57d289922..8448d0a1b8c 100644 --- a/packages/web3-eth/types/index.d.ts +++ b/packages/web3-eth/types/index.d.ts @@ -34,18 +34,16 @@ import {AbiCoder} from 'web3-eth-abi'; import {Network} from 'web3-net'; import {Personal} from 'web3-eth-personal'; import {AbiItem} from 'web3-utils'; +import {Ens} from 'web3-eth-ens'; export class Eth extends AbstractWeb3Module { - constructor( - provider: provider, - options?: Web3ModuleOptions - ); + constructor(provider: provider, options?: Web3ModuleOptions); Contract: new (jsonInterface: AbiItem[] | AbiItem, address?: string, options?: ContractOptions) => Contract; - Iban: new(iban: string) => Iban; + Iban: new (iban: string) => Iban; personal: Personal; accounts: Accounts; - ens: any; // change once ens types as written + ens: Ens; abi: AbiCoder; net: Network; @@ -53,8 +51,16 @@ export class Eth extends AbstractWeb3Module { subscribe(type: 'logs', options?: Logs, callback?: (error: Error, log: Log) => void): Subscription; subscribe(type: 'syncing', options?: null, callback?: (error: Error, result: any) => void): Subscription; - subscribe(type: 'newBlockHeaders', options?: null, callback?: (error: Error, blockHeader: BlockHeader) => void): Subscription; - subscribe(type: 'pendingTransactions', options?: null, callback?: (error: Error, transactionHash: string) => void): Subscription; + subscribe( + type: 'newBlockHeaders', + options?: null, + callback?: (error: Error, blockHeader: BlockHeader) => void + ): Subscription; + subscribe( + type: 'pendingTransactions', + options?: null, + callback?: (error: Error, transactionHash: string) => void + ): Subscription; getProtocolVersion(callback?: (error: Error, protocolVersion: string) => void): Promise; @@ -75,55 +81,127 @@ export class Eth extends AbstractWeb3Module { 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; + 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; + 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; + 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; + 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: RLPEncodedTransaction) => 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: RLPEncodedTransaction) => void + ): Promise; signTransaction(transaction: Transaction, address: string): Promise; - signTransaction(transaction: Transaction, address: string, callback: (error: Error, signedTransaction: RLPEncodedTransaction) => void): Promise; + signTransaction( + transaction: Transaction, + address: string, + callback: (error: Error, signedTransaction: RLPEncodedTransaction) => 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; + call( + transaction: Transaction, + defaultBlock: number | string, + callback: (error: Error, data: string) => void + ): Promise; estimateGas(transaction: Transaction, callback?: (error: Error, gas: number) => void): Promise; @@ -156,27 +234,27 @@ export interface Syncing { } 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 + 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 + size: number; + difficulty: number; + totalDifficulty: number; uncles: string[]; } @@ -188,9 +266,9 @@ export interface PastLogsOptions { } export interface Logs { - fromBlock?: number - address?: string - topics?: Array + fromBlock?: number; + address?: string; + topics?: Array; } export interface Subscription { @@ -201,9 +279,9 @@ export interface Subscription { unsubscribe(callback?: (error: Error, result: boolean) => void): Promise; - on(type: 'data', handler: (data: T) => void): void + on(type: 'data', handler: (data: T) => void): void; - on(type: 'changed', handler: (data: T) => void): void + on(type: 'changed', handler: (data: T) => void): void; - on(type: 'error', handler: (data: Error) => void): void + on(type: 'error', handler: (data: Error) => void): void; } From f45d4682f661d61b558e44f59bc8f7de4d61208a Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Sat, 30 Mar 2019 11:56:28 +0000 Subject: [PATCH 3/8] feat: write better typings for ens --- packages/web3-eth-ens/types/index.d.ts | 119 ++++++++++++++++--------- 1 file changed, 75 insertions(+), 44 deletions(-) diff --git a/packages/web3-eth-ens/types/index.d.ts b/packages/web3-eth-ens/types/index.d.ts index fcda25ca7f3..2b108d81181 100644 --- a/packages/web3-eth-ens/types/index.d.ts +++ b/packages/web3-eth-ens/types/index.d.ts @@ -13,7 +13,7 @@ */ /** * @file index.d.ts - * @author Samuel Furter + * @author Samuel Furter , Josh Stevens * @date 2018 */ @@ -22,47 +22,83 @@ import {Accounts} from 'web3-eth-accounts'; import {AbiCoder} from 'web3-eth-abi'; import {Contract, ContractModuleFactory} from 'web3-eth-contract'; import {ProvidersModuleFactory, provider} from 'web3-providers'; -import {AbstractWeb3Module, PromiEvent} from 'web3-core'; +import {AbstractWeb3Module, PromiEvent, TransactionConfig} from 'web3-core'; import {formatters} from 'web3-core-helpers'; import {Network} from 'web3-net'; import {Utils} from 'web3-utils'; +import * as net from 'net'; export class Ens extends AbstractWeb3Module { - constructor( - provider: provider, - accounts: Accounts, - ensModuleOptions: object - ); + constructor(provider: provider, accounts: Accounts, ensModuleOptions: object); registry: Registry; resolver(name: string): Promise; - supportsInterface(name: string, interfaceId: string, callback?: () => {}): Promise; - - getAddress(name: string, callback?: () => {}): Promise; - - setAddress(name: string, address: string, sendOptions: TxObject, callback?: () => {}): PromiEvent; - - getPubkey(name: string, callback?: () => {}): Promise; - - setPubkey(name: string, x: string, y: string, sendOptions: TxObject, callback?: () => {}): PromiEvent; - - setText(name: string, key: string, value: string, sendOptions: TxObject, callback?: () => {}): PromiEvent; - - getText(name: string, key: string, callback?: () => {}): Promise; - - getContent(name: string, callback?: () => {}): Promise; - - setContent(name: string, hash: string, sendOptions: TxObject, callback?: () => {}): PromiEvent; - - getMultihash(name: string, callback?: () => {}): Promise; - - setMultihash(name: string, hash: string, sendOptions: TxObject, callback?: () => {}): PromiEvent; - - getContenthash(name: string, callback?: () => {}): Promise; - - setContenthash(name: string, hash: string, sendOptions: TxObject, callback?: () => {}): PromiEvent; + supportsInterface( + name: string, + interfaceId: string, + callback?: (error: Error, supportsInterface: boolean) => void + ): Promise; + + getAddress(name: string, callback?: (error: Error, address: string) => void): Promise; + + setAddress( + name: string, + address: string, + sendOptions: TransactionConfig, + callback?: (error: Error, result: any) => void + ): PromiEvent; + + getPubkey( + name: string, + callback?: (error: Error, result: {[x: string]: string}) => void + ): Promise<{[x: string]: string}>; + + setPubkey( + name: string, + x: string, + y: string, + sendOptions: TransactionConfig, + callback?: (error: Error, result: any) => void + ): PromiEvent; + + getText(name: string, key: string, callback?: (error: Error, ensName: string) => void): Promise; + + setText( + name: string, + key: string, + value: string, + sendOptions: TransactionConfig, + callback?: (error: Error, result: any) => void + ): PromiEvent; + + getContent(name: string, callback?: (error: Error, contentHash: string) => void): Promise; + + setContent( + name: string, + hash: string, + sendOptions: TransactionConfig, + callback?: (error: Error, result: any) => void + ): PromiEvent; + + getMultihash(name: string, callback?: (error: Error, multihash: string) => void): Promise; + + setMultihash( + name: string, + hash: string, + sendOptions: TransactionConfig, + callback?: (error: Error, result: any) => void + ): PromiEvent; + + getContenthash(name: string, callback?: (error: Error, contenthash: string) => void): Promise; + + setContenthash( + name: string, + hash: string, + sendOptions: TransactionConfig, + callback?: (error: Error, result: any) => void + ): PromiEvent; } export class Registry { @@ -79,20 +115,15 @@ export class Registry { net: Network ); - owner(name: string, callback?: () => {}): Promise; + ens: Ens; + + resolverContract: Contract | null; + + setProvider(provider: provider, net?: net.Socket): boolean; + + owner(name: string, callback?: (error: Error, address: string) => void): Promise; resolver(name: string): Promise; checkNetwork(): Promise; } - -export interface TxObject { - from?: string | number; - to?: string; - gasPrice?: string; - gas?: number | string; - value?: number | string; - chainId?: number; - data?: string; - nonce?: number; -} From 07efa39be66cde136f296e1fac2b59414cd59ef8 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Sat, 30 Mar 2019 11:56:38 +0000 Subject: [PATCH 4/8] test: write tests for new typings --- packages/web3-eth-ens/types/tests/ens-test.ts | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/web3-eth-ens/types/tests/ens-test.ts b/packages/web3-eth-ens/types/tests/ens-test.ts index 94a7a589a6c..ab654eecf55 100644 --- a/packages/web3-eth-ens/types/tests/ens-test.ts +++ b/packages/web3-eth-ens/types/tests/ens-test.ts @@ -30,39 +30,65 @@ ens.resolver('name'); // $ExpectType Promise ens.supportsInterface('name', 'interfaceId'); +// $ExpectType Promise +ens.supportsInterface('name', 'interfaceId', (error: Error, supportsInterface: boolean) => {}); // $ExpectType Promise ens.getAddress('name'); +// $ExpectType Promise +ens.getAddress('name', (error: Error, address: string) => {}); // $ExpectType PromiEvent ens.setAddress('name', 'address', {}); +// $ExpectType PromiEvent +ens.setAddress('name', 'address', {}, (error: Error, result: any) => {}); -// $ExpectType Promise +// $ExpectType Promise<{ [x: string]: string; }> ens.getPubkey('name'); +// $ExpectType Promise<{ [x: string]: string; }> +ens.getPubkey('name', (error: Error, result: {[x: string]: string}) => {}); // $ExpectType PromiEvent ens.setPubkey('name', 'x', 'y', {}); +// $ExpectType PromiEvent +ens.setPubkey('name', 'x', 'y', (error: Error, result: any) => {}); // $ExpectType Promise ens.getText('name', 'key'); +// $ExpectType Promise +ens.getText('name', 'key', (error: Error, ensName: string) => {}); // $ExpectType PromiEvent ens.setText('name', 'key', 'value', {}); +// $ExpectType PromiEvent +ens.setText('name', 'key', 'value', (error: Error, result: any) => {}); // $ExpectType Promise ens.getContent('name'); +// $ExpectType Promise +ens.getContent('name', (error: Error, contentHash: string) => {}); // $ExpectType PromiEvent ens.setContent('name', 'hash', {}); +// $ExpectType PromiEvent +ens.setContent('name', 'hash', {}, (error: Error, result: any) => {}); // $ExpectType Promise ens.getMultihash('name'); +// $ExpectType Promise +ens.getMultihash('name', (error: Error, multihash: string) => {}); // $ExpectType PromiEvent ens.setMultihash('name', 'hash', {}); +// $ExpectType PromiEvent +ens.setMultihash('name', 'hash', {}, (error: Error, result: any) => {}); // $ExpectType Promise ens.getContenthash('name'); +// $ExpectType Promise +ens.getContenthash('name', (error: Error, contenthash: string) => {}); // $ExpectType PromiEvent ens.setContenthash('name', 'hash', {}); +// $ExpectType PromiEvent +ens.setContenthash('name', 'hash', {}, (error: Error, result: any) => {}); From e3f967a638cb637d70c8cf9abd9d5ec1830711b9 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Sat, 30 Mar 2019 12:02:02 +0000 Subject: [PATCH 5/8] fix merge conflicts --- packages/web3-eth/types/index.d.ts | 195 +++++++++-------------------- 1 file changed, 59 insertions(+), 136 deletions(-) diff --git a/packages/web3-eth/types/index.d.ts b/packages/web3-eth/types/index.d.ts index 8448d0a1b8c..13d6e021cb9 100644 --- a/packages/web3-eth/types/index.d.ts +++ b/packages/web3-eth/types/index.d.ts @@ -37,10 +37,13 @@ import {AbiItem} from 'web3-utils'; import {Ens} from 'web3-eth-ens'; export class Eth extends AbstractWeb3Module { - constructor(provider: provider, options?: Web3ModuleOptions); + constructor( + provider: provider, + options?: Web3ModuleOptions + ); Contract: new (jsonInterface: AbiItem[] | AbiItem, address?: string, options?: ContractOptions) => Contract; - Iban: new (iban: string) => Iban; + Iban: new(iban: string) => Iban; personal: Personal; accounts: Accounts; ens: Ens; @@ -51,16 +54,8 @@ export class Eth extends AbstractWeb3Module { subscribe(type: 'logs', options?: Logs, callback?: (error: Error, log: Log) => void): Subscription; subscribe(type: 'syncing', options?: null, callback?: (error: Error, result: any) => void): Subscription; - subscribe( - type: 'newBlockHeaders', - options?: null, - callback?: (error: Error, blockHeader: BlockHeader) => void - ): Subscription; - subscribe( - type: 'pendingTransactions', - options?: null, - callback?: (error: Error, transactionHash: string) => void - ): Subscription; + subscribe(type: 'newBlockHeaders', options?: null, callback?: (error: Error, blockHeader: BlockHeader) => void): Subscription; + subscribe(type: 'pendingTransactions', options?: null, callback?: (error: Error, transactionHash: string) => void): Subscription; getProtocolVersion(callback?: (error: Error, protocolVersion: string) => void): Promise; @@ -81,127 +76,55 @@ export class Eth extends AbstractWeb3Module { 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; + 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; + 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; + 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; + 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: RLPEncodedTransaction) => 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: RLPEncodedTransaction) => void): Promise; signTransaction(transaction: Transaction, address: string): Promise; - signTransaction( - transaction: Transaction, - address: string, - callback: (error: Error, signedTransaction: RLPEncodedTransaction) => void - ): Promise; + signTransaction(transaction: Transaction, address: string, callback: (error: Error, signedTransaction: RLPEncodedTransaction) => 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; + call(transaction: Transaction, defaultBlock: number | string, callback: (error: Error, data: string) => void): Promise; estimateGas(transaction: Transaction, callback?: (error: Error, gas: number) => void): Promise; @@ -234,27 +157,27 @@ export interface Syncing { } 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; + 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; + size: number + difficulty: number + totalDifficulty: number uncles: string[]; } @@ -266,9 +189,9 @@ export interface PastLogsOptions { } export interface Logs { - fromBlock?: number; - address?: string; - topics?: Array; + fromBlock?: number + address?: string + topics?: Array } export interface Subscription { @@ -279,9 +202,9 @@ export interface Subscription { unsubscribe(callback?: (error: Error, result: boolean) => void): Promise; - on(type: 'data', handler: (data: T) => void): void; + on(type: 'data', handler: (data: T) => void): void - on(type: 'changed', handler: (data: T) => void): void; + on(type: 'changed', handler: (data: T) => void): void - on(type: 'error', handler: (data: Error) => void): void; + on(type: 'error', handler: (data: Error) => void): void } From 1c7a0f28e44e6a2d9f377686815684f442c5b3c8 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Sat, 30 Mar 2019 12:10:52 +0000 Subject: [PATCH 6/8] test: resolve eth tests with ens --- packages/web3-eth/types/tests/eth.tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-eth/types/tests/eth.tests.ts b/packages/web3-eth/types/tests/eth.tests.ts index 5141bcb2e67..7e88f6d161b 100644 --- a/packages/web3-eth/types/tests/eth.tests.ts +++ b/packages/web3-eth/types/tests/eth.tests.ts @@ -34,7 +34,7 @@ eth.personal; // $ExpectType Accounts eth.accounts; -// $ExpectType any +// $ExpectType Ens eth.ens; // $ExpectType AbiCoder From 73a3000a24a5812afcf99e7d2a9fda4166c1b8cd Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Sat, 30 Mar 2019 12:13:43 +0000 Subject: [PATCH 7/8] fix ens tests --- packages/web3-eth-ens/types/tests/ens-test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web3-eth-ens/types/tests/ens-test.ts b/packages/web3-eth-ens/types/tests/ens-test.ts index ad723af8497..1e7c6e78978 100644 --- a/packages/web3-eth-ens/types/tests/ens-test.ts +++ b/packages/web3-eth-ens/types/tests/ens-test.ts @@ -51,7 +51,7 @@ ens.getPubkey('name', (error: Error, result: {[x: string]: string}) => {}); // $ExpectType PromiEvent ens.setPubkey('name', 'x', 'y', {}); // $ExpectType PromiEvent -ens.setPubkey('name', 'x', 'y', (error: Error, result: any) => {}); +ens.setPubkey('name', 'x', 'y', {}, (error: Error, result: any) => {}); // $ExpectType Promise ens.getText('name', 'key'); @@ -61,7 +61,7 @@ ens.getText('name', 'key', (error: Error, ensName: string) => {}); // $ExpectType PromiEvent ens.setText('name', 'key', 'value', {}); // $ExpectType PromiEvent -ens.setText('name', 'key', 'value', (error: Error, result: any) => {}); +ens.setText('name', 'key', 'value', {}, (error: Error, result: any) => {}); // $ExpectType Promise ens.getContent('name'); From 259aa47f100cd238abc36b2b5c8599380bfe7fa4 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Sat, 30 Mar 2019 12:15:16 +0000 Subject: [PATCH 8/8] docs: add contribution name --- packages/web3-eth-ens/types/tests/ens-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-eth-ens/types/tests/ens-test.ts b/packages/web3-eth-ens/types/tests/ens-test.ts index 1e7c6e78978..4444a1c609c 100644 --- a/packages/web3-eth-ens/types/tests/ens-test.ts +++ b/packages/web3-eth-ens/types/tests/ens-test.ts @@ -13,7 +13,7 @@ */ /** * @file ens-test.ts - * @author Samuel Furter + * @author Samuel Furter , Josh Stevens * @date 2018 */