store both mmr index and block height into database for output (#2903)

* store both mmr index and block height into database for output

* rustfmt

* fix: mmr position is 1-based instead of 0-based

* (Hash, u64, u64) deserves a type
This commit is contained in:
Gary Yu
2019-08-30 00:14:39 +08:00
committed by Antioch Peverell
parent 97f961fc67
commit d36a0b29ef
9 changed files with 216 additions and 76 deletions
+2 -2
View File
@@ -70,8 +70,8 @@ impl TxHashSetHandler {
// allows traversal of utxo set
fn outputs(&self, start_index: u64, mut max: u64) -> Result<OutputListing, Error> {
//set a limit here
if max > 1000 {
max = 1000;
if max > 10_000 {
max = 10_000;
}
let chain = w(&self.chain)?;
let outputs = chain
+18 -9
View File
@@ -51,15 +51,24 @@ pub fn get_output(
let chain = w(chain)?;
for x in outputs.iter().filter(|x| chain.is_unspent(x).is_ok()) {
let block_height = chain
.get_header_for_output(&x)
.context(ErrorKind::Internal(
"Can't get header for output".to_owned(),
))?
.height;
let output_pos = chain.get_output_pos(&x.commit).unwrap_or(0);
return Ok((Output::new(&commit, block_height, output_pos), x.clone()));
for x in outputs.iter() {
let res = chain.is_unspent(x);
match res {
Ok(output_pos) => {
return Ok((
Output::new(&commit, output_pos.height, output_pos.position),
x.clone(),
));
}
Err(e) => {
trace!(
"get_output: err: {} for commit: {:?} with feature: {:?}",
e.to_string(),
x.commit,
x.features
);
}
}
}
Err(ErrorKind::NotFound)?
}
+5 -4
View File
@@ -276,10 +276,11 @@ impl OutputPrintable {
};
let out_id = core::OutputIdentifier::from_output(&output);
let spent = chain.is_unspent(&out_id).is_err();
let block_height = match spent {
true => None,
false => Some(chain.get_header_for_output(&out_id)?.height),
let res = chain.is_unspent(&out_id);
let (spent, block_height) = if let Ok(output_pos) = res {
(false, Some(output_pos.height))
} else {
(true, None)
};
let proof = if include_proof {