Skip to content

Commit

Permalink
Merge pull request #185 from multiversx/more-endpoints-on-test-caller
Browse files Browse the repository at this point in the history
More endpoints on test caller
  • Loading branch information
iulianpascalau authored Aug 16, 2024
2 parents 342f490 + 3a37e30 commit d78ce26
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
51 changes: 51 additions & 0 deletions test-caller/src/test-caller.rs
Original file line number Diff line number Diff line change
@@ -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<M: ManagedTypeApi> {
pub size: u64,
pub address: ManagedAddress<M>,
pub token_identifier: TokenIdentifier<M>,
}

#[multiversx_sc::contract]
pub trait TestCallerContract {
#[init]
Expand All @@ -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<CalledData<Self::Api>> {
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<CalledData<Self::Api>>;
}
6 changes: 4 additions & 2 deletions test-caller/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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
)
}

Expand Down

0 comments on commit d78ce26

Please sign in to comment.