From c9375ab49a13c363e27fb84d4451261ec42e30da Mon Sep 17 00:00:00 2001 From: Pedro Branco Date: Thu, 5 Dec 2024 12:26:29 +0000 Subject: [PATCH] Add Typescript types for client --- src/index.d.ts | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/index.d.ts diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..4566073 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,112 @@ +declare module 'bitcoin-core' { + + interface Auth { + pass?: string; + user?: string; + } + + interface MethodFeature { + supported: boolean; + } + + interface Method { + features: Record; + supported: boolean; + } + + interface RequesterConfig { + methods: Record; + version?: string; + } + + interface Parser { + rpc(response: any): any; + rest(extension: string, response: any): any; + } + + interface RequestConfig { + baseUrl: string; + headers: Record; + timeout: number; + } + + interface Request { + getAsync(url: string, options?: Record): Promise; + postAsync(url: string, options?: Record): Promise; + defaults(config: RequestConfig): Request; + } + + interface ClientConfig { + headers?: Record; + host?: string; + logger?: any; + password?: string; + timeout?: number; + username?: string; + version?: string; + wallet?: string; + allowDefaultWallet?: boolean; + } + + interface ReturnFormatOptions { + extension?: 'json' | 'bin' | 'hex'; + } + + interface BlockHashOptions extends ReturnFormatOptions { + summary?: boolean; + } + + interface UnspentTransactionOutput { + id: string; + index: number; + } + + class Client { + auth: Auth | null; + hasNamedParametersSupport: boolean; + headers: Record; + host: string; + password?: string; + timeout: number; + wallet?: string; + version?: string; + + methods: Record; + request: Request; + requester: any; // Assume Requester type + parser: Parser; + + constructor(config?: ClientConfig); + + command(...args: any[]): Promise; + + getTransactionByHash( + hash: string, + options?: ReturnFormatOptions + ): Promise; + + getBlockByHash( + hash: string, + options?: BlockHashOptions + ): Promise; + + getBlockHeadersByHash( + hash: string, + count: number, + options?: ReturnFormatOptions + ): Promise; + + getBlockchainInformation(): Promise; + + getUnspentTransactionOutputs( + outpoints: UnspentTransactionOutput[], + options?: ReturnFormatOptions + ): Promise; + + getMemoryPoolContent(): Promise; + + getMemoryPoolInformation(): Promise; + } + + export = Client; +}