Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Fix 3380: Add AbstractProvider #3451

Merged
merged 7 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/web3-core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -408,9 +411,15 @@ export interface LogsOptions {

export type BlockNumber = string | number | BN | BigNumber | 'latest' | 'pending' | 'earliest' | 'genesis';

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 =
| HttpProvider
| IpcProvider
| WebsocketProvider
| AbstractProvider
| string
| null;
10 changes: 10 additions & 0 deletions packages/web3/types/tests/web3-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,3 +88,10 @@ web3 = new Web3('https://localhost:5000/', netSocket);

// $ExpectType Web3
web3 = new Web3();

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());