Skip to content

Commit a23f72c

Browse files
committed
rustfmt: Run on lightning-block-sync/src/rest.rs
1 parent e27aad5 commit a23f72c

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

lightning-block-sync/src/rest.rs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Simple REST client implementation which implements [`BlockSource`] against a Bitcoin Core REST
22
//! endpoint.
33
4-
use crate::{BlockData, BlockHeaderData, BlockSource, AsyncBlockSourceResult};
5-
use crate::http::{BinaryResponse, HttpEndpoint, HttpClient, JsonResponse};
6-
use crate::gossip::UtxoSource;
74
use crate::convert::GetUtxosResponse;
5+
use crate::gossip::UtxoSource;
6+
use crate::http::{BinaryResponse, HttpClient, HttpEndpoint, JsonResponse};
7+
use crate::{AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource};
88

9-
use bitcoin::OutPoint;
109
use bitcoin::hash_types::BlockHash;
10+
use bitcoin::OutPoint;
1111

1212
use std::convert::TryFrom;
1313
use std::convert::TryInto;
@@ -29,41 +29,54 @@ impl RestClient {
2929

3030
/// Requests a resource encoded in `F` format and interpreted as type `T`.
3131
pub async fn request_resource<F, T>(&self, resource_path: &str) -> std::io::Result<T>
32-
where F: TryFrom<Vec<u8>, Error = std::io::Error> + TryInto<T, Error = std::io::Error> {
32+
where
33+
F: TryFrom<Vec<u8>, Error = std::io::Error> + TryInto<T, Error = std::io::Error>,
34+
{
3335
let host = format!("{}:{}", self.endpoint.host(), self.endpoint.port());
3436
let uri = format!("{}/{}", self.endpoint.path().trim_end_matches("/"), resource_path);
35-
let mut client = if let Some(client) = self.client.lock().unwrap().take() { client }
36-
else { HttpClient::connect(&self.endpoint)? };
37+
let mut client = if let Some(client) = self.client.lock().unwrap().take() {
38+
client
39+
} else {
40+
HttpClient::connect(&self.endpoint)?
41+
};
3742
let res = client.get::<F>(&uri, &host).await?.try_into();
3843
*self.client.lock().unwrap() = Some(client);
3944
res
4045
}
4146
}
4247

4348
impl BlockSource for RestClient {
44-
fn get_header<'a>(&'a self, header_hash: &'a BlockHash, _height: Option<u32>) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
49+
fn get_header<'a>(
50+
&'a self, header_hash: &'a BlockHash, _height: Option<u32>,
51+
) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
4552
Box::pin(async move {
4653
let resource_path = format!("headers/1/{}.json", header_hash.to_string());
4754
Ok(self.request_resource::<JsonResponse, _>(&resource_path).await?)
4855
})
4956
}
5057

51-
fn get_block<'a>(&'a self, header_hash: &'a BlockHash) -> AsyncBlockSourceResult<'a, BlockData> {
58+
fn get_block<'a>(
59+
&'a self, header_hash: &'a BlockHash,
60+
) -> AsyncBlockSourceResult<'a, BlockData> {
5261
Box::pin(async move {
5362
let resource_path = format!("block/{}.bin", header_hash.to_string());
54-
Ok(BlockData::FullBlock(self.request_resource::<BinaryResponse, _>(&resource_path).await?))
63+
Ok(BlockData::FullBlock(
64+
self.request_resource::<BinaryResponse, _>(&resource_path).await?,
65+
))
5566
})
5667
}
5768

5869
fn get_best_block<'a>(&'a self) -> AsyncBlockSourceResult<'a, (BlockHash, Option<u32>)> {
59-
Box::pin(async move {
60-
Ok(self.request_resource::<JsonResponse, _>("chaininfo.json").await?)
61-
})
70+
Box::pin(
71+
async move { Ok(self.request_resource::<JsonResponse, _>("chaininfo.json").await?) },
72+
)
6273
}
6374
}
6475

6576
impl UtxoSource for RestClient {
66-
fn get_block_hash_by_height<'a>(&'a self, block_height: u32) -> AsyncBlockSourceResult<'a, BlockHash> {
77+
fn get_block_hash_by_height<'a>(
78+
&'a self, block_height: u32,
79+
) -> AsyncBlockSourceResult<'a, BlockHash> {
6780
Box::pin(async move {
6881
let resource_path = format!("blockhashbyheight/{}.bin", block_height);
6982
Ok(self.request_resource::<BinaryResponse, _>(&resource_path).await?)
@@ -72,7 +85,8 @@ impl UtxoSource for RestClient {
7285

7386
fn is_output_unspent<'a>(&'a self, outpoint: OutPoint) -> AsyncBlockSourceResult<'a, bool> {
7487
Box::pin(async move {
75-
let resource_path = format!("getutxos/{}-{}.json", outpoint.txid.to_string(), outpoint.vout);
88+
let resource_path =
89+
format!("getutxos/{}-{}.json", outpoint.txid.to_string(), outpoint.vout);
7690
let utxo_result =
7791
self.request_resource::<JsonResponse, GetUtxosResponse>(&resource_path).await?;
7892
Ok(utxo_result.hit_bitmap_nonempty)
@@ -83,8 +97,8 @@ impl UtxoSource for RestClient {
8397
#[cfg(test)]
8498
mod tests {
8599
use super::*;
86-
use crate::http::BinaryResponse;
87100
use crate::http::client_tests::{HttpServer, MessageBody};
101+
use crate::http::BinaryResponse;
88102
use bitcoin::hashes::Hash;
89103

90104
/// Parses binary data as a string-encoded `u32`.
@@ -97,7 +111,7 @@ mod tests {
97111
Ok(s) => match u32::from_str_radix(s, 10) {
98112
Err(e) => Err(std::io::Error::new(std::io::ErrorKind::InvalidData, e)),
99113
Ok(n) => Ok(n),
100-
}
114+
},
101115
}
102116
}
103117
}
@@ -140,7 +154,7 @@ mod tests {
140154
let server = HttpServer::responding_with_ok(MessageBody::Content(
141155
// A real response contains a few more fields, but we actually only look at the
142156
// "bitmap" field, so this should suffice for testing
143-
"{\"chainHeight\": 1, \"bitmap\":\"0\",\"utxos\":[]}"
157+
"{\"chainHeight\": 1, \"bitmap\":\"0\",\"utxos\":[]}",
144158
));
145159
let client = RestClient::new(server.endpoint()).unwrap();
146160

@@ -154,7 +168,7 @@ mod tests {
154168
let server = HttpServer::responding_with_ok(MessageBody::Content(
155169
// A real response contains lots more data, but we actually only look at the "bitmap"
156170
// field, so this should suffice for testing
157-
"{\"chainHeight\": 1, \"bitmap\":\"1\",\"utxos\":[]}"
171+
"{\"chainHeight\": 1, \"bitmap\":\"1\",\"utxos\":[]}",
158172
));
159173
let client = RestClient::new(server.endpoint()).unwrap();
160174

rustfmt_excluded_files

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
./lightning-background-processor/src/lib.rs
22
./lightning-block-sync/src/lib.rs
3-
./lightning-block-sync/src/rest.rs
43
./lightning-block-sync/src/rpc.rs
54
./lightning-block-sync/src/test_utils.rs
65
./lightning-block-sync/src/utils.rs

0 commit comments

Comments
 (0)