Skip to content

Commit

Permalink
Backend: format with fantomas v4.5.3
Browse files Browse the repository at this point in the history
Command to install: dotnet tool install --global fantomas-tool --version 4.5.3
Command to run: fantomas --recurse src/GWallet.Backend/
(or $HOME/.dotnet/tools/fantomas in case of running from CI)

Fantomas bugs that geewallet would benefit from, if fixed:

* fsprojects/fantomas#1901

* fsprojects/fantomas#1469

* fsprojects/fantomas#712

* fsprojects/fantomas#684

* fsprojects/fantomas#815

* fsprojects/fantomas#1442

* fsprojects/fantomas#1233

* fsprojects/fantomas#1223

* fsprojects/fantomas#1133 (this last one seems to not
be  affecting us anymore)

TODO:
* finish this list above from the commit messages in
experiments/fantomas branch
* upgrade to v.NEXT (after 4.5.3, so 4.5.4?) to see if
our vanity alignment has been fixed in our exceptions
  • Loading branch information
knocte committed Sep 27, 2021
1 parent 9fbf91e commit 7d9e1aa
Show file tree
Hide file tree
Showing 40 changed files with 6,194 additions and 3,357 deletions.
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[*.fs]
end_of_line=lf
indent_size=4
max_line_length=80
fsharp_indent_on_try_with=false
fsharp_max_if_then_else_short_width=0
fsharp_max_infix_operator_expression=80
fsharp_max_function_binding_width=0
fsharp_max_record_width=0
fsharp_max_value_binding_width=80
fsharp_multiline_block_brackets_on_same_column=true
fsharp_multi_line_lambda_closing_newline=true
fsharp_newline_between_type_definition_and_members=true
fsharp_semicolon_at_end_of_line=false
fsharp_space_after_comma=true
fsharp_space_before_class_constructor=true
fsharp_space_before_colon=false
fsharp_space_before_lowercase_invocation=true
fsharp_space_before_member=true
fsharp_space_before_parameter=true
fsharp_space_before_semicolon=false
fsharp_space_before_uppercase_invocation=true
fsharp_space_after_semicolon=true
fsharp_space_around_delimiter=true
fsharp_strict_mode=false
fsharp_disable_elmish_syntax=true
1,068 changes: 712 additions & 356 deletions src/GWallet.Backend/Account.fs

Large diffs are not rendered by default.

69 changes: 43 additions & 26 deletions src/GWallet.Backend/AccountTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ type WatchWalletInfo =

type FileRepresentation =
{
Name: string;
Content: unit->string;
Name: string
Content: unit -> string
}

