Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ where
>(
self,
index: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValue5<ManagedBuffer<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>, u64, BigUint<Env::Api>, MultiValueManagedVec<Env::Api, ManagedBuffer<Env::Api>>>> {
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValue5<ManagedBuffer<Env::Api>, TokenId<Env::Api>, u64, NonZeroBigUint<Env::Api>, MultiValueManagedVec<Env::Api, ManagedBuffer<Env::Api>>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("callback_data_at_index")
Expand Down Expand Up @@ -1577,7 +1577,7 @@ where
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<ManagedBuffer<Env::Api>>,
Arg2: ProxyArg<u64>,
Arg3: ProxyArg<MultiValueEncoded<Env::Api, EsdtTokenPaymentMultiValue<Env::Api>>>,
Arg3: ProxyArg<MultiValueEncoded<Env::Api, PaymentMultiValue<Env::Api>>>,
>(
self,
to: Arg0,
Expand Down Expand Up @@ -1749,8 +1749,8 @@ where
Api: ManagedTypeApi,
{
pub callback_name: ManagedBuffer<Api>,
pub token_identifier: EgldOrEsdtTokenIdentifier<Api>,
pub token_identifier: TokenId<Api>,
pub token_nonce: u64,
pub token_amount: BigUint<Api>,
pub token_amount: NonZeroBigUint<Api>,
pub args: ManagedVec<Api, ManagedBuffer<Api>>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct QueuedCall<M: ManagedTypeApi> {
pub gas_limit: u64,
pub endpoint_name: ManagedBuffer<M>,
pub args: ManagedArgBuffer<M>,
pub payments: EgldOrMultiEsdtPayment<M>,
pub payments: PaymentVec<M>,
}

/// Testing multiple calls per transaction.
Expand Down Expand Up @@ -81,23 +81,18 @@ pub trait ForwarderQueue {
to: ManagedAddress,
gas_limit: u64,
endpoint_name: ManagedBuffer,
token: EsdtTokenIdentifier,
amount: BigUint,
token: TokenId,
amount: NonZeroBigUint,
args: MultiValueEncoded<ManagedBuffer>,
) {
let mut payment = ManagedVec::new();
payment.push(EsdtTokenPayment::new(token, 0, amount));

let payments = EgldOrMultiEsdtPayment::MultiEsdt(payment);

let call_type = QueuedCallType::Promise;
self.queued_calls().push_back(QueuedCall {
call_type,
to,
gas_limit,
endpoint_name,
args: args.to_arg_buffer(),
payments,
payments: PaymentVec::from_single_item(Payment::new(token, 0, amount)),
});
}

Expand All @@ -123,29 +118,22 @@ pub trait ForwarderQueue {
endpoint_name: ManagedBuffer,
args: MultiValueEncoded<ManagedBuffer>,
) {
let payments = self.call_value().any_payment();
let payments = self.call_value().all();

match &payments {
EgldOrMultiEsdtPayment::Egld(egld_value) => {
self.add_queued_call_egld_event(&call_type, &to, &endpoint_name, egld_value);
}
EgldOrMultiEsdtPayment::MultiEsdt(esdt_payments) => {
self.add_queued_call_esdt_event(
&call_type,
&to,
&endpoint_name,
&esdt_payments.clone().into_multi_value(),
);
}
}
self.add_queued_call_event(
&call_type,
&to,
&endpoint_name,
&payments.clone().into_multi_value(),
);

self.queued_calls().push_back(QueuedCall {
call_type,
to,
gas_limit,
endpoint_name,
args: args.to_arg_buffer(),
payments,
payments: payments.clone(),
});
}

Expand All @@ -155,24 +143,12 @@ pub trait ForwarderQueue {
while let Some(node) = self.queued_calls().pop_front() {
let call = node.clone().into_value();

match &call.payments {
EgldOrMultiEsdtPayment::Egld(egld_value) => {
self.forward_queued_call_egld_event(
&call.call_type,
&call.to,
&call.endpoint_name,
egld_value,
);
}
EgldOrMultiEsdtPayment::MultiEsdt(esdt_payments) => {
self.forward_queued_call_esdt_event(
&call.call_type,
&call.to,
&call.endpoint_name,
&esdt_payments.clone().into_multi_value(),
);
}
};
self.forward_queued_call_payment_event(
&call.call_type,
&call.to,
&call.endpoint_name,
&call.payments.clone().into_multi_value(),
);

let contract_call = self
.tx()
Expand Down Expand Up @@ -205,7 +181,7 @@ pub trait ForwarderQueue {
#[label("promises-callback")]
fn promises_callback_method(&self) {
self.callback_count().update(|c| *c += 1);
let payments = self.call_value().any_payment();
let payments = self.call_value().all();

let payments_data_string = self
.tx()
Expand All @@ -225,42 +201,21 @@ pub trait ForwarderQueue {
#[storage_mapper("callback_payments")]
fn callback_payments(&self) -> SingleValueMapper<ManagedBuffer>;

#[event("forward_queued_callback")]
fn forward_queued_callback_event(&self);

#[event("forward_queued_call_egld")]
fn forward_queued_call_egld_event(
&self,
#[indexed] call_type: &QueuedCallType,
#[indexed] to: &ManagedAddress,
#[indexed] endpoint_name: &ManagedBuffer,
#[indexed] egld_value: &BigUint,
);

#[event("forward_queued_call_esdt")]
fn forward_queued_call_esdt_event(
&self,
#[indexed] call_type: &QueuedCallType,
#[indexed] to: &ManagedAddress,
#[indexed] endpoint_name: &ManagedBuffer,
#[indexed] multi_esdt: &MultiValueEncoded<EsdtTokenPaymentMultiValue>,
);

#[event("add_queued_call_egld")]
fn add_queued_call_egld_event(
#[event("forward_queued_call_payment")]
fn forward_queued_call_payment_event(
&self,
#[indexed] call_type: &QueuedCallType,
#[indexed] to: &ManagedAddress,
#[indexed] endpoint_name: &ManagedBuffer,
#[indexed] egld_value: &BigUint,
#[indexed] multi_esdt: &MultiValueEncoded<PaymentMultiValue>,
);

#[event("add_queued_call_esdt")]
fn add_queued_call_esdt_event(
#[event("add_queued_call")]
fn add_queued_call_event(
&self,
#[indexed] call_type: &QueuedCallType,
#[indexed] to: &ManagedAddress,
#[indexed] endpoint_name: &ManagedBuffer,
#[indexed] multi_esdt: &MultiValueEncoded<EsdtTokenPaymentMultiValue>,
#[indexed] multi_esdt: &MultiValueEncoded<PaymentMultiValue>,
);
}
15 changes: 6 additions & 9 deletions contracts/feature-tests/composability/forwarder/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ multiversx_sc::derive_imports!();
#[derive(TopEncode, TopDecode, Debug)]
pub struct CallbackData<M: ManagedTypeApi> {
pub callback_name: ManagedBuffer<M>,
pub token_identifier: EgldOrEsdtTokenIdentifier<M>,
pub token_identifier: TokenId<M>,
pub token_nonce: u64,
pub token_amount: BigUint<M>,
pub token_amount: NonZeroBigUint<M>,
pub args: ManagedVec<M, ManagedBuffer<M>>,
}

Expand All @@ -16,14 +16,11 @@ pub trait CommonModule {
#[event("retrieve_funds_callback")]
fn retrieve_funds_callback_event(
&self,
#[indexed] token: &EgldOrEsdtTokenIdentifier,
#[indexed] token: &TokenId,
#[indexed] nonce: u64,
#[indexed] payment: &BigUint,
#[indexed] payment: &NonZeroBigUint,
);

#[event("callback_result")]
fn callback_result(&self, #[indexed] result: MultiValueEncoded<ManagedBuffer>);

#[view]
#[storage_mapper("callback_data")]
fn callback_data(&self) -> VecMapper<CallbackData<Self::Api>>;
Expand All @@ -34,9 +31,9 @@ pub trait CommonModule {
index: usize,
) -> MultiValue5<
ManagedBuffer,
EgldOrEsdtTokenIdentifier,
TokenId,
u64,
BigUint,
NonZeroBigUint,
MultiValueManagedVec<Self::Api, ManagedBuffer>,
> {
let cb_data = self.callback_data().get(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ where
>(
self,
index: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValue5<ManagedBuffer<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>, u64, BigUint<Env::Api>, MultiValueManagedVec<Env::Api, ManagedBuffer<Env::Api>>>> {
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValue5<ManagedBuffer<Env::Api>, TokenId<Env::Api>, u64, NonZeroBigUint<Env::Api>, MultiValueManagedVec<Env::Api, ManagedBuffer<Env::Api>>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("callback_data_at_index")
Expand Down Expand Up @@ -1577,7 +1577,7 @@ where
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<ManagedBuffer<Env::Api>>,
Arg2: ProxyArg<u64>,
Arg3: ProxyArg<MultiValueEncoded<Env::Api, EsdtTokenPaymentMultiValue<Env::Api>>>,
Arg3: ProxyArg<MultiValueEncoded<Env::Api, PaymentMultiValue<Env::Api>>>,
>(
self,
to: Arg0,
Expand Down Expand Up @@ -1749,8 +1749,8 @@ where
Api: ManagedTypeApi,
{
pub callback_name: ManagedBuffer<Api>,
pub token_identifier: EgldOrEsdtTokenIdentifier<Api>,
pub token_identifier: TokenId<Api>,
pub token_nonce: u64,
pub token_amount: BigUint<Api>,
pub token_amount: NonZeroBigUint<Api>,
pub args: ManagedVec<Api, ManagedBuffer<Api>>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,24 @@ pub trait ForwarderAsyncCallModule: common::CommonModule {

#[callback]
fn retrieve_funds_callback(&self) {
let (token, nonce, payment) = self.call_value().egld_or_single_esdt().into_tuple();
self.retrieve_funds_callback_event(&token, nonce, &payment);

let _ = self.callback_data().push(&CallbackData {
callback_name: ManagedBuffer::from(b"retrieve_funds_callback"),
token_identifier: token,
token_nonce: nonce,
token_amount: payment,
args: ManagedVec::new(),
});
self.async_callback_event();

let call_value = self.call_value().all();
for payment in &*call_value {
self.retrieve_funds_callback_event(
&payment.token_identifier,
payment.token_nonce,
&payment.amount,
);

let _ = self.callback_data().push(&CallbackData {
callback_name: ManagedBuffer::from(b"retrieve_funds_callback"),
token_identifier: payment.token_identifier.clone(),
token_nonce: payment.token_nonce,
token_amount: payment.amount.clone(),
args: ManagedVec::new(),
});
}
}

#[endpoint]
Expand Down Expand Up @@ -199,4 +207,7 @@ pub trait ForwarderAsyncCallModule: common::CommonModule {
.payment(payment_args.convert_payment_multi_triples())
.async_call_and_exit();
}

#[event("async_callback")]
fn async_callback_event(&self);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,14 @@ pub trait CallPromisesDirectModule {
to: ManagedAddress,
endpoint_name: ManagedBuffer,
extra_gas_for_callback: u64,
token_payment_args: MultiValueEncoded<EsdtTokenPaymentMultiValue>,
token_payment_args: MultiValueEncoded<PaymentMultiValue>,
) {
let mut token_payments_vec = ManagedVec::new();
for token_payment_arg in token_payment_args {
token_payments_vec.push(token_payment_arg.into_inner());
}

let gas_limit = (self.blockchain().get_gas_left() - extra_gas_for_callback) * 9 / 10;

self.tx()
.to(&to)
.raw_call(endpoint_name)
.payment(EgldOrMultiEsdtPayment::MultiEsdt(token_payments_vec))
.payment(MultiTransfer(token_payment_args.convert_payment()))
.gas(gas_limit)
.callback(self.callbacks().the_one_callback(2001, 2002u32.into()))
.gas_for_callback(extra_gas_for_callback)
Expand Down
Loading
Loading