@@ -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} ;
@@ -82,16 +83,19 @@ impl Blockchain {
8283 let prev_block = & self . blocks [ i - 1 ] ;
8384 let prev_blockhash = prev_block. block_hash ( ) ;
8485 let time = prev_block. header . time + height as u32 ;
86+ let txdata = vec ! [ get_random_tx( ) ] ;
87+ let hashes = txdata. iter ( ) . map ( |obj| obj. txid ( ) . as_hash ( ) ) ;
88+
8589 self . blocks . push ( Block {
8690 header : BlockHeader {
8791 version : 0 ,
8892 prev_blockhash,
89- merkle_root : Default :: default ( ) ,
93+ merkle_root : bitcoin_merkle_root ( hashes ) . unwrap ( ) . into ( ) ,
9094 time,
9195 bits,
9296 nonce : 0 ,
9397 } ,
94- txdata : vec ! [ ] ,
98+ txdata,
9599 } ) ;
96100 }
97101 self
@@ -196,14 +200,15 @@ impl Blockchain {
196200 let prev_blockhash = prev_block. block_hash ( ) ;
197201 let time = prev_block. header . time + ( self . blocks . len ( ) + 1 ) as u32 ;
198202 let txdata = match txs {
203+ None => vec ! [ get_random_tx( ) ] ,
204+ Some ( v) if v. is_empty ( ) => vec ! [ get_random_tx( ) ] ,
199205 Some ( t) => t,
200- None => vec ! [ ] ,
201206 } ;
202207 let hashes = txdata. iter ( ) . map ( |obj| obj. txid ( ) . as_hash ( ) ) ;
203208 let mut header = BlockHeader {
204209 version : 0 ,
205210 prev_blockhash,
206- merkle_root : bitcoin_merkle_root ( hashes) . into ( ) ,
211+ merkle_root : bitcoin_merkle_root ( hashes) . unwrap ( ) . into ( ) ,
207212 time,
208213 bits,
209214 nonce : 0 ,
@@ -222,7 +227,7 @@ impl Blockchain {
222227
223228impl BlockSource for Blockchain {
224229 fn get_header < ' a > (
225- & ' a mut self ,
230+ & ' a self ,
226231 header_hash : & ' a BlockHash ,
227232 _height_hint : Option < u32 > ,
228233 ) -> AsyncBlockSourceResult < ' a , BlockHeaderData > {
@@ -245,10 +250,7 @@ impl BlockSource for Blockchain {
245250 } )
246251 }
247252
248- fn get_block < ' a > (
249- & ' a mut self ,
250- header_hash : & ' a BlockHash ,
251- ) -> AsyncBlockSourceResult < ' a , Block > {
253+ fn get_block < ' a > ( & ' a self , header_hash : & ' a BlockHash ) -> AsyncBlockSourceResult < ' a , Block > {
252254 Box :: pin ( async move {
253255 for ( height, block) in self . blocks . iter ( ) . enumerate ( ) {
254256 if block. header . block_hash ( ) == * header_hash {
@@ -265,7 +267,7 @@ impl BlockSource for Blockchain {
265267 } )
266268 }
267269
268- fn get_best_block ( & mut self ) -> AsyncBlockSourceResult < ( BlockHash , Option < u32 > ) > {
270+ fn get_best_block ( & self ) -> AsyncBlockSourceResult < ( BlockHash , Option < u32 > ) > {
269271 Box :: pin ( async move {
270272 if * self . unreachable . lock ( ) . unwrap ( ) {
271273 return Err ( BlockSourceError :: transient ( "Connection refused" ) ) ;
@@ -300,7 +302,7 @@ pub(crate) fn get_random_tx() -> Transaction {
300302 rng. gen_range( 0 ..200 ) ,
301303 ) ,
302304 script_sig: Script :: new( ) ,
303- witness: Vec :: new( ) ,
305+ witness: Witness :: new( ) ,
304306 sequence: 0 ,
305307 } ] ,
306308 output : vec ! [ TxOut {
@@ -356,7 +358,7 @@ pub(crate) fn store_appointment_and_fks_to_db(
356358
357359pub ( crate ) async fn get_last_n_blocks ( chain : & mut Blockchain , n : usize ) -> Vec < ValidatedBlock > {
358360 let tip = chain. tip ( ) ;
359- let mut poller = ChainPoller :: new ( chain, Network :: Bitcoin ) ;
361+ let poller = ChainPoller :: new ( chain, Network :: Bitcoin ) ;
360362
361363 let mut last_n_blocks = Vec :: new ( ) ;
362364 let mut last_known_block = tip;
0 commit comments