@@ -80,18 +80,21 @@ pub trait Pile {
80
80
> ;
81
81
type Keep : Aora < Id = Opid , Item = SmallOrdMap < u16 , <Self :: Seal as RgbSeal >:: Definiton > > ;
82
82
type Index : Index < Opid , <Self :: Seal as RgbSeal >:: WitnessId > ;
83
+ type Stand : Index < <Self :: Seal as RgbSeal >:: WitnessId , Opid > ;
83
84
type Mine : Cru < <Self :: Seal as RgbSeal >:: WitnessId , Option < WitnessStatus > > ;
84
85
85
86
fn hoard ( & self ) -> & Self :: Hoard ;
86
87
fn cache ( & self ) -> & Self :: Cache ;
87
88
fn keep ( & self ) -> & Self :: Keep ;
88
89
fn index ( & self ) -> & Self :: Index ;
90
+ fn stand ( & self ) -> & Self :: Stand ;
89
91
fn mine ( & self ) -> & Self :: Mine ;
90
92
91
93
fn hoard_mut ( & mut self ) -> & mut Self :: Hoard ;
92
94
fn cache_mut ( & mut self ) -> & mut Self :: Cache ;
93
95
fn keep_mut ( & mut self ) -> & mut Self :: Keep ;
94
96
fn index_mut ( & mut self ) -> & mut Self :: Index ;
97
+ fn stand_mut ( & mut self ) -> & mut Self :: Stand ;
95
98
fn mine_mut ( & mut self ) -> & mut Self :: Mine ;
96
99
97
100
fn retrieve ( & mut self , opid : Opid ) -> impl ExactSizeIterator < Item = SealWitness < Self :: Seal > > ;
@@ -104,6 +107,7 @@ pub trait Pile {
104
107
) {
105
108
let pubid = published. pub_id ( ) ;
106
109
self . index_mut ( ) . add ( opid, pubid) ;
110
+ self . stand_mut ( ) . add ( pubid, opid) ;
107
111
if self . hoard_mut ( ) . has ( & pubid) {
108
112
let mut prev_anchor = self . hoard_mut ( ) . read ( pubid) ;
109
113
if prev_anchor != anchor {
@@ -182,15 +186,19 @@ pub mod fs {
182
186
}
183
187
184
188
#[ derive( Clone , Debug ) ]
185
- pub struct FileIndex < Id >
186
- where Id : Copy + Ord + From < [ u8 ; 32 ] > + Into < [ u8 ; 32 ] >
189
+ pub struct FileIndex < K , V >
190
+ where
191
+ K : Copy + Ord + From < [ u8 ; 32 ] > + Into < [ u8 ; 32 ] > ,
192
+ V : Copy + Ord + From < [ u8 ; 32 ] > + Into < [ u8 ; 32 ] > ,
187
193
{
188
194
path : PathBuf ,
189
- cache : BTreeMap < Opid , BTreeSet < Id > > ,
195
+ cache : BTreeMap < K , BTreeSet < V > > ,
190
196
}
191
197
192
- impl < Id > FileIndex < Id >
193
- where Id : Copy + Ord + From < [ u8 ; 32 ] > + Into < [ u8 ; 32 ] >
198
+ impl < K , V > FileIndex < K , V >
199
+ where
200
+ K : Copy + Ord + From < [ u8 ; 32 ] > + Into < [ u8 ; 32 ] > ,
201
+ V : Copy + Ord + From < [ u8 ; 32 ] > + Into < [ u8 ; 32 ] > ,
194
202
{
195
203
pub fn create ( path : PathBuf ) -> io:: Result < Self > {
196
204
File :: create_new ( & path) ?;
@@ -202,7 +210,7 @@ pub mod fs {
202
210
let mut file = File :: open ( & path) ?;
203
211
let mut buf = [ 0u8 ; 32 ] ;
204
212
while file. read_exact ( & mut buf) . is_ok ( ) {
205
- let opid = Opid :: from ( buf) ;
213
+ let opid = K :: from ( buf) ;
206
214
let mut ids = BTreeSet :: new ( ) ;
207
215
let mut len = [ 0u8 ; 4 ] ;
208
216
file. read_exact ( & mut len) . expect ( "cannot read index file" ) ;
@@ -220,33 +228,35 @@ pub mod fs {
220
228
221
229
pub fn save ( & self ) -> io:: Result < ( ) > {
222
230
let mut index_file = File :: create ( & self . path ) ?;
223
- for ( opid , ids ) in & self . cache {
224
- index_file. write_all ( opid . as_slice ( ) ) ?;
225
- let len = ids . len ( ) as u32 ;
231
+ for ( key , values ) in & self . cache {
232
+ index_file. write_all ( ( * key ) . into ( ) . as_slice ( ) ) ?;
233
+ let len = values . len ( ) as u32 ;
226
234
index_file. write_all ( & len. to_le_bytes ( ) ) ?;
227
- for id in ids {
235
+ for id in values {
228
236
index_file. write_all ( & ( * id) . into ( ) ) ?;
229
237
}
230
238
}
231
239
Ok ( ( ) )
232
240
}
233
241
}
234
242
235
- impl < Id : Copy > Index < Opid , Id > for FileIndex < Id >
236
- where Id : Copy + Ord + From < [ u8 ; 32 ] > + Into < [ u8 ; 32 ] >
243
+ impl < K , V > Index < K , V > for FileIndex < K , V >
244
+ where
245
+ K : Copy + Ord + From < [ u8 ; 32 ] > + Into < [ u8 ; 32 ] > ,
246
+ V : Copy + Ord + From < [ u8 ; 32 ] > + Into < [ u8 ; 32 ] > ,
237
247
{
238
- fn keys ( & self ) -> impl Iterator < Item = Opid > { self . cache . keys ( ) . copied ( ) }
248
+ fn keys ( & self ) -> impl Iterator < Item = K > { self . cache . keys ( ) . copied ( ) }
239
249
240
- fn has ( & self , key : Opid ) -> bool { self . cache . contains_key ( & key) }
250
+ fn has ( & self , key : K ) -> bool { self . cache . contains_key ( & key) }
241
251
242
- fn get ( & self , key : Opid ) -> impl ExactSizeIterator < Item = Id > {
252
+ fn get ( & self , key : K ) -> impl ExactSizeIterator < Item = V > {
243
253
match self . cache . get ( & key) {
244
254
Some ( ids) => ids. clone ( ) . into_iter ( ) ,
245
255
None => bset ! [ ] . into_iter ( ) ,
246
256
}
247
257
}
248
258
249
- fn add ( & mut self , key : Opid , val : Id ) {
259
+ fn add ( & mut self , key : K , val : V ) {
250
260
self . cache . entry ( key) . or_default ( ) . insert ( val) ;
251
261
self . save ( ) . expect ( "Cannot save index file" ) ;
252
262
}
@@ -258,7 +268,8 @@ pub mod fs {
258
268
hoard : FileAora < Seal :: WitnessId , Seal :: Client > ,
259
269
cache : FileAora < Seal :: WitnessId , Seal :: Published > ,
260
270
keep : FileAora < Opid , SmallOrdMap < u16 , Seal :: Definiton > > ,
261
- index : FileIndex < Seal :: WitnessId > ,
271
+ index : FileIndex < Opid , Seal :: WitnessId > ,
272
+ stand : FileIndex < Seal :: WitnessId , Opid > ,
262
273
mine : FileCru ,
263
274
_phantom : PhantomData < Seal > ,
264
275
}
@@ -279,12 +290,24 @@ pub mod fs {
279
290
let index = FileIndex :: create ( index_file. clone ( ) ) . unwrap_or_else ( |_| {
280
291
panic ! ( "unable to create index file '{}'" , index_file. display( ) )
281
292
} ) ;
293
+ let stand_file = path. join ( "stand.dat" ) ;
294
+ let stand = FileIndex :: create ( stand_file. clone ( ) ) . unwrap_or_else ( |_| {
295
+ panic ! ( "unable to create stand file '{}'" , stand_file. display( ) )
296
+ } ) ;
282
297
let mine_file = path. join ( "mine.dat" ) ;
283
298
let mine = FileCru :: create ( mine_file. clone ( ) ) . unwrap_or_else ( |_| {
284
299
panic ! ( "unable to create mining info file '{}'" , mine_file. display( ) )
285
300
} ) ;
286
301
287
- Self { hoard, cache, keep, index, mine, _phantom : PhantomData }
302
+ Self {
303
+ hoard,
304
+ cache,
305
+ keep,
306
+ index,
307
+ stand,
308
+ mine,
309
+ _phantom : PhantomData ,
310
+ }
288
311
}
289
312
}
290
313
@@ -300,12 +323,23 @@ pub mod fs {
300
323
let index_file = path. join ( "index.dat" ) ;
301
324
let index = FileIndex :: open ( index_file. clone ( ) )
302
325
. unwrap_or_else ( |_| panic ! ( "unable to open index file '{}'" , index_file. display( ) ) ) ;
326
+ let stand_file = path. join ( "stand.dat" ) ;
327
+ let stand = FileIndex :: open ( stand_file. clone ( ) )
328
+ . unwrap_or_else ( |_| panic ! ( "unable to open stand file '{}'" , stand_file. display( ) ) ) ;
303
329
let mine_file = path. join ( "mine.dat" ) ;
304
330
let mine = FileCru :: open ( mine_file. clone ( ) ) . unwrap_or_else ( |_| {
305
331
panic ! ( "unable to open mining info file '{}'" , mine_file. display( ) )
306
332
} ) ;
307
333
308
- Self { hoard, cache, keep, index, mine, _phantom : PhantomData }
334
+ Self {
335
+ hoard,
336
+ cache,
337
+ keep,
338
+ index,
339
+ stand,
340
+ mine,
341
+ _phantom : PhantomData ,
342
+ }
309
343
}
310
344
}
311
345
@@ -320,7 +354,8 @@ pub mod fs {
320
354
type Hoard = FileAora < Seal :: WitnessId , Seal :: Client > ;
321
355
type Cache = FileAora < Seal :: WitnessId , Seal :: Published > ;
322
356
type Keep = FileAora < Opid , SmallOrdMap < u16 , Seal :: Definiton > > ;
323
- type Index = FileIndex < Seal :: WitnessId > ;
357
+ type Index = FileIndex < Opid , Seal :: WitnessId > ;
358
+ type Stand = FileIndex < Seal :: WitnessId , Opid > ;
324
359
type Mine = FileCru ;
325
360
326
361
fn hoard ( & self ) -> & Self :: Hoard { & self . hoard }
@@ -331,6 +366,8 @@ pub mod fs {
331
366
332
367
fn index ( & self ) -> & Self :: Index { & self . index }
333
368
369
+ fn stand ( & self ) -> & Self :: Stand { & self . stand }
370
+
334
371
fn mine ( & self ) -> & Self :: Mine { & self . mine }
335
372
336
373
fn hoard_mut ( & mut self ) -> & mut Self :: Hoard { & mut self . hoard }
@@ -341,6 +378,8 @@ pub mod fs {
341
378
342
379
fn index_mut ( & mut self ) -> & mut Self :: Index { & mut self . index }
343
380
381
+ fn stand_mut ( & mut self ) -> & mut Self :: Stand { & mut self . stand }
382
+
344
383
fn mine_mut ( & mut self ) -> & mut Self :: Mine { & mut self . mine }
345
384
346
385
fn retrieve ( & mut self , opid : Opid ) -> impl ExactSizeIterator < Item = SealWitness < Seal > > {
0 commit comments