-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EsdtTokenPaymentRefs, tx.esdt_refs, direct_esdt unified syntax impl
- Loading branch information
1 parent
0c234ab
commit 051fecf
Showing
10 changed files
with
170 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
framework/base/src/types/interaction/tx_payment/tx_payment_single_esdt_ref.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use crate::{ | ||
api::ManagedTypeApi, | ||
contract_base::SendRawWrapper, | ||
types::{ | ||
BigUint, EsdtTokenPayment, EsdtTokenPaymentRefs, ManagedAddress, ManagedVec, | ||
MultiEsdtPayment, TokenIdentifier, TxFrom, TxToSpecified, | ||
}, | ||
}; | ||
|
||
use super::{AnnotatedEgldPayment, FullPaymentData, FunctionCall, TxEgldValue, TxEnv, TxPayment}; | ||
|
||
impl<'a, Env> TxPayment<Env> for EsdtTokenPaymentRefs<'a, Env::Api> | ||
where | ||
Env: TxEnv, | ||
{ | ||
fn is_no_payment(&self) -> bool { | ||
self.amount == &0u32 | ||
} | ||
|
||
fn perform_transfer_execute( | ||
self, | ||
env: &Env, | ||
to: &ManagedAddress<Env::Api>, | ||
gas_limit: u64, | ||
fc: FunctionCall<Env::Api>, | ||
) { | ||
if self.token_nonce == 0 { | ||
// fungible ESDT | ||
let _ = SendRawWrapper::<Env::Api>::new().transfer_esdt_execute( | ||
to, | ||
self.token_identifier, | ||
self.amount, | ||
gas_limit, | ||
&fc.function_name, | ||
&fc.arg_buffer, | ||
); | ||
} else { | ||
// non-fungible/semi-fungible ESDT | ||
let _ = SendRawWrapper::<Env::Api>::new().transfer_esdt_nft_execute( | ||
to, | ||
self.token_identifier, | ||
self.token_nonce, | ||
self.amount, | ||
gas_limit, | ||
&fc.function_name, | ||
&fc.arg_buffer, | ||
); | ||
} | ||
} | ||
|
||
fn with_normalized<From, To, F, R>( | ||
self, | ||
env: &Env, | ||
from: &From, | ||
to: To, | ||
fc: FunctionCall<Env::Api>, | ||
f: F, | ||
) -> R | ||
where | ||
From: TxFrom<Env>, | ||
To: TxToSpecified<Env>, | ||
F: FnOnce(&ManagedAddress<Env::Api>, &BigUint<Env::Api>, &FunctionCall<Env::Api>) -> R, | ||
{ | ||
to.with_address_ref(env, |to_addr| { | ||
if self.token_nonce == 0 { | ||
let fc_conv = fc.convert_to_single_transfer_fungible_call(self); | ||
f(to_addr, &BigUint::zero(), &fc_conv) | ||
} else { | ||
let fc_conv = fc.convert_to_single_transfer_nft_call(to_addr, self); | ||
f(&from.resolve_address(env), &BigUint::zero(), &fc_conv) | ||
} | ||
}) | ||
} | ||
|
||
fn into_full_payment_data(self, _env: &Env) -> FullPaymentData<Env::Api> { | ||
FullPaymentData { | ||
egld: None, | ||
multi_esdt: MultiEsdtPayment::from_single_item(self.to_owned_payment()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters