Skip to content

Commit

Permalink
address expression conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Mar 26, 2024
1 parent e83cb66 commit 819c438
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions framework/base/src/types/interaction/expr/address_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ impl AddressExpr {
}
result
}

#[cfg(feature = "alloc")]
pub fn eval_to_expr(&self) -> alloc::string::String {
alloc::format!("{ADDRESS_PREFIX}{}", self.0)
}
}

#[cfg(test)]
Expand Down
5 changes: 5 additions & 0 deletions framework/base/src/types/interaction/expr/sc_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ impl<'a> ScExpr<'a> {
}
result
}

#[cfg(feature = "alloc")]
pub fn eval_to_expr(&self) -> alloc::string::String {
alloc::format!("{SC_PREFIX}{}", self.0)
}
}

#[cfg(test)]
Expand Down
20 changes: 20 additions & 0 deletions framework/scenario/src/scenario/model/value/address_key.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use multiversx_sc::types::{AddressExpr, ScExpr};

use super::{value_from_slice, AddressValue};
use crate::{
multiversx_sc::types::Address,
Expand Down Expand Up @@ -114,3 +116,21 @@ impl From<&Address> for AddressKey {
}
}
}

impl From<AddressExpr> for AddressKey {
fn from(from: AddressExpr) -> Self {
AddressKey {
value: from.eval_to_array().into(),
original: from.eval_to_expr(),
}
}
}

impl From<ScExpr<'_>> for AddressKey {
fn from(from: ScExpr) -> Self {
AddressKey {
value: from.eval_to_array().into(),
original: from.eval_to_expr(),
}
}
}

0 comments on commit 819c438

Please sign in to comment.