Skip to content

Commit 4cdb12f

Browse files
committed
Drop unnecessary Result in RpcClient::new
.. as it's infallible
1 parent a952d2d commit 4cdb12f

File tree

1 file changed

+11
-11
lines changed
  • lightning-block-sync/src

1 file changed

+11
-11
lines changed

lightning-block-sync/src/rpc.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ impl RpcClient {
5050
/// Creates a new RPC client connected to the given endpoint with the provided credentials. The
5151
/// credentials should be a base64 encoding of a user name and password joined by a colon, as is
5252
/// required for HTTP basic access authentication.
53-
pub fn new(credentials: &str, endpoint: HttpEndpoint) -> std::io::Result<Self> {
54-
Ok(Self {
53+
pub fn new(credentials: &str, endpoint: HttpEndpoint) -> Self {
54+
Self {
5555
basic_auth: "Basic ".to_string() + credentials,
5656
endpoint,
5757
client: Mutex::new(None),
5858
id: AtomicUsize::new(0),
59-
})
59+
}
6060
}
6161

6262
/// Calls a method with the response encoded in JSON format and interpreted as type `T`.
@@ -204,7 +204,7 @@ mod tests {
204204
#[tokio::test]
205205
async fn call_method_returning_unknown_response() {
206206
let server = HttpServer::responding_with_not_found();
207-
let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
207+
let client = RpcClient::new(CREDENTIALS, server.endpoint());
208208

209209
match client.call_method::<u64>("getblockcount", &[]).await {
210210
Err(e) => assert_eq!(e.kind(), std::io::ErrorKind::Other),
@@ -216,7 +216,7 @@ mod tests {
216216
async fn call_method_returning_malfomred_response() {
217217
let response = serde_json::json!("foo");
218218
let server = HttpServer::responding_with_ok(MessageBody::Content(response));
219-
let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
219+
let client = RpcClient::new(CREDENTIALS, server.endpoint());
220220

221221
match client.call_method::<u64>("getblockcount", &[]).await {
222222
Err(e) => {
@@ -233,7 +233,7 @@ mod tests {
233233
"error": { "code": -8, "message": "invalid parameter" },
234234
});
235235
let server = HttpServer::responding_with_server_error(response);
236-
let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
236+
let client = RpcClient::new(CREDENTIALS, server.endpoint());
237237

238238
let invalid_block_hash = serde_json::json!("foo");
239239
match client.call_method::<u64>("getblock", &[invalid_block_hash]).await {
@@ -251,7 +251,7 @@ mod tests {
251251
async fn call_method_returning_missing_result() {
252252
let response = serde_json::json!({});
253253
let server = HttpServer::responding_with_ok(MessageBody::Content(response));
254-
let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
254+
let client = RpcClient::new(CREDENTIALS, server.endpoint());
255255

256256
match client.call_method::<u64>("getblockcount", &[]).await {
257257
Err(e) => {
@@ -266,7 +266,7 @@ mod tests {
266266
async fn call_method_returning_malformed_result() {
267267
let response = serde_json::json!({ "result": "foo" });
268268
let server = HttpServer::responding_with_ok(MessageBody::Content(response));
269-
let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
269+
let client = RpcClient::new(CREDENTIALS, server.endpoint());
270270

271271
match client.call_method::<u64>("getblockcount", &[]).await {
272272
Err(e) => {
@@ -281,7 +281,7 @@ mod tests {
281281
async fn call_method_returning_valid_result() {
282282
let response = serde_json::json!({ "result": 654470 });
283283
let server = HttpServer::responding_with_ok(MessageBody::Content(response));
284-
let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
284+
let client = RpcClient::new(CREDENTIALS, server.endpoint());
285285

286286
match client.call_method::<u64>("getblockcount", &[]).await {
287287
Err(e) => panic!("Unexpected error: {:?}", e),
@@ -293,7 +293,7 @@ mod tests {
293293
async fn fails_to_fetch_spent_utxo() {
294294
let response = serde_json::json!({ "result": null });
295295
let server = HttpServer::responding_with_ok(MessageBody::Content(response));
296-
let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
296+
let client = RpcClient::new(CREDENTIALS, server.endpoint());
297297
let outpoint = OutPoint::new(bitcoin::Txid::from_byte_array([0; 32]), 0);
298298
let unspent_output = client.is_output_unspent(outpoint).await.unwrap();
299299
assert_eq!(unspent_output, false);
@@ -303,7 +303,7 @@ mod tests {
303303
async fn fetches_utxo() {
304304
let response = serde_json::json!({ "result": {"bestblock": 1, "confirmations": 42}});
305305
let server = HttpServer::responding_with_ok(MessageBody::Content(response));
306-
let client = RpcClient::new(CREDENTIALS, server.endpoint()).unwrap();
306+
let client = RpcClient::new(CREDENTIALS, server.endpoint());
307307
let outpoint = OutPoint::new(bitcoin::Txid::from_byte_array([0; 32]), 0);
308308
let unspent_output = client.is_output_unspent(outpoint).await.unwrap();
309309
assert_eq!(unspent_output, true);

0 commit comments

Comments
 (0)