From c2f26562667f6e99f2ae463cf2eede4caf31c64d Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 12 Aug 2024 14:54:24 +0300 Subject: [PATCH 1/4] - added more endpoints on test caller contract --- test-caller/src/test-caller.rs | 34 ++++++++++++++++++++++++++++++++++ test-caller/wasm/src/lib.rs | 5 +++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/test-caller/src/test-caller.rs b/test-caller/src/test-caller.rs index 6b560154..f39cefa8 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,26 @@ 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); + } + + #[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..0dbc2207 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: 3 // Async Callback (empty): 1 -// Total number of exported functions: 5 +// Total number of exported functions: 6 #![no_std] @@ -22,6 +22,7 @@ multiversx_sc_wasm_adapter::endpoints! { upgrade => upgrade callPayable => call_payable callNonPayable => call_non_payable + callPayableWithParams => call_payable_with_params ) } From e063437e1ae5b6a36e23db6de581104f2a0ab36d Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 13 Aug 2024 14:09:49 +0300 Subject: [PATCH 2/4] - added more endpoints on test caller contract --- test-caller/src/test-caller.rs | 17 +++++++++++++++++ test-caller/wasm/src/lib.rs | 5 +++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/test-caller/src/test-caller.rs b/test-caller/src/test-caller.rs index f39cefa8..43aef4cd 100644 --- a/test-caller/src/test-caller.rs +++ b/test-caller/src/test-caller.rs @@ -46,6 +46,23 @@ pub trait TestCallerContract { _ = 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 0..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 0dbc2207..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: 3 +// Endpoints: 4 // Async Callback (empty): 1 -// Total number of exported functions: 6 +// Total number of exported functions: 7 #![no_std] @@ -23,6 +23,7 @@ multiversx_sc_wasm_adapter::endpoints! { callPayable => call_payable callNonPayable => call_non_payable callPayableWithParams => call_payable_with_params + getCalledDataParams => get_called_data_params ) } From b3548783a3069b48caa4131ae881370e4020b9b7 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Wed, 14 Aug 2024 17:14:40 +0300 Subject: [PATCH 3/4] - fix contract --- test-caller/src/test-caller.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-caller/src/test-caller.rs b/test-caller/src/test-caller.rs index 43aef4cd..ba3a1629 100644 --- a/test-caller/src/test-caller.rs +++ b/test-caller/src/test-caller.rs @@ -53,7 +53,7 @@ pub trait TestCallerContract { let mut values = MultiValueEncoded::new(); let len = self.called_data_params().len(); - for i in 0..len { + for i in 1..len { if self.called_data_params().item_is_empty(i) { continue; } From 3a37e30b1f1680f16d51affaf48d837250979b4d Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Wed, 14 Aug 2024 17:28:34 +0300 Subject: [PATCH 4/4] - fix contract --- test-caller/src/test-caller.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-caller/src/test-caller.rs b/test-caller/src/test-caller.rs index ba3a1629..2c7fcf17 100644 --- a/test-caller/src/test-caller.rs +++ b/test-caller/src/test-caller.rs @@ -53,7 +53,7 @@ pub trait TestCallerContract { let mut values = MultiValueEncoded::new(); let len = self.called_data_params().len(); - for i in 1..len { + for i in 1..=len { if self.called_data_params().item_is_empty(i) { continue; }