Skip to content

Commit

Permalink
Upgrade fantomas to beta-001
Browse files Browse the repository at this point in the history
dotnet tool install -g fantomas-tool --add-source https://www.myget.org/F/fantomas/api/v3/index.json --framework netcoreapp3.1 --version 4.0.0-beta-001

Things pending to look at in this version:

- crash: reported at fsprojects/fantomas#1218
  • Loading branch information
knocte committed Nov 6, 2020
1 parent 0385d30 commit 2e4e42e
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 370 deletions.
116 changes: 49 additions & 67 deletions src/GWallet.Backend/Account.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ open GWallet.Backend.FSharpUtil.UwpHacks

module Account =

let private GetShowableBalanceInternal
(account: IAccount)
(mode: ServerSelectionMode)
(cancelSourceOption: Option<CustomCancelSource>)
: Async<Option<decimal>>
=
let private GetShowableBalanceInternal (account: IAccount)
(mode: ServerSelectionMode)
(cancelSourceOption: Option<CustomCancelSource>)
: Async<Option<decimal>> =
match account with
| :? UtxoCoin.IUtxoAccount as utxoAccount ->
if not (account.Currency.IsUtxo ()) then
Expand All @@ -30,12 +28,10 @@ module Account =
account.Currency
Ether.Account.GetShowableBalance account mode cancelSourceOption

let GetShowableBalance
(account: IAccount)
(mode: ServerSelectionMode)
(cancelSourceOption: Option<CustomCancelSource>)
: Async<MaybeCached<decimal>>
=
let GetShowableBalance (account: IAccount)
(mode: ServerSelectionMode)
(cancelSourceOption: Option<CustomCancelSource>)
: Async<MaybeCached<decimal>> =
async {
if Config.NoNetworkBalanceForDebuggingPurposes then
return Fresh 1m
Expand Down Expand Up @@ -107,7 +103,8 @@ module Account =
EtherPublicAddress = etherPublicAddress
}

let GetArchivedAccountsWithPositiveBalance (cancelSourceOption: Option<CustomCancelSource>): Async<seq<ArchivedAccount * decimal>> =
let GetArchivedAccountsWithPositiveBalance (cancelSourceOption: Option<CustomCancelSource>)
: Async<seq<ArchivedAccount * decimal>> =
let asyncJobs =
seq<Async<ArchivedAccount * Option<decimal>>> {
let allCurrencies = Currency.GetAll ()
Expand Down Expand Up @@ -253,13 +250,12 @@ module Account =
return uri
}

let SignTransaction
(account: NormalAccount)
(destination: string)
(amount: TransferAmount)
(transactionMetadata: IBlockchainFeeInfo)
(password: string)
=
let SignTransaction (account: NormalAccount)
(destination: string)
(amount: TransferAmount)
(transactionMetadata: IBlockchainFeeInfo)
(password: string)
=

match transactionMetadata with
| :? Ether.TransactionMetadata as etherTxMetadata ->
Expand Down Expand Up @@ -339,12 +335,11 @@ module Account =
CreateArchivedAccount currency privateKeyAsString |> ignore
Config.RemoveNormalAccount account

let SweepArchivedFunds
(account: ArchivedAccount)
(balance: decimal)
(destination: IAccount)
(txMetadata: IBlockchainFeeInfo)
=
let SweepArchivedFunds (account: ArchivedAccount)
(balance: decimal)
(destination: IAccount)
(txMetadata: IBlockchainFeeInfo)
=
match txMetadata with
| :? Ether.TransactionMetadata as etherTxMetadata ->
Ether.Account.SweepArchivedFunds account balance destination etherTxMetadata
Expand All @@ -355,14 +350,12 @@ module Account =
| _ -> failwith "If tx metadata is UTXO type, archived account should be too"
| _ -> failwith "tx metadata type unknown"

