3
3
//! This module contains the definition of the raw client that wraps the transport method
4
4
5
5
use std:: collections:: { BTreeMap , BTreeSet , HashMap , VecDeque } ;
6
- use std:: convert:: TryFrom ;
7
6
use std:: io:: { BufRead , BufReader , Read , Write } ;
8
7
use std:: mem:: drop;
9
8
use std:: net:: { TcpStream , ToSocketAddrs } ;
@@ -348,6 +347,8 @@ impl RawClient<ElectrumSslStream> {
348
347
validate_domain : bool ,
349
348
tcp_stream : TcpStream ,
350
349
) -> Result < Self , Error > {
350
+ use std:: convert:: TryFrom ;
351
+
351
352
let builder = ClientConfig :: builder ( ) . with_safe_defaults ( ) ;
352
353
353
354
let config = if validate_domain {
@@ -658,6 +659,21 @@ impl<S: Read + Write> RawClient<S> {
658
659
Ok ( ( ) )
659
660
}
660
661
662
+ pub ( crate ) fn internal_raw_call_with_vec (
663
+ & self ,
664
+ method_name : & str ,
665
+ params : Vec < Param > ,
666
+ ) -> Result < serde_json:: Value , Error > {
667
+ let req = Request :: new_id (
668
+ self . last_id . fetch_add ( 1 , Ordering :: SeqCst ) ,
669
+ & method_name,
670
+ params,
671
+ ) ;
672
+ let result = self . call ( req) ?;
673
+
674
+ Ok ( result)
675
+ }
676
+
661
677
#[ inline]
662
678
#[ cfg( feature = "debug-calls" ) ]
663
679
fn increment_calls ( & self ) {
@@ -670,15 +686,12 @@ impl<S: Read + Write> RawClient<S> {
670
686
}
671
687
672
688
impl < T : Read + Write > ElectrumApi for RawClient < T > {
673
- fn raw_call ( & self , call : & Call ) -> Result < serde_json:: Value , Error > {
674
- let req = Request :: new_id (
675
- self . last_id . fetch_add ( 1 , Ordering :: SeqCst ) ,
676
- & call. 0 ,
677
- call. 1 . to_vec ( ) ,
678
- ) ;
679
- let result = self . call ( req) ?;
680
-
681
- Ok ( result)
689
+ fn raw_call (
690
+ & self ,
691
+ method_name : & str ,
692
+ params : impl IntoIterator < Item = Param > ,
693
+ ) -> Result < serde_json:: Value , Error > {
694
+ self . internal_raw_call_with_vec ( method_name, params. into_iter ( ) . collect ( ) )
682
695
}
683
696
684
697
fn batch_call ( & self , batch : & Batch ) -> Result < Vec < serde_json:: Value > , Error > {
@@ -1312,9 +1325,10 @@ mod test {
1312
1325
) ,
1313
1326
Param :: Bool ( false ) ,
1314
1327
] ;
1315
- let call = ( "blockchain.transaction.get" . to_string ( ) , params) ;
1316
1328
1317
- let resp = client. raw_call ( & call) . unwrap ( ) ;
1329
+ let resp = client
1330
+ . raw_call ( "blockchain.transaction.get" , params)
1331
+ . unwrap ( ) ;
1318
1332
1319
1333
assert_eq ! (
1320
1334
resp,
0 commit comments