Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a possibility to reveal multiple transactions #600

Merged
merged 2 commits into from
Sep 7, 2023
Merged
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
38 changes: 26 additions & 12 deletions src/store/tbtc/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,34 @@ 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 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(
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
Loading