static member FromFile (file: FileInfo) =
{
Name = Path.GetFileName file.FullName
Expand All @@ -21,59 +22,75 @@ type FileRepresentation =

type ConceptAccount =
{
Currency: Currency;
FileRepresentation: FileRepresentation;
ExtractPublicAddressFromConfigFileFunc: FileRepresentation->string;
Currency: Currency
FileRepresentation: FileRepresentation
ExtractPublicAddressFromConfigFileFunc: FileRepresentation -> string
}

type AccountKind =
| Normal
| ReadOnly
| Archived
static member All() =

static member All () =
seq {
yield Normal
yield ReadOnly
yield Archived
}

type IAccount =
abstract Currency: Currency
abstract PublicAddress: string
abstract Currency : Currency
abstract PublicAddress : string

[<AbstractClass>]
type BaseAccount(currency: Currency, accountFile: FileRepresentation,
fromAccountFileToPublicAddress: FileRepresentation -> string) =
type BaseAccount
(
currency: Currency,
accountFile: FileRepresentation,
fromAccountFileToPublicAddress: FileRepresentation -> string
) =
member val AccountFile = accountFile

abstract Kind: AccountKind
abstract Kind : AccountKind

interface IAccount with
member val Currency = currency
member val PublicAddress =
fromAccountFileToPublicAddress accountFile
member val PublicAddress = fromAccountFileToPublicAddress accountFile


type NormalAccount(currency: Currency, accountFile: FileRepresentation,
fromAccountFileToPublicAddress: FileRepresentation -> string) =
inherit BaseAccount(currency, accountFile, fromAccountFileToPublicAddress)
type NormalAccount
(
currency: Currency,
accountFile: FileRepresentation,
fromAccountFileToPublicAddress: FileRepresentation -> string
) =
inherit BaseAccount (currency, accountFile, fromAccountFileToPublicAddress)

member internal __.GetEncryptedPrivateKey() =
accountFile.Content()
member internal __.GetEncryptedPrivateKey () =
accountFile.Content ()

override __.Kind = AccountKind.Normal

type ReadOnlyAccount(currency: Currency, accountFile: FileRepresentation,
fromAccountFileToPublicAddress: FileRepresentation -> string) =
inherit BaseAccount(currency, accountFile, fromAccountFileToPublicAddress)
type ReadOnlyAccount
(
currency: Currency,
accountFile: FileRepresentation,
fromAccountFileToPublicAddress: FileRepresentation -> string
) =
inherit BaseAccount (currency, accountFile, fromAccountFileToPublicAddress)

override __.Kind = AccountKind.ReadOnly

type ArchivedAccount(currency: Currency, accountFile: FileRepresentation,
fromAccountFileToPublicAddress: FileRepresentation -> string) =
inherit BaseAccount(currency, accountFile, fromAccountFileToPublicAddress)
type ArchivedAccount
(
currency: Currency,
accountFile: FileRepresentation,
fromAccountFileToPublicAddress: FileRepresentation -> string
) =
inherit BaseAccount (currency, accountFile, fromAccountFileToPublicAddress)

member internal __.GetUnencryptedPrivateKey() =
accountFile.Content()
member internal __.GetUnencryptedPrivateKey () =
accountFile.Content ()

override __.Kind = AccountKind.Archived
14 changes: 7 additions & 7 deletions src/GWallet.Backend/BinaryMarshalling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ open System.Runtime.Serialization.Formatters.Binary

module BinaryMarshalling =

let private binFormatter = BinaryFormatter()
let private binFormatter = BinaryFormatter ()

let Serialize obj: array<byte> =
use memStream = new MemoryStream()
binFormatter.Serialize(memStream, obj)
memStream.ToArray()
let Serialize obj : array<byte> =
use memStream = new MemoryStream ()
binFormatter.Serialize (memStream, obj)
memStream.ToArray ()

let Deserialize (buffer: array<byte>) =
use memStream = new MemoryStream(buffer)
use memStream = new MemoryStream (buffer)
memStream.Position <- 0L
binFormatter.Deserialize memStream

let SerializeToString obj: string =
let SerializeToString obj : string =
let byteArray = Serialize obj
Convert.ToBase64String byteArray

Expand Down
61 changes: 31 additions & 30 deletions src/GWallet.Backend/BlockExplorer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,37 @@ open GWallet.Backend.FSharpUtil.UwpHacks

module BlockExplorer =

let GetTransactionHistory (account: IAccount): Uri =
let GetTransactionHistory (account: IAccount) : Uri =
let baseUrl =
match account.Currency with
| Currency.BTC ->
// SmartBit explorer is built on top of NBitcoin: https://github.com/ProgrammingBlockchain/ProgrammingBlockchain/issues/1
"https://www.smartbit.com.au/address/"
| Currency.LTC ->
// because the more popular https://live.blockcypher.com/ltc/ doesn't seem to have segwit support
"https://chainz.cryptoid.info/ltc/address.dws?"
| Currency.ETH ->
// most popular one...
"https://etherscan.io/address/"
| Currency.ETC ->
// maybe blockscout is better? minergate.com seems to only show blocks, not addresses
"https://etcblockexplorer.com/address/addr/"
| Currency.SAI | Currency.DAI ->
SPrintF1 "https://etherscan.io/token/%s?a=" (TokenManager.GetTokenContractAddress account.Currency)
Uri(baseUrl + account.PublicAddress)
match account.Currency with
| Currency.BTC ->
// SmartBit explorer is built on top of NBitcoin: https://github.com/ProgrammingBlockchain/ProgrammingBlockchain/issues/1
"https://www.smartbit.com.au/address/"
| Currency.LTC ->
// because the more popular https://live.blockcypher.com/ltc/ doesn't seem to have segwit support
"https://chainz.cryptoid.info/ltc/address.dws?"
| Currency.ETH ->
// most popular one...
"https://etherscan.io/address/"
| Currency.ETC ->
// maybe blockscout is better? minergate.com seems to only show blocks, not addresses
"https://etcblockexplorer.com/address/addr/"
| Currency.SAI
| Currency.DAI ->
SPrintF1
"https://etherscan.io/token/%s?a="
(TokenManager.GetTokenContractAddress account.Currency)

let GetTransaction (currency: Currency) (txHash: string): Uri =
Uri (baseUrl + account.PublicAddress)

let GetTransaction (currency: Currency) (txHash: string) : Uri =
let baseUrl =
match currency with
| Currency.BTC ->
"https://www.smartbit.com.au/tx/"
| Currency.LTC ->
"https://chainz.cryptoid.info/ltc/tx.dws?"
| Currency.ETH ->
"https://etherscan.io/tx/"
| Currency.ETC ->
"https://etcblockexplorer.com/tx/"
| Currency.DAI | Currency.SAI ->
"https://etherscan.io/tx/"
Uri(baseUrl + txHash)
match currency with
| Currency.BTC -> "https://www.smartbit.com.au/tx/"
| Currency.LTC -> "https://chainz.cryptoid.info/ltc/tx.dws?"
| Currency.ETH -> "https://etherscan.io/tx/"
| Currency.ETC -> "https://etcblockexplorer.com/tx/"
| Currency.DAI
| Currency.SAI -> "https://etherscan.io/tx/"

Uri (baseUrl + txHash)
Loading

0 comments on commit 7d9e1aa

Please sign in to comment.