Merges `data` into `self.data`. # Arguments `data` - Must be valid data verified via `BitVMClient::validate_data()` function
(&mut self, data: BitVMClientPublicData)
| 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() { |