@@ -45,8 +45,8 @@ pub use stacks_common::consts::SIGNER_SLOTS_PER_USER;
4545use stacks_common:: types:: chainstate:: {
4646 BlockHeaderHash , BurnchainHeaderHash , ConsensusHash , SortitionId , StacksPublicKey ,
4747} ;
48- use stacks_common:: util:: hash:: { Hash160 , Sha512Trunc256Sum } ;
49- use stacks_common:: util:: serde_serializers:: { prefix_hex, prefix_opt_hex} ;
48+ use stacks_common:: util:: hash:: { hex_bytes , Hash160 , Sha512Trunc256Sum } ;
49+ use stacks_common:: util:: serde_serializers:: { prefix_hex, prefix_opt_hex, prefix_string_0x } ;
5050use stacks_common:: util:: HexError ;
5151use stacks_common:: versions:: STACKS_NODE_VERSION ;
5252use tiny_http:: {
@@ -229,6 +229,8 @@ pub enum SignerEvent<T: SignerEventTrait> {
229229 signer_sighash : Option < Sha512Trunc256Sum > ,
230230 /// The block height for the newly processed stacks block
231231 block_height : u64 ,
232+ /// The transactions included in the block
233+ transactions : Vec < StacksTransaction > ,
232234 } ,
233235}
234236
@@ -577,18 +579,26 @@ impl<T: SignerEventTrait> TryFrom<BlockValidateResponse> for SignerEvent<T> {
577579 }
578580}
579581
580- #[ derive( Debug , Deserialize ) ]
581- struct BurnBlockEvent {
582+ /// Burn block JSON payload from the event receiver
583+ #[ derive( Debug , Deserialize , Clone ) ]
584+ pub struct BurnBlockEvent {
585+ /// The hash of the burn block
582586 #[ serde( with = "prefix_hex" ) ]
583- burn_block_hash : BurnchainHeaderHash ,
584- burn_block_height : u64 ,
585- reward_recipients : Vec < serde_json:: Value > ,
586- reward_slot_holders : Vec < String > ,
587- burn_amount : u64 ,
587+ pub burn_block_hash : BurnchainHeaderHash ,
588+ /// The height of the burn block
589+ pub burn_block_height : u64 ,
590+ /// The reward recipients
591+ pub reward_recipients : Vec < serde_json:: Value > ,
592+ /// The reward slot holders
593+ pub reward_slot_holders : Vec < String > ,
594+ /// The amount of burn
595+ pub burn_amount : u64 ,
596+ /// The consensus hash of the burn block
588597 #[ serde( with = "prefix_hex" ) ]
589- consensus_hash : ConsensusHash ,
598+ pub consensus_hash : ConsensusHash ,
599+ /// The parent burn block hash
590600 #[ serde( with = "prefix_hex" ) ]
591- parent_burn_block_hash : BurnchainHeaderHash ,
601+ pub parent_burn_block_hash : BurnchainHeaderHash ,
592602}
593603
594604impl < T : SignerEventTrait > TryFrom < BurnBlockEvent > for SignerEvent < T > {
@@ -605,6 +615,45 @@ impl<T: SignerEventTrait> TryFrom<BurnBlockEvent> for SignerEvent<T> {
605615 }
606616}
607617
618+ /// A subset of `TransactionEventPayload`, received from the event
619+ /// dispatcher.
620+ #[ derive( Clone , Debug , PartialEq , Serialize , Deserialize ) ]
621+ pub struct NewBlockTransaction {
622+ /// The raw transaction bytes. If this is a burn operation,
623+ /// this will be "00".
624+ #[ serde( with = "prefix_string_0x" ) ]
625+ raw_tx : String ,
626+ }
627+
628+ impl NewBlockTransaction {
629+ pub fn get_stacks_transaction ( & self ) -> Result < Option < StacksTransaction > , CodecError > {
630+ if self . raw_tx == "00" {
631+ Ok ( None )
632+ } else {
633+ let tx_bytes = hex_bytes ( & self . raw_tx ) . map_err ( |e| {
634+ CodecError :: DeserializeError ( format ! ( "Failed to deserialize raw tx: {}" , e) )
635+ } ) ?;
636+ let tx = StacksTransaction :: consensus_deserialize ( & mut & tx_bytes[ ..] ) ?;
637+ Ok ( Some ( tx) )
638+ }
639+ }
640+ }
641+
642+ /// "Special" deserializer to turn `{ tx_raw: "0x..." }` into `StacksTransaction`.
643+ fn deserialize_raw_tx_hex < ' de , D : serde:: Deserializer < ' de > > (
644+ d : D ,
645+ ) -> Result < Vec < StacksTransaction > , D :: Error > {
646+ let tx_objs: Vec < NewBlockTransaction > = serde:: Deserialize :: deserialize ( d) ?;
647+ Ok ( tx_objs
648+ . iter ( )
649+ . map ( |tx| tx. get_stacks_transaction ( ) )
650+ . collect :: < Result < Vec < _ > , _ > > ( )
651+ . map_err ( serde:: de:: Error :: custom) ?
652+ . into_iter ( )
653+ . flatten ( )
654+ . collect :: < Vec < _ > > ( ) )
655+ }
656+
608657#[ derive( Debug , Deserialize ) ]
609658struct BlockEvent {
610659 #[ serde( with = "prefix_hex" ) ]
@@ -617,6 +666,8 @@ struct BlockEvent {
617666 #[ serde( with = "prefix_hex" ) ]
618667 block_hash : BlockHeaderHash ,
619668 block_height : u64 ,
669+ #[ serde( deserialize_with = "deserialize_raw_tx_hex" ) ]
670+ transactions : Vec < StacksTransaction > ,
620671}
621672
622673impl < T : SignerEventTrait > TryFrom < BlockEvent > for SignerEvent < T > {
@@ -628,6 +679,7 @@ impl<T: SignerEventTrait> TryFrom<BlockEvent> for SignerEvent<T> {
628679 block_id : block_event. index_block_hash ,
629680 consensus_hash : block_event. consensus_hash ,
630681 block_height : block_event. block_height ,
682+ transactions : block_event. transactions ,
631683 } )
632684 }
633685}
0 commit comments