From 4fd86c1b2191aaaabc2b8a6ec5fc1078d75a28b5 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 22 Nov 2022 11:16:11 -0800 Subject: pds: human-readable CIDs etc in commit node in web UI --- adenosine-pds/src/repo.rs | 17 +++++++++++++++++ adenosine-pds/templates/at_repo.html | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/adenosine-pds/src/repo.rs b/adenosine-pds/src/repo.rs index 9f5fca0..fd75432 100644 --- a/adenosine-pds/src/repo.rs +++ b/adenosine-pds/src/repo.rs @@ -11,6 +11,7 @@ use libipld::multihash::Code; use libipld::prelude::Codec; use libipld::store::DefaultParams; use libipld::{Block, Cid, Ipld}; +use serde_json::{json, Value}; use std::borrow::Cow; use std::collections::BTreeMap; use std::collections::HashSet; @@ -28,6 +29,22 @@ pub struct RepoCommit { pub mst_cid: Cid, } +impl RepoCommit { + /// Returns a JSON object version of this struct, with CIDs and signatures in expected format + /// (aka, CID as a string, not an array of bytes). + pub fn to_pretty_json(&self) -> Value { + json!({ + "sig": data_encoding::HEXUPPER.encode(&self.sig), + "commit_cid": self.commit_cid.to_string(), + "root_cid": self.root_cid.to_string(), + "did": self.did.to_string(), + "prev": self.prev.map(|v| v.to_string()), + "meta_cid": self.meta_cid.to_string(), + "mst_cid": self.mst_cid.to_string(), + }) + } +} + pub struct RepoStore { db: BlockStore, } diff --git a/adenosine-pds/templates/at_repo.html b/adenosine-pds/templates/at_repo.html index 31296db..cc45930 100644 --- a/adenosine-pds/templates/at_repo.html +++ b/adenosine-pds/templates/at_repo.html @@ -15,6 +15,6 @@
{{ describe|json }}

commit node

-
{{ commit|json }}
+
{{ commit.to_pretty_json()|json }}
{% endblock %} -- cgit v1.2.3