@@ -1087,29 +1087,27 @@ pub struct Client {
1087
1087
1088
1088
impl fmt:: Debug for Client {
1089
1089
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1090
- write ! (
1091
- f,
1092
- "bitcoincore_rpc::Client(jsonrpc::Client(last_nonce={}))" ,
1093
- self . client. last_nonce( )
1094
- )
1090
+ write ! ( f, "bitcoincore_rpc::Client({:?})" , self . client)
1095
1091
}
1096
1092
}
1097
1093
1098
1094
impl Client {
1099
1095
/// Creates a client to a bitcoind JSON-RPC server.
1100
1096
///
1101
1097
/// Can only return [Err] when using cookie authentication.
1102
- pub fn new ( url : String , auth : Auth ) -> Result < Self > {
1098
+ pub fn new ( url : & str , auth : Auth ) -> Result < Self > {
1103
1099
let ( user, pass) = auth. get_user_pass ( ) ?;
1104
- Ok ( Client {
1105
- client : jsonrpc:: client:: Client :: new ( url, user, pass) ,
1106
- } )
1100
+ jsonrpc:: client:: Client :: simple_http ( url, user, pass)
1101
+ . map ( |client| Client {
1102
+ client,
1103
+ } )
1104
+ . map_err ( |e| super :: error:: Error :: JsonRpc ( e. into ( ) ) )
1107
1105
}
1108
1106
1109
- /// Create a new Client.
1107
+ /// Create a new Client using the given [jsonrpc::Client] .
1110
1108
pub fn from_jsonrpc ( client : jsonrpc:: client:: Client ) -> Client {
1111
1109
Client {
1112
- client : client ,
1110
+ client,
1113
1111
}
1114
1112
}
1115
1113
@@ -1126,14 +1124,22 @@ impl RpcApi for Client {
1126
1124
cmd : & str ,
1127
1125
args : & [ serde_json:: Value ] ,
1128
1126
) -> Result < T > {
1129
- let req = self . client . build_request ( & cmd, & args) ;
1127
+ let raw_args: Vec < _ > = args
1128
+ . iter ( )
1129
+ . map ( |a| {
1130
+ let json_string = serde_json:: to_string ( a) ?;
1131
+ serde_json:: value:: RawValue :: from_string ( json_string) // we can't use to_raw_value here due to compat with Rust 1.29
1132
+ } )
1133
+ . map ( |a| a. map_err ( |e| Error :: Json ( e) ) )
1134
+ . collect :: < Result < Vec < _ > > > ( ) ?;
1135
+ let req = self . client . build_request ( & cmd, & raw_args) ;
1130
1136
if log_enabled ! ( Debug ) {
1131
1137
debug ! ( target: "bitcoincore_rpc" , "JSON-RPC request: {} {}" , cmd, serde_json:: Value :: from( args) ) ;
1132
1138
}
1133
1139
1134
- let resp = self . client . send_request ( & req) . map_err ( Error :: from) ;
1140
+ let resp = self . client . send_request ( req) . map_err ( Error :: from) ;
1135
1141
log_response ( cmd, & resp) ;
1136
- Ok ( resp?. into_result ( ) ?)
1142
+ Ok ( resp?. result ( ) ?)
1137
1143
}
1138
1144
}
1139
1145
@@ -1151,7 +1157,12 @@ fn log_response(cmd: &str, resp: &Result<jsonrpc::Response>) {
1151
1157
debug ! ( target: "bitcoincore_rpc" , "JSON-RPC error for {}: {:?}" , cmd, e) ;
1152
1158
}
1153
1159
} else if log_enabled ! ( Trace ) {
1154
- let result = resp. result . as_ref ( ) . unwrap_or ( & serde_json:: Value :: Null ) ;
1160
+ // we can't use to_raw_value here due to compat with Rust 1.29
1161
+ let def = serde_json:: value:: RawValue :: from_string (
1162
+ serde_json:: Value :: Null . to_string ( ) ,
1163
+ )
1164
+ . unwrap ( ) ;
1165
+ let result = resp. result . as_ref ( ) . unwrap_or ( & def) ;
1155
1166
trace ! ( target: "bitcoincore_rpc" , "JSON-RPC response for {}: {}" , cmd, result) ;
1156
1167
}
1157
1168
}
0 commit comments