Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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()
};
Expand All @@ -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);
Expand Down