From c4891f86e0588f6d565f186c1e17b43f17d24632 Mon Sep 17 00:00:00 2001 From: Thiendekaco Date: Thu, 18 Jul 2024 20:42:28 +0700 Subject: [PATCH] [Issue 228] [fix] - finalize when sign psbt --- .../handler/BitcoinRequestHandler.ts | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/extension-base/src/services/request-service/handler/BitcoinRequestHandler.ts b/packages/extension-base/src/services/request-service/handler/BitcoinRequestHandler.ts index 8964f698d67..dd402a0c89a 100644 --- a/packages/extension-base/src/services/request-service/handler/BitcoinRequestHandler.ts +++ b/packages/extension-base/src/services/request-service/handler/BitcoinRequestHandler.ts @@ -312,6 +312,14 @@ export default class BitcoinRequestHandler { // Sign the Psbt using the pair's bitcoin object try { psptSignedTransaction = pair.bitcoin.signTransaction(psbt, signAtIndexGenerate, allowedSighash); + + if (!psptSignedTransaction) { + throw new Error('Unable to sign'); + } + + for (const index of signAtIndexGenerate) { + psptSignedTransaction.finalizeInput(index); + } } catch (e) { if (transaction) { transaction.emitterTransaction?.emit('error', { ...eventData, errors: [new TransactionError(BasicTxErrorType.INVALID_PARAMS, (e as Error).message)], id: transaction.id, extrinsicHash: transaction.id }); @@ -320,15 +328,7 @@ export default class BitcoinRequestHandler { throw new Error((e as Error).message); } - if (!psptSignedTransaction) { - throw new Error('Unable to sign'); - } - if (!broadcast) { - for (const index of signAtIndexGenerate) { - psptSignedTransaction.finalizeInput(index); - } - return { psbt: psptSignedTransaction.toHex() }; @@ -353,13 +353,6 @@ export default class BitcoinRequestHandler { const chainInfo = this.#chainService.getChainInfoByKey(chain); - try { - psptSignedTransaction.finalizeAllInputs(); - } catch (e) { - emitterTransaction.emit('error', { ...eventData, errors: [new TransactionError(BasicTxErrorType.INVALID_PARAMS, (e as Error).message)] }); - throw new Error((e as Error).message); - } - const hexTransaction = psptSignedTransaction.extractTransaction().toHex(); this.#transactionService.emitterEventTransaction(emitterTransaction, eventData, chainInfo.slug, hexTransaction);