From 58e41d95fd1e3bf772b78944800e390ad7fde2e0 Mon Sep 17 00:00:00 2001 From: michalsmiarowski Date: Tue, 22 Aug 2023 16:45:42 +0200 Subject: [PATCH 1/2] Add a possibility to reveal multiple transactions Add a possibility to reveal multiple transactions send to the same BTC deposit address. In such case the user should use `/tBTC/mint/continue` url to initiate the minting of each subsequent transaction after he revealed the first one. --- src/store/tbtc/effects.ts | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/store/tbtc/effects.ts b/src/store/tbtc/effects.ts index ef0ab3b47..945dd984e 100644 --- a/src/store/tbtc/effects.ts +++ b/src/store/tbtc/effects.ts @@ -78,20 +78,31 @@ export const findUtxoEffect = async ( continue } - // UTXOs returned from `findAllUnspentTransactionOutputs` are in - // reversed order so we have to get the last element of the `utxos` - // array to get the oldest utxo related to this deposit address. - const utxo = utxos.pop()! - - // Check if deposit is revealed. - const deposit = await forkApi.pause( - listenerApi.extra.threshold.tbtc.getRevealedDeposit(utxo) - ) + let utxo = utxos[0] + let areAllDepositRevealed = true + + // We have to find the first utxo that is revealed. The UTXOs returned + // from `findAllUnspentTransactionOutputs` are in reversed order so + // that's why we start our search from the last elements of the `utxos`. + // If all deposits are revealed then we just use the first utxo (which + // should be the most recent transaction) + for (let i = utxos.length - 1; i >= 0; i--) { + // Check if deposit is revealed. + const deposit = await forkApi.pause( + listenerApi.extra.threshold.tbtc.getRevealedDeposit(utxos[i]) + ) + const isDepositRevealed = deposit.revealedAt !== 0 - const isDepositRevealed = deposit.revealedAt !== 0 + if (!isDepositRevealed) { + utxo = utxos[i] + areAllDepositRevealed = false + break + } + } - if (isDepositRevealed) { - // Deposit already revealed, force start from step 1 and remove deposit data. + if (areAllDepositRevealed) { + // All deposits are already revealed. Force start from step 1 and + // remove deposit data. removeDataForAccount( depositor, JSON.parse( From 30d657fc7225f883070330a10f4697567c5a9be9 Mon Sep 17 00:00:00 2001 From: michalsmiarowski Date: Wed, 23 Aug 2023 12:03:49 +0200 Subject: [PATCH 2/2] Improve comment Improve comment that describes how we search for the oldest UTXO that is not revealed. --- src/store/tbtc/effects.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/store/tbtc/effects.ts b/src/store/tbtc/effects.ts index 945dd984e..8022c5fcb 100644 --- a/src/store/tbtc/effects.ts +++ b/src/store/tbtc/effects.ts @@ -81,11 +81,14 @@ export const findUtxoEffect = async ( let utxo = utxos[0] let areAllDepositRevealed = true - // We have to find the first utxo that is revealed. The UTXOs returned - // from `findAllUnspentTransactionOutputs` are in reversed order so - // that's why we start our search from the last elements of the `utxos`. - // If all deposits are revealed then we just use the first utxo (which - // should be the most recent transaction) + // We have to find the first UTXO that is not revealed. The UTXOs + // returned from `findAllUnspentTransactionOutputs` are in reversed + // order so we have to start our search from the last element of the + // `utxos` so that we search them in the order they were done. We go + // through all of them up to the first one to find the oldest UTXO that + // is not revealed. + // If all deposits are revealed then we just use the first UTXO (which + // should be the most recent transaction). for (let i = utxos.length - 1; i >= 0; i--) { // Check if deposit is revealed. const deposit = await forkApi.pause(