let SendPayment
(account: NormalAccount)
(txMetadata: IBlockchainFeeInfo)
(destination: string)
(amount: TransferAmount)
(password: string)
: Async<Uri>
=
let SendPayment (account: NormalAccount)
(txMetadata: IBlockchainFeeInfo)
(destination: string)
(amount: TransferAmount)
(password: string)
: Async<Uri> =
let baseAccount = account :> IAccount
if (baseAccount.PublicAddress.Equals (destination, StringComparison.InvariantCultureIgnoreCase)) then
raise DestinationEqualToOrigin
Expand Down Expand Up @@ -507,22 +500,18 @@ module Account =
let Remove (account: ReadOnlyAccount) =
Config.RemoveReadOnlyAccount account

let private CreateConceptEtherAccountInternal
(password: string)
(seed: array<byte>)
: Async<FileRepresentation * (FileRepresentation -> string)>
=
let private CreateConceptEtherAccountInternal (password: string)
(seed: array<byte>)
: Async<FileRepresentation * (FileRepresentation -> string)> =
async {
let! virtualFile = Ether.Account.Create password seed
return virtualFile, Ether.Account.GetPublicAddressFromNormalAccountFile
}

let private CreateConceptAccountInternal
(currency: Currency)
(password: string)
(seed: array<byte>)
: Async<FileRepresentation * (FileRepresentation -> string)>
=
let private CreateConceptAccountInternal (currency: Currency)
(password: string)
(seed: array<byte>)
: Async<FileRepresentation * (FileRepresentation -> string)> =
async {
if currency.IsUtxo () then
let! virtualFile = UtxoCoin.Account.Create currency password seed
Expand All @@ -545,12 +534,10 @@ module Account =
}
}

