RPC
This commit is contained in:
@@ -9,7 +9,10 @@ export class StateClient {
|
||||
private cache: { chainId: string; blocks: TestnetBlock[]; bytes: number } | undefined;
|
||||
private inFlight: Promise<TestnetSnapshot> | undefined;
|
||||
private readonly fetcher: typeof fetch;
|
||||
constructor(fetcher: typeof fetch = fetch) { this.fetcher = fetcher; }
|
||||
constructor(fetcher: typeof fetch = globalThis.fetch) {
|
||||
// Browser Web APIs require the Window/global receiver, not this StateClient instance.
|
||||
this.fetcher = fetcher.bind(globalThis);
|
||||
}
|
||||
async json<T>(path: string, signal: AbortSignal): Promise<T> {
|
||||
const response = await this.fetcher(`/api/${path}`, { cache: 'no-store', redirect: 'error', signal });
|
||||
if (!/^application\/json(?:\s*;|$)/i.test(response.headers.get('content-type') ?? '') || !response.body) throw new Error('Node must return JSON.');
|
||||
|
||||
Reference in New Issue
Block a user