From 819c43868a39dace3f0e25f92c2c760b9372e761 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Tue, 26 Mar 2024 19:51:19 +0200 Subject: [PATCH] address expression conversions --- .../types/interaction/expr/address_expr.rs | 5 +++++ .../src/types/interaction/expr/sc_expr.rs | 5 +++++ .../src/scenario/model/value/address_key.rs | 20 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/framework/base/src/types/interaction/expr/address_expr.rs b/framework/base/src/types/interaction/expr/address_expr.rs index a5b9756638..ce2fa10fb5 100644 --- a/framework/base/src/types/interaction/expr/address_expr.rs +++ b/framework/base/src/types/interaction/expr/address_expr.rs @@ -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)] diff --git a/framework/base/src/types/interaction/expr/sc_expr.rs b/framework/base/src/types/interaction/expr/sc_expr.rs index 551d4eaf0a..1613587402 100644 --- a/framework/base/src/types/interaction/expr/sc_expr.rs +++ b/framework/base/src/types/interaction/expr/sc_expr.rs @@ -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)] diff --git a/framework/scenario/src/scenario/model/value/address_key.rs b/framework/scenario/src/scenario/model/value/address_key.rs index 5bbc1d79ae..889cca69ae 100644 --- a/framework/scenario/src/scenario/model/value/address_key.rs +++ b/framework/scenario/src/scenario/model/value/address_key.rs @@ -1,3 +1,5 @@ +use multiversx_sc::types::{AddressExpr, ScExpr}; + use super::{value_from_slice, AddressValue}; use crate::{ multiversx_sc::types::Address, @@ -114,3 +116,21 @@ impl From<&Address> for AddressKey { } } } + +impl From for AddressKey { + fn from(from: AddressExpr) -> Self { + AddressKey { + value: from.eval_to_array().into(), + original: from.eval_to_expr(), + } + } +} + +impl From> for AddressKey { + fn from(from: ScExpr) -> Self { + AddressKey { + value: from.eval_to_array().into(), + original: from.eval_to_expr(), + } + } +}