From 11de67b1dab9e08f63a53f130695420b7e114eda Mon Sep 17 00:00:00 2001 From: ahonn Date: Thu, 18 Jul 2024 17:11:45 +1000 Subject: [PATCH] feat: check spore transaction witnesses length --- src/services/transaction.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/services/transaction.ts b/src/services/transaction.ts index 199b6bb6..fb4b0899 100644 --- a/src/services/transaction.ts +++ b/src/services/transaction.ts @@ -66,9 +66,9 @@ interface ITransactionProcessor { export const TRANSACTION_QUEUE_NAME = 'rgbpp-ckb-transaction-queue'; class InvalidTransactionError extends Error { - public data: ITransactionRequest; + public data?: ITransactionRequest; - constructor(message: string, data: ITransactionRequest) { + constructor(message: string, data?: ITransactionRequest) { super(message); this.name = this.constructor.name; this.data = data; @@ -340,11 +340,11 @@ export default class TransactionProcessor // make sure the spore cobuild witness is the last witness if (needPaymasterCell) { const witnesses = signedTx.witnesses; - signedTx.witnesses = [ - ...witnesses.slice(0, witnesses.length - 2), - witnesses[witnesses.length - 1], - witnesses[witnesses.length - 2], - ]; + const len = witnesses.length; + if (len < 2) { + throw new InvalidTransactionError('Not enough spore transaction witnesses'); + } + signedTx.witnesses = [...witnesses.slice(0, len - 2), witnesses[len - 1], witnesses[len - 2]]; } const tx = await this.appendSporeCobuildWitness(signedTx);