@@ -133,7 +133,7 @@ where
133
133
last_id : AtomicUsize ,
134
134
waiting_map : Mutex < HashMap < usize , Sender < ChannelMessage > > > ,
135
135
136
- headers : Mutex < Option < VecDeque < RawHeaderNotification > > > ,
136
+ headers : Mutex < VecDeque < RawHeaderNotification > > ,
137
137
script_notifications : Mutex < HashMap < ScriptHash , VecDeque < ScriptStatus > > > ,
138
138
139
139
#[ cfg( feature = "debug-calls" ) ]
@@ -154,7 +154,7 @@ where
154
154
last_id : AtomicUsize :: new ( 0 ) ,
155
155
waiting_map : Mutex :: new ( HashMap :: new ( ) ) ,
156
156
157
- headers : Mutex :: new ( None ) ,
157
+ headers : Mutex :: new ( VecDeque :: new ( ) ) ,
158
158
script_notifications : Mutex :: new ( HashMap :: new ( ) ) ,
159
159
160
160
#[ cfg( feature = "debug-calls" ) ]
@@ -648,17 +648,11 @@ impl<S: Read + Write> RawClient<S> {
648
648
649
649
fn handle_notification ( & self , method : & str , result : serde_json:: Value ) -> Result < ( ) , Error > {
650
650
match method {
651
- "blockchain.headers.subscribe" => {
652
- let mut queue = self . headers . lock ( ) ?;
653
- match queue. as_mut ( ) {
654
- None => return Err ( Error :: NotSubscribedToHeaders ) ,
655
- Some ( queue) => queue. append (
656
- & mut serde_json:: from_value :: < Vec < RawHeaderNotification > > ( result) ?
657
- . into_iter ( )
658
- . collect ( ) ,
659
- ) ,
660
- }
661
- }
651
+ "blockchain.headers.subscribe" => self . headers . lock ( ) ?. append (
652
+ & mut serde_json:: from_value :: < Vec < RawHeaderNotification > > ( result) ?
653
+ . into_iter ( )
654
+ . collect ( ) ,
655
+ ) ,
662
656
"blockchain.scripthash.subscribe" => {
663
657
let unserialized: ScriptNotification = serde_json:: from_value ( result) ?;
664
658
let mut script_notifications = self . script_notifications . lock ( ) ?;
@@ -768,11 +762,6 @@ impl<T: Read + Write> ElectrumApi for RawClient<T> {
768
762
}
769
763
770
764
fn block_headers_subscribe_raw ( & self ) -> Result < RawHeaderNotification , Error > {
771
- let mut headers = self . headers . lock ( ) ?;
772
- if headers. is_none ( ) {
773
- * headers = Some ( VecDeque :: new ( ) ) ;
774
- }
775
-
776
765
let req = Request :: new_id (
777
766
self . last_id . fetch_add ( 1 , Ordering :: SeqCst ) ,
778
767
"blockchain.headers.subscribe" ,
@@ -784,11 +773,7 @@ impl<T: Read + Write> ElectrumApi for RawClient<T> {
784
773
}
785
774
786
775
fn block_headers_pop_raw ( & self ) -> Result < Option < RawHeaderNotification > , Error > {
787
- let mut queue = self . headers . lock ( ) ?;
788
- match queue. as_mut ( ) {
789
- None => Err ( Error :: NotSubscribedToHeaders ) ,
790
- Some ( queue) => Ok ( queue. pop_front ( ) ) ,
791
- }
776
+ Ok ( self . headers . lock ( ) ?. pop_front ( ) )
792
777
}
793
778
794
779
fn block_header_raw ( & self , height : usize ) -> Result < Vec < u8 > , Error > {
@@ -1348,16 +1333,6 @@ mod test {
1348
1333
assert ! ( resp. height >= 639000 ) ;
1349
1334
}
1350
1335
1351
- #[ test]
1352
- fn test_block_headers_subscribe_pop ( ) {
1353
- let client = RawClient :: new ( get_test_server ( ) , None ) . unwrap ( ) ;
1354
- let resp = client. block_headers_pop ( ) ;
1355
- assert_eq ! ( format!( "{:?}" , resp) , "Err(NotSubscribedToHeaders)" ) ;
1356
- client. block_headers_subscribe ( ) . unwrap ( ) ;
1357
- let resp = client. block_headers_pop ( ) ;
1358
- assert ! ( resp. is_ok( ) ) ;
1359
- }
1360
-
1361
1336
#[ test]
1362
1337
fn test_script_subscribe ( ) {
1363
1338
use std:: str:: FromStr ;
0 commit comments