add flag 'no_merkle_proof' to /v1/blocks api to get blocks without checking merkle proof (#2843)
This commit is contained in:
committed by
hashmap
parent
e345405201
commit
2cb37913ba
@@ -79,15 +79,18 @@ impl Handler for HeaderHandler {
|
||||
///
|
||||
/// Optionally return results as "compact blocks" by passing "?compact" query
|
||||
/// param GET /v1/blocks/<hash>?compact
|
||||
///
|
||||
/// Optionally turn off the Merkle proof extraction by passing "?no_merkle_proof" query
|
||||
/// param GET /v1/blocks/<hash>?no_merkle_proof
|
||||
pub struct BlockHandler {
|
||||
pub chain: Weak<chain::Chain>,
|
||||
}
|
||||
|
||||
impl BlockHandler {
|
||||
fn get_block(&self, h: &Hash) -> Result<BlockPrintable, Error> {
|
||||
fn get_block(&self, h: &Hash, include_merkle_proof: bool) -> Result<BlockPrintable, Error> {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::<Result<Vec<_>, _>>()
|
||||
.context(ErrorKind::Internal("cain error".to_owned()))?;
|
||||
|
||||
@@ -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::<Result<Vec<_>, _>>()
|
||||
.context(ErrorKind::Internal("cain error".to_owned()))?,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user