Skip to content

Commit

Permalink
Update fantomas to 4.3.0-alpha-002-alpha-043
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.3.0-alpha-002-alpha-043

New bugs:
fsprojects/fantomas#1223
fsprojects/fantomas#1226
fsprojects/fantomas#1220
fsprojects/fantomas#1219
fsprojects/fantomas#1222
  • Loading branch information
knocte committed Nov 10, 2020
1 parent 2a7d5ec commit a07b4f0
Show file tree
Hide file tree
Showing 20 changed files with 1,179 additions and 1,007 deletions.
296 changes: 156 additions & 140 deletions src/GWallet.Backend/Account.fs

Large diffs are not rendered by default.

498 changes: 264 additions & 234 deletions src/GWallet.Backend/Caching.fs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/GWallet.Backend/Currency.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ type Currency =
#endif

static member Parse (currencyString: string): Currency =
Currency.GetAll().First(fun currency -> currencyString = currency.ToString ())
Currency
.GetAll()
.First(fun currency -> currencyString = currency.ToString ())

member self.IsEther () =
self = Currency.ETC || self = Currency.ETH
Expand Down
180 changes: 91 additions & 89 deletions src/GWallet.Backend/Ether/EtherAccount.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ module internal Account =
if not (currency.IsEtherBased ()) then
failwith
<| SPrintF1 "Assertion failed: currency %A should be Ether-type" currency

match kind with
| AccountKind.ReadOnly ->
ReadOnlyAccount (currency, accountFile, (fun accountFile -> accountFile.Name)) :> IAccount
| 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<CustomCancelSource>)
=
let private GetBalance (account: IAccount)
(mode: ServerSelectionMode)
(balType: BalanceType)
(cancelSourceOption: Option<CustomCancelSource>)
=
async {
let! balance =
if (account.Currency.IsEther ()) then
Expand All @@ -66,27 +66,25 @@ module internal Account =
return balance
}

let private GetBalanceFromServer
(account: IAccount)
(balType: BalanceType)
(mode: ServerSelectionMode)
(cancelSourceOption: Option<CustomCancelSource>)
: Async<Option<decimal>>
=
let private GetBalanceFromServer (account: IAccount)
(balType: BalanceType)
(mode: ServerSelectionMode)
(cancelSourceOption: Option<CustomCancelSource>)
: Async<Option<decimal>> =
async {
try
let! balance = GetBalance account mode balType cancelSourceOption
return Some balance
with ex when (FSharpUtil.FindException<ResourceUnavailabilityException> ex).IsSome -> return None
with ex when (FSharpUtil.FindException<ResourceUnavailabilityException> ex)
.IsSome -> return None
}

let internal GetShowableBalance
(account: IAccount)
(mode: ServerSelectionMode)
(cancelSourceOption: Option<CustomCancelSource>)
: Async<Option<decimal>>
=
let getBalanceWithoutCaching (maybeUnconfirmedBalanceTaskAlreadyStarted: Option<Task<Option<decimal>>>): Async<Option<decimal>> =
let internal GetShowableBalance (account: IAccount)
(mode: ServerSelectionMode)
(cancelSourceOption: Option<CustomCancelSource>)
: Async<Option<decimal>> =
let getBalanceWithoutCaching (maybeUnconfirmedBalanceTaskAlreadyStarted: Option<Task<Option<decimal>>>)
: Async<Option<decimal>> =
async {
let! confirmed = GetBalanceFromServer account BalanceType.Confirmed mode cancelSourceOption

Expand Down Expand Up @@ -162,7 +160,7 @@ module internal Account =
failwith
<| SPrintF1
"Serialization doesn't support such a big integer (%s) for the nonce, please report this issue."
(result.ToString ())
(result.ToString ())

let int64result: Int64 = BigInteger.op_Explicit value

Expand All @@ -177,7 +175,7 @@ module internal Account =
failwith
<| SPrintF1
"Serialization doesn't support such a big integer (%s) for the gas, please report this issue."
(gasPrice.Value.ToString ())
(gasPrice.Value.ToString ())

let gasPrice64: Int64 = BigInteger.op_Explicit gasPrice.Value

Expand All @@ -197,15 +195,15 @@ module internal Account =

let feeValue = ethMinerFee.CalculateAbsoluteValue ()

if (amount.ValueToSend
<> amount.BalanceAtTheMomentOfSending
if (amount.ValueToSend <> amount.BalanceAtTheMomentOfSending
&& feeValue > (amount.BalanceAtTheMomentOfSending - amount.ValueToSend)) then
raise <| InsufficientBalanceForFee (Some feeValue)

return {
Ether.Fee = ethMinerFee
Ether.TransactionCount = txCount
}
return
{
Ether.Fee = ethMinerFee
Ether.TransactionCount = txCount
}
}

// FIXME: this should raise InsufficientBalanceForFee
Expand All @@ -225,18 +223,19 @@ module internal Account =
failwith
<| SPrintF1
"Serialization doesn't support such a big integer (%s) for the gas cost of the token transfer, please report this issue."
(tokenTransferFee.Value.ToString ())
(tokenTransferFee.Value.ToString ())

let gasCost64: Int64 = BigInteger.op_Explicit tokenTransferFee.Value

let ethMinerFee = MinerFee (gasCost64, gasPrice64, DateTime.UtcNow, baseCurrency)

let! txCount = GetTransactionCount account.Currency account.PublicAddress

return {
Ether.Fee = ethMinerFee
Ether.TransactionCount = txCount
}
return
{
Ether.Fee = ethMinerFee
Ether.TransactionCount = txCount
}
}

