diff --git a/contracts/okp4-objectarium/src/contract.rs b/contracts/okp4-objectarium/src/contract.rs index 026fdd37..52ce551f 100644 --- a/contracts/okp4-objectarium/src/contract.rs +++ b/contracts/okp4-objectarium/src/contract.rs @@ -161,7 +161,7 @@ pub mod execute { Ok(Response::new() .add_attribute("action", "store_object") - .add_attribute("id", object.id.clone())) + .add_attribute("id", object.id.to_string())) } pub fn pin_object( @@ -1260,7 +1260,7 @@ mod tests { .save(deps.as_mut().storage, &data) .expect("no error when storing data"); - let msg = QueryMsg::ObjectData { id: id.into() }; + let msg = QueryMsg::ObjectData { id: id.to_string() }; let result = query(deps.as_ref(), mock_env(), msg); assert_eq!( diff --git a/contracts/okp4-objectarium/src/crypto.rs b/contracts/okp4-objectarium/src/crypto.rs index edcc9c20..a0c19b92 100644 --- a/contracts/okp4-objectarium/src/crypto.rs +++ b/contracts/okp4-objectarium/src/crypto.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; use sha2; use sha2::Digest; use std::any::type_name; +use std::fmt; /// HashAlgorithm is the type of the hash algorithm. pub enum HashAlgorithm { @@ -34,7 +35,7 @@ impl HashAlgorithm { } } -/// Hash represent a Object hash as binary value. +/// Hash represent a Object hash as binary value. #[derive( Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, JsonSchema, )] @@ -83,9 +84,11 @@ impl TryFrom for Hash { } } -impl From for String { - fn from(hash: Hash) -> Self { - base16ct::lower::encode_string(hash.0.as_slice()) +// Allows for a (user-friendly) string representation of Hash as a lower Base16 (hex) encoding. +impl fmt::Display for Hash { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let hex_string = base16ct::lower::encode_string(&self.0); + write!(f, "{}", hex_string) } } diff --git a/contracts/okp4-objectarium/src/state.rs b/contracts/okp4-objectarium/src/state.rs index 7fb4ce44..7b1cf41b 100644 --- a/contracts/okp4-objectarium/src/state.rs +++ b/contracts/okp4-objectarium/src/state.rs @@ -275,7 +275,7 @@ pub struct Object { impl From<&Object> for ObjectResponse { fn from(object: &Object) -> Self { ObjectResponse { - id: object.id.clone().into(), + id: object.id.to_string(), size: object.size, owner: object.owner.clone().into(), is_pinned: object.pin_count > Uint128::zero(),