Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ManagedVecItem - ref for EsdtTokenPayment #1891

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chain/core/src/types/flags/esdt_token_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ESDT_TYPE_INVALID: &[u8] = &[];

// Note: In the current implementation, SemiFungible is never returned

#[derive(TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, PartialEq, Eq, Debug)]
#[derive(TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, Copy, PartialEq, Eq, Debug)]
pub enum EsdtTokenType {
Fungible,
NonFungible,
Expand Down
8 changes: 4 additions & 4 deletions contracts/core/wegld-swap/src/wegld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ pub trait EgldEsdtSwap: multiversx_sc_modules::pause::PauseModule {
let (payment_token, payment_amount) = self.call_value().single_fungible_esdt();
let wrapped_egld_token_id = self.wrapped_egld_token_id().get();

require!(payment_token == wrapped_egld_token_id, "Wrong esdt token");
require!(payment_amount > 0u32, "Must pay more than 0 tokens!");
require!(*payment_token == wrapped_egld_token_id, "Wrong esdt token");
require!(*payment_amount > 0u32, "Must pay more than 0 tokens!");
require!(
payment_amount <= self.get_locked_egld_balance(),
*payment_amount <= self.get_locked_egld_balance(),
"Contract does not have enough funds"
);

Expand All @@ -51,7 +51,7 @@ pub trait EgldEsdtSwap: multiversx_sc_modules::pause::PauseModule {

// 1 wrapped eGLD = 1 eGLD, so we pay back the same amount
let caller = self.blockchain().get_caller();
self.tx().to(&caller).egld(&payment_amount).transfer();
self.tx().to(&caller).egld(&*payment_amount).transfer();
}

#[view(getLockedEgldBalance)]
Expand Down
4 changes: 2 additions & 2 deletions contracts/examples/digital-cash/src/pay_fee_and_fund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub trait PayFeeAndFund: storage::StorageModule + helpers::HelpersModule {
#[endpoint(payFeeAndFundESDT)]
#[payable("*")]
fn pay_fee_and_fund_esdt(&self, address: ManagedAddress, valability: u64) {
let mut payments = self.call_value().all_esdt_transfers().clone_value();
let fee = EgldOrEsdtTokenPayment::from(payments.get(0));
let mut payments = self.call_value().all_esdt_transfers().clone();
let fee = EgldOrEsdtTokenPayment::from(payments.get(0).clone());
let caller_address = self.blockchain().get_caller();
self.update_fees(caller_address, &address, fee);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ pub trait EsdtTransferWithFee {
"Mismatching payment for covering fees"
);
let _ = self.get_payment_after_fees(fee_type, &next_payment);
new_payments.push(payment);
new_payments.push(payment.clone());
},
Fee::Percentage(_) => {
new_payments.push(self.get_payment_after_fees(fee_type, &payment));
},
Fee::Unset => {
new_payments.push(payment);
new_payments.push(payment.clone());
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/fractional-nfts/src/fractional_nfts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub trait FractionalNfts: default_issue_callbacks::DefaultIssueCallbacksModule {
let fractional_token = fractional_token_mapper.get_token_id_ref();
let hash = ManagedBuffer::new();
let fractional_info =
FractionalUriInfo::new(original_payment, initial_fractional_amount.clone());
FractionalUriInfo::new(original_payment.clone(), initial_fractional_amount.clone());
let uris = fractional_info.to_uris();

let fractional_nonce = self.send().esdt_nft_create(
Expand Down
38 changes: 29 additions & 9 deletions contracts/examples/nft-subscription/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,54 @@ pub trait NftSubscription:
#[payable("*")]
#[endpoint]
fn update_attributes(&self, attributes: ManagedBuffer) {
let (id, nonce, _) = self.call_value().single_esdt().into_tuple();
self.update_subscription_attributes::<ManagedBuffer>(&id, nonce, attributes);
let payment = self.call_value().single_esdt();
self.update_subscription_attributes::<ManagedBuffer>(
&payment.token_identifier,
payment.token_nonce,
attributes,
);
self.tx()
.to(ToCaller)
.single_esdt(&id, nonce, &BigUint::from(1u8))
.single_esdt(
&payment.token_identifier,
payment.token_nonce,
&BigUint::from(1u8),
)
.transfer();
}

#[payable("*")]
#[endpoint]
fn renew(&self, duration: u64) {
let (id, nonce, _) = self.call_value().single_esdt().into_tuple();
self.renew_subscription::<ManagedBuffer>(&id, nonce, duration);
let payment = self.call_value().single_esdt();
self.renew_subscription::<ManagedBuffer>(
&payment.token_identifier,
payment.token_nonce,
duration,
);
self.tx()
.to(ToCaller)
.single_esdt(&id, nonce, &BigUint::from(1u8))
.single_esdt(
&payment.token_identifier,
payment.token_nonce,
&BigUint::from(1u8),
)
.transfer();
}

#[payable("*")]
#[endpoint]
fn cancel(&self) {
let (id, nonce, _) = self.call_value().single_esdt().into_tuple();
self.cancel_subscription::<ManagedBuffer>(&id, nonce);
let payment = self.call_value().single_esdt();
self.cancel_subscription::<ManagedBuffer>(&payment.token_identifier, payment.token_nonce);

self.tx()
.to(ToCaller)
.single_esdt(&id, nonce, &BigUint::from(1u8))
.single_esdt(
&payment.token_identifier,
payment.token_nonce,
&BigUint::from(1u8),
)
.transfer();
}

Expand Down
14 changes: 10 additions & 4 deletions contracts/examples/order-book/pair/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,28 @@ pub trait ValidationModule: common::CommonModule {
let (token_id, amount) = self.call_value().single_fungible_esdt();
let second_token_id = self.second_token_id().get();
require!(
token_id == second_token_id,
*token_id == second_token_id,
"Token in and second token id should be the same"
);

Payment { token_id, amount }
Payment {
token_id: token_id.clone(),
amount: amount.clone(),
}
}

fn require_valid_sell_payment(&self) -> Payment<Self::Api> {
let (token_id, amount) = self.call_value().single_fungible_esdt();
let first_token_id = self.first_token_id().get();
require!(
token_id == first_token_id,
*token_id == first_token_id,
"Token in and first token id should be the same"
);

Payment { token_id, amount }
Payment {
token_id: token_id.clone(),
amount: amount.clone(),
}
}

fn require_valid_match_input_order_ids(&self, order_ids: &ManagedVec<u64>) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/examples/seed-nft-minter/src/seed_nft_minter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub trait SeedNftMinter:
} else {
esdt_payments
.try_get(0)
.map(|esdt_payment| esdt_payment.amount)
.map(|esdt_payment| esdt_payment.amount.clone())
.unwrap_or_default()
};
total_amount += amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ pub trait FungibleTokenMapperFeatures:
fn custom_issue_non_zero_supply_cb(&self, #[call_result] result: ManagedAsyncCallResult<()>) {
match result {
ManagedAsyncCallResult::Ok(()) => {
let token_identifier = self.call_value().single_esdt().token_identifier;
self.fungible_token_mapper().set_token_id(token_identifier);
let token_identifier = &self.call_value().single_esdt().token_identifier;
self.fungible_token_mapper()
.set_token_id(token_identifier.clone());
},
ManagedAsyncCallResult::Err(_) => {
self.fungible_token_mapper().clear();
Expand Down Expand Up @@ -128,9 +129,9 @@ pub trait FungibleTokenMapperFeatures:
#[payable("*")]
#[endpoint]
fn require_same_token_fungible(&self) {
let payment_token = self.call_value().single_esdt().token_identifier;
let payment_token = &self.call_value().single_esdt().token_identifier;
self.fungible_token_mapper()
.require_same_token(&payment_token);
.require_same_token(payment_token);
}

#[payable("*")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub trait FirstContract {
let expected_token_identifier = self.get_contract_esdt_token_identifier();

require!(
actual_token_identifier == expected_token_identifier,
*actual_token_identifier == expected_token_identifier,
"Wrong esdt token"
);

Expand All @@ -45,13 +45,13 @@ pub trait FirstContract {
let expected_token_identifier = self.get_contract_esdt_token_identifier();

require!(
actual_token_identifier == expected_token_identifier,
*actual_token_identifier == expected_token_identifier,
"Wrong esdt token"
);

self.call_esdt_second_contract(
&expected_token_identifier,
&(esdt_value / 2u32),
&(esdt_value.clone() / 2u32),
&self.get_second_contract_address(),
&ManagedBuffer::from(SECOND_CONTRACT_ACCEPT_ESDT_PAYMENT),
&ManagedVec::new(),
Expand All @@ -65,7 +65,7 @@ pub trait FirstContract {
let expected_token_identifier = self.get_contract_esdt_token_identifier();

require!(
actual_token_identifier == expected_token_identifier,
*actual_token_identifier == expected_token_identifier,
"Wrong esdt token"
);

Expand All @@ -86,7 +86,7 @@ pub trait FirstContract {
let expected_token_identifier = self.get_contract_esdt_token_identifier();

require!(
actual_token_identifier == expected_token_identifier,
*actual_token_identifier == expected_token_identifier,
"Wrong esdt token"
);

Expand All @@ -107,7 +107,7 @@ pub trait FirstContract {
let expected_token_identifier = self.get_contract_esdt_token_identifier();

require!(
actual_token_identifier == expected_token_identifier,
*actual_token_identifier == expected_token_identifier,
"Wrong esdt token"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub trait Child {
#[callback]
fn esdt_issue_callback(&self, #[call_result] _result: IgnoreValue) {
let (token_identifier, _amount) = self.call_value().single_fungible_esdt();
self.wrapped_egld_token_identifier().set(&token_identifier);
self.wrapped_egld_token_identifier().set(token_identifier);
}

// storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait ForwarderTransferExecuteModule {
self.vault_proxy()
.contract(to)
.accept_funds()
.payment((payment.token_identifier, 0, payment.amount))
.single_esdt(&payment.token_identifier, 0, &payment.amount)
.transfer_execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub trait ForwarderEsdtModule: fwd_storage_legacy::ForwarderStorageModule {
#[endpoint]
fn send_esdt_with_fees(&self, to: ManagedAddress, percentage_fees: BigUint) {
let (token_id, payment) = self.call_value().single_fungible_esdt();
let fees = &payment * &percentage_fees / PERCENTAGE_TOTAL;
let amount_to_send = payment - fees;
let fees = &*payment * &percentage_fees / PERCENTAGE_TOTAL;
let amount_to_send = payment.clone() - fees;

self.send().direct_esdt(&to, &token_id, 0, &amount_to_send);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ pub trait ForwarderRaw:
} else {
for payment in payments.iter() {
let _ = self.callback_payments().push(&(
EgldOrEsdtTokenIdentifier::esdt(payment.token_identifier),
EgldOrEsdtTokenIdentifier::esdt(payment.token_identifier.clone()),
payment.token_nonce,
payment.amount,
payment.amount.clone(),
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ pub trait ForwarderRawAsync: super::forwarder_raw_common::ForwarderRawCommon {
let (token, payment) = self.call_value().single_fungible_esdt();
self.forward_contract_call(
to,
EgldOrEsdtTokenIdentifier::esdt(token),
payment,
EgldOrEsdtTokenIdentifier::esdt(token.clone()),
payment.clone(),
endpoint_name,
args,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub trait ForwarderEsdtModule: fwd_storage::ForwarderStorageModule {
#[endpoint]
fn send_esdt_with_fees(&self, to: ManagedAddress, percentage_fees: BigUint) {
let (token_id, payment) = self.call_value().single_fungible_esdt();
let fees = &payment * &percentage_fees / PERCENTAGE_TOTAL;
let amount_to_send = payment - fees;
let fees = percentage_fees * &*payment / PERCENTAGE_TOTAL;
let amount_to_send = payment.clone() - fees;

self.tx()
.to(&to)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ pub trait CallPromisesBackTransfersModule: common::CommonModule {
}

for esdt_transfer in &back_transfers.esdt_payments {
let (token, nonce, payment) = esdt_transfer.into_tuple();
let esdt_token_id = EgldOrEsdtTokenIdentifier::esdt(token);
self.retrieve_funds_callback_event(&esdt_token_id, nonce, &payment);
let esdt_token_id =
EgldOrEsdtTokenIdentifier::esdt(esdt_transfer.token_identifier.clone());
self.retrieve_funds_callback_event(
&esdt_token_id,
esdt_transfer.token_nonce,
&esdt_transfer.amount,
);

let _ = self.callback_data().push(&CallbackData {
callback_name: ManagedBuffer::from(b"retrieve_funds_callback"),
token_identifier: esdt_token_id,
token_nonce: nonce,
token_amount: payment,
token_nonce: esdt_transfer.token_nonce,
token_amount: esdt_transfer.amount.clone(),
args: ManagedVec::new(),
});
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/feature-tests/composability/vault/src/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ pub trait Vault {
);

new_tokens.push(EsdtTokenPayment::new(
payment.token_identifier,
payment.token_identifier.clone(),
new_token_nonce,
payment.amount,
payment.amount.clone(),
));
}

Expand Down
10 changes: 5 additions & 5 deletions contracts/feature-tests/payable-features/src/payable_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub trait PayableFeatures {
#[payable("*")]
fn payment_array_3(&self) -> MultiValue3<EsdtTokenPayment, EsdtTokenPayment, EsdtTokenPayment> {
let [payment_a, payment_b, payment_c] = self.call_value().multi_esdt();
(payment_a, payment_b, payment_c).into()
(payment_a.clone(), payment_b.clone(), payment_c.clone()).into()
}

#[endpoint]
Expand Down Expand Up @@ -129,7 +129,7 @@ pub trait PayableFeatures {
&self,
#[payment] payment: BigUint,
) -> MultiValue2<BigUint, TokenIdentifier> {
let token = self.call_value().single_esdt().token_identifier;
let token = self.call_value().single_esdt().token_identifier.clone();
(payment, token).into()
}

Expand All @@ -140,14 +140,14 @@ pub trait PayableFeatures {
#[payment_token] token: EgldOrEsdtTokenIdentifier,
) -> MultiValue2<BigUint, EgldOrEsdtTokenIdentifier> {
let payment = self.call_value().single_esdt();
(payment.amount, token).into()
(payment.amount.clone(), token).into()
}

#[endpoint]
#[payable("PAYABLE-FEATURES-TOKEN")]
fn payable_token_4(&self) -> MultiValue2<BigUint, TokenIdentifier> {
let payment = self.call_value().single_esdt().amount;
let token = self.call_value().single_esdt().token_identifier;
let payment = self.call_value().single_esdt().amount.clone();
let token = self.call_value().single_esdt().token_identifier.clone();
(payment, token).into()
}
}
Loading
Loading