@@ -29,9 +29,11 @@ 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;
36
+ use clarity:: types:: chainstate:: StacksBlockId ;
35
37
use clarity:: vm:: types:: serialization:: SerializationError ;
36
38
use clarity:: vm:: types:: QualifiedContractIdentifier ;
37
39
use serde:: { Deserialize , Serialize } ;
@@ -202,13 +204,21 @@ pub enum SignerEvent<T: SignerEventTrait> {
202
204
burn_height : u64 ,
203
205
/// the burn hash for the newly processed burn block
204
206
burn_header_hash : BurnchainHeaderHash ,
207
+ /// the consensus hash for the newly processed burn block
208
+ consensus_hash : ConsensusHash ,
205
209
/// the time at which this event was received by the signer's event processor
206
210
received_time : SystemTime ,
207
211
} ,
208
212
/// A new processed Stacks block was received from the node with the given block hash
209
213
NewBlock {
210
- /// The block header hash for the newly processed stacks block
211
- block_hash : Sha512Trunc256Sum ,
214
+ /// The stacks block ID (or index block hash) of the new block
215
+ block_id : StacksBlockId ,
216
+ /// The consensus hash of the block (either the tenure it was produced during for Stacks 3.0
217
+ /// or the burn block that won the sortition in Stacks 2.0)
218
+ consensus_hash : ConsensusHash ,
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 > ,
212
222
/// The block height for the newly processed stacks block
213
223
block_height : u64 ,
214
224
} ,
@@ -551,54 +561,50 @@ impl<T: SignerEventTrait> TryFrom<BlockValidateResponse> for SignerEvent<T> {
551
561
552
562
#[ derive( Debug , Deserialize ) ]
553
563
struct BurnBlockEvent {
554
- burn_block_hash : String ,
564
+ #[ serde( with = "prefix_hex" ) ]
565
+ burn_block_hash : BurnchainHeaderHash ,
555
566
burn_block_height : u64 ,
556
567
reward_recipients : Vec < serde_json:: Value > ,
557
568
reward_slot_holders : Vec < String > ,
558
569
burn_amount : u64 ,
570
+ #[ serde( with = "prefix_hex" ) ]
571
+ consensus_hash : ConsensusHash ,
559
572
}
560
573
561
574
impl < T : SignerEventTrait > TryFrom < BurnBlockEvent > for SignerEvent < T > {
562
575
type Error = EventError ;
563
576
564
577
fn try_from ( burn_block_event : BurnBlockEvent ) -> Result < Self , Self :: Error > {
565
- let burn_header_hash = burn_block_event
566
- . burn_block_hash
567
- . get ( 2 ..)
568
- . ok_or_else ( || EventError :: Deserialize ( "Hex string should be 0x prefixed" . into ( ) ) )
569
- . and_then ( |hex| {
570
- BurnchainHeaderHash :: from_hex ( hex)
571
- . map_err ( |e| EventError :: Deserialize ( format ! ( "Invalid hex string: {e}" ) ) )
572
- } ) ?;
573
-
574
578
Ok ( SignerEvent :: NewBurnBlock {
575
579
burn_height : burn_block_event. burn_block_height ,
576
580
received_time : SystemTime :: now ( ) ,
577
- burn_header_hash,
581
+ burn_header_hash : burn_block_event. burn_block_hash ,
582
+ consensus_hash : burn_block_event. consensus_hash ,
578
583
} )
579
584
}
580
585
}
581
586
582
587
#[ derive( Debug , Deserialize ) ]
583
588
struct BlockEvent {
584
- block_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 ,
585
597
block_height : u64 ,
586
598
}
587
599
588
600
impl < T : SignerEventTrait > TryFrom < BlockEvent > for SignerEvent < T > {
589
601
type Error = EventError ;
590
602
591
603
fn try_from ( block_event : BlockEvent ) -> Result < Self , Self :: Error > {
592
- let block_hash: Sha512Trunc256Sum = block_event
593
- . block_hash
594
- . get ( 2 ..)
595
- . ok_or_else ( || EventError :: Deserialize ( "Hex string should be 0x prefixed" . into ( ) ) )
596
- . and_then ( |hex| {
597
- Sha512Trunc256Sum :: from_hex ( hex)
598
- . map_err ( |e| EventError :: Deserialize ( format ! ( "Invalid hex string: {e}" ) ) )
599
- } ) ?;
600
604
Ok ( SignerEvent :: NewBlock {
601
- block_hash,
605
+ signer_sighash : block_event. signer_signature_hash ,
606
+ block_id : block_event. index_block_hash ,
607
+ consensus_hash : block_event. consensus_hash ,
602
608
block_height : block_event. block_height ,
603
609
} )
604
610
}
0 commit comments