-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1501 from multiversx/call-local
SendWrapper builtin function call refactor
- Loading branch information
Showing
5 changed files
with
83 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::{ | ||
api::{const_handles, use_raw_handle, BlockchainApi, BlockchainApiImpl, CallTypeApi}, | ||
contract_base::BlockchainWrapper, | ||
types::{AnnotatedValue, ManagedAddress, ManagedBuffer, ManagedType, TxScEnv}, | ||
}; | ||
|
||
use super::{TxTo, TxToSpecified}; | ||
|
||
/// Indicates that transaction should be sent to itself. | ||
pub struct ToSelf; | ||
|
||
impl<Api> AnnotatedValue<TxScEnv<Api>, ManagedAddress<Api>> for ToSelf | ||
where | ||
Api: CallTypeApi + BlockchainApi, | ||
{ | ||
fn annotation(&self, env: &TxScEnv<Api>) -> ManagedBuffer<Api> { | ||
self.with_address_ref(env, |addr_ref| addr_ref.hex_expr()) | ||
} | ||
|
||
fn into_value(self, _env: &TxScEnv<Api>) -> ManagedAddress<Api> { | ||
BlockchainWrapper::<Api>::new().get_sc_address() | ||
} | ||
} | ||
|
||
impl<Api> TxTo<TxScEnv<Api>> for ToSelf where Api: CallTypeApi + BlockchainApi {} | ||
impl<Api> TxToSpecified<TxScEnv<Api>> for ToSelf | ||
where | ||
Api: CallTypeApi + BlockchainApi, | ||
{ | ||
fn with_address_ref<F, R>(&self, env: &TxScEnv<Api>, f: F) -> R | ||
where | ||
F: FnOnce(&ManagedAddress<Api>) -> R, | ||
{ | ||
let sc_address_handle: Api::ManagedBufferHandle = use_raw_handle(const_handles::ADDRESS_CALLER); | ||
Api::blockchain_api_impl().load_sc_address_managed(sc_address_handle.clone()); | ||
f(&ManagedAddress::from_handle(sc_address_handle)) | ||
} | ||
} |