@@ -8,69 +8,7 @@ module Balance = struct
8
8
let of_int = of_nanomina_int_exn
9
9
end
10
10
11
- module Account = struct
12
- (* want bin_io, not available with Account.t *)
13
- type t = Mina_base.Account.Stable.Latest .t
14
- [@@ deriving bin_io_unversioned , sexp , equal , compare , hash , yojson ]
15
-
16
- type key = Mina_base.Account.Key.Stable.Latest .t
17
- [@@ deriving bin_io_unversioned , sexp , equal , compare , hash ]
18
-
19
- (* use Account items needed *)
20
- let empty = Mina_base.Account. empty
21
-
22
- let public_key = Mina_base.Account. public_key
23
-
24
- let identifier = Mina_base.Account. identifier
25
-
26
- let key_gen = Mina_base.Account. key_gen
27
-
28
- let gen = Mina_base.Account. gen
29
-
30
- let create = Mina_base.Account. create
31
-
32
- let balance Mina_base.Account. { balance; _ } = balance
33
-
34
- let update_balance t bal = { t with Mina_base.Account. balance = bal }
35
-
36
- let token Mina_base.Account. { token_id; _ } = token_id
37
- end
38
-
39
11
module Receipt = Mina_base. Receipt
40
-
41
- module Hash = struct
42
- module T = struct
43
- type t = Md5 .t [@@ deriving sexp , hash , compare , bin_io_unversioned , equal ]
44
- end
45
-
46
- include T
47
-
48
- include Codable. Make_base58_check (struct
49
- type t = T .t [@@ deriving bin_io_unversioned ]
50
-
51
- let description = " Ledger test hash"
52
-
53
- let version_byte = Base58_check.Version_bytes. ledger_test_hash
54
- end )
55
-
56
- include Hashable. Make_binable (T )
57
-
58
- (* to prevent pre-image attack,
59
- * important impossible to create an account such that (merge a b = hash_account account) *)
60
-
61
- let hash_account account =
62
- Md5. digest_string (Format. sprintf ! " 0%{sexp: Account.t}" account)
63
-
64
- let merge ~height a b =
65
- let res =
66
- Md5. digest_string
67
- (sprintf " test_ledger_%d:%s%s" height (Md5. to_hex a) (Md5. to_hex b))
68
- in
69
- res
70
-
71
- let empty_account = hash_account Account. empty
72
- end
73
-
74
12
module Intf = Merkle_ledger. Intf
75
13
76
14
module In_memory_kvdb : Intf .Key_value_database with type config := string =
@@ -146,7 +84,13 @@ module Storage_locations : Intf.Storage_locations = struct
146
84
let key_value_db_dir = " "
147
85
end
148
86
149
- module Key = struct
87
+ module Key : sig
88
+ include Merkle_ledger.Intf. Key with type t = Mina_base.Account.Key. t
89
+
90
+ val gen : t Base_quickcheck.Generator .t
91
+
92
+ val gen_keys : int -> t list
93
+ end = struct
150
94
[%% versioned
151
95
module Stable = struct
152
96
module V1 = struct
@@ -159,9 +103,9 @@ module Key = struct
159
103
160
104
let to_string = Signature_lib.Public_key.Compressed. to_base58_check
161
105
162
- let gen = Account. key_gen
106
+ let gen = Mina_base. Account. key_gen
163
107
164
- let empty : t = Account. empty.public_key
108
+ let empty : t = Mina_base. Account. empty.public_key
165
109
166
110
let gen_keys num_keys =
167
111
Quickcheck. random_value (Quickcheck.Generator. list_with_length num_keys gen)
172
116
173
117
module Token_id = Mina_base. Token_id
174
118
175
- module Account_id = struct
119
+ module Account_id : sig
120
+ include
121
+ Merkle_ledger.Intf. Account_id
122
+ with type token_id := Mina_base.Token_id. t
123
+ and type key := Key. t
124
+
125
+ val gen : t Base_quickcheck.Generator .t
126
+
127
+ val gen_accounts : int -> t list
128
+
129
+ val eq :
130
+ (Mina_wire_types.Mina_base_account_id .M .V2 .t , t ) Core_kernel.Type_equal .t
131
+ end = struct
176
132
[%% versioned
177
133
module Stable = struct
178
134
module V2 = struct
@@ -183,6 +139,8 @@ module Account_id = struct
183
139
end
184
140
end ]
185
141
142
+ type t = Mina_base.Account_id .t
143
+
186
144
include Hashable. Make_binable (Stable. Latest )
187
145
include Comparable. Make (Stable. Latest )
188
146
@@ -203,9 +161,89 @@ module Account_id = struct
203
161
let gen_accounts num_accounts =
204
162
Quickcheck. random_value
205
163
(Quickcheck.Generator. list_with_length num_accounts gen)
164
+
165
+ let eq = Core_kernel.Type_equal. T
206
166
end
207
167
208
- module Base_inputs = struct
168
+ module Account : sig
169
+ include
170
+ Merkle_ledger.Intf. Account
171
+ with type token_id := Token_id. t
172
+ and type account_id := Account_id. t
173
+ and type balance := Balance. t
174
+ and type t = Mina_base.Account. t
175
+
176
+ val gen : t Base_quickcheck.Generator .t
177
+
178
+ val create : Mina_base.Account_id .t -> Balance .t -> t
179
+
180
+ val update_balance : t -> Balance .t -> t
181
+
182
+ val public_key : t -> Mina_base.Account.Key .t
183
+ end = struct
184
+ (* want bin_io, not available with Account.t *)
185
+ type t = Mina_base.Account.Stable.Latest .t
186
+ [@@ deriving bin_io_unversioned , sexp , equal , compare , hash , yojson ]
187
+
188
+ (* use Account items needed *)
189
+ let empty = Mina_base.Account. empty
190
+
191
+ let public_key = Mina_base.Account. public_key
192
+
193
+ let gen = Mina_base.Account. gen
194
+
195
+ let create = Mina_base.Account. create
196
+
197
+ let balance Mina_base.Account. { balance; _ } = balance
198
+
199
+ let update_balance t bal = { t with Mina_base.Account. balance = bal }
200
+
201
+ let token Mina_base.Account. { token_id; _ } = token_id
202
+
203
+ let identifier ({ public_key; token_id; _ } : t ) =
204
+ Account_id. create public_key token_id
205
+ end
206
+
207
+ module Hash : Merkle_ledger .Intf. Hash with type account := Account. t = struct
208
+ module T = struct
209
+ type t = Md5 .t [@@ deriving sexp , hash , compare , bin_io_unversioned , equal ]
210
+ end
211
+
212
+ include T
213
+
214
+ include Codable. Make_base58_check (struct
215
+ type t = T .t [@@ deriving bin_io_unversioned ]
216
+
217
+ let description = " Ledger test hash"
218
+
219
+ let version_byte = Base58_check.Version_bytes. ledger_test_hash
220
+ end )
221
+
222
+ include Hashable. Make_binable (T )
223
+
224
+ (* to prevent pre-image attack,
225
+ * important impossible to create an account such that (merge a b = hash_account account) *)
226
+
227
+ let hash_account account =
228
+ Md5. digest_string (Format. sprintf ! " 0%{sexp: Account.t}" account)
229
+
230
+ let merge ~height a b =
231
+ let res =
232
+ Md5. digest_string
233
+ (sprintf " test_ledger_%d:%s%s" height (Md5. to_hex a) (Md5. to_hex b))
234
+ in
235
+ res
236
+
237
+ let empty_account = hash_account Account. empty
238
+ end
239
+
240
+ module Make_base_inputs
241
+ (Account : Merkle_ledger.Intf. Account
242
+ with type account_id := Account_id. t
243
+ and type token_id := Token_id. t
244
+ and type balance := Balance. t)
245
+ (Hash : Merkle_ledger.Intf.Hash with type account := Account.t ) =
246
+ struct
209
247
module Key = Key
210
248
module Account_id = Account_id
211
249
module Token_id = Token_id
@@ -221,3 +259,5 @@ module Base_inputs = struct
221
259
module Account = Account
222
260
module Hash = Hash
223
261
end
262
+
263
+ module Base_inputs = Make_base_inputs (Account ) (Hash )
0 commit comments