From fba9a976ea7b0af8d497065e5dcaabbedda8384e Mon Sep 17 00:00:00 2001 From: Revertron Date: Sat, 3 Apr 2021 12:07:44 +0200 Subject: [PATCH] Fixed duplicate zone names in GUI. --- src/blockchain/chain.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/blockchain/chain.rs b/src/blockchain/chain.rs index 5f45dc6..4944b13 100644 --- a/src/blockchain/chain.rs +++ b/src/blockchain/chain.rs @@ -1,5 +1,5 @@ use std::cell::RefCell; -use std::collections::HashSet; +use std::collections::{HashSet, HashMap}; use chrono::Utc; #[allow(unused_imports)] @@ -273,14 +273,14 @@ impl Chain { } pub fn get_zones(&self) -> Vec { - let mut result = Vec::new(); + let mut map = HashMap::new(); match self.db.prepare(SQL_GET_TRANSACTIONS_WITH_ZONE) { Ok(mut statement) => { while statement.next().unwrap() == State::Row { let data = statement.read::(0).unwrap(); info!("Got zone data {}", &data); - if let Ok(zone_data) = serde_json::from_str(&data) { - result.push(zone_data); + if let Ok(zone_data) = serde_json::from_str::(&data) { + map.insert(zone_data.name.clone(), zone_data); } } } @@ -288,6 +288,7 @@ impl Chain { warn!("Can't get zones from DB {}", e); } } + let result: Vec = map.drain().map(|(_, value)| value).collect(); result }