diff --git a/src/GWallet.Backend/Account.fs b/src/GWallet.Backend/Account.fs index d2c977718..4ea644403 100644 --- a/src/GWallet.Backend/Account.fs +++ b/src/GWallet.Backend/Account.fs @@ -9,12 +9,10 @@ open GWallet.Backend.FSharpUtil.UwpHacks module Account = - let private GetShowableBalanceInternal - (account: IAccount) - (mode: ServerSelectionMode) - (cancelSourceOption: Option) - : Async> - = + let private GetShowableBalanceInternal (account: IAccount) + (mode: ServerSelectionMode) + (cancelSourceOption: Option) + : Async> = match account with | :? UtxoCoin.IUtxoAccount as utxoAccount -> if not (account.Currency.IsUtxo ()) then @@ -30,12 +28,10 @@ module Account = account.Currency Ether.Account.GetShowableBalance account mode cancelSourceOption - let GetShowableBalance - (account: IAccount) - (mode: ServerSelectionMode) - (cancelSourceOption: Option) - : Async> - = + let GetShowableBalance (account: IAccount) + (mode: ServerSelectionMode) + (cancelSourceOption: Option) + : Async> = async { if Config.NoNetworkBalanceForDebuggingPurposes then return Fresh 1m @@ -107,7 +103,8 @@ module Account = EtherPublicAddress = etherPublicAddress } - let GetArchivedAccountsWithPositiveBalance (cancelSourceOption: Option): Async> = + let GetArchivedAccountsWithPositiveBalance (cancelSourceOption: Option) + : Async> = let asyncJobs = seq>> { let allCurrencies = Currency.GetAll () @@ -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 -> @@ -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 @@ -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 - = + let SendPayment (account: NormalAccount) + (txMetadata: IBlockchainFeeInfo) + (destination: string) + (amount: TransferAmount) + (password: string) + : Async = let baseAccount = account :> IAccount if (baseAccount.PublicAddress.Equals (destination, StringComparison.InvariantCultureIgnoreCase)) then raise DestinationEqualToOrigin @@ -507,22 +500,18 @@ module Account = let Remove (account: ReadOnlyAccount) = Config.RemoveReadOnlyAccount account - let private CreateConceptEtherAccountInternal - (password: string) - (seed: array) - : Async string)> - = + let private CreateConceptEtherAccountInternal (password: string) + (seed: array) + : Async string)> = async { let! virtualFile = Ether.Account.Create password seed return virtualFile, Ether.Account.GetPublicAddressFromNormalAccountFile } - let private CreateConceptAccountInternal - (currency: Currency) - (password: string) - (seed: array) - : Async string)> - = + let private CreateConceptAccountInternal (currency: Currency) + (password: string) + (seed: array) + : Async string)> = async { if currency.IsUtxo () then let! virtualFile = UtxoCoin.Account.Create currency password seed @@ -545,12 +534,10 @@ module Account = } } - let private CreateConceptAccountAux - (currency: Currency) - (password: string) - (seed: array) - : Async> - = + let private CreateConceptAccountAux (currency: Currency) + (password: string) + (seed: array) + : Async> = async { let! singleAccount = CreateConceptAccount currency password seed return singleAccount :: List.Empty @@ -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> - = + let GenerateMasterPrivateKey (passphrase: string) + (dobPartOfSalt: DateTime) + (emailPartOfSalt: string) + : Async> = async { let salt = SPrintF2 "%s+%s" (dobPartOfSalt.Date.ToString ("yyyyMMdd")) (emailPartOfSalt.ToLower ()) @@ -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 () match txMetadata with @@ -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) diff --git a/src/GWallet.Backend/Caching.fs b/src/GWallet.Backend/Caching.fs index d50ff4f93..5be0597cc 100644 --- a/src/GWallet.Backend/Caching.fs +++ b/src/GWallet.Backend/Caching.fs @@ -48,11 +48,9 @@ type CachedNetworkData = } member self.ToDietCache (readOnlyAccounts: seq) = - let rec extractAddressesFromAccounts - (acc: Map>) - (accounts: List) - : Map> - = + let rec extractAddressesFromAccounts (acc: Map>) + (accounts: List) + : Map> = match accounts with | [] -> acc | head :: tail -> @@ -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 -> @@ -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>>) - (newMap: Map>>) - (addressList: List) - (accumulator: Map>>) - : Map>> - = + let rec private MergeBalancesInternal (oldMap: Map>>) + (newMap: Map>>) + (addressList: List) + (accumulator: Map>>) + : Map>> = match addressList with | [] -> accumulator | (currency, address) :: tail -> @@ -236,11 +231,9 @@ module Caching = MergeBalancesInternal oldMap newMap tail newAcc - let private MergeBalances - (oldMap: Map>>) - (newMap: Map>>) - : Map>> - = + let private MergeBalances (oldMap: Map>>) + (newMap: Map>>) + : Map>> = let addressList = seq { for currency, subMap in Map.toList newMap do @@ -309,12 +302,10 @@ module Caching = let mutable sessionCachedNetworkData = initialSessionCachedNetworkData let mutable sessionServerRanking = initialServerStats - let GetSumOfAllTransactions - (trans: Map>>>) - currency - address - : decimal - = + let GetSumOfAllTransactions (trans: Map>>>) + currency + address + : decimal = let now = DateTime.UtcNow let currencyTrans = trans.TryFind currency match currencyTrans with @@ -455,6 +446,7 @@ module Caching = let! currencyAddresses = newCachedValueWithNewBalance.OutgoingTransactions.TryFind currency let! addressTransactions = currencyAddresses.TryFind address + let allCombinationsOfTransactions = MapCombinations addressTransactions let newAddressTransactions = diff --git a/src/GWallet.Backend/Ether/EtherAccount.fs b/src/GWallet.Backend/Ether/EtherAccount.fs index f44526b0e..1d84aa140 100644 --- a/src/GWallet.Backend/Ether/EtherAccount.fs +++ b/src/GWallet.Backend/Ether/EtherAccount.fs @@ -47,12 +47,11 @@ module internal Account = | AccountKind.Normal -> NormalAccount (currency, accountFile, GetPublicAddressFromNormalAccountFile) :> IAccount | _ -> failwith <| SPrintF1 "Kind (%A) not supported for this API" kind - let private GetBalance - (account: IAccount) - (mode: ServerSelectionMode) - (balType: BalanceType) - (cancelSourceOption: Option) - = + let private GetBalance (account: IAccount) + (mode: ServerSelectionMode) + (balType: BalanceType) + (cancelSourceOption: Option) + = async { let! balance = if (account.Currency.IsEther ()) then @@ -66,13 +65,11 @@ module internal Account = return balance } - let private GetBalanceFromServer - (account: IAccount) - (balType: BalanceType) - (mode: ServerSelectionMode) - (cancelSourceOption: Option) - : Async> - = + let private GetBalanceFromServer (account: IAccount) + (balType: BalanceType) + (mode: ServerSelectionMode) + (cancelSourceOption: Option) + : Async> = async { try let! balance = GetBalance account mode balType cancelSourceOption @@ -80,13 +77,12 @@ module internal Account = with ex when (FSharpUtil.FindException ex).IsSome -> return None } - let internal GetShowableBalance - (account: IAccount) - (mode: ServerSelectionMode) - (cancelSourceOption: Option) - : Async> - = - let getBalanceWithoutCaching (maybeUnconfirmedBalanceTaskAlreadyStarted: Option>>): Async> = + let internal GetShowableBalance (account: IAccount) + (mode: ServerSelectionMode) + (cancelSourceOption: Option) + : Async> = + let getBalanceWithoutCaching (maybeUnconfirmedBalanceTaskAlreadyStarted: Option>>) + : Async> = async { let! confirmed = GetBalanceFromServer account BalanceType.Confirmed mode cancelSourceOption @@ -278,13 +274,12 @@ module internal Account = failwith <| SPrintF1 "Assertion failed: Ether currency %A not supported?" currency - let private SignEtherTransaction - (currency: Currency) - (txMetadata: TransactionMetadata) - (destination: string) - (amount: TransferAmount) - (privateKey: EthECKey) - = + let private SignEtherTransaction (currency: Currency) + (txMetadata: TransactionMetadata) + (destination: string) + (amount: TransferAmount) + (privateKey: EthECKey) + = let chain = GetNetwork currency if (GetNetwork txMetadata.Fee.Currency <> chain) then @@ -323,14 +318,13 @@ module internal Account = trans - let private SignEtherTokenTransaction - (currency: Currency) - (txMetadata: TransactionMetadata) - (origin: string) - (destination: string) - (amount: TransferAmount) - (privateKey: EthECKey) - = + let private SignEtherTokenTransaction (currency: Currency) + (txMetadata: TransactionMetadata) + (origin: string) + (destination: string) + (amount: TransferAmount) + (privateKey: EthECKey) + = let chain = GetNetwork currency let privKeyInBytes = privateKey.GetPrivateKeyAsBytes () @@ -349,13 +343,12 @@ module internal Account = signer.SignTransaction (privKeyInBytes, chain, contractAddress, etherValue, nonce, gasPrice, gasLimit, data) - let private SignTransactionWithPrivateKey - (account: IAccount) - (txMetadata: TransactionMetadata) - (destination: string) - (amount: TransferAmount) - (privateKey: EthECKey) - = + let private SignTransactionWithPrivateKey (account: IAccount) + (txMetadata: TransactionMetadata) + (destination: string) + (amount: TransferAmount) + (privateKey: EthECKey) + = let trans = if account.Currency.IsEthToken () then @@ -383,13 +376,12 @@ module internal Account = failwith "Transaction could not be verified?" trans - let SignTransaction - (account: NormalAccount) - (txMetadata: TransactionMetadata) - (destination: string) - (amount: TransferAmount) - (password: string) - = + let SignTransaction (account: NormalAccount) + (txMetadata: TransactionMetadata) + (destination: string) + (amount: TransferAmount) + (password: string) + = let privateKey = GetPrivateKey account password SignTransactionWithPrivateKey account txMetadata destination amount privateKey @@ -397,12 +389,11 @@ module internal Account = let CheckValidPassword (account: NormalAccount) (password: string) = GetPrivateKey account password |> ignore - let SweepArchivedFunds - (account: ArchivedAccount) - (balance: decimal) - (destination: IAccount) - (txMetadata: TransactionMetadata) - = + let SweepArchivedFunds (account: ArchivedAccount) + (balance: decimal) + (destination: IAccount) + (txMetadata: TransactionMetadata) + = let accountFrom = (account :> IAccount) let amount = TransferAmount (balance, balance, accountFrom.Currency) let ecPrivKey = EthECKey (account.GetUnencryptedPrivateKey ()) @@ -412,13 +403,12 @@ module internal Account = BroadcastRawTransaction accountFrom.Currency signedTrans - let SendPayment - (account: NormalAccount) - (txMetadata: TransactionMetadata) - (destination: string) - (amount: TransferAmount) - (password: string) - = + let SendPayment (account: NormalAccount) + (txMetadata: TransactionMetadata) + (destination: string) + (amount: TransferAmount) + (password: string) + = let baseAccount = account :> IAccount if (baseAccount.PublicAddress.Equals (destination, StringComparison.InvariantCultureIgnoreCase)) then raise DestinationEqualToOrigin @@ -451,12 +441,10 @@ module internal Account = let public ExportUnsignedTransactionToJson trans = Marshalling.Serialize trans - let SaveUnsignedTransaction - (transProposal: UnsignedTransactionProposal) - (txMetadata: TransactionMetadata) - (readOnlyAccounts: seq) - : string - = + let SaveUnsignedTransaction (transProposal: UnsignedTransactionProposal) + (txMetadata: TransactionMetadata) + (readOnlyAccounts: seq) + : string = let unsignedTransaction = { diff --git a/src/GWallet.Backend/Ether/EtherServer.fs b/src/GWallet.Backend/Ether/EtherServer.fs index 4a6808f26..c78c57b62 100644 --- a/src/GWallet.Backend/Ether/EtherServer.fs +++ b/src/GWallet.Backend/Ether/EtherServer.fs @@ -286,11 +286,10 @@ module Server = | ServerSelectionMode.Fast -> 3u | ServerSelectionMode.Analysis -> 2u - let private FaultTolerantParallelClientInnerSettings - (numberOfConsistentResponsesRequired: uint32) - (mode: ServerSelectionMode) - maybeConsistencyConfig - = + let private FaultTolerantParallelClientInnerSettings (numberOfConsistentResponsesRequired: uint32) + (mode: ServerSelectionMode) + maybeConsistencyConfig + = let consistencyConfig = match maybeConsistencyConfig with @@ -322,11 +321,10 @@ module Server = FaultTolerantParallelClientInnerSettings numberOfConsistentResponsesRequired mode - let private FaultTolerantParallelClientSettingsForBalanceCheck - (mode: ServerSelectionMode) - (currency: Currency) - (cacheOrInitialBalanceMatchFunc: decimal -> bool) - = + let private FaultTolerantParallelClientSettingsForBalanceCheck (mode: ServerSelectionMode) + (currency: Currency) + (cacheOrInitialBalanceMatchFunc: decimal -> bool) + = let consistencyConfig = if etcEcosystemIsMomentarilyCentralized && currency = Currency.ETC then None @@ -376,16 +374,12 @@ module Server = // FIXME: seems there's some code duplication between this function and UtxoCoinAccount.fs's GetServerFuncs function // and room for simplification to not pass a new ad-hoc delegate? - let GetServerFuncs<'R> - (web3Func: SomeWeb3 -> Async<'R>) - (etherServers: seq) - : seq> - = - let Web3ServerToGenericServer - (web3ClientFunc: SomeWeb3 -> Async<'R>) - (etherServer: ServerDetails) - : Server - = + let GetServerFuncs<'R> (web3Func: SomeWeb3 -> Async<'R>) + (etherServers: seq) + : seq> = + let Web3ServerToGenericServer (web3ClientFunc: SomeWeb3 -> Async<'R>) + (etherServer: ServerDetails) + : Server = { Details = etherServer Retrieval = Web3ServerToRetrievalFunc etherServer web3ClientFunc @@ -394,11 +388,9 @@ module Server = let serverFuncs = Seq.map (Web3ServerToGenericServer web3Func) etherServers serverFuncs - let private GetRandomizedFuncs<'R> - (currency: Currency) - (web3Func: SomeWeb3 -> Async<'R>) - : List> - = + let private GetRandomizedFuncs<'R> (currency: Currency) + (web3Func: SomeWeb3 -> Async<'R>) + : List> = let etherServers = Web3ServerSeedList.Randomize currency GetServerFuncs web3Func etherServers |> List.ofSeq @@ -479,14 +471,12 @@ module Server = | None -> false | Some balance -> someRetrievedBalance = balance - let GetEtherBalance - (currency: Currency) - (address: string) - (balType: BalanceType) - (mode: ServerSelectionMode) - (cancelSourceOption: Option) - : Async - = + let GetEtherBalance (currency: Currency) + (address: string) + (balType: BalanceType) + (mode: ServerSelectionMode) + (cancelSourceOption: Option) + : Async = async { let web3Funcs = let web3Func (web3: Web3): Async = @@ -549,14 +539,12 @@ module Server = } - let GetTokenBalance - (currency: Currency) - (address: string) - (balType: BalanceType) - (mode: ServerSelectionMode) - (cancelSourceOption: Option) - : Async - = + let GetTokenBalance (currency: Currency) + (address: string) + (balType: BalanceType) + (mode: ServerSelectionMode) + (cancelSourceOption: Option) + : Async = async { let web3Funcs = let web3Func (web3: Web3): Async = @@ -678,11 +666,9 @@ module Server = return raise (FSharpUtil.ReRaise ex) } - let private GetTransactionDetailsFromTransactionReceipt - (currency: Currency) - (txHash: string) - : Async - = + let private GetTransactionDetailsFromTransactionReceipt (currency: Currency) + (txHash: string) + : Async = async { let web3Funcs = let web3Func (web3: Web3): Async = diff --git a/src/GWallet.Backend/FSharpUtil.fs b/src/GWallet.Backend/FSharpUtil.fs index 7082440d5..2f18a361d 100644 --- a/src/GWallet.Backend/FSharpUtil.fs +++ b/src/GWallet.Backend/FSharpUtil.fs @@ -182,6 +182,7 @@ module FSharpUtil = let! allJobsStarted = allJobsInParallel let! _ = Async.AwaitTask taskSource.Task + return allJobsStarted } diff --git a/src/GWallet.Backend/FaultTolerantParallelClient.fs b/src/GWallet.Backend/FaultTolerantParallelClient.fs index 9973f8e82..bcbfa9f60 100644 --- a/src/GWallet.Backend/FaultTolerantParallelClient.fs +++ b/src/GWallet.Backend/FaultTolerantParallelClient.fs @@ -96,7 +96,9 @@ type MutableStateUnsafeAccessor<'T> (initialState: 'T) = type MutableStateCapsule<'T> (initialState: 'T) = let state = MutableStateUnsafeAccessor initialState let lockObject = Object () - member __.SafeDo (func: MutableStateUnsafeAccessor<'T> -> 'R): 'R = lock lockObject (fun _ -> func state) + + member __.SafeDo (func: MutableStateUnsafeAccessor<'T> -> 'R): 'R = + lock lockObject (fun _ -> func state) type ServerJob<'K, 'R when 'K: equality and 'K :> ICommunicationHistory> = { @@ -303,17 +305,15 @@ type FaultTolerantParallelClient<'K, 'E when 'K: equality and 'K :> ICommunicati serverTask - let rec WhenSomeInternal - (consistencySettings: Option>) - (initialServerCount: uint32) - (startedTasks: List>) - (jobsToLaunchLater: List>) - (resultsSoFar: List<'R>) - (failedFuncsSoFar: List>) - (cancellationSource: Option) - (cancelState: ClientCancelState) - : Async> - = + let rec WhenSomeInternal (consistencySettings: Option>) + (initialServerCount: uint32) + (startedTasks: List>) + (jobsToLaunchLater: List>) + (resultsSoFar: List<'R>) + (failedFuncsSoFar: List>) + (cancellationSource: Option) + (cancelState: ClientCancelState) + : Async> = async { if startedTasks = List.Empty then return InconsistentOrNotEnoughResults @@ -448,15 +448,13 @@ type FaultTolerantParallelClient<'K, 'E when 'K: equality and 'K :> ICommunicati // "Async.WhenAny" in TomasP's tryJoinads source code, however it seemed a bit complex for me to wrap my head around // it (and I couldn't just consume it and call it a day, I had to modify it to be "WhenSome" instead of "WhenAny", // as in when N>1), so I decided to write my own, using Tasks to make sure I would not spawn duplicate jobs - let WhenSome - (settings: FaultTolerantParallelClientSettings<'R>) - consistencyConfig - (funcs: List>) - (resultsSoFar: List<'R>) - (failedFuncsSoFar: List>) - (cancellationSource: Option) - : Async> - = + let WhenSome (settings: FaultTolerantParallelClientSettings<'R>) + consistencyConfig + (funcs: List>) + (resultsSoFar: List<'R>) + (failedFuncsSoFar: List>) + (cancellationSource: Option) + : Async> = let initialServerCount = funcs.Length |> uint32 @@ -526,17 +524,15 @@ type FaultTolerantParallelClient<'K, 'E when 'K: equality and 'K :> ICommunicati jobWithCancellation - let rec QueryInternalImplementation - (settings: FaultTolerantParallelClientSettings<'R>) - (initialFuncCount: uint32) - (funcs: List>) - (resultsSoFar: List<'R>) - (failedFuncsSoFar: List>) - (retries: uint32) - (retriesForInconsistency: uint32) - (cancellationSource: Option) - : Async<'R> - = + let rec QueryInternalImplementation (settings: FaultTolerantParallelClientSettings<'R>) + (initialFuncCount: uint32) + (funcs: List>) + (resultsSoFar: List<'R>) + (failedFuncsSoFar: List>) + (retries: uint32) + (retriesForInconsistency: uint32) + (cancellationSource: Option) + : Async<'R> = async { if not (funcs.Any ()) then return raise (ArgumentException ("number of funcs must be higher than zero", "funcs")) diff --git a/src/GWallet.Backend/Properties/AssemblyInfo.fs b/src/GWallet.Backend/Properties/AssemblyInfo.fs index 6aad0ab41..1f7acbf3d 100644 --- a/src/GWallet.Backend/Properties/AssemblyInfo.fs +++ b/src/GWallet.Backend/Properties/AssemblyInfo.fs @@ -15,9 +15,11 @@ open System.Runtime.InteropServices // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. + [] // The following GUID is for the ID of the typelib if this project is exposed to COM + [] do () diff --git a/src/GWallet.Backend/Properties/CommonAssemblyInfo.fs b/src/GWallet.Backend/Properties/CommonAssemblyInfo.fs index 059059c91..5f6fc0893 100644 --- a/src/GWallet.Backend/Properties/CommonAssemblyInfo.fs +++ b/src/GWallet.Backend/Properties/CommonAssemblyInfo.fs @@ -17,6 +17,7 @@ open System.Reflection // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [] + [] [] diff --git a/src/GWallet.Backend/Server.fs b/src/GWallet.Backend/Server.fs index 8b629922e..4e0693b4c 100644 --- a/src/GWallet.Backend/Server.fs +++ b/src/GWallet.Backend/Server.fs @@ -79,11 +79,9 @@ module ServerRegistry = let ServersEmbeddedResourceFileName = "servers.json" - let internal TryFindValue - (map: ServerRanking) - (serverPredicate: ServerDetails -> bool) - : Option - = + let internal TryFindValue (map: ServerRanking) + (serverPredicate: ServerDetails -> bool) + : Option = let rec tryFind currencyAndServers server = match currencyAndServers with | [] -> None diff --git a/src/GWallet.Backend/UtxoCoin/ElectrumClient.fs b/src/GWallet.Backend/UtxoCoin/ElectrumClient.fs index 381d5573e..ffca625a7 100644 --- a/src/GWallet.Backend/UtxoCoin/ElectrumClient.fs +++ b/src/GWallet.Backend/UtxoCoin/ElectrumClient.fs @@ -107,6 +107,8 @@ module ElectrumClient = (SPrintF1 "Fee estimation returned an invalid non-positive value %M" estimateFeeResult.Result) + + return estimateFeeResult.Result } diff --git a/src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs b/src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs index 229fae5f5..3a6cffbe1 100644 --- a/src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs +++ b/src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs @@ -18,7 +18,8 @@ type internal TransactionOutpoint = OutputIndex: int } - member self.ToCoin (): Coin = Coin (self.Transaction, uint32 self.OutputIndex) + member self.ToCoin (): Coin = + Coin (self.Transaction, uint32 self.OutputIndex) type internal IUtxoAccount = inherit IAccount @@ -120,12 +121,10 @@ module Account = let amountInBtc = (Money.Satoshis amountToShowInSatoshis).ToUnit MoneyUnit.BTC amountInBtc - let private BalanceMatchWithCacheOrInitialBalance - address - currency - (someRetrievedBalance: BlockchainScriptHashGetBalanceInnerResult) - : bool - = + let private BalanceMatchWithCacheOrInitialBalance address + currency + (someRetrievedBalance: BlockchainScriptHashGetBalanceInnerResult) + : bool = if Caching.Instance.FirstRun then BalanceToShow someRetrievedBalance = 0m else @@ -133,12 +132,10 @@ module Account = | None -> false | Some balance -> BalanceToShow someRetrievedBalance = balance - let private GetBalances - (account: IUtxoAccount) - (mode: ServerSelectionMode) - (cancelSourceOption: Option) - : Async - = + let private GetBalances (account: IUtxoAccount) + (mode: ServerSelectionMode) + (cancelSourceOption: Option) + : Async = let scriptHashHex = GetElectrumScriptHashFromPublicAddress account.Currency account.PublicAddress let querySettings = @@ -147,12 +144,10 @@ module Account = let balanceJob = ElectrumClient.GetBalance scriptHashHex Server.Query account.Currency querySettings balanceJob cancelSourceOption - let private GetBalancesFromServer - (account: IUtxoAccount) - (mode: ServerSelectionMode) - (cancelSourceOption: Option) - : Async> - = + let private GetBalancesFromServer (account: IUtxoAccount) + (mode: ServerSelectionMode) + (cancelSourceOption: Option) + : Async> = async { try let! balances = GetBalances account mode cancelSourceOption @@ -160,12 +155,10 @@ module Account = with ex when (FSharpUtil.FindException ex).IsSome -> return None } - let internal GetShowableBalance - (account: IUtxoAccount) - (mode: ServerSelectionMode) - (cancelSourceOption: Option) - : Async> - = + let internal GetShowableBalance (account: IUtxoAccount) + (mode: ServerSelectionMode) + (cancelSourceOption: Option) + : Async> = async { let! maybeBalances = GetBalancesFromServer account mode cancelSourceOption @@ -184,13 +177,11 @@ module Account = coin.ToScriptCoin account.PublicKey.WitHash.ScriptPubKey :> ICoin - let private CreateTransactionAndCoinsToBeSigned - (account: IUtxoAccount) - (transactionInputs: List) - (destination: string) - (amount: TransferAmount) - : TransactionBuilder - = + let private CreateTransactionAndCoinsToBeSigned (account: IUtxoAccount) + (transactionInputs: List) + (destination: string) + (amount: TransferAmount) + : TransactionBuilder = let coins = List.map (ConvertToICoin account) transactionInputs let transactionBuilder = (GetNetwork account.Currency).CreateTransactionBuilder() @@ -221,11 +212,9 @@ module Account = Value: Int64 } - let private ConvertToInputOutpointInfo - currency - (utxo: UnspentTransactionOutputInfo) - : Async - = + let private ConvertToInputOutpointInfo currency + (utxo: UnspentTransactionOutputInfo) + : Async = async { let job = ElectrumClient.GetBlockchainTransaction utxo.TransactionId let! transRaw = Server.Query currency (QuerySettings.Default ServerSelectionMode.Fast) job None @@ -245,14 +234,12 @@ module Account = return ret } - let rec private EstimateFees - (txBuilder: TransactionBuilder) - (feeRate: FeeRate) - (account: IUtxoAccount) - (usedInputsSoFar: List) - (unusedUtxos: List) - : Async> - = + let rec private EstimateFees (txBuilder: TransactionBuilder) + (feeRate: FeeRate) + (account: IUtxoAccount) + (usedInputsSoFar: List) + (unusedUtxos: List) + : Async> = async { try let fees = txBuilder.EstimateFees feeRate @@ -266,24 +253,21 @@ module Account = let newCoin = newInput |> ConvertToICoin account let newTxBuilder = txBuilder.AddCoins [ newCoin ] + let newInputs = newInput :: usedInputsSoFar return! EstimateFees newTxBuilder feeRate account newInputs tail } - let internal EstimateFee - (account: IUtxoAccount) - (amount: TransferAmount) - (destination: string) - : Async - = + let internal EstimateFee (account: IUtxoAccount) + (amount: TransferAmount) + (destination: string) + : Async = async { - let rec addInputsUntilAmount - (utxos: List) - soFarInSatoshis - amount - (acc: List) - : List * List - = + let rec addInputsUntilAmount (utxos: List) + soFarInSatoshis + amount + (acc: List) + : List * List = match utxos with | [] -> // should `raise InsufficientFunds` instead? @@ -386,13 +370,12 @@ module Account = with :? NBitcoin.NotEnoughFundsException -> return raise <| InsufficientBalanceForFee None } - let private SignTransactionWithPrivateKey - (account: IUtxoAccount) - (txMetadata: TransactionMetadata) - (destination: string) - (amount: TransferAmount) - (privateKey: Key) - = + let private SignTransactionWithPrivateKey (account: IUtxoAccount) + (txMetadata: TransactionMetadata) + (destination: string) + (amount: TransferAmount) + (privateKey: Key) + = let btcMinerFee = txMetadata.Fee @@ -422,13 +405,12 @@ module Account = encryptedSecret.GetKey (password) with :? SecurityException -> raise (InvalidPassword) - let internal SignTransaction - (account: NormalUtxoAccount) - (txMetadata: TransactionMetadata) - (destination: string) - (amount: TransferAmount) - (password: string) - = + let internal SignTransaction (account: NormalUtxoAccount) + (txMetadata: TransactionMetadata) + (destination: string) + (amount: TransferAmount) + (password: string) + = let privateKey = GetPrivateKey account password @@ -448,13 +430,12 @@ module Account = // and show the info from the RawTx, using NBitcoin to extract it BroadcastRawTransaction currency transaction.RawTransaction - let internal SendPayment - (account: NormalUtxoAccount) - (txMetadata: TransactionMetadata) - (destination: string) - (amount: TransferAmount) - (password: string) - = + let internal SendPayment (account: NormalUtxoAccount) + (txMetadata: TransactionMetadata) + (destination: string) + (amount: TransferAmount) + (password: string) + = let baseAccount = account :> IAccount if (baseAccount.PublicAddress.Equals (destination, StringComparison.InvariantCultureIgnoreCase)) then raise DestinationEqualToOrigin @@ -466,12 +447,10 @@ module Account = let public ExportUnsignedTransactionToJson trans = Marshalling.Serialize trans - let internal SaveUnsignedTransaction - (transProposal: UnsignedTransactionProposal) - (txMetadata: TransactionMetadata) - (readOnlyAccounts: seq) - : string - = + let internal SaveUnsignedTransaction (transProposal: UnsignedTransactionProposal) + (txMetadata: TransactionMetadata) + (readOnlyAccounts: seq) + : string = let unsignedTransaction = { @@ -482,12 +461,11 @@ module Account = ExportUnsignedTransactionToJson unsignedTransaction - let internal SweepArchivedFunds - (account: ArchivedUtxoAccount) - (balance: decimal) - (destination: IAccount) - (txMetadata: TransactionMetadata) - = + let internal SweepArchivedFunds (account: ArchivedUtxoAccount) + (balance: decimal) + (destination: IAccount) + (txMetadata: TransactionMetadata) + = let currency = (account :> IAccount).Currency let network = GetNetwork currency let amount = TransferAmount (balance, balance, currency) diff --git a/src/GWallet.Backend/UtxoCoin/UtxoCoinServer.fs b/src/GWallet.Backend/UtxoCoin/UtxoCoinServer.fs index 6348ba20c..f77ac70a4 100644 --- a/src/GWallet.Backend/UtxoCoin/UtxoCoinServer.fs +++ b/src/GWallet.Backend/UtxoCoin/UtxoCoinServer.fs @@ -46,10 +46,9 @@ module Server = ServerSelectionMode.Fast (Some (SpecificNumberOfConsistentResponsesRequired 1u)) - let private FaultTolerantParallelClientSettingsForBalanceCheck - (mode: ServerSelectionMode) - cacheOrInitialBalanceMatchFunc - = + let private FaultTolerantParallelClientSettingsForBalanceCheck (mode: ServerSelectionMode) + cacheOrInitialBalanceMatchFunc + = let consistencyConfig = if mode = ServerSelectionMode.Fast then Some (OneServerConsistentWithCertainValueOrTwoServers cacheOrInitialBalanceMatchFunc) @@ -63,17 +62,13 @@ module Server = // FIXME: seems there's some code duplication between this function and EtherServer.fs's GetServerFuncs function // and room for simplification to not pass a new ad-hoc delegate? - let internal GetServerFuncs<'R> - (electrumClientFunc: Async -> Async<'R>) - (electrumServers: seq) - : seq> - = - - let ElectrumServerToRetrievalFunc - (server: ServerDetails) - (electrumClientFunc: Async -> Async<'R>) - : Async<'R> - = + let internal GetServerFuncs<'R> (electrumClientFunc: Async -> Async<'R>) + (electrumServers: seq) + : seq> = + + let ElectrumServerToRetrievalFunc (server: ServerDetails) + (electrumClientFunc: Async -> Async<'R>) + : Async<'R> = async { try let stratumClient = ElectrumClient.StratumServer server @@ -90,11 +85,9 @@ module Server = (SPrintF1 "Some problem when connecting to %s" server.ServerInfo.NetworkPath, ex) } - let ElectrumServerToGenericServer - (electrumClientFunc: Async -> Async<'R>) - (electrumServer: ServerDetails) - : Server - = + let ElectrumServerToGenericServer (electrumClientFunc: Async -> Async<'R>) + (electrumServer: ServerDetails) + : Server = { Details = electrumServer Retrieval = ElectrumServerToRetrievalFunc electrumServer electrumClientFunc @@ -103,22 +96,18 @@ module Server = let serverFuncs = Seq.map (ElectrumServerToGenericServer electrumClientFunc) electrumServers serverFuncs - let private GetRandomizedFuncs<'R> - (currency: Currency) - (electrumClientFunc: Async -> Async<'R>) - : List> - = + let private GetRandomizedFuncs<'R> (currency: Currency) + (electrumClientFunc: Async -> Async<'R>) + : List> = let electrumServers = ElectrumServerSeedList.Randomize currency GetServerFuncs electrumClientFunc electrumServers |> List.ofSeq - let Query<'R when 'R: equality> - currency - (settings: QuerySettings<'R>) - (job: Async -> Async<'R>) - (cancelSourceOption: Option) - : Async<'R> - = + let Query<'R when 'R: equality> currency + (settings: QuerySettings<'R>) + (job: Async -> Async<'R>) + (cancelSourceOption: Option) + : Async<'R> = let query = match cancelSourceOption with | None -> faultTolerantElectrumClient.Query