Skip to content

Commit 0bd550f

Browse files
author
Conor Okus
committed
Improve readability
1 parent 6990a67 commit 0bd550f

File tree

3 files changed

+10
-25
lines changed

3 files changed

+10
-25
lines changed

examples/bitcoind-rpc-client/src/bitcoind_client.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{sync::{Arc}};
22

33
use bitcoin::{BlockHash, Block};
44
use lightning_block_sync::{rpc::RpcClient, http::{HttpEndpoint}, BlockSource, AsyncBlockSourceResult, BlockHeaderData};
5+
use serde_json::json;
56
use tokio::sync::Mutex;
67

78
use crate::convert::{CreateWalletResponse, BlockchainInfoResponse, NewAddressResponse, GetBalanceResponse, GenerateToAddressResponse};
@@ -48,7 +49,7 @@ impl BitcoindClient {
4849
let rpc_creditials =
4950
base64::encode(format!("{}:{}", rpc_user.clone(), rpc_password.clone()));
5051
let mut bitcoind_rpc_client = RpcClient::new(&rpc_creditials, http_endpoint)?;
51-
let _dummy = bitcoind_rpc_client
52+
bitcoind_rpc_client
5253
.call_method::<BlockchainInfoResponse>("getblockchaininfo", &vec![])
5354
.await
5455
.map_err(|_| {
@@ -81,15 +82,15 @@ impl BitcoindClient {
8182

8283
pub async fn create_wallet(&self) -> CreateWalletResponse {
8384
let mut rpc = self.bitcoind_rpc_client.lock().await;
84-
let create_wallet_args = vec![serde_json::json!("test-wallet")];
85+
let create_wallet_args = vec![json!("test-wallet")];
8586

8687
rpc.call_method::<CreateWalletResponse>("createwallet", &create_wallet_args).await.unwrap()
8788
}
8889

8990
pub async fn get_new_address(&self) -> String {
9091
let mut rpc = self.bitcoind_rpc_client.lock().await;
9192

92-
let addr_args = vec![serde_json::json!("LDK output address")];
93+
let addr_args = vec![json!("LDK output address")];
9394
let addr = rpc.call_method::<NewAddressResponse>("getnewaddress", &addr_args).await.unwrap();
9495
addr.0.to_string()
9596
}
@@ -103,16 +104,9 @@ impl BitcoindClient {
103104
pub async fn generate_to_address(&self, block_num: u64, address: &str) -> GenerateToAddressResponse {
104105
let mut rpc = self.bitcoind_rpc_client.lock().await;
105106

106-
let generate_to_address_args = vec![serde_json::json!(block_num), serde_json::json!(address)];
107+
let generate_to_address_args = vec![json!(block_num), json!(address)];
107108

108109

109110
rpc.call_method::<GenerateToAddressResponse>("generatetoaddress", &generate_to_address_args).await.unwrap()
110111
}
111-
}
112-
113-
114-
115-
116-
117-
118-
112+
}

examples/bitcoind-rpc-client/src/convert.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::convert::TryInto;
33
use bitcoin::{BlockHash, hashes::hex::FromHex};
44
use lightning_block_sync::http::JsonResponse;
55

6-
// TryInto implementation specifies the conversion logic from json response to BlockchainInfo object.
6+
/// TryInto implementation specifies the conversion logic from json response to BlockchainInfo object.
77
pub struct BlockchainInfoResponse {
88
pub latest_height: usize,
99
pub latest_blockhash: BlockHash,
@@ -54,7 +54,7 @@ impl TryInto<GenerateToAddressResponse> for JsonResponse {
5454

5555
for item in self.0.as_array().unwrap() {
5656
x.push(BlockHash::from_hex(item.as_str().unwrap())
57-
.unwrap());
57+
.unwrap());
5858
}
5959

6060
Ok(GenerateToAddressResponse(x))
@@ -69,13 +69,4 @@ impl TryInto<NewAddressResponse> for JsonResponse {
6969
fn try_into(self) -> std::io::Result<NewAddressResponse> {
7070
Ok(NewAddressResponse(self.0.as_str().unwrap().to_string()))
7171
}
72-
}
73-
74-
75-
76-
77-
78-
79-
80-
81-
72+
}

examples/bitcoind-rpc-client/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ async fn start_ldk() {
5050
// Show balance
5151
let balance = bitcoind_client.get_balance().await;
5252
println!("Balance: {}", balance.0);
53-
}
53+
}

0 commit comments

Comments
 (0)