Skip to content

Commit

Permalink
Add a possibility to reveal multiple transactions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michalsmiarowski committed Aug 22, 2023
1 parent 3aca665 commit 58e41d9
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/store/tbtc/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 58e41d9

Please sign in to comment.