Skip to content

Commit

Permalink
style(objectarium): convert to Display trait
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Apr 1, 2024
1 parent 8841634 commit ecd9d67
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions contracts/okp4-objectarium/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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!(
Expand Down
11 changes: 7 additions & 4 deletions contracts/okp4-objectarium/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
)]
Expand Down Expand Up @@ -83,9 +84,11 @@ impl TryFrom<String> for Hash {
}
}

impl From<Hash> 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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/okp4-objectarium/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit ecd9d67

Please sign in to comment.