multiversx_sc/api/
send_api.rs

1use super::{BlockchainApi, HandleTypeInfo, ManagedTypeApi, ManagedTypeApiImpl, RawHandle};
2
3pub trait SendApi: ManagedTypeApi + BlockchainApi {
4    type SendApiImpl: SendApiImpl
5        + HandleTypeInfo<
6            ManagedBufferHandle = Self::ManagedBufferHandle,
7            BigIntHandle = Self::BigIntHandle,
8            BigFloatHandle = Self::BigFloatHandle,
9            EllipticCurveHandle = Self::EllipticCurveHandle,
10        >;
11
12    fn send_api_impl() -> Self::SendApiImpl;
13}
14
15/// API that groups methods that either send EGLD or ESDT, or that call other contracts.
16pub trait SendApiImpl: ManagedTypeApiImpl {
17    /// Sends EGLD to an address (optionally) and executes like an async call, but without callback.
18    fn transfer_value_execute(
19        &self,
20        to_handle: RawHandle,
21        egld_value_handle: RawHandle,
22        gas_limit: u64,
23        endpoint_name_handle: RawHandle,
24        arg_buffer_handle: RawHandle,
25    );
26
27    fn multi_transfer_esdt_nft_execute(
28        &self,
29        to_handle: RawHandle,
30        payments_handle: RawHandle,
31        gas_limit: u64,
32        endpoint_name_handle: RawHandle,
33        arg_buffer_handle: RawHandle,
34    );
35
36    fn multi_transfer_esdt_nft_execute_with_return(
37        &self,
38        to_handle: RawHandle,
39        payments_handle: RawHandle,
40        gas_limit: u64,
41        endpoint_name_handle: RawHandle,
42        arg_buffer_handle: RawHandle,
43    ) -> i32;
44
45    /// Sends an asynchronous call to another contract.
46    /// Calling this method immediately terminates tx execution.
47    /// Using it directly is generally discouraged.
48    fn async_call_raw(
49        &self,
50        to_handle: RawHandle,
51        egld_value_handle: RawHandle,
52        endpoint_name_handle: RawHandle,
53        arg_buffer_handle: RawHandle,
54    ) -> !;
55
56    #[allow(clippy::too_many_arguments)]
57    fn create_async_call_raw(
58        &self,
59        to_handle: RawHandle,
60        egld_value_handle: RawHandle,
61        endpoint_name_handle: RawHandle,
62        arg_buffer_handle: RawHandle,
63        success_callback: &'static str,
64        error_callback: &'static str,
65        gas: u64,
66        extra_gas_for_callback: u64,
67        callback_closure: RawHandle,
68    );
69
70    /// Deploys a new contract in the same shard.
71    /// Unlike `async_call_raw`, the deployment is synchronous and tx execution continues afterwards.
72    /// Also unlike `async_call_raw`, it uses an argument buffer to pass arguments
73    /// If the deployment fails, Option::None is returned
74    #[allow(clippy::too_many_arguments)]
75    fn deploy_contract(
76        &self,
77        gas: u64,
78        egld_value_handle: RawHandle,
79        code_handle: RawHandle,
80        code_metadata_handle: RawHandle,
81        arg_buffer_handle: RawHandle,
82        new_address_handle: RawHandle,
83        result_handle: RawHandle,
84    );
85
86    /// Deploys a new contract in the same shard by re-using the code of an already deployed source contract.
87    /// The deployment is done synchronously and the new contract's address is returned.
88    /// If the deployment fails, Option::None is returned
89    #[allow(clippy::too_many_arguments)]
90    fn deploy_from_source_contract(
91        &self,
92        gas: u64,
93        egld_value_handle: RawHandle,
94        source_contract_address_handle: RawHandle,
95        code_metadata_handle: RawHandle,
96        arg_buffer_handle: RawHandle,
97        new_address_handle: RawHandle,
98        result_handle: RawHandle,
99    );
100
101    fn upgrade_from_source_contract(
102        &self,
103        sc_address_handle: RawHandle,
104        gas: u64,
105        egld_value_handle: RawHandle,
106        source_contract_address_handle: RawHandle,
107        code_metadata_handle: RawHandle,
108        arg_buffer_handle: RawHandle,
109    );
110
111    /// Upgrades a child contract of the currently executing contract.
112    /// The upgrade is synchronous, and the current transaction will fail if the upgrade fails.
113    /// The child contract's new init function will be called with the provided arguments
114    fn upgrade_contract(
115        &self,
116        sc_address_handle: RawHandle,
117        gas: u64,
118        egld_value_handle: RawHandle,
119        code_handle: RawHandle,
120        code_metadata_handle: RawHandle,
121        arg_buffer_handle: RawHandle,
122    );
123
124    /// Same shard, in-line execution of another contract.
125    fn execute_on_dest_context_raw(
126        &self,
127        gas: u64,
128        address_handle: RawHandle,
129        egld_value_handle: RawHandle,
130        endpoint_name_handle: RawHandle,
131        arg_buffer_handle: RawHandle,
132        result_handle: RawHandle,
133    );
134
135    fn execute_on_same_context_raw(
136        &self,
137        gas: u64,
138        address_handle: RawHandle,
139        egld_value_handle: RawHandle,
140        endpoint_name_handle: RawHandle,
141        arg_buffer_handle: RawHandle,
142        result_handle: RawHandle,
143    );
144
145    fn execute_on_dest_context_readonly_raw(
146        &self,
147        gas: u64,
148        address_handle: RawHandle,
149        endpoint_name_handle: RawHandle,
150        arg_buffer_handle: RawHandle,
151        result_handle: RawHandle,
152    );
153
154    /// Same shard, in-line execution of another contract, does not fail in case of error.
155    fn execute_on_dest_context_error_return_raw(
156        &self,
157        gas: u64,
158        address_handle: RawHandle,
159        egld_value_handle: RawHandle,
160        endpoint_name_handle: RawHandle,
161        arg_buffer_handle: RawHandle,
162        result_handle: RawHandle,
163    ) -> i32;
164
165    fn clean_return_data(&self);
166
167    fn delete_from_return_data(&self, index: usize);
168}