diff --git a/src/accumulator/proof.rs b/src/accumulator/proof.rs index 3af18d9..3d3ff7e 100644 --- a/src/accumulator/proof.rs +++ b/src/accumulator/proof.rs @@ -10,10 +10,10 @@ pub struct Proof { /// Targets are the i'th of leaf locations to delete and they are the bottommost leaves. /// With the tree below, the Targets can only consist of one of these: 02, 03, 04. ///```! - /// // 06 - /// // |-------\ - /// // 04 05 - /// // |---\ |---\ + /// // 06 + /// // |-------\ + /// // 04 05 + /// // |---\ |---\ /// // 02 03 /// ``` targets: Vec, @@ -41,11 +41,11 @@ impl Proof { /// Assuming a tree with leaf values [0, 1, 2, 3, 4, 5, 6, 7], we should see something like this: ///```! /// 14 - /// |-----------------\ - /// 12 13 - /// |---------\ |--------\ - /// 08 09 10 11 - /// |----\ |----\ |----\ |----\ + /// |-----------------\ + /// 12 13 + /// |---------\ |--------\ + /// 08 09 10 11 + /// |----\ |----\ |----\ |----\ /// 00 01 02 03 04 05 06 07 /// ``` /// If we are proving `00` (i.e. 00 is our target), then we need 01, @@ -76,7 +76,7 @@ impl Proof { /// not valid given the current stump. ///# Examples /// ``` - /// use bitcoin_hashes::{sha256, Hash, HashEngine}; + /// use bitcoin_hashes::{sha256::Hash as Sha256, Hash, HashEngine}; /// use std::str::FromStr; /// use rustreexo::accumulator::{stump::Stump, proof::Proof}; /// let s = Stump::new(); @@ -87,29 +87,28 @@ impl Proof { /// /// let mut proof_hashes = Vec::new(); /// // This tree will look like this - /// // 14 - /// // |-----------------\ - /// // 12 13 - /// // |---------\ |--------\ - /// // 08 09 10 11 - /// // |----\ |----\ |----\ |----\ + /// // 14 + /// // |-----------------\ + /// // 12 13 + /// // |---------\ |--------\ + /// // 08 09 10 11 + /// // |----\ |----\ |----\ |----\ /// // 00 01 02 03 04 05 06 07 /// // For proving 0, we need 01, 09 and 13's hashes. 00, 08, 12 and 14 can be calculated - /// proof_hashes.push(bitcoin_hashes::sha256::Hash::from_str("4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a").unwrap()); - /// proof_hashes.push(bitcoin_hashes::sha256::Hash::from_str("9576f4ade6e9bc3a6458b506ce3e4e890df29cb14cb5d3d887672aef55647a2b").unwrap()); - /// proof_hashes.push(bitcoin_hashes::sha256::Hash::from_str("29590a14c1b09384b94a2c0e94bf821ca75b62eacebc47893397ca88e3bbcbd7").unwrap()); - /// + /// proof_hashes.push(Sha256::from_str("4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a").unwrap()); + /// proof_hashes.push(Sha256::from_str("9576f4ade6e9bc3a6458b506ce3e4e890df29cb14cb5d3d887672aef55647a2b").unwrap()); + /// proof_hashes.push(Sha256::from_str("29590a14c1b09384b94a2c0e94bf821ca75b62eacebc47893397ca88e3bbcbd7").unwrap()); + /// /// let mut hashes = Vec::new(); /// for i in test_values { - /// let mut engine = bitcoin_hashes::sha256::Hash::engine(); - /// engine.input(&[i]); - /// let hash = sha256::Hash::from_engine(engine); - /// hashes.push(hash); + /// let mut engine = Sha256::engine(); + /// engine.input(&[i]); + /// let hash = Sha256::from_engine(engine); + /// hashes.push(hash); /// } - /// /// let s = s.modify(&hashes, &vec![], &Proof::default()).unwrap(); /// let p = Proof::new(targets, proof_hashes); - /// assert!(p.verify(&vec![hashes[0]] , &s).expect("No error should happens")); + /// assert!(p.verify(&vec![hashes[0]] , &s).expect("This proof is valid")); ///``` pub fn verify(&self, del_hashes: &Vec, stump: &Stump) -> Result { if self.targets.len() == 0 { diff --git a/src/accumulator/stump.rs b/src/accumulator/stump.rs index 1a9baf5..44ba708 100644 --- a/src/accumulator/stump.rs +++ b/src/accumulator/stump.rs @@ -10,6 +10,11 @@ pub struct Stump { impl Stump { /// Creates an empty Stump + ///# Example + /// ``` + /// use rustreexo::accumulator::stump::Stump; + /// let s = Stump::new(); + /// ``` pub fn new() -> Self { Stump { leafs: 0, @@ -18,15 +23,20 @@ impl Stump { } /// Modify is the external API to change the accumulator state. Since order /// matters, you can only modify, providing a list of utxos to be added, - /// and txos (@TODO) to be removed, along with it's proof. Either may be + /// and txos to be removed, along with it's proof. Either may be /// empty. ///# Example /// ``` /// use rustreexo::accumulator::{stump::Stump, proof::Proof}; - /// let mut s = Stump::new(); - /// let utxos = vec![]; + /// use bitcoin_hashes::sha256::Hash; + /// use std::str::FromStr; + /// + /// let s = Stump::new(); + /// let utxos = vec![Hash::from_str("b151a956139bb821d4effa34ea95c17560e0135d1e4661fc23cedc3af49dac42").unwrap()]; /// let stxos = vec![]; - /// s.modify(&utxos, &stxos, &Proof::default()); + /// let s = s.modify(&utxos, &stxos, &Proof::default()); + /// assert!(s.is_ok()); + /// assert_eq!(s.unwrap().roots, utxos); /// ``` pub fn modify( &self, @@ -72,14 +82,13 @@ impl Stump { /// use rustreexo::accumulator::{stump::Stump, proof::Proof}; /// let s_old = Stump::new(); /// let mut s_new = Stump::new(); - /// + /// /// let s_old = s_old.modify(&vec![], &vec![], &Proof::default()).unwrap(); /// s_new = s_old.clone(); /// s_new = s_new.modify(&vec![], &vec![], &Proof::default()).unwrap(); - /// + /// /// // A reorg happened - /// - /// s_new.undo(s_old); + /// s_new.undo(s_old); ///``` pub fn undo(&mut self, old_state: Stump) { self.leafs = old_state.leafs;