From 68536b9dc024d084f7ca445024230c619e679b60 Mon Sep 17 00:00:00 2001 From: redshift <213178690+1ftredsh@users.noreply.github.com> Date: Wed, 11 Mar 2026 18:31:05 +0000 Subject: [PATCH] fixed wallet send error for cocod --- src/daemon.ts | 54 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/daemon.ts b/src/daemon.ts index 2d44172..aab3468 100644 --- a/src/daemon.ts +++ b/src/daemon.ts @@ -318,23 +318,47 @@ async function main(): Promise { return activeMintUrl; }, async sendToken(mintUrl: string, amount: number): Promise { - try { - const output = await runWalletCommand([ - "send", - "cashu", - String(amount), - "--mint-url", - mintUrl, - ]); - const token = pickTokenLine(output); - if (!token) { - throw new Error("Wallet CLI did not return a token."); + const maxRetries = 3; + const retryDelayMs = 5000; + const retryErrorPattern = "Proof already reserved by operation"; + + for (let attempt = 0; attempt <= maxRetries; attempt++) { + try { + const output = await runWalletCommand([ + "send", + "cashu", + String(amount), + "--mint-url", + mintUrl, + ]); + const token = pickTokenLine(output); + if (!token) { + throw new Error("Wallet CLI did not return a token."); + } + return token; + } catch (error) { + const errorMessage = + error instanceof Error ? error.message : String(error); + + const shouldRetry = + attempt < maxRetries && + errorMessage.includes(retryErrorPattern); + + if (shouldRetry) { + logger.log( + `sendToken attempt ${attempt + 1} failed with reserved proof error, retrying in ${retryDelayMs / 1000}s...`, + ); + await new Promise((resolve) => + setTimeout(resolve, retryDelayMs), + ); + continue; + } + + logger.error("Error in walletAdapter sendToken:", error); + throw error; } - return token; - } catch (error) { - logger.error("Error in walletAdapter sendToken:", error); - throw error; } + throw new Error("sendToken failed after max retries"); }, async receiveToken(token: string): Promise<{ success: boolean;