From 1f9f0654f02a4ab65ff2f3f5d8b05245f10c4d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C9=B4=E1=B4=8F=E1=B4=A0=E1=B4=80?= <146671001+ovnanova@users.noreply.github.com> Date: Wed, 21 Feb 2024 23:59:45 -0800 Subject: [PATCH] what if we construct a tagged IPLD node with the CID tag and insert it into the result map --- native/hexpds_dagcbor_internal/src/lib.rs | 27 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/native/hexpds_dagcbor_internal/src/lib.rs b/native/hexpds_dagcbor_internal/src/lib.rs index d547301..af1edcc 100644 --- a/native/hexpds_dagcbor_internal/src/lib.rs +++ b/native/hexpds_dagcbor_internal/src/lib.rs @@ -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) { @@ -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 = m.into_iter().map(|(k, v)| { - (k, json_to_ipld(v)) - }).collect(); - Ipld::Map(map) - }, + // Value::Object(m) => { + // let map: BTreeMap = m.into_iter().map(|(k, v)| { + // (k, json_to_ipld(v)) + // }).collect(); + // Ipld::Map(map) + // }, } }