From 94b586b8a2d0b89b55e310ccb072c90df2feddf9 Mon Sep 17 00:00:00 2001 From: Evan Kaloudis Date: Fri, 8 Nov 2024 19:58:03 -0500 Subject: [PATCH] On-chain tx: finalizePsbtAndBroadcast: LND fundingStateStep -> bitcoinjs-lib --- stores/TransactionsStore.ts | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/stores/TransactionsStore.ts b/stores/TransactionsStore.ts index 629369650..d1833cad6 100644 --- a/stores/TransactionsStore.ts +++ b/stores/TransactionsStore.ts @@ -170,18 +170,33 @@ export default class TransactionsStore { public finalizePsbtAndBroadcast = (funded_psbt: string) => { this.funded_psbt = ''; this.loading = true; - return BackendUtils.finalizePsbt({ funded_psbt }) - .then((data: any) => { - const raw_final_tx = data.raw_final_tx; - this.broadcast(raw_final_tx); - }) - .catch((error: any) => { + return new Promise((resolve) => { + try { + // Parse the PSBT + const psbt = bitcoin.Psbt.fromBase64(funded_psbt); + // Step 2: Finalize each input + psbt.data.inputs.forEach((input: any, index: number) => { + if (!input.finalScriptSig && !input.finalScriptWitness) { + psbt.finalizeInput(index); // This finalizes the input + } + }); + + // Step 3: Extract the transaction + const txHex = psbt.extractTransaction().toHex(); + + this.broadcast(txHex); + + resolve(true); + } catch (error: any) { // handle error - this.error_msg = errorToUserFriendly(error.message); + this.error_msg = errorToUserFriendly(error?.message || error); this.error = true; this.loading = false; - }); + + resolve(true); + } + }); }; @action