use elrond_codec::{multi_types::IgnoreValue, TopDecodeMulti, TopEncodeMulti};
use crate::{
api::CallTypeApi, contract_base::ExitCodecErrorHandler, err_msg, types::ManagedBuffer,
};
use super::{AsyncCall, ContractCallNoPayment, ContractCallWithEgld, ManagedArgBuffer};
pub trait ContractCall<SA>: Sized
where
SA: CallTypeApi + 'static,
{
type OriginalResult: TopEncodeMulti;
#[doc(hidden)]
fn into_normalized(self) -> ContractCallWithEgld<SA, Self::OriginalResult>;
#[doc(hidden)]
fn get_mut_basic(&mut self) -> &mut ContractCallNoPayment<SA, Self::OriginalResult>;
#[doc(hidden)]
fn proxy_arg<T: TopEncodeMulti>(&mut self, endpoint_arg: &T) {
let h = ExitCodecErrorHandler::<SA>::from(err_msg::CONTRACT_CALL_ENCODE_ERROR);
let Ok(()) =
endpoint_arg.multi_encode_or_handle_err(&mut self.get_mut_basic().arg_buffer, h);
}
fn push_raw_argument<RawArg: Into<ManagedBuffer<SA>>>(&mut self, raw_arg: RawArg) {
self.get_mut_basic().arg_buffer.push_arg_raw(raw_arg.into())
}
fn with_raw_arguments(mut self, raw_argument_buffer: ManagedArgBuffer<SA>) -> Self {
self.get_mut_basic().arg_buffer = raw_argument_buffer;
self
}
#[inline]
fn with_gas_limit(mut self, gas_limit: u64) -> Self {
self.get_mut_basic().explicit_gas_limit = gas_limit;
self
}
#[inline]
fn async_call(self) -> AsyncCall<SA> {
self.into_normalized().async_call()
}
#[inline]
#[cfg(feature = "promises")]
fn async_call_promise(self) -> super::AsyncCallPromises<SA> {
self.into_normalized().async_call_promise()
}
#[inline]
fn execute_on_dest_context<RequestedResult>(self) -> RequestedResult
where
RequestedResult: TopDecodeMulti,
{
self.into_normalized().execute_on_dest_context()
}
#[deprecated(
since = "0.36.1",
note = "Redundant method, use `let _: IgnoreValue = contract_call.execute_on_dest_context(...)` instead"
)]
fn execute_on_dest_context_ignore_result(self) {
let _ = self.execute_on_dest_context::<IgnoreValue>();
}
#[inline]
fn execute_on_dest_context_readonly<RequestedResult>(self) -> RequestedResult
where
RequestedResult: TopDecodeMulti,
{
self.into_normalized().execute_on_dest_context_readonly()
}
#[inline]
fn execute_on_same_context<RequestedResult>(self) -> RequestedResult
where
RequestedResult: TopDecodeMulti,
{
self.into_normalized().execute_on_same_context()
}
fn transfer_execute(self);
}