UNPKG

1.44 kBTypeScriptView Raw
1// Copyright 2017-2018 @polkadot/api-provider authors & contributors
2// This software may be modified and distributed under the terms
3// of the ISC license. See the LICENSE file for details.
4
5export type JsonRpcObject = {
6 id: number;
7 jsonrpc: '2.0';
8};
9
10export type JsonRpcRequest = JsonRpcObject & {
11 method: string;
12 params: Array<any>;
13};
14
15export type JsonRpcResponseBase$Error = {
16 code: number,
17 message: string
18};
19
20type JsonRpcResponse$Single = {
21 error?: JsonRpcResponseBase$Error;
22 result?: any;
23};
24
25type JsonRpcResponse$Subscription = {
26 method?: string;
27 params: {
28 error?: JsonRpcResponseBase$Error;
29 result: any;
30 subscription: number;
31 }
32};
33
34export type JsonRpcResponseBase = JsonRpcResponse$Single & JsonRpcResponse$Subscription;
35
36export type JsonRpcResponse = JsonRpcObject & JsonRpcResponseBase;
37
38export type ProviderInterface$Callback = (error: Error | null, result: any) => void;
39
40export type ProviderInterface$Emitted = 'connected' | 'disconnected';
41
42export type ProviderInterface$EmitCb = (value?: any) => any;
43
44export interface ProviderInterface {
45 isConnected (): boolean,
46 on (type: ProviderInterface$Emitted, sub: ProviderInterface$EmitCb): void,
47 send (method: string, params: Array<any>): Promise<any>,
48 subscribe (type: string, method: string, params: Array<any>, cb: ProviderInterface$Callback): Promise<number>,
49 unsubscribe (type: string, method: string, id: number): Promise<boolean>
50}