drt_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 REWA or DCDT, or that call other contracts.
16pub trait SendApiImpl: ManagedTypeApiImpl {
17    /// Sends REWA 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        rewa_value_handle: RawHandle,
22        gas_limit: u64,
23        endpoint_name_handle: RawHandle,
24        arg_buffer_handle: RawHandle,
25    ) -> Result<(), &'static [u8]>;
26
27    fn multi_transfer_dcdt_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    ) -> Result<(), &'static [u8]>;
35
36    /// Sends an asynchronous call to another contract.
37    /// Calling this method immediately terminates tx execution.
38    /// Using it directly is generally discouraged.
39    fn async_call_raw(
40        &self,
41        to_handle: RawHandle,
42        rewa_value_handle: RawHandle,
43        endpoint_name_handle: RawHandle,
44        arg_buffer_handle: RawHandle,
45    ) -> !;
46
47    #[allow(clippy::too_many_arguments)]
48    fn create_async_call_raw(
49        &self,
50        to_handle: RawHandle,
51        rewa_value_handle: RawHandle,
52        endpoint_name_handle: RawHandle,
53        arg_buffer_handle: RawHandle,
54        success_callback: &'static str,
55        error_callback: &'static str,
56        gas: u64,
57        extra_gas_for_callback: u64,
58        callback_closure: RawHandle,
59    );
60
61    /// Deploys a new contract in the same shard.
62    /// Unlike `async_call_raw`, the deployment is synchronous and tx execution continues afterwards.
63    /// Also unlike `async_call_raw`, it uses an argument buffer to pass arguments
64    /// If the deployment fails, Option::None is returned
65    #[allow(clippy::too_many_arguments)]
66    fn deploy_contract(
67        &self,
68        gas: u64,
69        rewa_value_handle: RawHandle,
70        code_handle: RawHandle,
71        code_metadata_handle: RawHandle,
72        arg_buffer_handle: RawHandle,
73        new_address_handle: RawHandle,
74        result_handle: RawHandle,
75    );
76
77    /// Deploys a new contract in the same shard by re-using the code of an already deployed source contract.
78    /// The deployment is done synchronously and the new contract's address is returned.
79    /// If the deployment fails, Option::None is returned
80    #[allow(clippy::too_many_arguments)]
81    fn deploy_from_source_contract(
82        &self,
83        gas: u64,
84        rewa_value_handle: RawHandle,
85        source_contract_address_handle: RawHandle,
86        code_metadata_handle: RawHandle,
87        arg_buffer_handle: RawHandle,
88        new_address_handle: RawHandle,
89        result_handle: RawHandle,
90    );
91
92    fn upgrade_from_source_contract(
93        &self,
94        sc_address_handle: RawHandle,
95        gas: u64,
96        rewa_value_handle: RawHandle,
97        source_contract_address_handle: RawHandle,
98        code_metadata_handle: RawHandle,
99        arg_buffer_handle: RawHandle,
100    );
101
102    /// Upgrades a child contract of the currently executing contract.
103    /// The upgrade is synchronous, and the current transaction will fail if the upgrade fails.
104    /// The child contract's new init function will be called with the provided arguments
105    fn upgrade_contract(
106        &self,
107        sc_address_handle: RawHandle,
108        gas: u64,
109        rewa_value_handle: RawHandle,
110        code_handle: RawHandle,
111        code_metadata_handle: RawHandle,
112        arg_buffer_handle: RawHandle,
113    );
114
115    /// Same shard, in-line execution of another contract.
116    fn execute_on_dest_context_raw(
117        &self,
118        gas: u64,
119        address_handle: RawHandle,
120        rewa_value_handle: RawHandle,
121        endpoint_name_handle: RawHandle,
122        arg_buffer_handle: RawHandle,
123        result_handle: RawHandle,
124    );
125
126    fn execute_on_same_context_raw(
127        &self,
128        gas: u64,
129        address_handle: RawHandle,
130        rewa_value_handle: RawHandle,
131        endpoint_name_handle: RawHandle,
132        arg_buffer_handle: RawHandle,
133        result_handle: RawHandle,
134    );
135
136    fn execute_on_dest_context_readonly_raw(
137        &self,
138        gas: u64,
139        address_handle: RawHandle,
140        endpoint_name_handle: RawHandle,
141        arg_buffer_handle: RawHandle,
142        result_handle: RawHandle,
143    );
144
145    fn clean_return_data(&self);
146
147    fn delete_from_return_data(&self, index: usize);
148}