summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md9
-rw-r--r--adenosine/src/ipld.rs31
-rw-r--r--adenosine/src/lib.rs2
3 files changed, 31 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8a20b62..1d51c05 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,15 @@
# CHANGELOG
+## [0.4.0] - NOTRELEASED
+
+Breaking protocol changes!
+
+## Changed
+
+- update to atproto repo v2 (MST fanout=4 and commit node change)
+- update lexicons ("lex refactor" from March 2023)
+
## [0.3.0] - 2023-03-04
Refactored common library code into `adenosine` crate. Will put common types,
diff --git a/adenosine/src/ipld.rs b/adenosine/src/ipld.rs
index 63f29dc..d188916 100644
--- a/adenosine/src/ipld.rs
+++ b/adenosine/src/ipld.rs
@@ -12,12 +12,16 @@ pub fn ipld_into_json_value(val: Ipld) -> Value {
Ipld::Integer(v) => json!(v),
Ipld::Float(v) => json!(v),
Ipld::String(s) => Value::String(s),
- Ipld::Bytes(b) => Value::String(data_encoding::BASE64_NOPAD.encode(&b)),
+ Ipld::Bytes(b) => json!({
+ "$bytes": Value::String(data_encoding::BASE64_NOPAD.encode(&b)),
+ }),
Ipld::List(l) => Value::Array(l.into_iter().map(ipld_into_json_value).collect()),
Ipld::Map(m) => Value::Object(serde_json::Map::from_iter(
m.into_iter().map(|(k, v)| (k, ipld_into_json_value(v))),
)),
- Ipld::Link(c) => Value::String(c.to_string()),
+ Ipld::Link(c) => json!({
+ "$link": Value::String(c.to_string()),
+ }),
}
}
@@ -34,14 +38,21 @@ pub fn json_value_into_ipld(val: Value) -> Ipld {
Value::Number(v) => Ipld::Float(v.as_f64().unwrap()),
Value::Array(l) => Ipld::List(l.into_iter().map(json_value_into_ipld).collect()),
Value::Object(m) => {
- let map: BTreeMap<String, Ipld> = BTreeMap::from_iter(m.into_iter().map(|(k, v)| {
- if k == "cid" && v.is_string() {
- (k, Ipld::Link(Cid::from_str(v.as_str().unwrap()).unwrap()))
- } else {
- (k, json_value_into_ipld(v))
- }
- }));
- Ipld::Map(map)
+ if m.len() == 1 && m.contains_key("$link") {
+ let cid_str = m["$link"].as_str().expect("$link as CID string");
+ Ipld::Link(Cid::from_str(cid_str).unwrap())
+ } else if m.len() == 1 && m.contains_key("$bytes") {
+ let bytes_b64 = m["$bytes"].as_str().expect("$bytes as base64 string");
+ Ipld::Bytes(
+ data_encoding::BASE64_NOPAD
+ .decode(bytes_b64.as_bytes())
+ .expect("valid base64 in $bytes"),
+ )
+ } else {
+ let map: BTreeMap<String, Ipld> =
+ BTreeMap::from_iter(m.into_iter().map(|(k, v)| (k, json_value_into_ipld(v))));
+ Ipld::Map(map)
+ }
}
}
}
diff --git a/adenosine/src/lib.rs b/adenosine/src/lib.rs
index b5e1a50..348496d 100644
--- a/adenosine/src/lib.rs
+++ b/adenosine/src/lib.rs
@@ -36,5 +36,5 @@ fn test_created_at_now() {
assert_eq!(&ts[4..5], "-");
assert_eq!(&ts[7..8], "-");
assert_eq!(&ts[10..11], "T");
- assert_eq!(&ts[ts.len()-1..ts.len()], "Z");
+ assert_eq!(&ts[ts.len() - 1..ts.len()], "Z");
}