aboutsummaryrefslogtreecommitdiff
path: root/lockchain-core/src/record.rs
diff options
context:
space:
mode:
authorKatharina Sabel <katharina.sabel@asquera.de>2018-04-16 10:21:28 +0200
committerKatharina Sabel <katharina.sabel@asquera.de>2018-04-16 10:21:28 +0200
commitff07b004c16939c86ac89a4d25b3ca1e243b172e (patch)
treeca458c3d3cdea804719773e38297a66037e0aade /lockchain-core/src/record.rs
parent7d62ae013640e00984d1d1ffed64857d949aa7c3 (diff)
Adding some new functions and bumping the version to 0.2.0
Diffstat (limited to 'lockchain-core/src/record.rs')
-rw-r--r--lockchain-core/src/record.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/lockchain-core/src/record.rs b/lockchain-core/src/record.rs
index 03d3262..5f721c0 100644
--- a/lockchain-core/src/record.rs
+++ b/lockchain-core/src/record.rs
@@ -5,6 +5,7 @@
use std::collections::BTreeMap;
use chrono::{Local, DateTime};
+use serde_json;
/// A generic payload for a record
@@ -16,6 +17,12 @@ pub enum Payload {
BTreeMap(BTreeMap<String, Payload>),
}
+/// The header of a record
+///
+/// Contains easily searchable fields of metadata. Nothing
+/// in the Header should ever be considered secure as the
+/// headers are kept cached for much longer than the rest
+/// of the data.
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct Header {
pub name: String,
@@ -26,10 +33,10 @@ pub struct Header {
pub date_updated: DateTime<Local>,
}
+///
#[derive(Debug, Serialize, Deserialize)]
pub struct Record {
pub header: Header,
- // pub fields: BTreeMap<String, Payload>,
pub body: BTreeMap<String, Payload>,
}
@@ -73,6 +80,18 @@ impl Record {
self.body.insert(String::from(key), val);
}
+ /// Contains a cloned value of single data field
+ pub fn get_data(&self, key: &str) -> Payload {
+ return self.body.get(key).unwrap().clone();
+ }
+
+ /// Serialise the entire body into a json tree
+ ///
+ /// Contains all secret values in a json tree that you can work with manually.
+ pub fn get_json(&self) -> String {
+ return serde_json::to_string(&self.body).unwrap();
+ }
+
/// Add a new tag to this record head. Checks that tags don't already exists
pub fn add_tag(&mut self, tag: &str) {
self.header.tags.push(String::from(tag));