-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
easy-3dp
authored and
MikhailK
committed
Apr 18, 2024
1 parent
3134dad
commit eca9c20
Showing
2 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,58 @@ | ||
use sp_core::H256; | ||
use sp_std::vec::Vec; | ||
use sp_std::str::from_utf8; | ||
use sp_std::collections::btree_set; | ||
|
||
pub(crate) fn check_obj(_alg_id: &[u8;16], _obj: &Vec<u8>, _hashes: &Vec<H256>) -> bool { | ||
// TODO: additional validation | ||
true | ||
|
||
use sp_std::vec; | ||
use sp_consensus_poscan::decompress_obj; | ||
|
||
let mut obj = _obj.clone(); | ||
|
||
if obj[..4] == vec![b'l', b'z', b's', b's'] { | ||
obj = decompress_obj(&obj[4..]); | ||
} | ||
|
||
check_simply_connected(&obj) | ||
} | ||
|
||
fn check_simply_connected(obj: &Vec<u8>) -> bool { | ||
if let Ok(text) = from_utf8(&obj) { | ||
let mut vs_list = btree_set::BTreeSet::new();//::with_capacity(6000); | ||
for line in text.lines() { | ||
let words: Vec<&str> = line.split_whitespace().collect(); | ||
if words.len() > 0 { | ||
match words[0] { | ||
"f" => { | ||
if words.len() == 4 { | ||
let mut vs = [0,0,0]; | ||
for idx in 1..=3 { | ||
let swords: Vec<&str> = words[idx].split("/").collect(); | ||
if swords.len() == 3 { | ||
if let Ok(i) = swords[0].parse() { | ||
vs[idx-1] = i; | ||
} | ||
} | ||
} | ||
if vs_list.is_empty() | ||
|| vs_list.contains(&vs[0]) | ||
|| vs_list.contains(&vs[1]) | ||
|| vs_list.contains(&vs[2]) { | ||
vs_list.insert(vs[0]); | ||
vs_list.insert(vs[1]); | ||
vs_list.insert(vs[2]); | ||
} else { | ||
return false; | ||
} | ||
} | ||
}, | ||
_=>{}, | ||
} | ||
} | ||
} | ||
true | ||
} else { | ||
false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters