|
|
@ -122,21 +122,20 @@ where F : Fn(&[u8], u64) { |
|
|
|
while let Ok(Some(block)) = rx.recv() { |
|
|
|
use prost::Message; |
|
|
|
let mut encoded_buf = vec![]; |
|
|
|
|
|
|
|
match block.encode(&mut encoded_buf) { |
|
|
|
Ok(_) => c(&encoded_buf, block.height), |
|
|
|
Err(e) => { |
|
|
|
eprintln!("Error encoding block: {:?}", e); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if let Err(e) = block.encode(&mut encoded_buf) { |
|
|
|
eprintln!("Error encoding block: {:?}", e); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
c(&encoded_buf, block.height); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if let Err(e) = ftx.send(Ok(())) { |
|
|
|
eprintln!("Error sending completion signal: {:?}", e); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
let mut response = client.get_block_range(request).await?.into_inner(); |
|
|
|
|
|
|
|
while let Some(block) = response.message().await? { |
|
|
@ -178,25 +177,44 @@ pub fn fetch_blocks<F : 'static + std::marker::Send>(uri: &http::Uri, start_heig |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// get_address_txids GRPC call
|
|
|
|
async fn get_address_txids<F : 'static + std::marker::Send>(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) { |
|
|
|
async fn get_address_txids<F : 'static + std::marker::Send>( |
|
|
|
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) { |
|
|
|
|
|
|
|
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 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(); |
|
|
|
|
|
|
|
while let Some(tx) = response.message().await? { |
|
|
|
c(&tx.data, tx.height); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
|
|
|
@ -234,10 +252,16 @@ where |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
|
|
|
|
pub fn fetch_transparent_txids<F : 'static + std::marker::Send>(uri: &http::Uri, address: String,
|
|
|
|
start_height: u64, end_height: u64, no_cert: bool, c: F) -> Result<(), String> |
|
|
|
where F : Fn(&[u8], u64) { |
|
|
|
|
|
|
|
pub fn fetch_transparent_txids<F : 'static + std::marker::Send>( |
|
|
|
uri: &http::Uri,
|
|
|
|
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() { |
|
|
|
Ok(r) => r, |
|
|
|
Err(e) => { |
|
|
@ -252,7 +276,7 @@ pub fn fetch_transparent_txids<F : 'static + std::marker::Send>(uri: &http::Uri, |
|
|
|
Err(e) => { |
|
|
|
let e = format!("Error with get_address_txids runtime {:?}", e); |
|
|
|
error!("{}", e); |
|
|
|
Err(e) |
|
|
|
return Err(e) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|