less debug, handle error if channel is closed
This commit is contained in:
@@ -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),
|
eprintln!("Error encoding block: {:?}", e);
|
||||||
Err(e) => {
|
break;
|
||||||
eprintln!("Error encoding block: {:?}", e);
|
|
||||||
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,
|
||||||
where F : Fn(&[u8], u64) {
|
address: String,
|
||||||
|
start_height: u64,
|
||||||
|
end_height: u64,
|
||||||
|
no_cert: bool,
|
||||||
|
c: F
|
||||||
|
) -> Result<(), Box<dyn std::error::Error>>
|
||||||
|
where F : Fn(&[u8], u64) {
|
||||||
|
|
||||||
|
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 mut client = get_client(uri, no_cert).await?;
|
|
||||||
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 = match client.get_address_txids(request).await {
|
||||||
|
Ok(response) => response,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Error getting address txids: {:?}", e);
|
||||||
|
return Err(e.into());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let maybe_response = client.get_address_txids(request).await?;
|
|
||||||
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,9 +252,15 @@ 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,
|
||||||
where F : Fn(&[u8], u64) {
|
address: String,
|
||||||
|
start_height: u64,
|
||||||
|
end_height: u64,
|
||||||
|
no_cert: bool,
|
||||||
|
c: F
|
||||||
|
) -> Result<(), String>
|
||||||
|
where F : Fn(&[u8], u64) {
|
||||||
|
|
||||||
let mut rt = match tokio::runtime::Runtime::new() {
|
let mut rt = match tokio::runtime::Runtime::new() {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user