Skip to content

Commit

Permalink
Backend: new ex type that includes currency
Browse files Browse the repository at this point in the history
Add new exception type that wraps ResultInconsistencyException
when checking for balances and includes currency for which the
operation has failed.

Fixes #246
  • Loading branch information
webwarrior-ws authored and knocte committed Jan 20, 2024
1 parent b72bb86 commit 8fa47e0
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/GWallet.Backend/Account.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ open System.Threading.Tasks

open GWallet.Backend.FSharpUtil.UwpHacks

// this exception, if it happens, it would cause a crash because we don't handle it yet
type InconsistentResultFromDifferentServersOfSameCurrency(currency: Currency,
innerException: ResultInconsistencyException) =
inherit Exception (SPrintF2 "Inconsistent results retrieving info for currency %A: %s"
(currency.ToString())
innerException.Message,
innerException)

module Account =

let private GetShowableBalanceInternal (account: IAccount)
Expand Down Expand Up @@ -35,16 +43,20 @@ module Account =
return Fresh 1m
else

let! maybeBalance = GetShowableBalanceInternal account mode cancelSourceOption
match maybeBalance with
| None ->
return NotFresh(Caching.Instance.RetrieveLastCompoundBalance account.PublicAddress account.Currency)
| Some balance ->
let compoundBalance,_ =
Caching.Instance.RetrieveAndUpdateLastCompoundBalance account.PublicAddress
account.Currency
balance
return Fresh compoundBalance
try
let! maybeBalance = GetShowableBalanceInternal account mode cancelSourceOption
match maybeBalance with
| None ->
return NotFresh(Caching.Instance.RetrieveLastCompoundBalance account.PublicAddress account.Currency)
| Some balance ->
let compoundBalance,_ =
Caching.Instance.RetrieveAndUpdateLastCompoundBalance account.PublicAddress
account.Currency
balance
return Fresh compoundBalance
with
| :? ResultInconsistencyException as innerEx ->
return raise <| InconsistentResultFromDifferentServersOfSameCurrency(account.Currency, innerEx)
}

let internal GetAccountFromFile accountFile (currency: Currency) kind: IAccount =
Expand Down

0 comments on commit 8fa47e0

Please sign in to comment.