106 lines
4 KiB
TypeScript
106 lines
4 KiB
TypeScript
import { AccountHistoryAPI } from './helpers/account_history';
|
|
import { Blockchain } from './helpers/blockchain';
|
|
import { BroadcastAPI } from './helpers/broadcast';
|
|
import { CondenserAPI } from './index-browser';
|
|
import { DatabaseAPI } from './helpers/database';
|
|
import { Nexus } from './helpers/nexus';
|
|
import { Tools } from './helpers/tools';
|
|
import { ClientOptions } from './client';
|
|
interface RPCError {
|
|
code: number;
|
|
message: string;
|
|
data?: any;
|
|
}
|
|
interface RPCResponse {
|
|
id: number | string;
|
|
error?: RPCError;
|
|
result?: any;
|
|
}
|
|
interface RPCCall {
|
|
id: number;
|
|
method: string;
|
|
jsonrpc: '2.0';
|
|
params: any[];
|
|
}
|
|
interface CoreClientLike {
|
|
callRaw?: (request: RPCCall, options?: any) => Promise<RPCResponse>;
|
|
call?: (method: string, params?: any, options?: any) => Promise<any>;
|
|
getCurrentEndpoint?: () => any;
|
|
close?: () => Promise<void> | void;
|
|
}
|
|
interface CoreModuleLike {
|
|
createRpcClient?: (endpoints: any, options?: any) => CoreClientLike;
|
|
RpcClient?: new (endpoints: any, options?: any) => CoreClientLike;
|
|
}
|
|
/** Experimental Client options. Extends the historic options without changing Client. */
|
|
export interface ExperimentalClientOptions extends ClientOptions {
|
|
/** Prebuilt blurt-rpc-core compatible client, useful for tests and custom transports. */
|
|
coreClient?: CoreClientLike;
|
|
/** Preloaded blurt-rpc-core module, useful for CommonJS integration tests. */
|
|
coreModule?: CoreModuleLike;
|
|
/**
|
|
* Node selection strategy forwarded to blurt-rpc-core.
|
|
*
|
|
* Defaults to `sticky` to preserve dblurt Client compatibility. Modern
|
|
* blurt-rpc-core strategies such as `round-robin` remain available only as
|
|
* explicit opt-in choices.
|
|
*/
|
|
nodeSelectionStrategy?: 'sticky' | 'round-robin' | 'weighted-random' | 'least-latency' | 'external-score' | any;
|
|
}
|
|
/**
|
|
* Experimental RPC Client backed by blurt-rpc-core.
|
|
*
|
|
* This class intentionally does not replace or extend the historic Client. It mirrors the
|
|
* dblurt helper surface while delegating JSON-RPC transport, retry and failover to
|
|
* blurt-rpc-core so compatibility can be measured before any migration decision.
|
|
*/
|
|
export declare class ExperimentalClient {
|
|
/** Client options, immutable. */
|
|
readonly options: ExperimentalClientOptions;
|
|
/** Address to Blurt RPC server. String or String[]; immutable after construction. */
|
|
address: string | string[];
|
|
/** Account History API helper */
|
|
readonly accountHistory: AccountHistoryAPI;
|
|
/** Blockchain helper */
|
|
readonly blockchain: Blockchain;
|
|
/** Broadcast API helper */
|
|
readonly broadcast: BroadcastAPI;
|
|
/** Condenser API helper */
|
|
readonly condenser: CondenserAPI;
|
|
/** Database API helper. */
|
|
readonly database: DatabaseAPI;
|
|
/** Nexus (A.k.a. Bridge) helper */
|
|
readonly nexus: Nexus;
|
|
/** Tools helper */
|
|
readonly tools: Tools;
|
|
/** Chain ID for current network. */
|
|
readonly chainId: Buffer;
|
|
/** Address prefix for current network. */
|
|
readonly addressPrefix: string;
|
|
currentAddress: string;
|
|
private readonly timeout;
|
|
private readonly backoff;
|
|
private readonly failoverThreshold;
|
|
private readonly coreClient?;
|
|
private readonly coreModule?;
|
|
private loadedCoreClient?;
|
|
/**
|
|
* @param address The address to the Blurt RPC server,
|
|
* e.g. `https://rpc.blurt.blog`. or [`https://rpc.blurt.blog`, `https://another.api.com`]
|
|
* @param options Experimental client options.
|
|
*/
|
|
constructor(address: string | string[], options?: ExperimentalClientOptions);
|
|
/** Make a RPC call to the server using blurt-rpc-core transport. */
|
|
call(api: string, method: string, params?: any): Promise<any>;
|
|
/** Close the underlying blurt-rpc-core client when it exposes close(). */
|
|
close(): Promise<void>;
|
|
private callViaResultMode;
|
|
private callOptions;
|
|
private getCoreClient;
|
|
private coreOptions;
|
|
private legacyStickyStrategy;
|
|
private legacySerializeParams;
|
|
private loadCoreModule;
|
|
private syncCurrentAddress;
|
|
}
|
|
export {};
|