less debug, handle error if channel is closed

This commit is contained in:
Deniod
2024-01-13 22:41:02 +01:00
parent 60550982e0
commit a307f828c9

View File

@@ -123,13 +123,12 @@ where F : Fn(&[u8], u64) {
use prost::Message; use prost::Message;
let mut encoded_buf = vec![]; let mut encoded_buf = vec![];
match block.encode(&mut encoded_buf) { if let Err(e) = block.encode(&mut encoded_buf) {
Ok(_) => c(&encoded_buf, block.height),
Err(e) => {
eprintln!("Error encoding block: {:?}", e); eprintln!("Error encoding block: {:?}", e);
break; break;
} }
}
c(&encoded_buf, block.height);
} }
if let Err(e) = ftx.send(Ok(())) { if let Err(e) = ftx.send(Ok(())) {
@@ -178,19 +177,38 @@ pub fn fetch_blocks<F : 'static + std::marker::Send>(uri: &http::Uri, start_heig
} }
} }
// get_address_txids GRPC call // get_address_txids GRPC call
async fn get_address_txids<F : 'static + std::marker::Send>(uri: &http::Uri, address: String, async fn get_address_txids<F : 'static + std::marker::Send>(
start_height: u64, end_height: u64, no_cert: bool, c: F) -> Result<(), Box<dyn std::error::Error>> uri: &http::Uri,
address: String,
start_height: u64,
end_height: u64,
no_cert: bool,
c: F
) -> Result<(), Box<dyn std::error::Error>>
where F : Fn(&[u8], u64) { where F : Fn(&[u8], u64) {
let mut client = get_client(uri, no_cert).await?; let mut client = match get_client(uri, no_cert).await {
Ok(client) => client,
Err(e) => {
eprintln!("Error creating client: {:?}", e);
return Err(e.into());
}
};
let start = Some(BlockId{ height: start_height, hash: vec!()}); let start = Some(BlockId{ height: start_height, hash: vec!()});
let end = Some(BlockId{ height: end_height, hash: vec!()}); let end = Some(BlockId{ height: end_height, hash: vec!()});
let request = Request::new(TransparentAddressBlockFilter{ address, range: Some(BlockRange{ start, end }) }); let request = Request::new(TransparentAddressBlockFilter{ address, range: Some(BlockRange{ start, end }) });
let maybe_response = client.get_address_txids(request).await?; let maybe_response = match client.get_address_txids(request).await {
Ok(response) => response,
Err(e) => {
eprintln!("Error getting address txids: {:?}", e);
return Err(e.into());
}
};
let mut response = maybe_response.into_inner(); let mut response = maybe_response.into_inner();
while let Some(tx) = response.message().await? { while let Some(tx) = response.message().await? {
@@ -234,8 +252,14 @@ where
Ok(()) Ok(())
} }
pub fn fetch_transparent_txids<F : 'static + std::marker::Send>(uri: &http::Uri, address: String, pub fn fetch_transparent_txids<F : 'static + std::marker::Send>(
start_height: u64, end_height: u64, no_cert: bool, c: F) -> Result<(), String> uri: &http::Uri,
address: String,
start_height: u64,
end_height: u64,
no_cert: bool,
c: F
) -> Result<(), String>
where F : Fn(&[u8], u64) { where F : Fn(&[u8], u64) {
let mut rt = match tokio::runtime::Runtime::new() { let mut rt = match tokio::runtime::Runtime::new() {
@@ -252,7 +276,7 @@ pub fn fetch_transparent_txids<F : 'static + std::marker::Send>(uri: &http::Uri,
Err(e) => { Err(e) => {
let e = format!("Error with get_address_txids runtime {:?}", e); let e = format!("Error with get_address_txids runtime {:?}", e);
error!("{}", e); error!("{}", e);
Err(e) return Err(e)
} }
} }
} }