diff --git a/api/src/handlers/blocks_api.rs b/api/src/handlers/blocks_api.rs index 4cea007a5f..9675ef52b8 100644 --- a/api/src/handlers/blocks_api.rs +++ b/api/src/handlers/blocks_api.rs @@ -79,15 +79,18 @@ impl Handler for HeaderHandler { /// /// Optionally return results as "compact blocks" by passing "?compact" query /// param GET /v1/blocks/?compact +/// +/// Optionally turn off the Merkle proof extraction by passing "?no_merkle_proof" query +/// param GET /v1/blocks/?no_merkle_proof pub struct BlockHandler { pub chain: Weak, } impl BlockHandler { - fn get_block(&self, h: &Hash) -> Result { + fn get_block(&self, h: &Hash, include_merkle_proof: bool) -> Result { let chain = w(&self.chain)?; let block = chain.get_block(h).context(ErrorKind::NotFound)?; - BlockPrintable::from_block(&block, chain, false) + BlockPrintable::from_block(&block, chain, false, include_merkle_proof) .map_err(|_| ErrorKind::Internal("chain error".to_owned()).into()) } @@ -141,6 +144,8 @@ impl Handler for BlockHandler { if let Some(param) = req.uri().query() { if param == "compact" { result_to_response(self.get_compact_block(&h)) + } else if param == "no_merkle_proof" { + result_to_response(self.get_block(&h, false)) } else { response( StatusCode::BAD_REQUEST, @@ -148,7 +153,7 @@ impl Handler for BlockHandler { ) } } else { - result_to_response(self.get_block(&h)) + result_to_response(self.get_block(&h, true)) } } } diff --git a/api/src/handlers/chain_api.rs b/api/src/handlers/chain_api.rs index 66bedcca77..963bd6a6e8 100644 --- a/api/src/handlers/chain_api.rs +++ b/api/src/handlers/chain_api.rs @@ -138,7 +138,13 @@ impl OutputHandler { .iter() .filter(|output| commitments.is_empty() || commitments.contains(&output.commit)) .map(|output| { - OutputPrintable::from_output(output, chain.clone(), Some(&header), include_proof) + OutputPrintable::from_output( + output, + chain.clone(), + Some(&header), + include_proof, + true, + ) }) .collect::, _>>() .context(ErrorKind::Internal("cain error".to_owned()))?; diff --git a/api/src/handlers/transactions_api.rs b/api/src/handlers/transactions_api.rs index a65047624d..9d8a827031 100644 --- a/api/src/handlers/transactions_api.rs +++ b/api/src/handlers/transactions_api.rs @@ -83,7 +83,7 @@ impl TxHashSetHandler { outputs: outputs .2 .iter() - .map(|x| OutputPrintable::from_output(x, chain.clone(), None, true)) + .map(|x| OutputPrintable::from_output(x, chain.clone(), None, true, true)) .collect::, _>>() .context(ErrorKind::Internal("cain error".to_owned()))?, }; diff --git a/api/src/types.rs b/api/src/types.rs index 5550047416..dee77704c1 100644 --- a/api/src/types.rs +++ b/api/src/types.rs @@ -257,6 +257,7 @@ impl OutputPrintable { chain: Arc, block_header: Option<&core::BlockHeader>, include_proof: bool, + include_merkle_proof: bool, ) -> Result { let output_type = if output.is_coinbase() { OutputType::Coinbase @@ -282,7 +283,7 @@ impl OutputPrintable { // We require the rewind() to be stable even after the PMMR is pruned and // compacted so we can still recreate the necessary proof. let mut merkle_proof = None; - if output.is_coinbase() && !spent { + if include_merkle_proof && output.is_coinbase() && !spent { if let Some(block_header) = block_header { merkle_proof = chain.get_merkle_proof(&out_id, &block_header).ok(); } @@ -583,6 +584,7 @@ impl BlockPrintable { block: &core::Block, chain: Arc, include_proof: bool, + include_merkle_proof: bool, ) -> Result { let inputs = block .inputs() @@ -598,6 +600,7 @@ impl BlockPrintable { chain.clone(), Some(&block.header), include_proof, + include_merkle_proof, ) }) .collect::, _>>()?; @@ -639,7 +642,9 @@ impl CompactBlockPrintable { let out_full = cb .out_full() .iter() - .map(|x| OutputPrintable::from_output(x, chain.clone(), Some(&block.header), false)) + .map(|x| { + OutputPrintable::from_output(x, chain.clone(), Some(&block.header), false, true) + }) .collect::, _>>()?; let kern_full = cb .kern_full()