mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
Optionally add rangeproofs to block api (#2999)
This commit is contained in:
parent
928279a676
commit
0e62b7e43e
2 changed files with 31 additions and 15 deletions
|
@ -87,10 +87,15 @@ pub struct BlockHandler {
|
|||
}
|
||||
|
||||
impl BlockHandler {
|
||||
fn get_block(&self, h: &Hash, include_merkle_proof: bool) -> Result<BlockPrintable, Error> {
|
||||
fn get_block(
|
||||
&self,
|
||||
h: &Hash,
|
||||
include_proof: bool,
|
||||
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, include_merkle_proof)
|
||||
BlockPrintable::from_block(&block, chain, include_proof, include_merkle_proof)
|
||||
.map_err(|_| ErrorKind::Internal("chain error".to_owned()).into())
|
||||
}
|
||||
|
||||
|
@ -141,19 +146,29 @@ impl Handler for BlockHandler {
|
|||
Ok(h) => h,
|
||||
};
|
||||
|
||||
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,
|
||||
format!("unsupported query parameter: {}", param),
|
||||
)
|
||||
let mut include_proof = false;
|
||||
let mut include_merkle_proof = true;
|
||||
if let Some(params) = req.uri().query() {
|
||||
let query = url::form_urlencoded::parse(params.as_bytes());
|
||||
let mut compact = false;
|
||||
for (param, _) in query {
|
||||
match param.as_ref() {
|
||||
"compact" => compact = true,
|
||||
"no_merkle_proof" => include_merkle_proof = false,
|
||||
"include_proof" => include_proof = true,
|
||||
_ => {
|
||||
return response(
|
||||
StatusCode::BAD_REQUEST,
|
||||
format!("unsupported query parameter: {}", param),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if compact {
|
||||
return result_to_response(self.get_compact_block(&h));
|
||||
}
|
||||
} else {
|
||||
result_to_response(self.get_block(&h, true))
|
||||
}
|
||||
result_to_response(self.get_block(&h, include_proof, include_merkle_proof))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,8 @@
|
|||
### GET Blocks
|
||||
|
||||
Returns data about a specific block given a hash, a height or an unspent commit.
|
||||
Optionally return results as "compact blocks" by passing `?compact` query.
|
||||
|
||||
Optionally, Merkle proofs can be excluded from the results by adding `?no_merkle_proof`, rangeproofs can be included by adding `?include_proof` or results can be returned as "compact blocks" by adding `?compact`.
|
||||
|
||||
* **URL**
|
||||
|
||||
|
|
Loading…
Reference in a new issue