let EstimateFee (account: IAccount) (amount: TransferAmount) destination: Async<TransactionMetadata> =
Expand All @@ -246,8 +245,9 @@ module internal Account =
elif account.Currency.IsEthToken () then
return! EstimateTokenTransferFee account amount.ValueToSend destination
else
return failwith
<| SPrintF1 "Assertion failed: currency %A should be Ether or Ether token" account.Currency
return
failwith
<| SPrintF1 "Assertion failed: currency %A should be Ether or Ether token" account.Currency
}

let private BroadcastRawTransaction (currency: Currency) trans =
Expand All @@ -270,6 +270,7 @@ module internal Account =
if not (currency.IsEtherBased ()) then
failwith
<| SPrintF1 "Assertion failed: currency %A should be Ether-type" currency

if currency.IsEthToken () || currency = ETH then
Config.EthNet
elif currency = ETC then
Expand All @@ -278,22 +279,22 @@ 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
invalidArg
"chain"
(SPrintF2
"Assertion failed: fee currency (%A) chain doesn't match with passed chain (%A)"
txMetadata.Fee.Currency
chain)
txMetadata.Fee.Currency
chain)

let amountToSendConsideringMinerFee =
if (amount.ValueToSend = amount.BalanceAtTheMomentOfSending) then
Expand Down Expand Up @@ -323,14 +324,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 ()
Expand All @@ -349,13 +349,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
Expand All @@ -371,38 +370,39 @@ module internal Account =
failwith
<| SPrintF2
"Assertion failed: fee currency (%A) doesn't match with passed chain (%A)"
txMetadata.Fee.Currency
account.Currency
txMetadata.Fee.Currency
account.Currency

SignEtherTransaction account.Currency txMetadata destination amount privateKey
else
failwith
<| SPrintF1 "Assertion failed: Ether currency %A not supported?" account.Currency

let chain = GetNetwork account.Currency

if not (signer.VerifyTransaction (trans, chain)) then
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

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 ())
Expand All @@ -412,14 +412,14 @@ 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

Expand All @@ -432,6 +432,7 @@ module internal Account =
let private CreateInternal (password: string) (seed: array<byte>): FileRepresentation =
let privateKey = EthECKey (seed, true)
let publicAddress = privateKey.GetPublicAddress ()

if not (addressUtil.IsChecksumAddress (publicAddress)) then
failwith ("Nethereum's GetPublicAddress gave a non-checksum address: " + publicAddress)

Expand All @@ -451,17 +452,18 @@ module internal Account =
let public ExportUnsignedTransactionToJson trans =
Marshalling.Serialize trans

let SaveUnsignedTransaction
(transProposal: UnsignedTransactionProposal)
(txMetadata: TransactionMetadata)
(readOnlyAccounts: seq<ReadOnlyAccount>)
: string
=
let SaveUnsignedTransaction (transProposal: UnsignedTransactionProposal)
(txMetadata: TransactionMetadata)
(readOnlyAccounts: seq<ReadOnlyAccount>)
: string =

let unsignedTransaction =
{
Proposal = transProposal
Cache = Caching.Instance.GetLastCachedData().ToDietCache readOnlyAccounts
Cache =
Caching
.Instance
.GetLastCachedData().ToDietCache readOnlyAccounts
Metadata = txMetadata
}

Expand Down
Loading

0 comments on commit a07b4f0

Please sign in to comment.