1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use super::{ErrorApiImpl, Handle, ManagedTypeApiImpl};
use crate::types::EsdtTokenType;
pub trait CallValueApi {
type CallValueApiImpl: CallValueApiImpl;
fn call_value_api_impl() -> Self::CallValueApiImpl;
}
pub trait CallValueApiImpl: ErrorApiImpl + ManagedTypeApiImpl + Sized {
fn check_not_payable(&self);
fn load_egld_value(&self, dest_handle: Handle);
fn load_all_esdt_transfers(&self, dest_handle: Handle) {
load_all_esdt_transfers_from_unmanaged(self, dest_handle);
}
fn esdt_num_transfers(&self) -> usize;
fn load_single_esdt_value(&self, dest_handle: Handle);
fn token(&self) -> Option<Handle>;
fn esdt_token_nonce(&self) -> u64;
fn esdt_token_type(&self) -> EsdtTokenType;
fn esdt_value_by_index(&self, index: usize) -> Handle;
fn token_by_index(&self, index: usize) -> Handle;
fn esdt_token_nonce_by_index(&self, index: usize) -> u64;
fn esdt_token_type_by_index(&self, index: usize) -> EsdtTokenType;
}
pub fn load_all_esdt_transfers_from_unmanaged<A>(api: &A, dest_handle: Handle)
where
A: CallValueApiImpl,
{
let num_transfers = api.esdt_num_transfers();
api.mb_overwrite(dest_handle, &[]);
for i in 0..num_transfers {
let token_identifier_handle = api.token_by_index(i);
let token_nonce = api.esdt_token_nonce_by_index(i);
let amount_handle = api.esdt_value_by_index(i);
api.mb_append_bytes(dest_handle, &token_identifier_handle.to_be_bytes()[..]);
api.mb_append_bytes(dest_handle, &token_nonce.to_be_bytes()[..]);
api.mb_append_bytes(dest_handle, &amount_handle.to_be_bytes()[..]);
}
}