Skip to content

Commit

Permalink
AnnotatedValue & TxEgldValue impl for ManagedRef of BigUint
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Mar 27, 2024
1 parent 09521e4 commit 0b229c2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub trait ProxyTestFirst {
.to(other_contract)
.raw_upgrade()
.argument(&456)
.egld(payment.clone_value())
.egld(payment)
.upgrade_contract(&code, CodeMetadata::UPGRADEABLE);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/modules/src/esdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub trait EsdtModule {
let egld_returned = self.call_value().egld_value();
self.tx()
.to(&initial_caller)
.egld(&*egld_returned)
.egld(egld_returned)
.transfer_if_not_empty();
},
}
Expand Down
29 changes: 28 additions & 1 deletion framework/base/src/types/interaction/annotated.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::types::{heap::Address, BigUint, ManagedAddress, ManagedBuffer};
use crate::{
proxy_imports::ManagedRef,
types::{heap::Address, BigUint, ManagedAddress, ManagedBuffer},
};

use super::TxEnv;

Expand Down Expand Up @@ -175,6 +178,30 @@ where
}
}

impl<'a, Env> AnnotatedValue<Env, BigUint<Env::Api>> for ManagedRef<'a, Env::Api, BigUint<Env::Api>>
where
Env: TxEnv,
{
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> {
self.to_display()
}

fn to_value(&self, _env: &Env) -> BigUint<Env::Api> {
(*self).clone_value()
}

fn into_value(self, _env: &Env) -> BigUint<Env::Api> {
self.clone_value()
}

fn with_value_ref<F, R>(&self, env: &Env, f: F) -> R
where
F: FnOnce(&BigUint<Env::Api>) -> R,
{
f(self)
}
}

impl<Env> AnnotatedValue<Env, BigUint<Env::Api>> for u64
where
Env: TxEnv,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::types::{AnnotatedValue, BigUint};
use crate::{
proxy_imports::ManagedRef,
types::{AnnotatedValue, BigUint},
};

use super::TxEnv;

Expand All @@ -10,4 +13,5 @@ where

impl<Env> TxEgldValue<Env> for BigUint<Env::Api> where Env: TxEnv {}
impl<Env> TxEgldValue<Env> for &BigUint<Env::Api> where Env: TxEnv {}
impl<'a, Env> TxEgldValue<Env> for ManagedRef<'a, Env::Api, BigUint<Env::Api>> where Env: TxEnv {}
impl<Env> TxEgldValue<Env> for u64 where Env: TxEnv {}
1 change: 1 addition & 0 deletions framework/base/src/types/managed/wrapped/managed_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ where
M: ManagedTypeApi,
T: ManagedType<M> + Clone,
{
/// Syntactic sugar for dereferencing and cloning the object.
pub fn clone_value(&self) -> T {
self.deref().clone()
}
Expand Down

0 comments on commit 0b229c2

Please sign in to comment.