Skip to content

Commit

Permalink
unified syntax - transfer-exec EGLD fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Jan 1, 2025
1 parent 29914f5 commit 3eb7d43
Show file tree
Hide file tree
Showing 4 changed files with 339 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ pub trait ForwarderTransferExecuteModule {
fn transf_exec_multi_accept_funds(
&self,
to: ManagedAddress,
token_payments: MultiValueEncoded<MultiValue3<TokenIdentifier, u64, BigUint>>,
token_payments: MultiValueEncoded<MultiValue3<EgldOrEsdtTokenIdentifier, u64, BigUint>>,
) {
let mut all_token_payments = ManagedVec::new();

for multi_arg in token_payments.into_iter() {
let (token_identifier, token_nonce, amount) = multi_arg.into_tuple();
let payment = EsdtTokenPayment::new(token_identifier, token_nonce, amount);
let payment = EgldOrEsdtTokenPayment::new(token_identifier, token_nonce, amount);

all_token_payments.push(payment);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
{
"gasSchedule": "v3",
"steps": [
{
"step": "setState",
"accounts": {
"address:a_user": {
"nonce": "0",
"balance": "0"
},
"sc:forwarder": {
"nonce": "0",
"balance": "100000",
"esdt": {
"str:FWD-TOKEN": "1000",
"str:NFT-123456": {
"instances": [
{
"nonce": "1",
"balance": "1"
}
]
},
"str:SFT-456789": {
"instances": [
{
"nonce": "3",
"balance": "10"
}
]
}
},
"code": "mxsc:../forwarder/output/forwarder.mxsc.json"
},
"sc:vault": {
"nonce": "0",
"balance": "0",
"code": "mxsc:../vault/output/vault.mxsc.json"
}
}
},
{
"step": "scCall",
"id": "forward egld x 1",
"tx": {
"from": "address:a_user",
"to": "sc:forwarder",
"function": "transf_exec_multi_accept_funds",
"arguments": [
"sc:vault",
"str:EGLD",
"0",
"1000"
],
"gasLimit": "1,400,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "0",
"message": "",
"logs": [
{
"address": "sc:forwarder",
"endpoint": "str:transferValueOnly",
"topics": [
"1000",
"sc:vault"
],
"data": [
"str:TransferAndExecute",
"str:accept_funds"
]
},
{
"address": "sc:vault",
"endpoint": "str:accept_funds",
"topics": [
"str:accept_funds",
"1000"
],
"data": [
""
]
}
]
}
},
{
"step": "scCall",
"id": "forward egld x 2",
"comment": "send fungible twice",
"tx": {
"from": "address:a_user",
"to": "sc:forwarder",
"function": "transf_exec_multi_accept_funds",
"arguments": [
"sc:vault",
"str:EGLD",
"0",
"1000",
"str:EGLD",
"0",
"2000"
],
"gasLimit": "1,400,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "0",
"message": "",
"logs": [
{
"address": "sc:forwarder",
"endpoint": "str:MultiESDTNFTTransfer",
"topics": [
"str:EGLD-000000",
"0",
"1000",
"str:EGLD-000000",
"0",
"2000",
"sc:vault"
],
"data": [
"str:TransferAndExecute",
"str:MultiESDTNFTTransfer",
"sc:vault",
"2",
"str:EGLD-000000",
"0",
"1000",
"str:EGLD-000000",
"0",
"2000",
"str:accept_funds"
]
},
{
"address": "sc:vault",
"endpoint": "str:accept_funds",
"topics": [
"str:accept_funds",
"0",
"str:EGLD",
"0",
"1000",
"str:EGLD",
"0",
"2000"
],
"data": [
""
]
}
]
}
},
{
"step": "checkState",
"accounts": {
"address:a_user": {
"nonce": "*",
"balance": "0",
"storage": {},
"code": ""
},
"sc:vault": {
"nonce": "0",
"balance": "4000",
"storage": {
"str:call_counts|nested:str:accept_funds": "2"
},
"code": "mxsc:../vault/output/vault.mxsc.json"
},
"sc:forwarder": {
"nonce": "0",
"balance": "96000",
"esdt": {
"str:FWD-TOKEN": "1000",
"str:NFT-123456": {
"instances": [
{
"nonce": "1",
"balance": "1"
}
]
},
"str:SFT-456789": {
"instances": [
{
"nonce": "3",
"balance": "10"
}
]
}
},
"storage": {},
"code": "mxsc:../forwarder/output/forwarder.mxsc.json"
}
}
},
{
"step": "scCall",
"id": "1",
"comment": "send EGLD+ESDT",
"tx": {
"from": "address:a_user",
"to": "sc:forwarder",
"function": "transf_exec_multi_accept_funds",
"arguments": [
"sc:vault",
"str:FWD-TOKEN",
"0",
"500",
"str:FWD-TOKEN",
"0",
"300",
"str:EGLD",
"0",
"3200",
"str:NFT-123456",
"1",
"1",
"str:SFT-456789",
"3",
"6",
"str:EGLD",
"0",
"3300"
],
"gasLimit": "1,400,000,000",
"gasPrice": "0"
},
"expect": {
"out": [],
"status": "0",
"message": "",
"gas": "*",
"refund": "*"
}
},
{
"step": "checkState",
"accounts": {
"address:a_user": {
"nonce": "*",
"balance": "0",
"storage": {},
"code": ""
},
"sc:vault": {
"nonce": "0",
"balance": "10500",
"esdt": {
"str:FWD-TOKEN": "800",
"str:NFT-123456": {
"instances": [
{
"nonce": "1",
"balance": "1"
}
]
},
"str:SFT-456789": {
"instances": [
{
"nonce": "3",
"balance": "6"
}
]
}
},
"storage": {
"str:call_counts|nested:str:accept_funds": "3"
},
"code": "mxsc:../vault/output/vault.mxsc.json"
},
"sc:forwarder": {
"nonce": "0",
"balance": "89500",
"esdt": {
"str:FWD-TOKEN": "200",
"str:SFT-456789": {
"instances": [
{
"nonce": "3",
"balance": "4"
}
]
}
},
"storage": {},
"code": "mxsc:../forwarder/output/forwarder.mxsc.json"
}
}
}
]
}
32 changes: 30 additions & 2 deletions framework/base/src/contract_base/wrappers/send_raw_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
HandleConstraints, ManagedBufferApiImpl, RawHandle, SendApiImpl, StaticVarApiImpl,
},
types::{
BigUint, CodeMetadata, EsdtTokenPayment, ManagedAddress, ManagedArgBuffer, ManagedBuffer,
ManagedType, ManagedVec, TokenIdentifier,
BigUint, CodeMetadata, EgldOrEsdtTokenPayment, EsdtTokenPayment, ManagedAddress,
ManagedArgBuffer, ManagedBuffer, ManagedType, ManagedVec, TokenIdentifier,
},
};

Expand Down Expand Up @@ -124,6 +124,34 @@ where
)
}

pub fn multi_egld_or_esdt_transfer_execute(
&self,
to: &ManagedAddress<A>,
payments: &ManagedVec<A, EgldOrEsdtTokenPayment<A>>,
gas_limit: u64,
endpoint_name: &ManagedBuffer<A>,
arg_buffer: &ManagedArgBuffer<A>,
) -> Result<(), &'static [u8]> {
if let Some(single_item) = payments.is_single_item() {
if single_item.token_identifier.is_egld() {
return self.direct_egld_execute(
to,
&single_item.amount,
gas_limit,
endpoint_name,
arg_buffer,
);
}
}
A::send_api_impl().multi_transfer_esdt_nft_execute(
to.get_handle().get_raw_handle(),
payments.get_handle().get_raw_handle(),
gas_limit,
endpoint_name.get_handle().get_raw_handle(),
arg_buffer.get_handle().get_raw_handle(),
)
}

pub fn async_call_raw(
&self,
to: &ManagedAddress<A>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use core::ops::Deref;

use crate::{
api::{HandleConstraints, SendApi, SendApiImpl},
types::{
BigUint, ManagedAddress, ManagedRef, ManagedType, MultiEgldOrEsdtPayment, TxFrom,
TxToSpecified,
},
contract_base::SendRawWrapper,
types::{BigUint, ManagedAddress, ManagedRef, MultiEgldOrEsdtPayment, TxFrom, TxToSpecified},
};

use super::{FullPaymentData, FunctionCall, TxEnv, TxPayment};
Expand All @@ -25,12 +22,12 @@ where
gas_limit: u64,
fc: FunctionCall<Env::Api>,
) {
let _ = Env::Api::send_api_impl().multi_transfer_esdt_nft_execute(
to.get_handle().get_raw_handle(),
self.get_handle().get_raw_handle(),
let _ = SendRawWrapper::<Env::Api>::new().multi_egld_or_esdt_transfer_execute(
to,
self,
gas_limit,
fc.function_name.get_handle().get_raw_handle(),
fc.arg_buffer.get_handle().get_raw_handle(),
&fc.function_name,
&fc.arg_buffer,
);
}

Expand Down

0 comments on commit 3eb7d43

Please sign in to comment.