Skip to content

Commit 427a309

Browse files
docs(examples): update docstring to match new flow
1 parent b2e88bd commit 427a309

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

examples/proof-update.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,20 @@ use rustreexo::accumulator::stump::Stump;
1818

1919
fn main() {
2020
let s = Stump::new();
21+
2122
// Get the hashes of the UTXOs we want to insert
2223
let utxos = get_utxo_hashes1();
23-
// Add the UTXOs to the accumulator. update_data is the data we need to update the proof
24-
// after the accumulator is updated.
24+
25+
// Compute the update data for this block. Notice that we called this before updating the
26+
// accumulator, as the accumulator state is required to compute this data.
2527
let update_data = s.get_update_data(&utxos, &[], &Proof::default()).unwrap();
28+
29+
// Now, update the accumulator with these UTXOs, no STXOs are being spent in this example.
2630
let s = s.modify(&utxos, &[], &Proof::default()).unwrap();
2731

2832
// Create an empty proof, we'll update it to hold our UTXOs
2933
let p = Proof::default();
34+
3035
// Update the proof with the UTXOs we added to the accumulator. This proof was initially empty,
3136
// but we can instruct this function to remember some UTXOs, given their positions in the list of
3237
// UTXOs we added to the accumulator. In this example, we ask it to cache 0 and 1.
@@ -37,18 +42,21 @@ fn main() {
3742
let (p, cached_hashes) = p
3843
.update(vec![], utxos.clone(), vec![], vec![0, 1], update_data)
3944
.unwrap();
45+
4046
// This should be a valid proof over 0 and 1.
4147
assert_eq!(p.n_targets(), 2);
4248
assert_eq!(s.verify(&p, &cached_hashes), Ok(true));
4349

4450
// Get a subset of the proof, for the first UTXO only
4551
let p1 = p.get_proof_subset(&cached_hashes, &[0], s.leaves).unwrap();
4652

53+
// Should still be valid
4754
assert_eq!(s.verify(&p1, &cached_hashes), Ok(true));
4855

4956
// Assume we have a block that (beyond coinbase) spends our UTXO `0` and creates 7 new UTXOs
5057
// We'll remove `0` as it got spent, and add 1..7 to our cache.
5158
let new_utxos = get_utxo_hashes2();
59+
5260
// First, update the accumulator
5361
let stump = s.modify(&new_utxos, &[utxos[0]], &p1).unwrap();
5462

0 commit comments

Comments
 (0)