Skip to content

Commit

Permalink
implemented get_block rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
idky137 committed Oct 28, 2024
1 parent 3a27f52 commit 30b1746
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion zaino-fetch/src/chain/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl FullBlock {
let header = Vec::new();

let compact_block = CompactBlock {
proto_version: 1, // TODO: check this is correct!
proto_version: 0,
height: self.height as u64,
hash: self.hdr.cached_hash.clone(),
prev_hash: self.hdr.raw_block_header.hash_prev_block.clone(),
Expand Down
17 changes: 11 additions & 6 deletions zaino-serve/src/rpc/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,11 @@ impl CompactTxStreamer for GrpcClient {

/// Return the compact block corresponding to the given block identifier.
///
/// This RPC has not been implemented as it is not currently used by zingolib.
/// If you require this RPC please open an issue or PR at the Zingo-Indexer github (https://github.com/zingolabs/zingo-indexer).
///
/// TODO: This RPC should be implemented alongside the block cache.
/// TODO: This implementation is slow. An internal block cache should be implemented that this rpc, along with the get_block rpc, can rely on.
/// - add get_block function that queries the block cache for block and calls get_block_from_node to fetch block if not present.
fn get_block<'life0, 'async_trait>(
&'life0 self,
_request: tonic::Request<BlockId>,
request: tonic::Request<BlockId>,
) -> core::pin::Pin<
Box<
dyn core::future::Future<
Expand All @@ -142,7 +140,14 @@ impl CompactTxStreamer for GrpcClient {
{
println!("[TEST] Received call of get_block.");
Box::pin(async {
Err(tonic::Status::unimplemented("get_block not yet implemented. If you require this RPC please open an issue or PR at the Zingo-Indexer github (https://github.com/zingolabs/zingo-indexer)."))
let zebrad_uri = self.zebrad_uri.clone();
let height = request.into_inner().height as u32;
match get_block_from_node(&zebrad_uri, &height).await {
Ok(block) => Ok(tonic::Response::new(block)),
Err(e) => {
return Err(tonic::Status::internal(e.to_string()));

Check failure on line 148 in zaino-serve/src/rpc/service.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unneeded `return` statement

error: unneeded `return` statement --> zaino-serve/src/rpc/service.rs:148:21 | 148 | return Err(tonic::Status::internal(e.to_string())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = note: `-D clippy::needless-return` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_return)]` help: remove `return` | 148 - return Err(tonic::Status::internal(e.to_string())); 148 + Err(tonic::Status::internal(e.to_string())) |

Check failure on line 148 in zaino-serve/src/rpc/service.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

unneeded `return` statement

error: unneeded `return` statement --> zaino-serve/src/rpc/service.rs:148:21 | 148 | return Err(tonic::Status::internal(e.to_string())); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = note: `-D clippy::needless-return` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_return)]` help: remove `return` | 148 - return Err(tonic::Status::internal(e.to_string())); 148 + Err(tonic::Status::internal(e.to_string())) |
}
}
})
}

Expand Down

0 comments on commit 30b1746

Please sign in to comment.