From 79ab9f37c9f502a055ac8695236831e457c0cdec Mon Sep 17 00:00:00 2001 From: odan Date: Thu, 2 Apr 2020 02:56:45 +0900 Subject: [PATCH 1/7] add AbstractProvider --- packages/web3-core/types/index.d.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/web3-core/types/index.d.ts b/packages/web3-core/types/index.d.ts index d682ea388bd..ef28a6ba04d 100644 --- a/packages/web3-core/types/index.d.ts +++ b/packages/web3-core/types/index.d.ts @@ -19,12 +19,15 @@ */ import * as net from 'net'; +import { EventEmitter } from "events" import { HttpProviderBase, HttpProviderOptions, IpcProviderBase, WebsocketProviderBase, - WebsocketProviderOptions + WebsocketProviderOptions, + JsonRpcPayload, + JsonRpcResponse } from 'web3-core-helpers'; import { Method } from 'web3-core-method'; import BN = require('bn.js'); @@ -410,9 +413,14 @@ export interface LogsOptions { export type BlockNumber = string | number | BN | BigNumber | 'latest' | 'pending' | 'earliest' | 'genesis'; +interface AbstractProvider extends EventEmitter { + send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void; + } + export type provider = | HttpProvider | IpcProvider | WebsocketProvider + | AbstractProvider | string | null; From 20491dff173b89924bcb08ad42a66db99b800bf8 Mon Sep 17 00:00:00 2001 From: odan Date: Thu, 2 Apr 2020 03:14:58 +0900 Subject: [PATCH 2/7] add test for AbstractProvider --- packages/web3-core/types/index.d.ts | 2 +- packages/web3/package.json | 1 + packages/web3/types/tests/web3-test.ts | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/web3-core/types/index.d.ts b/packages/web3-core/types/index.d.ts index ef28a6ba04d..fb3c29e84dd 100644 --- a/packages/web3-core/types/index.d.ts +++ b/packages/web3-core/types/index.d.ts @@ -413,7 +413,7 @@ export interface LogsOptions { export type BlockNumber = string | number | BN | BigNumber | 'latest' | 'pending' | 'earliest' | 'genesis'; -interface AbstractProvider extends EventEmitter { +export interface AbstractProvider extends EventEmitter { send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void; } diff --git a/packages/web3/package.json b/packages/web3/package.json index 21cd5ae5ab8..20f964e73ed 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -52,6 +52,7 @@ "@types/node": "^12.6.1", "web3-bzz": "1.2.6", "web3-core": "1.2.6", + "web3-core-helpers": "1.2.6", "web3-eth": "1.2.6", "web3-eth-personal": "1.2.6", "web3-net": "1.2.6", diff --git a/packages/web3/types/tests/web3-test.ts b/packages/web3/types/tests/web3-test.ts index 7aaeaafc6b0..7e9b3ec0f39 100644 --- a/packages/web3/types/tests/web3-test.ts +++ b/packages/web3/types/tests/web3-test.ts @@ -19,6 +19,9 @@ import Web3 from 'web3'; import * as net from 'net'; +import { AbstractProvider } from 'web3-core'; +import { JsonRpcPayload, JsonRpcResponse } from "web3-core-helpers" +import { EventEmitter } from 'events'; // $ExpectType Utils Web3.utils; @@ -85,3 +88,9 @@ web3 = new Web3('https://localhost:5000/', netSocket); // $ExpectType Web3 web3 = new Web3(); + +class CustomProvider extends EventEmitter implements AbstractProvider { + send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void) {} +} +// $ExpectType Web3 +web3 = new Web3(new CustomProvider()); From 8b6a490b0bb1b097704ecc05e8176cf7bbd902d3 Mon Sep 17 00:00:00 2001 From: John Williamson Date: Fri, 3 Apr 2020 14:21:47 +1000 Subject: [PATCH 3/7] added method return --- packages/web3-eth-contract/types/index.d.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/web3-eth-contract/types/index.d.ts b/packages/web3-eth-contract/types/index.d.ts index 336f15fc487..b922a7f13a9 100644 --- a/packages/web3-eth-contract/types/index.d.ts +++ b/packages/web3-eth-contract/types/index.d.ts @@ -46,7 +46,9 @@ export class Contract { deploy(options: DeployOptions): ContractSendMethod; - methods: any; + methods: { + [key: string]: ContractSendMethod; + }; once( event: string, @@ -89,6 +91,11 @@ export interface ContractSendMethod { callback?: (err: Error, transactionHash: string) => void ): PromiEvent; + call( + options?: CallOptions, + callback?: (err: Error, result: any) => void + ): Promise; + estimateGas( options: EstimateGasOptions, callback?: (err: Error, gas: number) => void @@ -108,6 +115,12 @@ export interface ContractSendMethod { encodeABI(): string; } +export interface CallOptions { + from?: string; + gasPrice?: string; + gas?: number; +} + export interface SendOptions { from: string; gasPrice?: string; From 27e06422c51b4ebb16e0a13c44bbf45118c781f9 Mon Sep 17 00:00:00 2001 From: viswanathkgp12 Date: Tue, 21 Apr 2020 00:40:59 +0530 Subject: [PATCH 4/7] updated types for web3 http provider #3335 --- packages/web3-providers-http/types/index.d.ts | 45 ++++++++++++++++++- .../types/tests/web3-provider-http-tests.ts | 4 +- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/packages/web3-providers-http/types/index.d.ts b/packages/web3-providers-http/types/index.d.ts index f006da28d61..75c221e5ebc 100644 --- a/packages/web3-providers-http/types/index.d.ts +++ b/packages/web3-providers-http/types/index.d.ts @@ -19,7 +19,48 @@ * @author Josh Stevens * @date 2018 */ +import * as http from "http"; +import * as https from "https"; -import { HttpProviderBase } from 'web3-core-helpers'; +import { HttpProviderBase, JsonRpcResponse } from "web3-core-helpers"; -export class HttpProvider extends HttpProviderBase {} +export interface HttpHeader { + name: string; + value: string; +} + +export interface HttpProviderAgent { + baseUrl?: string; + http?: http.Agent; + https?: https.Agent; +} + +export interface HttpProviderOptions { + withCredentials?: boolean; + timeout?: number; + headers?: HttpHeader[]; + agent?: HttpProviderAgent; + keepAlive?: boolean; +} + +export class HttpProvider extends HttpProviderBase { + host: string; + + withCredentials: boolean; + timeout: number; + headers?: HttpHeader[]; + agent?: HttpProviderAgent; + connected: boolean; + + constructor(host?: string, options?: HttpProviderOptions); + + send( + payload: object, + callback?: ( + error: Error | null, + result: JsonRpcResponse | undefined + ) => void + ): void; + disconnect(): boolean; + supportsSubscriptions(): boolean; +} diff --git a/packages/web3-providers-http/types/tests/web3-provider-http-tests.ts b/packages/web3-providers-http/types/tests/web3-provider-http-tests.ts index 798a84b7b62..961ec583297 100644 --- a/packages/web3-providers-http/types/tests/web3-provider-http-tests.ts +++ b/packages/web3-providers-http/types/tests/web3-provider-http-tests.ts @@ -42,10 +42,10 @@ const httpProvider = new HttpProvider('http://localhost:8545', { }); // $ExpectType void -httpProvider.send({} as any, (error: Error | null) => {}); +httpProvider.send({}, (error: Error | null) => {}); // $ExpectType void -httpProvider.send({} as any, (error: Error | null, result: JsonRpcResponse | undefined) => {}); +httpProvider.send({}, (error: Error | null, result: JsonRpcResponse | undefined) => {}); // $ExpectType boolean httpProvider.disconnect(); From 31550f789b913fd0d78483a7ae536b2595964ff8 Mon Sep 17 00:00:00 2001 From: viswanathkgp12 Date: Tue, 21 Apr 2020 01:02:22 +0530 Subject: [PATCH 5/7] changed to single quotes for consistency --- packages/web3-providers-http/types/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/web3-providers-http/types/index.d.ts b/packages/web3-providers-http/types/index.d.ts index 75c221e5ebc..2f68ab35d75 100644 --- a/packages/web3-providers-http/types/index.d.ts +++ b/packages/web3-providers-http/types/index.d.ts @@ -19,10 +19,10 @@ * @author Josh Stevens * @date 2018 */ -import * as http from "http"; -import * as https from "https"; +import * as http from 'http'; +import * as https from 'https'; -import { HttpProviderBase, JsonRpcResponse } from "web3-core-helpers"; +import { HttpProviderBase, JsonRpcResponse } from 'web3-core-helpers'; export interface HttpHeader { name: string; From d3ef78ebbab9244bd8854b507bddd44667ac28c3 Mon Sep 17 00:00:00 2001 From: odan Date: Mon, 4 May 2020 16:33:19 +0900 Subject: [PATCH 6/7] add interface of sendAsync --- packages/web3-core/types/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/web3-core/types/index.d.ts b/packages/web3-core/types/index.d.ts index 25049e5ff09..97ba5635eef 100644 --- a/packages/web3-core/types/index.d.ts +++ b/packages/web3-core/types/index.d.ts @@ -411,8 +411,9 @@ export interface LogsOptions { export type BlockNumber = string | number | BN | BigNumber | 'latest' | 'pending' | 'earliest' | 'genesis'; -export interface AbstractProvider extends EventEmitter { +export interface AbstractProvider { send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void; + sendAsync(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void; } export type provider = From 28dc7456068cb4b23cca74f61f9a897e38693ade Mon Sep 17 00:00:00 2001 From: odan Date: Tue, 5 May 2020 13:38:45 +0900 Subject: [PATCH 7/7] fix web3-test.ts --- packages/web3/types/tests/web3-test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/web3/types/tests/web3-test.ts b/packages/web3/types/tests/web3-test.ts index 7e9b3ec0f39..f17985861ce 100644 --- a/packages/web3/types/tests/web3-test.ts +++ b/packages/web3/types/tests/web3-test.ts @@ -89,8 +89,9 @@ web3 = new Web3('https://localhost:5000/', netSocket); // $ExpectType Web3 web3 = new Web3(); -class CustomProvider extends EventEmitter implements AbstractProvider { +class CustomProvider implements AbstractProvider { send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void) {} + sendAsync(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void) {} } // $ExpectType Web3 web3 = new Web3(new CustomProvider());