@@ -28,6 +28,7 @@ use bitcoin::hashes::Hash;
2828use bitcoin:: network:: constants:: Network ;
2929use bitcoin:: util:: hash:: bitcoin_merkle_root;
3030use bitcoin:: util:: uint:: Uint256 ;
31+ use bitcoin:: Witness ;
3132use lightning_block_sync:: poll:: {
3233 ChainPoller , Poll , Validate , ValidatedBlock , ValidatedBlockHeader ,
3334} ;
@@ -86,16 +87,18 @@ impl Blockchain {
8687 let prev_block = & self . blocks [ i - 1 ] ;
8788 let prev_blockhash = prev_block. block_hash ( ) ;
8889 let time = prev_block. header . time + height as u32 ;
90+ let txdata = vec ! [ get_random_tx( ) ] ;
91+ let hashes = txdata. iter ( ) . map ( |obj| obj. txid ( ) . as_hash ( ) ) ;
8992 self . blocks . push ( Block {
9093 header : BlockHeader {
9194 version : 0 ,
9295 prev_blockhash,
93- merkle_root : Default :: default ( ) ,
96+ merkle_root : bitcoin_merkle_root ( hashes ) . unwrap ( ) . into ( ) ,
9497 time,
9598 bits,
9699 nonce : 0 ,
97100 } ,
98- txdata : vec ! [ ] ,
101+ txdata,
99102 } ) ;
100103 }
101104 self
@@ -200,14 +203,20 @@ impl Blockchain {
200203 let prev_blockhash = prev_block. block_hash ( ) ;
201204 let time = prev_block. header . time + ( self . blocks . len ( ) + 1 ) as u32 ;
202205 let txdata = match txs {
203- Some ( t) => t,
204- None => vec ! [ ] ,
206+ Some ( v) => {
207+ if v. is_empty ( ) {
208+ vec ! [ get_random_tx( ) ]
209+ } else {
210+ v
211+ }
212+ }
213+ None => vec ! [ get_random_tx( ) ] ,
205214 } ;
206215 let hashes = txdata. iter ( ) . map ( |obj| obj. txid ( ) . as_hash ( ) ) ;
207216 let mut header = BlockHeader {
208217 version : 0 ,
209218 prev_blockhash,
210- merkle_root : bitcoin_merkle_root ( hashes) . into ( ) ,
219+ merkle_root : bitcoin_merkle_root ( hashes) . unwrap ( ) . into ( ) ,
211220 time,
212221 bits,
213222 nonce : 0 ,
@@ -226,7 +235,7 @@ impl Blockchain {
226235
227236impl BlockSource for Blockchain {
228237 fn get_header < ' a > (
229- & ' a mut self ,
238+ & ' a self ,
230239 header_hash : & ' a BlockHash ,
231240 _height_hint : Option < u32 > ,
232241 ) -> AsyncBlockSourceResult < ' a , BlockHeaderData > {
@@ -249,10 +258,7 @@ impl BlockSource for Blockchain {
249258 } )
250259 }
251260
252- fn get_block < ' a > (
253- & ' a mut self ,
254- header_hash : & ' a BlockHash ,
255- ) -> AsyncBlockSourceResult < ' a , Block > {
261+ fn get_block < ' a > ( & ' a self , header_hash : & ' a BlockHash ) -> AsyncBlockSourceResult < ' a , Block > {
256262 Box :: pin ( async move {
257263 for ( height, block) in self . blocks . iter ( ) . enumerate ( ) {
258264 if block. header . block_hash ( ) == * header_hash {
@@ -269,7 +275,7 @@ impl BlockSource for Blockchain {
269275 } )
270276 }
271277
272- fn get_best_block ( & mut self ) -> AsyncBlockSourceResult < ( BlockHash , Option < u32 > ) > {
278+ fn get_best_block ( & self ) -> AsyncBlockSourceResult < ( BlockHash , Option < u32 > ) > {
273279 Box :: pin ( async move {
274280 if * self . unreachable . lock ( ) . unwrap ( ) {
275281 return Err ( BlockSourceError :: transient ( "Connection refused" ) ) ;
@@ -304,7 +310,7 @@ pub(crate) fn get_random_tx() -> Transaction {
304310 rng. gen_range( 0 ..200 ) ,
305311 ) ,
306312 script_sig: Script :: new( ) ,
307- witness: Vec :: new( ) ,
313+ witness: Witness :: new( ) ,
308314 sequence: 0 ,
309315 } ] ,
310316 output : vec ! [ TxOut {
@@ -363,7 +369,7 @@ pub(crate) fn store_appointment_and_fks_to_db(
363369
364370pub ( crate ) async fn get_last_n_blocks ( chain : & mut Blockchain , n : usize ) -> Vec < ValidatedBlock > {
365371 let tip = chain. tip ( ) ;
366- let mut poller = ChainPoller :: new ( chain, Network :: Bitcoin ) ;
372+ let poller = ChainPoller :: new ( chain, Network :: Bitcoin ) ;
367373
368374 let mut last_n_blocks = Vec :: new ( ) ;
369375 let mut last_known_block = tip;
0 commit comments