MCPcopy Create free account
hub / github.com/BitVM/BitVM / merge_data

Method merge_data

bridge/src/client/client.rs:579–620  ·  view source on GitHub ↗

Merges `data` into `self.data`. # Arguments `data` - Must be valid data verified via `BitVMClient::validate_data()` function

(&mut self, data: BitVMClientPublicData)

Source from the content-addressed store, hash-verified

577 ///
578 /// * `data` - Must be valid data verified via `BitVMClient::validate_data()` function
579 pub fn merge_data(&mut self, data: BitVMClientPublicData) {
580 // peg-in graphs
581 let mut peg_in_graphs_by_id: HashMap<String, &mut PegInGraph> = HashMap::new();
582 for peg_in_graph in self.data.peg_in_graphs.iter_mut() {
583 peg_in_graphs_by_id.insert(peg_in_graph.id().clone(), peg_in_graph);
584 }
585
586 let mut peg_in_graphs_to_add: Vec<&PegInGraph> = Vec::new();
587 for peg_in_graph in data.peg_in_graphs.iter() {
588 let graph = peg_in_graphs_by_id.get_mut(peg_in_graph.id());
589 if let Some(graph) = graph {
590 graph.merge(peg_in_graph);
591 } else {
592 peg_in_graphs_to_add.push(peg_in_graph);
593 }
594 }
595
596 for graph in peg_in_graphs_to_add.into_iter() {
597 self.data.peg_in_graphs.push(graph.clone());
598 }
599
600 // peg-out graphs
601 let mut peg_out_graphs_by_id: HashMap<String, &mut PegOutGraph> = HashMap::new();
602 for peg_out_graph in self.data.peg_out_graphs.iter_mut() {
603 let id = peg_out_graph.id().clone();
604 peg_out_graphs_by_id.insert(id, peg_out_graph);
605 }
606
607 let mut peg_out_graphs_to_add: Vec<&PegOutGraph> = Vec::new();
608 for peg_out_graph in data.peg_out_graphs.iter() {
609 let graph = peg_out_graphs_by_id.get_mut(peg_out_graph.id());
610 if let Some(graph) = graph {
611 graph.merge(peg_out_graph);
612 } else {
613 peg_out_graphs_to_add.push(peg_out_graph);
614 }
615 }
616
617 for graph in peg_out_graphs_to_add.into_iter() {
618 self.data.peg_out_graphs.push(graph.clone());
619 }
620 }
621
622 // fn process(&self) {
623 // for peg_in_graph in self.data.peg_in_graphs.iter() {

Callers 4

read_from_data_storeMethod · 0.80
process_filesMethod · 0.80
test_merge_add_new_graphFunction · 0.80

Calls 4

cloneMethod · 0.80
idMethod · 0.45
mergeMethod · 0.45
pushMethod · 0.45

Tested by 2

test_merge_add_new_graphFunction · 0.64