multiversx_sc/types/interaction/markers/
to_self.rs1use crate::{
2 api::{const_handles, BlockchainApi, BlockchainApiImpl, CallTypeApi},
3 contract_base::BlockchainWrapper,
4 types::{
5 AnnotatedValue, ManagedAddress, ManagedBuffer, ManagedType, TxScEnv, TxTo, TxToSpecified,
6 },
7};
8
9pub struct ToSelf;
11
12impl<Api> AnnotatedValue<TxScEnv<Api>, ManagedAddress<Api>> for ToSelf
13where
14 Api: CallTypeApi + BlockchainApi,
15{
16 fn annotation(&self, env: &TxScEnv<Api>) -> ManagedBuffer<Api> {
17 self.with_address_ref(env, |addr_ref| addr_ref.hex_expr())
18 }
19
20 #[inline]
21 fn to_value(&self, _env: &TxScEnv<Api>) -> ManagedAddress<Api> {
22 BlockchainWrapper::<Api>::new().get_sc_address()
23 }
24
25 fn with_value_ref<F, R>(&self, _env: &TxScEnv<Api>, f: F) -> R
26 where
27 F: FnOnce(&ManagedAddress<Api>) -> R,
28 {
29 unsafe {
30 let temp = ManagedAddress::temp_const_ref(const_handles::ADDRESS_CALLER);
31 Api::blockchain_api_impl().load_sc_address_managed(temp.get_handle());
32 f(&temp)
33 }
34 }
35}
36
37impl<Api> TxTo<TxScEnv<Api>> for ToSelf where Api: CallTypeApi + BlockchainApi {}
38impl<Api> TxToSpecified<TxScEnv<Api>> for ToSelf where Api: CallTypeApi + BlockchainApi {}