Skip to content

Commit

Permalink
On-chain tx: finalizePsbtAndBroadcast: LND fundingStateStep -> bitcoi…
Browse files Browse the repository at this point in the history
…njs-lib
  • Loading branch information
kaloudis committed Nov 9, 2024
1 parent 0a6e400 commit 94b586b
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions stores/TransactionsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 94b586b

Please sign in to comment.