1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2019 Conflux Foundation. All rights reserved.
// Conflux is free software and distributed under GNU General Public License.
// See http://www.gnu.org/licenses/

#[derive(Clone)]
pub struct DeltaMptIterator {
    pub mpt: Arc<DeltaMpt>,
    pub maybe_root_node: Option<NodeRefDeltaMpt>,
}

impl DeltaMptIterator {
    pub fn iterate<'a, DeltaMptDumper: KVInserter<MptKeyValue>>(
        &self, dumper: &mut DeltaMptDumper,
    ) -> Result<()> {
        match &self.maybe_root_node {
            None => {}
            Some(root_node) => {
                let arc_db = self.mpt.get_arc_db()?;
                let db = &mut *arc_db.to_owned_read()?;
                let owned_node_set = Default::default();
                let mut cow_root_node = CowNodeRef::new(
                    root_node.clone(),
                    &owned_node_set,
                    self.mpt.get_mpt_id(),
                );
                let guarded_trie_node =
                    GuardedValue::take(cow_root_node.get_trie_node(
                        self.mpt.get_node_memory_manager(),
                        &self.mpt.get_node_memory_manager().get_allocator(),
                        db,
                    )?);
                cow_root_node.iterate_internal(
                    &owned_node_set,
                    &self.mpt,
                    guarded_trie_node,
                    CompressedPathRaw::new_zeroed(0, 0),
                    dumper,
                    db,
                )?;
            }
        }

        Ok(())
    }
}

use crate::{
    impls::{
        delta_mpt::{CowNodeRef, DeltaMpt, NodeRefDeltaMpt},
        errors::Result,
        merkle_patricia_trie::{CompressedPathRaw, KVInserter, MptKeyValue},
    },
    utils::guarded_value::GuardedValue,
};
use std::sync::Arc;