diff --git a/test-caller/src/test-caller.rs b/test-caller/src/test-caller.rs index 6b560154..2c7fcf17 100644 --- a/test-caller/src/test-caller.rs +++ b/test-caller/src/test-caller.rs @@ -1,5 +1,17 @@ #![no_std] +use multiversx_sc::api::ManagedTypeApi; +use multiversx_sc::derive_imports::*; +use multiversx_sc::imports::*; + +#[type_abi] +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, Clone, ManagedVecItem)] +pub struct CalledData { + pub size: u64, + pub address: ManagedAddress, + pub token_identifier: TokenIdentifier, +} + #[multiversx_sc::contract] pub trait TestCallerContract { #[init] @@ -14,4 +26,43 @@ pub trait TestCallerContract { #[endpoint(callNonPayable)] fn call_non_payable(&self) {} + + #[payable("*")] + #[view(callPayableWithParams)] + fn call_payable_with_params( + &self, + size: u64, + address: ManagedAddress, + ) { + let payment = self.call_value().single_esdt(); + let token_identifier = payment.token_identifier; + + let data = CalledData{ + size, + address, + token_identifier, + }; + + _ = self.called_data_params().push(&data); + } + + #[view(getCalledDataParams)] + fn get_called_data_params( + &self, + ) -> MultiValueEncoded> { + let mut values = MultiValueEncoded::new(); + let len = self.called_data_params().len(); + + for i in 1..=len { + if self.called_data_params().item_is_empty(i) { + continue; + } + let value = self.called_data_params().get_unchecked(i); + values.push(value); + } + values + } + + #[storage_mapper("calledDataParams")] + fn called_data_params(&self) -> VecMapper>; } diff --git a/test-caller/wasm/src/lib.rs b/test-caller/wasm/src/lib.rs index 32ffa035..43f3fc05 100644 --- a/test-caller/wasm/src/lib.rs +++ b/test-caller/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 2 +// Endpoints: 4 // Async Callback (empty): 1 -// Total number of exported functions: 5 +// Total number of exported functions: 7 #![no_std] @@ -22,6 +22,8 @@ multiversx_sc_wasm_adapter::endpoints! { upgrade => upgrade callPayable => call_payable callNonPayable => call_non_payable + callPayableWithParams => call_payable_with_params + getCalledDataParams => get_called_data_params ) }