Page MenuHomePhabricator

D8791.diff
No OneTemporary

D8791.diff

diff --git a/services/comm-services-lib/src/blob/mod.rs b/services/comm-services-lib/src/blob/mod.rs
--- a/services/comm-services-lib/src/blob/mod.rs
+++ b/services/comm-services-lib/src/blob/mod.rs
@@ -1,2 +1,3 @@
#[cfg(feature = "blob-client")]
pub mod client;
+pub mod types;
diff --git a/services/comm-services-lib/src/blob/types.rs b/services/comm-services-lib/src/blob/types.rs
new file mode 100644
--- /dev/null
+++ b/services/comm-services-lib/src/blob/types.rs
@@ -0,0 +1,54 @@
+use aws_sdk_dynamodb::types::AttributeValue;
+use derive_more::Constructor;
+use std::collections::HashMap;
+
+use crate::database::{AttributeTryInto, DBItemError, TryFromAttribute};
+
+const BLOB_HASH_DDB_MAP_KEY: &str = "blob_hash";
+const HOLDER_DDB_MAP_KEY: &str = "holder";
+
+/// Blob owning information - stores both blob_hash and holder
+#[derive(Clone, Debug, Constructor)]
+pub struct BlobInfo {
+ pub blob_hash: String,
+ pub holder: String,
+}
+
+impl From<BlobInfo> for AttributeValue {
+ fn from(value: BlobInfo) -> Self {
+ let map = HashMap::from([
+ (
+ BLOB_HASH_DDB_MAP_KEY.to_string(),
+ AttributeValue::S(value.blob_hash),
+ ),
+ (
+ HOLDER_DDB_MAP_KEY.to_string(),
+ AttributeValue::S(value.holder),
+ ),
+ ]);
+ AttributeValue::M(map)
+ }
+}
+impl From<&BlobInfo> for AttributeValue {
+ fn from(value: &BlobInfo) -> Self {
+ AttributeValue::from(value.to_owned())
+ }
+}
+
+impl TryFromAttribute for BlobInfo {
+ fn try_from_attr(
+ attribute_name: impl Into<String>,
+ attribute: Option<AttributeValue>,
+ ) -> Result<Self, DBItemError> {
+ let attr_name: String = attribute_name.into();
+ let mut inner_map: HashMap<String, AttributeValue> =
+ attribute.attr_try_into(&attr_name)?;
+ let blob_hash = inner_map
+ .remove("blob_hash")
+ .attr_try_into(format!("{attr_name}.blob_hash"))?;
+ let holder = inner_map
+ .remove("holder")
+ .attr_try_into(format!("{attr_name}.holder"))?;
+ Ok(BlobInfo { blob_hash, holder })
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 12:06 PM (20 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2584640
Default Alt Text
D8791.diff (2 KB)

Event Timeline