diff --git a/devtools/src/bin/inspect/block.rs b/devtools/src/bin/inspect/block.rs index f6a79b73c7..e32323964b 100644 --- a/devtools/src/bin/inspect/block.rs +++ b/devtools/src/bin/inspect/block.rs @@ -7,6 +7,7 @@ use std::convert::{TryFrom, TryInto}; use std::io::{self, Read}; use sha2::{Digest, Sha256}; +use zcash_client_backend::proto::compact_formats::CompactBlock; use zcash_encoding::Vector; use zcash_primitives::{ block::BlockHeader, @@ -282,6 +283,13 @@ fn inspect_header_inner(header: &BlockHeader, params: Option) { } } +/// Used when a block hash is resolved via lightwalletd. +pub(crate) fn inspect_block_hash(block: &CompactBlock, network: &'static str) { + eprintln!("Zcash block hash"); + eprintln!(" - Network: {}", network); + eprintln!(" - Height: {}", block.height()); +} + pub(crate) fn inspect(block: &Block, context: Option) { eprintln!("Zcash block"); let params = block diff --git a/devtools/src/bin/inspect/lookup.rs b/devtools/src/bin/inspect/lookup.rs index 8a902f378d..972c828967 100644 --- a/devtools/src/bin/inspect/lookup.rs +++ b/devtools/src/bin/inspect/lookup.rs @@ -1,6 +1,7 @@ use tonic::transport::{Channel, ClientTlsConfig}; -use zcash_client_backend::proto::service::{ - compact_tx_streamer_client::CompactTxStreamerClient, TxFilter, +use zcash_client_backend::proto::{ + compact_formats::CompactBlock, + service::{compact_tx_streamer_client::CompactTxStreamerClient, BlockId, TxFilter}, }; use zcash_primitives::transaction::Transaction; use zcash_protocol::consensus::{BlockHeight, BranchId, Network}; @@ -58,6 +59,18 @@ impl Lightwalletd { }) } + pub(crate) async fn lookup_block_hash(&mut self, candidate: [u8; 32]) -> Option { + let request = BlockId { + hash: candidate.into(), + ..Default::default() + }; + self.inner + .get_block(request) + .await + .ok() + .map(|b| b.into_inner()) + } + pub(crate) async fn lookup_txid( &mut self, candidate: [u8; 32], diff --git a/devtools/src/bin/inspect/main.rs b/devtools/src/bin/inspect/main.rs index cad487df94..2d2acf1a96 100644 --- a/devtools/src/bin/inspect/main.rs +++ b/devtools/src/bin/inspect/main.rs @@ -121,7 +121,7 @@ fn inspect_bytes(bytes: Vec, context: Option, lookup: bool) { } fn inspect_possible_hash(bytes: [u8; 32], context: Option, lookup: bool) { - let maybe_mainnet_block_hash = bytes.iter().take(4).all(|c| c == &0); + let mut maybe_mainnet_block_hash = bytes.iter().take(4).all(|c| c == &0); if lookup { // Block hashes and txids are byte-reversed; we didn't do this when parsing the @@ -134,6 +134,13 @@ fn inspect_possible_hash(bytes: [u8; 32], context: Option, lookup: bool match lookup::Lightwalletd::mainnet().await { Err(e) => eprintln!("Error: Failed to connect to mainnet lightwalletd: {:?}", e), Ok(mut mainnet) => { + if let Some(block) = mainnet.lookup_block_hash(candidate).await { + block::inspect_block_hash(&block, "main"); + return true; + } else { + maybe_mainnet_block_hash = false; + } + if let Some((tx, mined_height)) = mainnet.lookup_txid(candidate).await { transaction::inspect(tx, context, mined_height); return true; @@ -144,6 +151,11 @@ fn inspect_possible_hash(bytes: [u8; 32], context: Option, lookup: bool match lookup::Lightwalletd::testnet().await { Err(e) => eprintln!("Error: Failed to connect to testnet lightwalletd: {:?}", e), Ok(mut testnet) => { + if let Some(block) = testnet.lookup_block_hash(candidate).await { + block::inspect_block_hash(&block, "main"); + return true; + } + if let Some((tx, mined_height)) = testnet.lookup_txid(candidate).await { transaction::inspect(tx, context, mined_height); return true;