Skip to content

Commit

Permalink
Add fantomas configuration file
Browse files Browse the repository at this point in the history
This version of fantomas doesn't crash anymore when formatting it:
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-alpha-012

Source will be formatted using this command:
fantomas --recurse src/GWallet.Backend/

Things that would need to be fixed manually before merging this to master:
- We can drop parens in many if statements, e.g.: StratumClient.fs'
CreateVersion's, ServerManager.fs' GetDummyBalanceAction, FTPC.fs'
FTPC type, EtherAccount.fs' GetTransactionCount
- Drop parents in ReadAllText calls of Account.fs
- Many raise lines should use <|, e.g. in WarpKey.fs, UtxoCoinAccount.fs,
and ElectrumServer.fs
- UtxoCoinAccount.fs' EstimateFees unneeded use of |> with 'head'

Fantomas issues from geewallet's wishlist:
- fsprojects/fantomas#712
- fsprojects/fantomas#684
- fsprojects/fantomas#964
- fsprojects/fantomas#1218

Issues not yet reported:
- There should be a setting called AlwaysSplitPipeOperatorInNewLine? but I actually don't understand
the consistency of this:
```
        use webClient = new WebClient()
        let serverListInJson = webClient.DownloadString urlToElectrumJsonFile
        ExtractServerListFromElectrumJsonFile serverListInJson
-           |> Seq.filter FilterCompatibleServer
+       |> Seq.filter FilterCompatibleServer

-    let DefaultBtcList =
-        Caching.Instance.GetServers Currency.BTC
-            |> List.ofSeq
+    let DefaultBtcList = Caching.Instance.GetServers Currency.BTC |> List.ofSeq
```
- MaxLineLength not being respected? look at how long some lines in
UtxoCoinAccount.fs' GetAccountFromFile are.
- UtxoCoinAccount.fs' TransactionOutpoint.ToCoin() should start on next
line.
- Why cut `truncated` var assignment in Formatting.fs'
DecimalAmountTruncating func?
- FaultTolerantParallelClient.fs' Runner.Run is tooooooo long
- Moving comment of FTPC.fs' CustomCancelSource's Dispose func
- This stupid diff adding an unneeded space:
```
             return! faultTolerantEtherClient.Query
                         (FaultTolerantParallelClientDefaultSettings
                             ServerSelectionMode.Fast
-                            currency
-                            (Some (AverageBetweenResponses (minResponsesRequired, AverageGasPrice))))
+                             currency
+                             (Some (AverageBetweenResponses (minResponsesRequired, AverageGasPrice))))
                         web3Funcs
```
- (Investigate) FSharpUtil.option{} that contains a `do! if...`, WAT
- In a lock() statement, it should allow placing the ending `)` in its own
line at the end, in the same column where `lock` starts.

Last but not least, investigate if alpha-012 contains unwanted things like
311bff817f89f8b47c0799eb7474da886175ef15, otherwise we might need to go
back to 04c48d5, which should be
alpha-011 with these fantomas-config.json settings:
{
  "IndentSpaceNum":4,
  "PageWidth":80,
  "SemicolonAtEndOfLine":false,
  "SpaceBeforeParameter":true,
  "SpaceBeforeLowercaseInvocation":true,
  "SpaceBeforeUppercaseInvocation":true,
  "SpaceBeforeClassConstructor":true,
  "SpaceBeforeMember":true,
  "SpaceBeforeColon":false,
  "SpaceAfterComma":true,
  "SpaceBeforeSemicolon":false,
  "SpaceAfterSemicolon":true,
  "IndentOnTryWith":true,
  "SpaceAroundDelimiter":true,
  "MaxIfThenElseShortWidth":0,
  "MaxInfixOperatorExpression":80,
  "MaxRecordWidth":0,
  "MaxFunctionBindingWidth":0,
  "MaxValueBindingWidth":80,
  "MultilineBlockBracketsOnSameColumn":true,
  "NewlineBetweenTypeDefinitionAndMembers":true,
  "KeepIfThenInSameLine":true,
  "StrictMode":false
}
  • Loading branch information
knocte committed Nov 6, 2020
1 parent c9cd074 commit fb3b4b6
Show file tree
Hide file tree
Showing 39 changed files with 3,459 additions and 2,953 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[*.fs]
indent_size=4,
max_line_length=80,
fsharp_semicolon_at_end_of_line=false
fsharp_space_before_parameter=true
fsharp_space_before_lowercase_invocation=true
fsharp_space_before_uppercase_invocation=true
fsharp_space_before_class_constructor=true
fsharp_space_before_member=true
fsharp_space_before_colon=false
fsharp_space_after_comma=true
fsharp_space_before_semicolon=false
fsharp_space_after_semicolon=true
fsharp_indent_on_try_with=true
fsharp_space_around_delimiter=true
fsharp_max_if_then_else_short_width=0
fsharp_max_infix_operator_expression=80
fsharp_max_record_width=0
fsharp_max_function_binding_width=0
fsharp_max_value_binding_width=80
fsharp_multiline_block_brackets_on_same_column=true
fsharp_newline_between_type_definition_and_members=true
fsharp_keep_if_then_in_same_line=true
fsharp_strict_mode=false
756 changes: 425 additions & 331 deletions src/GWallet.Backend/Account.fs

Large diffs are not rendered by default.

55 changes: 30 additions & 25 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,63 @@ 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 member Currency: Currency with get
abstract member PublicAddress: string with get
abstract Currency: Currency
abstract PublicAddress: string

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

abstract member Kind: AccountKind
abstract Kind: AccountKind

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


type NormalAccount(currency: Currency, accountFile: FileRepresentation,
fromAccountFileToPublicAddress: FileRepresentation -> string) =
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) =
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) =
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
55 changes: 27 additions & 28 deletions src/GWallet.Backend/BlockExplorer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,33 @@ module BlockExplorer =

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 ->
// the only one? minergate.com seems to only show blocks, not addresses
"https://gastracker.io/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 ->
// the only one? minergate.com seems to only show blocks, not addresses
"https://gastracker.io/addr/"
| Currency.SAI
| Currency.DAI ->
SPrintF1 "https://etherscan.io/token/%s?a=" (TokenManager.GetTokenContractAddress account.Currency)

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://gastracker.io/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://gastracker.io/tx/"
| Currency.DAI
| Currency.SAI -> "https://etherscan.io/tx/"

Uri (baseUrl + txHash)
Loading

0 comments on commit fb3b4b6

Please sign in to comment.