let private CreateConceptAccountAux
(currency: Currency)
(password: string)
(seed: array<byte>)
: Async<List<ConceptAccount>>
=
let private CreateConceptAccountAux (currency: Currency)
(password: string)
(seed: array<byte>)
: Async<List<ConceptAccount>> =
async {
let! singleAccount = CreateConceptAccount currency password seed
return singleAccount :: List.Empty
Expand Down Expand Up @@ -580,12 +567,10 @@ module Account =
let newAccountFile = Config.AddAccount conceptAccount AccountKind.Normal
NormalAccount (conceptAccount.Currency, newAccountFile, conceptAccount.ExtractPublicAddressFromConfigFileFunc)

let GenerateMasterPrivateKey
(passphrase: string)
(dobPartOfSalt: DateTime)
(emailPartOfSalt: string)
: Async<array<byte>>
=
let GenerateMasterPrivateKey (passphrase: string)
(dobPartOfSalt: DateTime)
(emailPartOfSalt: string)
: Async<array<byte>> =
async {
let salt =
SPrintF2 "%s+%s" (dobPartOfSalt.Date.ToString ("yyyyMMdd")) (emailPartOfSalt.ToLower ())
Expand Down Expand Up @@ -655,11 +640,9 @@ module Account =
let public ExportUnsignedTransactionToJson trans =
Marshalling.Serialize trans

let private SerializeUnsignedTransactionPlain
(transProposal: UnsignedTransactionProposal)
(txMetadata: IBlockchainFeeInfo)
: string
=
let private SerializeUnsignedTransactionPlain (transProposal: UnsignedTransactionProposal)
(txMetadata: IBlockchainFeeInfo)
: string =
let readOnlyAccounts = GetAllActiveAccounts().OfType<ReadOnlyAccount> ()

match txMetadata with
Expand All @@ -669,11 +652,10 @@ module Account =
UtxoCoin.Account.SaveUnsignedTransaction transProposal btcTxMetadata readOnlyAccounts
| _ -> failwith "fee type unknown"

let SaveUnsignedTransaction
(transProposal: UnsignedTransactionProposal)
(txMetadata: IBlockchainFeeInfo)
(filePath: string)
=
let SaveUnsignedTransaction (transProposal: UnsignedTransactionProposal)
(txMetadata: IBlockchainFeeInfo)
(filePath: string)
=
let json = SerializeUnsignedTransactionPlain transProposal txMetadata
File.WriteAllText (filePath, json)

Expand Down
50 changes: 21 additions & 29 deletions src/GWallet.Backend/Caching.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ type CachedNetworkData =
}

member self.ToDietCache (readOnlyAccounts: seq<ReadOnlyAccount>) =
let rec extractAddressesFromAccounts
(acc: Map<PublicAddress, List<DietCurrency>>)
(accounts: List<IAccount>)
: Map<PublicAddress, List<DietCurrency>>
=
let rec extractAddressesFromAccounts (acc: Map<PublicAddress, List<DietCurrency>>)
(accounts: List<IAccount>)
: Map<PublicAddress, List<DietCurrency>> =
match accounts with
| [] -> acc
| head :: tail ->
Expand Down Expand Up @@ -168,12 +166,11 @@ module Caching =
| None -> maybeFirstRun, resultingNetworkData, Map.empty
| Some serverStats -> false, resultingNetworkData, serverStats

let rec private MergeRatesInternal
(oldMap: Map<'K, CachedValue<'V>>)
(newMap: Map<'K, CachedValue<'V>>)
(currencyList: List<'K>)
(accumulator: Map<'K, CachedValue<'V>>)
=
let rec private MergeRatesInternal (oldMap: Map<'K, CachedValue<'V>>)
(newMap: Map<'K, CachedValue<'V>>)
(currencyList: List<'K>)
(accumulator: Map<'K, CachedValue<'V>>)
=
match currencyList with
| [] -> accumulator
| address :: tail ->
Expand All @@ -198,13 +195,11 @@ module Caching =
let currencyList = Map.toList newMap |> List.map fst
MergeRatesInternal oldMap newMap currencyList oldMap

let rec private MergeBalancesInternal
(oldMap: Map<Currency, Map<PublicAddress, CachedValue<'V>>>)
(newMap: Map<Currency, Map<PublicAddress, CachedValue<'V>>>)
(addressList: List<Currency * PublicAddress>)
(accumulator: Map<Currency, Map<PublicAddress, CachedValue<'V>>>)
: Map<Currency, Map<PublicAddress, CachedValue<'V>>>
=
let rec private MergeBalancesInternal (oldMap: Map<Currency, Map<PublicAddress, CachedValue<'V>>>)
(newMap: Map<Currency, Map<PublicAddress, CachedValue<'V>>>)
(addressList: List<Currency * PublicAddress>)
(accumulator: Map<Currency, Map<PublicAddress, CachedValue<'V>>>)
: Map<Currency, Map<PublicAddress, CachedValue<'V>>> =
match addressList with
| [] -> accumulator
| (currency, address) :: tail ->
Expand Down Expand Up @@ -236,11 +231,9 @@ module Caching =

MergeBalancesInternal oldMap newMap tail newAcc

let private MergeBalances
(oldMap: Map<Currency, Map<PublicAddress, CachedValue<'V>>>)
(newMap: Map<Currency, Map<PublicAddress, CachedValue<'V>>>)
: Map<Currency, Map<PublicAddress, CachedValue<'V>>>
=
let private MergeBalances (oldMap: Map<Currency, Map<PublicAddress, CachedValue<'V>>>)
(newMap: Map<Currency, Map<PublicAddress, CachedValue<'V>>>)
: Map<Currency, Map<PublicAddress, CachedValue<'V>>> =
let addressList =
seq {
for currency, subMap in Map.toList newMap do
Expand Down Expand Up @@ -309,12 +302,10 @@ module Caching =
let mutable sessionCachedNetworkData = initialSessionCachedNetworkData
let mutable sessionServerRanking = initialServerStats

let GetSumOfAllTransactions
(trans: Map<Currency, Map<PublicAddress, Map<string, CachedValue<decimal>>>>)
currency
address
: decimal
=
let GetSumOfAllTransactions (trans: Map<Currency, Map<PublicAddress, Map<string, CachedValue<decimal>>>>)
currency
address
: decimal =
let now = DateTime.UtcNow
let currencyTrans = trans.TryFind currency
match currencyTrans with
Expand Down Expand Up @@ -455,6 +446,7 @@ module Caching =
let! currencyAddresses = newCachedValueWithNewBalance.OutgoingTransactions.TryFind currency

let! addressTransactions = currencyAddresses.TryFind address

let allCombinationsOfTransactions = MapCombinations addressTransactions

let newAddressTransactions =
Expand Down
Loading

0 comments on commit 2e4e42e

Please sign in to comment.