@@ -29,6 +29,7 @@ use blockstack_lib::chainstate::stacks::StacksTransaction;
29
29
use blockstack_lib:: net:: api:: postblock_proposal:: {
30
30
BlockValidateReject , BlockValidateResponse , ValidateRejectCode ,
31
31
} ;
32
+ use blockstack_lib:: net:: api:: { prefix_hex, prefix_opt_hex} ;
32
33
use blockstack_lib:: net:: stackerdb:: MINER_SLOT_COUNT ;
33
34
use blockstack_lib:: util_lib:: boot:: boot_code_id;
34
35
use blockstack_lib:: version_string;
@@ -215,8 +216,9 @@ pub enum SignerEvent<T: SignerEventTrait> {
215
216
/// The consensus hash of the block (either the tenure it was produced during for Stacks 3.0
216
217
/// or the burn block that won the sortition in Stacks 2.0)
217
218
consensus_hash : ConsensusHash ,
218
- /// The signer sighash for the newly processed stacks block
219
- signer_sighash : Sha512Trunc256Sum ,
219
+ /// The signer sighash for the newly processed stacks block. If the newly processed block is a 2.0
220
+ /// block, there is *no* signer sighash
221
+ signer_sighash : Option < Sha512Trunc256Sum > ,
220
222
/// The block height for the newly processed stacks block
221
223
block_height : u64 ,
222
224
} ,
@@ -559,86 +561,50 @@ impl<T: SignerEventTrait> TryFrom<BlockValidateResponse> for SignerEvent<T> {
559
561
560
562
#[ derive( Debug , Deserialize ) ]
561
563
struct BurnBlockEvent {
562
- burn_block_hash : String ,
564
+ #[ serde( with = "prefix_hex" ) ]
565
+ burn_block_hash : BurnchainHeaderHash ,
563
566
burn_block_height : u64 ,
564
567
reward_recipients : Vec < serde_json:: Value > ,
565
568
reward_slot_holders : Vec < String > ,
566
569
burn_amount : u64 ,
567
- consensus_hash : String ,
570
+ #[ serde( with = "prefix_hex" ) ]
571
+ consensus_hash : ConsensusHash ,
568
572
}
569
573
570
574
impl < T : SignerEventTrait > TryFrom < BurnBlockEvent > for SignerEvent < T > {
571
575
type Error = EventError ;
572
576
573
577
fn try_from ( burn_block_event : BurnBlockEvent ) -> Result < Self , Self :: Error > {
574
- let burn_header_hash = burn_block_event
575
- . burn_block_hash
576
- . get ( 2 ..)
577
- . ok_or_else ( || EventError :: Deserialize ( "Hex string should be 0x prefixed" . into ( ) ) )
578
- . and_then ( |hex| {
579
- BurnchainHeaderHash :: from_hex ( hex)
580
- . map_err ( |e| EventError :: Deserialize ( format ! ( "Invalid hex string: {e}" ) ) )
581
- } ) ?;
582
-
583
- let consensus_hash = burn_block_event
584
- . consensus_hash
585
- . get ( 2 ..)
586
- . ok_or_else ( || EventError :: Deserialize ( "Hex string should be 0x prefixed" . into ( ) ) )
587
- . and_then ( |hex| {
588
- ConsensusHash :: from_hex ( hex)
589
- . map_err ( |e| EventError :: Deserialize ( format ! ( "Invalid hex string: {e}" ) ) )
590
- } ) ?;
591
-
592
578
Ok ( SignerEvent :: NewBurnBlock {
593
579
burn_height : burn_block_event. burn_block_height ,
594
580
received_time : SystemTime :: now ( ) ,
595
- burn_header_hash,
596
- consensus_hash,
581
+ burn_header_hash : burn_block_event . burn_block_hash ,
582
+ consensus_hash : burn_block_event . consensus_hash ,
597
583
} )
598
584
}
599
585
}
600
586
601
587
#[ derive( Debug , Deserialize ) ]
602
588
struct BlockEvent {
603
- index_block_hash : String ,
604
- signer_signature_hash : String ,
605
- consensus_hash : String ,
589
+ #[ serde( with = "prefix_hex" ) ]
590
+ index_block_hash : StacksBlockId ,
591
+ #[ serde( with = "prefix_opt_hex" ) ]
592
+ signer_signature_hash : Option < Sha512Trunc256Sum > ,
593
+ #[ serde( with = "prefix_hex" ) ]
594
+ consensus_hash : ConsensusHash ,
595
+ #[ serde( with = "prefix_hex" ) ]
596
+ block_hash : BlockHeaderHash ,
606
597
block_height : u64 ,
607
598
}
608
599
609
600
impl < T : SignerEventTrait > TryFrom < BlockEvent > for SignerEvent < T > {
610
601
type Error = EventError ;
611
602
612
603
fn try_from ( block_event : BlockEvent ) -> Result < Self , Self :: Error > {
613
- let signer_sighash = block_event
614
- . signer_signature_hash
615
- . get ( 2 ..)
616
- . ok_or_else ( || EventError :: Deserialize ( "Hex string should be 0x prefixed" . into ( ) ) )
617
- . and_then ( |hex| {
618
- Sha512Trunc256Sum :: from_hex ( hex)
619
- . map_err ( |e| EventError :: Deserialize ( format ! ( "Invalid hex string: {e}" ) ) )
620
- } ) ?;
621
- let consensus_hash = block_event
622
- . consensus_hash
623
- . get ( 2 ..)
624
- . ok_or_else ( || EventError :: Deserialize ( "Hex string should be 0x prefixed" . into ( ) ) )
625
- . and_then ( |hex| {
626
- ConsensusHash :: from_hex ( hex)
627
- . map_err ( |e| EventError :: Deserialize ( format ! ( "Invalid hex string: {e}" ) ) )
628
- } ) ?;
629
- let block_id = block_event
630
- . index_block_hash
631
- . get ( 2 ..)
632
- . ok_or_else ( || EventError :: Deserialize ( "Hex string should be 0x prefixed" . into ( ) ) )
633
- . and_then ( |hex| {
634
- StacksBlockId :: from_hex ( hex)
635
- . map_err ( |e| EventError :: Deserialize ( format ! ( "Invalid hex string: {e}" ) ) )
636
- } ) ?;
637
-
638
604
Ok ( SignerEvent :: NewBlock {
639
- block_id ,
640
- signer_sighash ,
641
- consensus_hash,
605
+ signer_sighash : block_event . signer_signature_hash ,
606
+ block_id : block_event . index_block_hash ,
607
+ consensus_hash : block_event . consensus_hash ,
642
608
block_height : block_event. block_height ,
643
609
} )
644
610
}
0 commit comments