Skip to content

Commit

Permalink
implemented get_block_nullifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
idky137 committed Oct 28, 2024
1 parent 30b1746 commit 18ba6aa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
52 changes: 51 additions & 1 deletion zaino-fetch/src/chain/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use crate::{
};
use sha2::{Digest, Sha256};
use std::io::Cursor;
use zaino_proto::proto::compact_formats::{ChainMetadata, CompactBlock};
use zaino_proto::proto::compact_formats::{
ChainMetadata, CompactBlock, CompactOrchardAction, CompactTx,
};

/// A block header, containing metadata about a block.
///
Expand Down Expand Up @@ -428,3 +430,51 @@ pub async fn get_block_from_node(
Err(e) => Err(e.into()),
}
}

/// Returns a compact block holding only action nullifiers.
///
/// Retrieves a full block from zebrad/zcashd using 2 get_block calls.
/// This is because a get_block verbose = 1 call is require to fetch txids.
///
/// TODO / NOTE: This should be rewritten when the BlockCache is added.
pub async fn get_nullifiers_from_node(
zebra_uri: &http::Uri,
height: &u32,
) -> Result<CompactBlock, BlockCacheError> {
match get_block_from_node(zebra_uri, height).await {
Ok(block) => Ok(CompactBlock {
proto_version: block.proto_version,
height: block.height,
hash: block.hash,
prev_hash: block.prev_hash,
time: block.time,
header: block.header,
vtx: block
.vtx
.into_iter()
.map(|tx| CompactTx {
index: tx.index,
hash: tx.hash,
fee: tx.fee,
spends: tx.spends,
outputs: Vec::new(),
actions: tx
.actions
.into_iter()
.map(|action| CompactOrchardAction {
nullifier: action.nullifier,
cmx: Vec::new(),
ephemeral_key: Vec::new(),
ciphertext: Vec::new(),
})
.collect(),
})
.collect(),
chain_metadata: Some(ChainMetadata {
sapling_commitment_tree_size: 0,
orchard_commitment_tree_size: 0,
}),
}),
Err(e) => Err(e.into()),

Check failure on line 478 in zaino-fetch/src/chain/block.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

useless conversion to the same type: `chain::error::BlockCacheError`

error: useless conversion to the same type: `chain::error::BlockCacheError` --> zaino-fetch/src/chain/block.rs:478:23 | 478 | Err(e) => Err(e.into()), | ^^^^^^^^ help: consider removing `.into()`: `e` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `-D clippy::useless-conversion` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::useless_conversion)]`

Check failure on line 478 in zaino-fetch/src/chain/block.rs

View workflow job for this annotation

GitHub Actions / Clippy (MSRV)

useless conversion to the same type: `chain::error::BlockCacheError`

error: useless conversion to the same type: `chain::error::BlockCacheError` --> zaino-fetch/src/chain/block.rs:478:23 | 478 | Err(e) => Err(e.into()), | ^^^^^^^^ help: consider removing `.into()`: `e` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `-D clippy::useless-conversion` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::useless_conversion)]`
}
}
19 changes: 14 additions & 5 deletions zaino-serve/src/rpc/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use tokio_stream::wrappers::ReceiverStream;

use crate::{rpc::GrpcClient, utils::get_build_info};
use zaino_fetch::{
chain::{block::get_block_from_node, mempool::Mempool},
chain::{
block::{get_block_from_node, get_nullifiers_from_node},
mempool::Mempool,
},
jsonrpc::{connector::JsonRpcConnector, response::GetTransactionResponse},
};
use zaino_proto::proto::{
Expand Down Expand Up @@ -153,11 +156,10 @@ impl CompactTxStreamer for GrpcClient {

/// Same as GetBlock except actions contain only nullifiers.
///
/// 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).
/// NOTE: This should be reimplemented with the introduction of the BlockCache.
fn get_block_nullifiers<'life0, 'async_trait>(
&'life0 self,
_request: tonic::Request<BlockId>,
request: tonic::Request<BlockId>,
) -> core::pin::Pin<
Box<
dyn core::future::Future<
Expand All @@ -172,7 +174,14 @@ impl CompactTxStreamer for GrpcClient {
{
println!("[TEST] Received call of get_block_nullifiers.");
Box::pin(async {
Err(tonic::Status::unimplemented("get_block_nullifiers 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_nullifiers_from_node(&zebrad_uri, &height).await {
Ok(block) => Ok(tonic::Response::new(block)),
Err(e) => {
return Err(tonic::Status::internal(e.to_string()));
}
}
})
}

Expand Down

0 comments on commit 18ba6aa

Please sign in to comment.