-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathAccountTypes.fs
79 lines (61 loc) · 2.3 KB
/
AccountTypes.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
namespace GWallet.Backend
open System.IO
type WatchWalletInfo =
{
UtxoCoinPublicKey: string
EtherPublicAddress: string
}
type FileRepresentation =
{
Name: string;
Content: unit->string;
}
static member FromFile (file: FileInfo) =
{
Name = Path.GetFileName file.FullName
Content = (fun _ -> File.ReadAllText file.FullName)
}
type ConceptAccount =
{
Currency: Currency;
FileRepresentation: FileRepresentation;
ExtractPublicAddressFromConfigFileFunc: FileRepresentation->string;
}
type AccountKind =
| Normal
| ReadOnly
| Archived
static member All() =
seq {
yield Normal
yield ReadOnly
yield Archived
}
type IAccount =
abstract member Currency: Currency with get
abstract member PublicAddress: string with get
[<AbstractClass>]
type BaseAccount(currency: Currency, accountFile: FileRepresentation,
fromAccountFileToPublicAddress: FileRepresentation -> string) =
member val AccountFile = accountFile with get
abstract member Kind: AccountKind
interface IAccount with
member val Currency = currency with get
member val PublicAddress =
fromAccountFileToPublicAddress accountFile with get
type NormalAccount(currency: Currency, accountFile: FileRepresentation,
fromAccountFileToPublicAddress: FileRepresentation -> string) =
inherit BaseAccount(currency, accountFile, fromAccountFileToPublicAddress)
member internal __.GetEncryptedPrivateKey() =
accountFile.Content()
override __.Kind = AccountKind.Normal
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)
member internal __.GetUnencryptedPrivateKey() =
accountFile.Content()
override __.Kind = AccountKind.Archived