Skip to content

Commit

Permalink
what if we construct a tagged IPLD node with the CID tag and insert i…
Browse files Browse the repository at this point in the history
…t into the result map
  • Loading branch information
mekaem committed Feb 22, 2024
1 parent 3deb34e commit 1f9f065
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions native/hexpds_dagcbor_internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ mod atoms {

pub fn json_to_ipld(val: Value) -> Ipld {
match val {
Value::Object(obj) => {
let mut result = BTreeMap::new();
for (k, v) in obj {
if k == "cid" {
if let Value::String(ref cid_str) = v {
if let Ok(cid) = Cid::from_str(&cid_str) {
result.insert(k, Ipld::Link(cid));
continue;
}
}
}
result.insert(k, json_to_ipld(v));
}
Ipld::Map(result)
},
Value::Null => Ipld::Null,
Value::Bool(b) => Ipld::Bool(b),
Value::String(s) => match Cid::from_str(&s) {
Expand All @@ -41,12 +56,12 @@ pub fn json_to_ipld(val: Value) -> Ipld {
}
},
Value::Array(l) => Ipld::List(l.into_iter().map(json_to_ipld).collect()),
Value::Object(m) => {
let map: BTreeMap<String, Ipld> = m.into_iter().map(|(k, v)| {
(k, json_to_ipld(v))
}).collect();
Ipld::Map(map)
},
// Value::Object(m) => {
// let map: BTreeMap<String, Ipld> = m.into_iter().map(|(k, v)| {
// (k, json_to_ipld(v))
// }).collect();
// Ipld::Map(map)
// },
}
}

Expand Down

0 comments on commit 1f9f065

Please sign in to comment.