@@ -3,11 +3,12 @@ use std::ops::Deref;
3
3
use super :: map:: ToHex ;
4
4
use super :: EventWriter ;
5
5
use crate :: model:: { BlockRecord , Era , EventData , TransactionRecord , TxInputRecord , TxOutputRecord } ;
6
+ use crate :: utils:: time:: TimeProvider ;
6
7
use crate :: { model:: EventContext , Error } ;
7
8
8
- use pallas :: crypto :: hash:: Hash ;
9
- use pallas :: ledger :: primitives :: byron;
10
- use pallas :: ledger :: traverse :: OriginalHash ;
9
+ use pallas_crypto :: hash:: Hash ;
10
+ use pallas_primitives :: byron;
11
+ use pallas_traverse :: OriginalHash ;
11
12
12
13
impl EventWriter {
13
14
fn to_byron_input_record ( & self , source : & byron:: TxIn ) -> Option < TxInputRecord > {
@@ -41,12 +42,9 @@ impl EventWriter {
41
42
}
42
43
43
44
fn to_byron_output_record ( & self , source : & byron:: TxOut ) -> Result < TxOutputRecord , Error > {
44
- let address: pallas:: ledger:: addresses:: Address =
45
- pallas:: ledger:: addresses:: ByronAddress :: new (
46
- & source. address . payload . 0 ,
47
- source. address . crc ,
48
- )
49
- . into ( ) ;
45
+ let address: pallas_addresses:: Address =
46
+ pallas_addresses:: ByronAddress :: new ( & source. address . payload . 0 , source. address . crc )
47
+ . into ( ) ;
50
48
51
49
Ok ( TxOutputRecord {
52
50
address : address. to_string ( ) ,
@@ -168,10 +166,12 @@ impl EventWriter {
168
166
hash : & Hash < 32 > ,
169
167
cbor : & [ u8 ] ,
170
168
) -> Result < BlockRecord , Error > {
171
- let abs_slot = pallas:: ledger:: traverse:: time:: byron_epoch_slot_to_absolute (
172
- source. header . consensus_data . 0 . epoch ,
173
- source. header . consensus_data . 0 . slot ,
174
- ) ;
169
+ let abs_slot = self . utils . time . as_ref ( ) . map ( |time| {
170
+ time. byron_epoch_slot_to_absolute (
171
+ source. header . consensus_data . 0 . epoch ,
172
+ source. header . consensus_data . 0 . slot ,
173
+ )
174
+ } ) ;
175
175
176
176
let mut record = BlockRecord {
177
177
era : Era :: Byron ,
@@ -181,7 +181,7 @@ impl EventWriter {
181
181
tx_count : source. body . tx_payload . len ( ) ,
182
182
hash : hash. to_hex ( ) ,
183
183
number : source. header . consensus_data . 2 [ 0 ] ,
184
- slot : abs_slot,
184
+ slot : abs_slot. unwrap_or_default ( ) ,
185
185
epoch : Some ( source. header . consensus_data . 0 . epoch ) ,
186
186
epoch_slot : Some ( source. header . consensus_data . 0 . slot ) ,
187
187
previous_hash : source. header . prev_block . to_hex ( ) ,
@@ -234,10 +234,9 @@ impl EventWriter {
234
234
hash : & Hash < 32 > ,
235
235
cbor : & [ u8 ] ,
236
236
) -> Result < BlockRecord , Error > {
237
- let abs_slot = pallas:: ledger:: traverse:: time:: byron_epoch_slot_to_absolute (
238
- source. header . consensus_data . epoch_id ,
239
- 0 ,
240
- ) ;
237
+ let abs_slot = self . utils . time . as_ref ( ) . map ( |time| {
238
+ time. byron_epoch_slot_to_absolute ( source. header . consensus_data . epoch_id , 0 )
239
+ } ) ;
241
240
242
241
Ok ( BlockRecord {
243
242
era : Era :: Byron ,
@@ -247,7 +246,7 @@ impl EventWriter {
247
246
vrf_vkey : Default :: default ( ) ,
248
247
tx_count : 0 ,
249
248
number : source. header . consensus_data . difficulty [ 0 ] ,
250
- slot : abs_slot,
249
+ slot : abs_slot. unwrap_or_default ( ) ,
251
250
epoch : Some ( source. header . consensus_data . epoch_id ) ,
252
251
epoch_slot : Some ( 0 ) ,
253
252
previous_hash : source. header . prev_block . to_hex ( ) ,
@@ -288,16 +287,18 @@ impl EventWriter {
288
287
) -> Result < ( ) , Error > {
289
288
let hash = block. header . original_hash ( ) ;
290
289
291
- let abs_slot = pallas:: ledger:: traverse:: time:: byron_epoch_slot_to_absolute (
292
- block. header . consensus_data . 0 . epoch ,
293
- block. header . consensus_data . 0 . slot ,
294
- ) ;
290
+ let abs_slot = self . utils . time . as_ref ( ) . map ( |time| {
291
+ time. byron_epoch_slot_to_absolute (
292
+ block. header . consensus_data . 0 . epoch ,
293
+ block. header . consensus_data . 0 . slot ,
294
+ )
295
+ } ) ;
295
296
296
297
let child = self . child_writer ( EventContext {
297
298
block_hash : Some ( hex:: encode ( hash) ) ,
298
299
block_number : Some ( block. header . consensus_data . 2 [ 0 ] ) ,
299
- slot : Some ( abs_slot) ,
300
- timestamp : self . compute_timestamp ( abs_slot ) ,
300
+ slot : abs_slot,
301
+ timestamp : abs_slot . and_then ( |slot| self . compute_timestamp ( slot ) ) ,
301
302
..EventContext :: default ( )
302
303
} ) ;
303
304
@@ -311,7 +312,7 @@ impl EventWriter {
311
312
/// Entry-point to start crawling a blocks for events. Meant to be used when
312
313
/// we haven't decoded the CBOR yet (for example, N2N).
313
314
pub fn crawl_from_byron_cbor ( & self , cbor : & [ u8 ] ) -> Result < ( ) , Error > {
314
- let ( _, block) : ( u16 , byron:: MintedBlock ) = pallas :: codec :: minicbor:: decode ( cbor) ?;
315
+ let ( _, block) : ( u16 , byron:: MintedBlock ) = pallas_codec :: minicbor:: decode ( cbor) ?;
315
316
self . crawl_byron_with_cbor ( & block, cbor)
316
317
}
317
318
@@ -328,16 +329,15 @@ impl EventWriter {
328
329
if self . config . include_byron_ebb {
329
330
let hash = block. header . original_hash ( ) ;
330
331
331
- let abs_slot = pallas:: ledger:: traverse:: time:: byron_epoch_slot_to_absolute (
332
- block. header . consensus_data . epoch_id ,
333
- 0 ,
334
- ) ;
332
+ let abs_slot = self . utils . time . as_ref ( ) . map ( |time| {
333
+ time. byron_epoch_slot_to_absolute ( block. header . consensus_data . epoch_id , 0 )
334
+ } ) ;
335
335
336
336
let child = self . child_writer ( EventContext {
337
337
block_hash : Some ( hex:: encode ( hash) ) ,
338
338
block_number : Some ( block. header . consensus_data . difficulty [ 0 ] ) ,
339
- slot : Some ( abs_slot) ,
340
- timestamp : self . compute_timestamp ( abs_slot ) ,
339
+ slot : abs_slot,
340
+ timestamp : abs_slot . and_then ( |slot| self . compute_timestamp ( slot ) ) ,
341
341
..EventContext :: default ( )
342
342
} ) ;
343
343
@@ -352,7 +352,7 @@ impl EventWriter {
352
352
/// Entry-point to start crawling a blocks for events. Meant to be used when
353
353
/// we haven't decoded the CBOR yet (for example, N2N).
354
354
pub fn crawl_from_ebb_cbor ( & self , cbor : & [ u8 ] ) -> Result < ( ) , Error > {
355
- let ( _, block) : ( u16 , byron:: MintedEbBlock ) = pallas :: codec :: minicbor:: decode ( cbor) ?;
355
+ let ( _, block) : ( u16 , byron:: MintedEbBlock ) = pallas_codec :: minicbor:: decode ( cbor) ?;
356
356
self . crawl_ebb_with_cbor ( & block, cbor)
357
357
}
358
358
}
0 commit comments