1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | import { FetchRequest } from "../utils/index.js";
|
13 | import { AbstractProvider } from "./abstract-provider.js";
|
14 | import { AbstractSigner } from "./abstract-signer.js";
|
15 | import { Network } from "./network.js";
|
16 | import type { TypedDataDomain, TypedDataField } from "../hash/index.js";
|
17 | import type { TransactionLike } from "../transaction/index.js";
|
18 | import type { PerformActionRequest, Subscriber, Subscription } from "./abstract-provider.js";
|
19 | import type { Networkish } from "./network.js";
|
20 | import type { Provider, TransactionRequest, TransactionResponse } from "./provider.js";
|
21 | import type { Signer } from "./signer.js";
|
22 |
|
23 |
|
24 |
|
25 | export type JsonRpcPayload = {
|
26 | |
27 |
|
28 |
|
29 | id: number;
|
30 | |
31 |
|
32 |
|
33 | method: string;
|
34 | |
35 |
|
36 |
|
37 | params: Array<any> | Record<string, any>;
|
38 | |
39 |
|
40 |
|
41 | jsonrpc: "2.0";
|
42 | };
|
43 |
|
44 |
|
45 |
|
46 | export type JsonRpcResult = {
|
47 | |
48 |
|
49 |
|
50 | id: number;
|
51 | |
52 |
|
53 |
|
54 | result: any;
|
55 | };
|
56 |
|
57 |
|
58 |
|
59 | export type JsonRpcError = {
|
60 | |
61 |
|
62 |
|
63 | id: number;
|
64 | |
65 |
|
66 |
|
67 | error: {
|
68 | code: number;
|
69 | message?: string;
|
70 | data?: any;
|
71 | };
|
72 | };
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | export type DebugEventJsonRpcApiProvider = {
|
78 | action: "sendRpcPayload";
|
79 | payload: JsonRpcPayload | Array<JsonRpcPayload>;
|
80 | } | {
|
81 | action: "receiveRpcResult";
|
82 | result: Array<JsonRpcResult | JsonRpcError>;
|
83 | } | {
|
84 | action: "receiveRpcError";
|
85 | error: Error;
|
86 | };
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | export type JsonRpcApiProviderOptions = {
|
119 | polling?: boolean;
|
120 | staticNetwork?: null | boolean | Network;
|
121 | batchStallTime?: number;
|
122 | batchMaxSize?: number;
|
123 | batchMaxCount?: number;
|
124 | cacheTimeout?: number;
|
125 | pollingInterval?: number;
|
126 | };
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | export interface JsonRpcTransactionRequest {
|
132 | |
133 |
|
134 |
|
135 | from?: string;
|
136 | |
137 |
|
138 |
|
139 | to?: string;
|
140 | |
141 |
|
142 |
|
143 | data?: string;
|
144 | |
145 |
|
146 |
|
147 | chainId?: string;
|
148 | |
149 |
|
150 |
|
151 | type?: string;
|
152 | |
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | gas?: string;
|
159 | |
160 |
|
161 |
|
162 | gasPrice?: string;
|
163 | |
164 |
|
165 |
|
166 | maxFeePerGas?: string;
|
167 | |
168 |
|
169 |
|
170 | maxPriorityFeePerGas?: string;
|
171 | |
172 |
|
173 |
|
174 | nonce?: string;
|
175 | |
176 |
|
177 |
|
178 | value?: string;
|
179 | |
180 |
|
181 |
|
182 | accessList?: Array<{
|
183 | address: string;
|
184 | storageKeys: Array<string>;
|
185 | }>;
|
186 | }
|
187 | export declare class JsonRpcSigner extends AbstractSigner<JsonRpcApiProvider> {
|
188 | address: string;
|
189 | constructor(provider: JsonRpcApiProvider, address: string);
|
190 | connect(provider: null | Provider): Signer;
|
191 | getAddress(): Promise<string>;
|
192 | populateTransaction(tx: TransactionRequest): Promise<TransactionLike<string>>;
|
193 | sendUncheckedTransaction(_tx: TransactionRequest): Promise<string>;
|
194 | sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>;
|
195 | signTransaction(_tx: TransactionRequest): Promise<string>;
|
196 | signMessage(_message: string | Uint8Array): Promise<string>;
|
197 | signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, _value: Record<string, any>): Promise<string>;
|
198 | unlock(password: string): Promise<boolean>;
|
199 | _legacySignMessage(_message: string | Uint8Array): Promise<string>;
|
200 | }
|
201 | /**
|
202 | * The JsonRpcApiProvider is an abstract class and **MUST** be
|
203 | * sub-classed.
|
204 | *
|
205 | * It provides the base for all JSON-RPC-based Provider interaction.
|
206 | *
|
207 | * Sub-classing Notes:
|
208 | * - a sub-class MUST override _send
|
209 | * - a sub-class MUST call the `_start()` method once connected
|
210 | */
|
211 | export declare abstract class JsonRpcApiProvider extends AbstractProvider {
|
212 | #private;
|
213 | constructor(network?: Networkish, options?: JsonRpcApiProviderOptions);
|
214 | /**
|
215 | * Returns the value associated with the option %%key%%.
|
216 | *
|
217 | * Sub-classes can use this to inquire about configuration options.
|
218 | */
|
219 | _getOption<K extends keyof JsonRpcApiProviderOptions>(key: K): JsonRpcApiProviderOptions[K];
|
220 | /**
|
221 | * Gets the [[Network]] this provider has committed to. On each call, the network
|
222 | * is detected, and if it has changed, the call will reject.
|
223 | */
|
224 | get _network(): Network;
|
225 | /**
|
226 | * Sends a JSON-RPC %%payload%% (or a batch) to the underlying channel.
|
227 | *
|
228 | * Sub-classes **MUST** override this.
|
229 | */
|
230 | abstract _send(payload: JsonRpcPayload | Array<JsonRpcPayload>): Promise<Array<JsonRpcResult | JsonRpcError>>;
|
231 | /**
|
232 | * Resolves to the non-normalized value by performing %%req%%.
|
233 | *
|
234 | * Sub-classes may override this to modify behavior of actions,
|
235 | * and should generally call ``super._perform`` as a fallback.
|
236 | */
|
237 | _perform(req: PerformActionRequest): Promise<any>;
|
238 | /**
|
239 | * Sub-classes may override this; it detects the *actual* network that
|
240 | * we are **currently** connected to.
|
241 | *
|
242 | * Keep in mind that [[send]] may only be used once [[ready]], otherwise the
|
243 | * _send primitive must be used instead.
|
244 | */
|
245 | _detectNetwork(): Promise<Network>;
|
246 | /**
|
247 | * Sub-classes **MUST** call this. Until [[_start]] has been called, no calls
|
248 | * will be passed to [[_send]] from [[send]]. If it is overridden, then
|
249 | * ``super._start()`` **MUST** be called.
|
250 | *
|
251 | * Calling it multiple times is safe and has no effect.
|
252 | */
|
253 | _start(): void;
|
254 | /**
|
255 | * Resolves once the [[_start]] has been called. This can be used in
|
256 | * sub-classes to defer sending data until the connection has been
|
257 | * established.
|
258 | */
|
259 | _waitUntilReady(): Promise<void>;
|
260 | /**
|
261 | * Return a Subscriber that will manage the %%sub%%.
|
262 | *
|
263 | * Sub-classes may override this to modify the behavior of
|
264 | * subscription management.
|
265 | */
|
266 | _getSubscriber(sub: Subscription): Subscriber;
|
267 | /**
|
268 | * Returns true only if the [[_start]] has been called.
|
269 | */
|
270 | get ready(): boolean;
|
271 | /**
|
272 | * Returns %%tx%% as a normalized JSON-RPC transaction request,
|
273 | * which has all values hexlified and any numeric values converted
|
274 | * to Quantity values.
|
275 | */
|
276 | getRpcTransaction(tx: TransactionRequest): JsonRpcTransactionRequest;
|
277 | /**
|
278 | * Returns the request method and arguments required to perform
|
279 | * %%req%%.
|
280 | */
|
281 | getRpcRequest(req: PerformActionRequest): null | {
|
282 | method: string;
|
283 | args: Array<any>;
|
284 | };
|
285 | |
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 | getRpcError(payload: JsonRpcPayload, _error: JsonRpcError): Error;
|
292 | |
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 | send(method: string, params: Array<any> | Record<string, any>): Promise<any>;
|
306 | |
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 | getSigner(address?: number | string): Promise<JsonRpcSigner>;
|
319 | listAccounts(): Promise<Array<JsonRpcSigner>>;
|
320 | destroy(): void;
|
321 | }
|
322 |
|
323 |
|
324 |
|
325 | export declare abstract class JsonRpcApiPollingProvider extends JsonRpcApiProvider {
|
326 | #private;
|
327 | constructor(network?: Networkish, options?: JsonRpcApiProviderOptions);
|
328 | _getSubscriber(sub: Subscription): Subscriber;
|
329 | /**
|
330 | * The polling interval (default: 4000 ms)
|
331 | */
|
332 | get pollingInterval(): number;
|
333 | set pollingInterval(value: number);
|
334 | }
|
335 | /**
|
336 | * The JsonRpcProvider is one of the most common Providers,
|
337 | * which performs all operations over HTTP (or HTTPS) requests.
|
338 | *
|
339 | * Events are processed by polling the backend for the current block
|
340 | * number; when it advances, all block-base events are then checked
|
341 | * for updates.
|
342 | */
|
343 | export declare class JsonRpcProvider extends JsonRpcApiPollingProvider {
|
344 | #private;
|
345 | constructor(url?: string | FetchRequest, network?: Networkish, options?: JsonRpcApiProviderOptions);
|
346 | _getConnection(): FetchRequest;
|
347 | send(method: string, params: Array<any> | Record<string, any>): Promise<any>;
|
348 | _send(payload: JsonRpcPayload | Array<JsonRpcPayload>): Promise<Array<JsonRpcResult>>;
|
349 | }
|
350 | //# sourceMappingURL=provider-jsonrpc.d.ts.map |
\ | No newline at end of file |