ethers.js/lib.commonjs/providers/provider-socket.d.ts

113 lines
3.7 KiB
TypeScript
Raw Permalink Normal View History

2023-03-03 18:25:07 -07:00
/**
* Generic long-lived socket provider.
*
* Sub-classing notes
* - a sub-class MUST call the `_start()` method once connected
* - a sub-class MUST override the `_write(string)` method
* - a sub-class MUST call `_processMessage(string)` for each message
*
2023-08-15 00:58:04 -04:00
* @_subsection: api/providers/abstract-provider:Socket Providers [about-socketProvider]
2023-03-03 18:25:07 -07:00
*/
import { JsonRpcApiProvider } from "./provider-jsonrpc.js";
import type { Subscriber, Subscription } from "./abstract-provider.js";
import type { EventFilter } from "./provider.js";
2023-11-27 06:11:49 -05:00
import type { JsonRpcApiProviderOptions, JsonRpcError, JsonRpcPayload, JsonRpcResult } from "./provider-jsonrpc.js";
2023-03-03 18:25:07 -07:00
import type { Networkish } from "./network.js";
2023-06-01 17:52:58 -04:00
/**
* A **SocketSubscriber** uses a socket transport to handle events and
* should use [[_emit]] to manage the events.
*/
2023-03-03 18:25:07 -07:00
export declare class SocketSubscriber implements Subscriber {
#private;
2023-06-01 17:52:58 -04:00
/**
* The filter.
*/
2023-03-03 18:25:07 -07:00
get filter(): Array<any>;
2023-06-01 17:52:58 -04:00
/**
* Creates a new **SocketSubscriber** attached to %%provider%% listening
* to %%filter%%.
*/
2023-03-03 18:25:07 -07:00
constructor(provider: SocketProvider, filter: Array<any>);
start(): void;
stop(): void;
pause(dropWhilePaused?: boolean): void;
resume(): void;
2023-06-01 17:52:58 -04:00
/**
* @_ignore:
*/
2023-03-03 18:25:07 -07:00
_handleMessage(message: any): void;
2023-06-01 17:52:58 -04:00
/**
* Sub-classes **must** override this to emit the events on the
* provider.
*/
2023-03-03 18:25:07 -07:00
_emit(provider: SocketProvider, message: any): Promise<void>;
}
2023-06-01 17:52:58 -04:00
/**
* A **SocketBlockSubscriber** listens for ``newHeads`` events and emits
* ``"block"`` events.
*/
2023-03-03 18:25:07 -07:00
export declare class SocketBlockSubscriber extends SocketSubscriber {
2023-06-01 17:52:58 -04:00
/**
* @_ignore:
*/
2023-03-03 18:25:07 -07:00
constructor(provider: SocketProvider);
_emit(provider: SocketProvider, message: any): Promise<void>;
}
2023-06-01 17:52:58 -04:00
/**
* A **SocketPendingSubscriber** listens for pending transacitons and emits
* ``"pending"`` events.
*/
2023-03-03 18:25:07 -07:00
export declare class SocketPendingSubscriber extends SocketSubscriber {
2023-06-01 17:52:58 -04:00
/**
* @_ignore:
*/
2023-03-03 18:25:07 -07:00
constructor(provider: SocketProvider);
_emit(provider: SocketProvider, message: any): Promise<void>;
}
2023-06-01 17:52:58 -04:00
/**
* A **SocketEventSubscriber** listens for event logs.
*/
2023-03-03 18:25:07 -07:00
export declare class SocketEventSubscriber extends SocketSubscriber {
#private;
2023-06-01 17:52:58 -04:00
/**
* The filter.
*/
2023-03-03 18:25:07 -07:00
get logFilter(): EventFilter;
2023-06-01 17:52:58 -04:00
/**
* @_ignore:
*/
2023-03-03 18:25:07 -07:00
constructor(provider: SocketProvider, filter: EventFilter);
_emit(provider: SocketProvider, message: any): Promise<void>;
}
/**
2023-06-01 17:52:58 -04:00
* A **SocketProvider** is backed by a long-lived connection over a
* socket, which can subscribe and receive real-time messages over
* its communication channel.
2023-03-03 18:25:07 -07:00
*/
export declare class SocketProvider extends JsonRpcApiProvider {
#private;
2023-06-01 17:52:58 -04:00
/**
* Creates a new **SocketProvider** connected to %%network%%.
*
* If unspecified, the network will be discovered.
*/
2023-11-27 06:11:49 -05:00
constructor(network?: Networkish, _options?: JsonRpcApiProviderOptions);
2023-03-03 18:25:07 -07:00
_getSubscriber(sub: Subscription): Subscriber;
2023-06-01 17:52:58 -04:00
/**
* Register a new subscriber. This is used internalled by Subscribers
* and generally is unecessary unless extending capabilities.
*/
2023-03-03 18:25:07 -07:00
_register(filterId: number | string, subscriber: SocketSubscriber): void;
_send(payload: JsonRpcPayload | Array<JsonRpcPayload>): Promise<Array<JsonRpcResult | JsonRpcError>>;
2023-06-01 17:52:58 -04:00
/**
* Sub-classes **must** call this with messages received over their
* transport to be processed and dispatched.
*/
2023-03-03 18:25:07 -07:00
_processMessage(message: string): Promise<void>;
2023-06-01 17:52:58 -04:00
/**
* Sub-classes **must** override this to send %%message%% over their
* transport.
*/
2023-03-03 18:25:07 -07:00
_write(message: string): Promise<void>;
}
//# sourceMappingURL=provider-socket.d.ts.map