update wallet restore, generate new merkle proof for coinbase outputs (#1008)

This commit is contained in:
Yeastplume
2018-04-26 14:01:01 +01:00
committed by GitHub
parent 820d55a532
commit 59664181e4
4 changed files with 112 additions and 13 deletions
+8 -1
View File
@@ -30,7 +30,7 @@ use pipe;
use store;
use txhashset;
use types::*;
use util::secp::pedersen::RangeProof;
use util::secp::pedersen::{Commitment, RangeProof};
use util::LOGGER;
/// Orphan pool size is limited by MAX_ORPHAN_SIZE
@@ -507,6 +507,13 @@ impl Chain {
Ok(merkle_proof)
}
/// Return a merkle proof valid for the current output pmmr state at the
/// given pos
pub fn get_merkle_proof_for_pos(&self, commit: Commitment) -> Result<MerkleProof, String> {
let mut txhashset = self.txhashset.write().unwrap();
txhashset.merkle_proof(commit)
}
/// Returns current txhashset roots
pub fn get_txhashset_roots(&self) -> (Hash, Hash, Hash) {
let mut txhashset = self.txhashset.write().unwrap();
+8
View File
@@ -205,6 +205,14 @@ impl TxHashSet {
(output_pmmr.root(), rproof_pmmr.root(), kernel_pmmr.root())
}
/// build a new merkle proof for the given position
pub fn merkle_proof(&mut self, commit: Commitment) -> Result<MerkleProof, String> {
let pos = self.commit_index.get_output_pos(&commit).unwrap();
let output_pmmr: PMMR<OutputIdentifier, _> =
PMMR::at(&mut self.output_pmmr_h.backend, self.output_pmmr_h.last_pos);
output_pmmr.merkle_proof(pos)
}
/// Compact the MMR data files and flush the rm logs
pub fn compact(&mut self) -> Result<(), Error> {
let commit_index = self.commit_index.clone();