@bigmi/core
Version:
TypeScript library for Bitcoin apps.
51 lines (50 loc) • 3.13 kB
TypeScript
import type { ErrorType } from '../errors/utils.js';
import type { Account } from '../types/account.js';
import type { Address } from '../types/address.js';
import type { Chain } from '../types/chain.js';
import type { BtcRpcRequestFn, RpcSchema } from '../types/request.js';
import type { BitcoinRpcMethods } from '../types/rpc.js';
import type { Transport } from '../types/transport.js';
import type { Prettify } from '../types/utils.js';
export type ClientConfig<transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, accountOrAddress extends Account | Address | undefined = Account | Address | undefined, rpcSchema extends RpcSchema | undefined = undefined> = {
account?: accountOrAddress | Account | Address | undefined;
batch?: {
multicall?: boolean | Prettify<MulticallBatchOptions> | undefined;
} | undefined;
cacheTime?: number | undefined;
chain?: Chain | undefined | chain;
key?: string | undefined;
name?: string | undefined;
pollingInterval?: number | undefined;
rpcSchema?: rpcSchema | undefined;
transport: transport;
type?: string | undefined;
};
export type Client<transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, account extends Account | undefined = Account | undefined, rpcSchema extends RpcSchema | undefined = undefined, extended extends Extended | undefined = Extended | undefined> = Client_Base<transport, chain, account, rpcSchema> & (extended extends Extended ? extended : unknown) & {
extend: <const client extends Extended>(fn: (client: Client<transport, chain, account, rpcSchema, extended>) => client) => Client<transport, chain, account, rpcSchema, Prettify<client> & (extended extends Extended ? extended : unknown)>;
};
type Client_Base<transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, account extends Account | undefined = Account | undefined, rpcSchema extends RpcSchema | undefined = undefined> = {
account: account;
cacheTime: number;
chain: chain;
key: string;
name: string;
pollingInterval: number;
request: BtcRpcRequestFn<rpcSchema extends undefined ? BitcoinRpcMethods : rpcSchema>;
transport: ReturnType<transport>['config'] & ReturnType<transport>['value'];
type: string;
uid: string;
};
type Extended = Prettify<{
[_ in keyof Client_Base]?: undefined;
} & {
[key: string]: unknown;
}>;
export type MulticallBatchOptions = {
batchSize?: number | undefined;
wait?: number | undefined;
};
export type CreateClientErrorType = ErrorType;
export declare function createClient<transport extends Transport, chain extends Chain | undefined = undefined, accountOrAddress extends Account | Address | undefined = undefined, rpcSchema extends RpcSchema | undefined = undefined>(parameters: ClientConfig<transport, chain, accountOrAddress, rpcSchema>): Prettify<Client<transport, chain, accountOrAddress extends Address ? Prettify<Account> : accountOrAddress, rpcSchema>>;
export declare function rpcSchema<rpcSchema extends RpcSchema>(): rpcSchema;
export {};