Skip to content

Commit

Permalink
Refactor Value enum to include support for boolean values
Browse files Browse the repository at this point in the history
  • Loading branch information
b3hr4d committed Sep 21, 2024
1 parent 6627f79 commit 680f6ac
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ledger/icrc/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub type Metadata = HashMap<String, Value>;
pub enum Value {
Blob(ByteBuf),
Text(String),
Bool(bool),
Nat(Nat),
Nat64(u64),
Int(Int),
Expand Down Expand Up @@ -68,6 +69,7 @@ impl Value {
}
Value::Blob(bytes) => Sha256::digest(bytes).into(),
Value::Text(text) => Sha256::digest(text.as_bytes()).into(),
Value::Bool(b) => Sha256::digest(&[*b as u8]).into(),
Value::Array(values) => {
let mut hasher = Sha256::new();
for v in values.iter() {
Expand Down Expand Up @@ -100,6 +102,7 @@ impl std::fmt::Display for Value {
match self {
Value::Blob(bytes) => write!(f, "{}", hex::encode(bytes.as_ref())),
Value::Text(text) => write!(f, "{}", text),
Value::Bool(b) => write!(f, "{}", b),
Value::Nat(nat) => write!(f, "{}", nat),
Value::Nat64(nat64) => write!(f, "{}", nat64),
Value::Int(int) => write!(f, "{}", int),
Expand Down

0 comments on commit 680f6ac

Please sign in to comment.