diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2022-11-22 11:16:11 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2022-11-22 11:16:11 -0800 |
commit | 4fd86c1b2191aaaabc2b8a6ec5fc1078d75a28b5 (patch) | |
tree | 94dd9d011c775349908072a07fe88f22c2965d7b /adenosine-pds/src/repo.rs | |
parent | 08837e7d340887560d74ee4ca09176baf1977317 (diff) | |
download | adenosine-4fd86c1b2191aaaabc2b8a6ec5fc1078d75a28b5.tar.gz adenosine-4fd86c1b2191aaaabc2b8a6ec5fc1078d75a28b5.zip |
pds: human-readable CIDs etc in commit node in web UI
Diffstat (limited to 'adenosine-pds/src/repo.rs')
-rw-r--r-- | adenosine-pds/src/repo.rs | 17 |
1 files changed, 17 insertions, 0 deletions
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<libipld::DefaultParams>, } |