@@ -72,6 +72,34 @@ impl StacksMessageCodec for NakamotoBlockVote {
72
72
}
73
73
}
74
74
75
+ #[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
76
+ /// Struct for storing information about a burn block
77
+ pub struct BurnBlockInfo {
78
+ /// The hash of the burn block
79
+ pub block_hash : BurnchainHeaderHash ,
80
+ /// The height of the burn block
81
+ pub block_height : u64 ,
82
+ /// The consensus hash of the burn block
83
+ pub consensus_hash : ConsensusHash ,
84
+ /// The hash of the parent burn block
85
+ pub parent_burn_block_hash : BurnchainHeaderHash ,
86
+ }
87
+
88
+ impl FromRow < BurnBlockInfo > for BurnBlockInfo {
89
+ fn from_row ( row : & rusqlite:: Row ) -> Result < Self , DBError > {
90
+ let block_hash: BurnchainHeaderHash = row. get ( 0 ) ?;
91
+ let block_height: u64 = row. get ( 1 ) ?;
92
+ let consensus_hash: ConsensusHash = row. get ( 2 ) ?;
93
+ let parent_burn_block_hash: BurnchainHeaderHash = row. get ( 3 ) ?;
94
+ Ok ( BurnBlockInfo {
95
+ block_hash,
96
+ block_height,
97
+ consensus_hash,
98
+ parent_burn_block_hash,
99
+ } )
100
+ }
101
+ }
102
+
75
103
#[ derive( Serialize , Deserialize , Debug , PartialEq , Default ) ]
76
104
/// Store extra version-specific info in `BlockInfo`
77
105
pub enum ExtraBlockInfo {
@@ -1068,6 +1096,26 @@ impl SignerDb {
1068
1096
Ok ( Some ( receive_time) )
1069
1097
}
1070
1098
1099
+ /// Lookup the burn block for a given burn block hash.
1100
+ pub fn get_burn_block_by_hash (
1101
+ & self ,
1102
+ burn_block_hash : & BurnchainHeaderHash ,
1103
+ ) -> Result < BurnBlockInfo , DBError > {
1104
+ let query =
1105
+ "SELECT block_hash, block_height, consensus_hash, parent_burn_block_hash FROM burn_blocks WHERE block_hash = ?" ;
1106
+ let args = params ! [ burn_block_hash] ;
1107
+
1108
+ query_row ( & self . db , query, args) ?. ok_or ( DBError :: NotFoundError )
1109
+ }
1110
+
1111
+ /// Lookup the burn block for a given consensus hash.
1112
+ pub fn get_burn_block_by_ch ( & self , ch : & ConsensusHash ) -> Result < BurnBlockInfo , DBError > {
1113
+ let query = "SELECT block_hash, block_height, consensus_hash, parent_burn_block_hash FROM burn_blocks WHERE consensus_hash = ?" ;
1114
+ let args = params ! [ ch] ;
1115
+
1116
+ query_row ( & self . db , query, args) ?. ok_or ( DBError :: NotFoundError )
1117
+ }
1118
+
1071
1119
/// Insert or replace a block into the database.
1072
1120
/// Preserves the `broadcast` column if replacing an existing block.
1073
1121
pub fn insert_block ( & mut self , block_info : & BlockInfo ) -> Result < ( ) , DBError > {
0 commit comments