From c0d3063bca87637d6723abf647d1060e3e23f73b Mon Sep 17 00:00:00 2001 From: redshift <213178690+1ftredsh@users.noreply.github.com> Date: Thu, 2 Apr 2026 00:10:27 +0200 Subject: [PATCH] added logs --- src/daemon/wallet/cocod-client.ts | 45 ++++++++++++++++++++----------- src/daemon/wallet/index.ts | 16 ++++++----- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/daemon/wallet/cocod-client.ts b/src/daemon/wallet/cocod-client.ts index a8f92ea..e6234a9 100644 --- a/src/daemon/wallet/cocod-client.ts +++ b/src/daemon/wallet/cocod-client.ts @@ -22,7 +22,10 @@ type SpawnedProcess = { unref?: () => void; }; -type SpawnDaemon = (args: string[], env: Record) => SpawnedProcess; +type SpawnDaemon = ( + args: string[], + env: Record, +) => SpawnedProcess; export type CocodState = "UNINITIALIZED" | "LOCKED" | "UNLOCKED" | "ERROR"; @@ -52,9 +55,7 @@ export interface CocodClient { getMintInfo(url: string): Promise; } -export function resolveCocodExecutable( - cocodPath?: string | null, -): string { +export function resolveCocodExecutable(cocodPath?: string | null): string { const trimmed = cocodPath?.trim(); return trimmed || "cocod"; } @@ -106,14 +107,16 @@ function delay(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); } -export function createCocodClient(options: { - cocodPath?: string | null; - socketPath?: string; - fetchImpl?: CocodFetch; - spawnDaemon?: SpawnDaemon; - pollIntervalMs?: number; - startupTimeoutMs?: number; -} = {}): CocodClient { +export function createCocodClient( + options: { + cocodPath?: string | null; + socketPath?: string; + fetchImpl?: CocodFetch; + spawnDaemon?: SpawnDaemon; + pollIntervalMs?: number; + startupTimeoutMs?: number; + } = {}, +): CocodClient { const executable = resolveCocodExecutable(options.cocodPath); const socketPath = options.socketPath || DEFAULT_SOCKET_PATH; const fetchImpl = options.fetchImpl || (fetch as CocodFetch); @@ -146,7 +149,9 @@ export function createCocodClient(options: { }; const response = await fetchImpl(`http://localhost${path}`, requestInit); - const data = (await response.json()) as CommandResponse; + const rawText = await response.text(); + logger.log(`[fetchJson] ${init.method || "GET"} ${path} status=${response.status} body=${rawText}`); + const data = JSON.parse(rawText) as CommandResponse; if (!response.ok) { throw new CocodHttpError( @@ -220,11 +225,13 @@ export function createCocodClient(options: { } function post(path: string, body: Record): Promise { - return callDaemon(path, { + const res = callDaemon(path, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); + logger.log("DEBUG", res); + return res; } return { @@ -242,7 +249,15 @@ export function createCocodClient(options: { return normalizeBalances(output); }, async receiveCashu(token: string): Promise { - return post("/receive/cashu", { token }); + logger.log(`[receiveCashu] Receiving Cashu token...`); + logger.log(`[receiveCashu] Token:`, token); + const response = await callDaemon("/receive/cashu", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ token }), + }); + logger.log(`[receiveCashu] Full response.output:`, response); + return response; }, async receiveBolt11(amount: number, mintUrl?: string): Promise { return post("/receive/bolt11", { amount, mintUrl }); diff --git a/src/daemon/wallet/index.ts b/src/daemon/wallet/index.ts index 2626754..32e3c37 100644 --- a/src/daemon/wallet/index.ts +++ b/src/daemon/wallet/index.ts @@ -13,10 +13,12 @@ export function decodeCashuTokenAmount(token: string): { return { amount, unit }; } -export async function createWalletAdapter(options: { - cocodPath?: string | null; - walletClient?: CocodClient; -} = {}) { +export async function createWalletAdapter( + options: { + cocodPath?: string | null; + walletClient?: CocodClient; + } = {}, +) { const client = options.walletClient || createCocodClient({ cocodPath: options.cocodPath }); let activeMintUrl: string | null = null; @@ -67,8 +69,7 @@ export async function createWalletAdapter(options: { error instanceof Error ? error.message : String(error); const shouldRetry = - attempt < maxRetries && - errorMessage.includes(retryErrorPattern); + attempt < maxRetries && errorMessage.includes(retryErrorPattern); if (shouldRetry) { logger.log( @@ -92,7 +93,8 @@ export async function createWalletAdapter(options: { message?: string; }> { try { - await client.receiveCashu(token); + const res = await client.receiveCashu(token); + logger.log("DEBUGSDF", res); const { amount, unit } = decodeCashuTokenAmount(token); return { success: true, amount, unit }; } catch (error) {