Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Commit

Permalink
Fix: recursion loop (#94)
Browse files Browse the repository at this point in the history
* fix: stop condition in case of infinite failure
Co-authored-by: Sebastien Verreault <[email protected]>
  • Loading branch information
sebastienverreault authored May 6, 2022
1 parent 77a6ec9 commit 0c554c4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions dealer/src/Dealer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ export class Dealer {
private async depositOnExchangeCallback(
onChainAddress: string,
transferSizeInBtc: number,
retries = 2,
): Promise<Result<void>> {
try {
const memo = `deposit of ${transferSizeInBtc} btc to ${this.strategy.name}`
Expand Down Expand Up @@ -411,11 +412,16 @@ export class Dealer {
} else {
this.logger.debug({ payOnChainResult }, "WalletOnChainPay failed.")

// try again with 50% amount in case we can work around fund limit
return this.depositOnExchangeCallback(
onChainAddress,
roundBtc(transferSizeInBtc / 2),
)
if (retries > 0) {
// try again with 50% amount in case we can work around fund limit
return this.depositOnExchangeCallback(
onChainAddress,
roundBtc(transferSizeInBtc / 2),
retries - 1,
)
}

return { ok: false, error: payOnChainResult.error }
}
} catch (error) {
return { ok: false, error: error }
Expand Down

0 comments on commit 0c554c4

Please sign in to comment.