forked from ethereumjs/eth-query
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
63 lines (53 loc) · 1.47 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
declare module '@metamask/eth-query' {
// What it says on the tin. We omit `null`, as that value is used for a
// successful response to indicate a lack of an error.
type EverythingButNull =
| string
| number
| boolean
// eslint-disable-next-line @typescript-eslint/ban-types
| object
| symbol
| undefined;
type Json =
| null
| boolean
| number
| string
| Json[]
| { [prop: string]: Json };
type JsonRpcParams = Json[] | Record<string, Json>;
type ProviderSendAsyncResponse<Result> = {
error?: { message: string };
result?: Result;
};
type ProviderSendAsyncCallback<Result> = (
error: unknown,
response: ProviderSendAsyncResponse<Result>,
) => void;
type Provider = {
sendAsync<Params extends JsonRpcParams, Result>(
payload: SendAsyncPayload<Params>,
callback: ProviderSendAsyncCallback<Result>,
): void;
};
type SendAsyncPayload<Params extends JsonRpcParams> = {
id: number;
jsonrpc: '2.0';
method: string;
params: Params;
};
type SendAsyncCallback<Result> = (
...args:
| [error: EverythingButNull, result: undefined]
| [error: null, result: Result]
) => void;
export default class EthQuery {
constructor(provider: Provider);
sendAsync<Params extends JsonRpcParams, Result>(
opts: Partial<SendAsyncPayload<Params>>,
callback: SendAsyncCallback<Result>,
): void;
[method: string]: (...args: any[]) => void;
}
}