-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unified syntax - TxToInto, with optimization attempt
- Loading branch information
1 parent
68a6df6
commit 4d87c31
Showing
18 changed files
with
262 additions
and
82 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
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
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 |
---|---|---|
@@ -1,35 +1,19 @@ | ||
use crate::{ | ||
api::{const_handles, use_raw_handle, BlockchainApi, BlockchainApiImpl, CallTypeApi}, | ||
api::CallTypeApi, | ||
contract_base::BlockchainWrapper, | ||
types::{ | ||
AnnotatedValue, ManagedAddress, ManagedBuffer, ManagedType, TxScEnv, TxTo, TxToSpecified, | ||
}, | ||
types::{ManagedAddress, ManagedRef, TxScEnv, TxToInto}, | ||
}; | ||
|
||
/// Indicates that transaction should be sent to the caller (the sender of the current transaction). | ||
pub struct ToCaller; | ||
|
||
impl<Api> AnnotatedValue<TxScEnv<Api>, ManagedAddress<Api>> for ToCaller | ||
impl<Api> TxToInto<TxScEnv<Api>> for ToCaller | ||
where | ||
Api: CallTypeApi + BlockchainApi, | ||
Api: CallTypeApi, | ||
{ | ||
fn annotation(&self, env: &TxScEnv<Api>) -> ManagedBuffer<Api> { | ||
self.with_address_ref(env, |addr_ref| addr_ref.hex_expr()) | ||
} | ||
|
||
fn to_value(&self, _env: &TxScEnv<Api>) -> ManagedAddress<Api> { | ||
BlockchainWrapper::<Api>::new().get_caller() | ||
} | ||
type Into = ManagedRef<'static, Api, ManagedAddress<Api>>; | ||
|
||
fn with_value_ref<F, R>(&self, _env: &TxScEnv<Api>, f: F) -> R | ||
where | ||
F: FnOnce(&ManagedAddress<Api>) -> R, | ||
{ | ||
let caller_handle: Api::ManagedBufferHandle = use_raw_handle(const_handles::ADDRESS_CALLER); | ||
Api::blockchain_api_impl().load_caller_managed(caller_handle.clone()); | ||
f(&ManagedAddress::from_handle(caller_handle)) | ||
fn into_recipient(self) -> Self::Into { | ||
BlockchainWrapper::<Api>::new().get_caller_ref() | ||
} | ||
} | ||
|
||
impl<Api> TxTo<TxScEnv<Api>> for ToCaller where Api: CallTypeApi + BlockchainApi {} | ||
impl<Api> TxToSpecified<TxScEnv<Api>> for ToCaller where Api: CallTypeApi + BlockchainApi {} |
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 |
---|---|---|
@@ -1,36 +1,19 @@ | ||
use crate::{ | ||
api::{const_handles, use_raw_handle, BlockchainApi, BlockchainApiImpl, CallTypeApi}, | ||
api::CallTypeApi, | ||
contract_base::BlockchainWrapper, | ||
types::{ | ||
AnnotatedValue, ManagedAddress, ManagedBuffer, ManagedType, TxScEnv, TxTo, TxToSpecified, | ||
}, | ||
types::{ManagedAddress, ManagedRef, TxScEnv, TxToInto}, | ||
}; | ||
|
||
/// Indicates that transaction should be sent to itself. | ||
pub struct ToSelf; | ||
|
||
impl<Api> AnnotatedValue<TxScEnv<Api>, ManagedAddress<Api>> for ToSelf | ||
impl<Api> TxToInto<TxScEnv<Api>> for ToSelf | ||
where | ||
Api: CallTypeApi + BlockchainApi, | ||
Api: CallTypeApi, | ||
{ | ||
fn annotation(&self, env: &TxScEnv<Api>) -> ManagedBuffer<Api> { | ||
self.with_address_ref(env, |addr_ref| addr_ref.hex_expr()) | ||
} | ||
|
||
fn to_value(&self, _env: &TxScEnv<Api>) -> ManagedAddress<Api> { | ||
BlockchainWrapper::<Api>::new().get_sc_address() | ||
} | ||
type Into = ManagedRef<'static, Api, ManagedAddress<Api>>; | ||
|
||
fn with_value_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)) | ||
fn into_recipient(self) -> Self::Into { | ||
BlockchainWrapper::<Api>::new().get_sc_address_ref() | ||
} | ||
} | ||
|
||
impl<Api> TxTo<TxScEnv<Api>> for ToSelf where Api: CallTypeApi + BlockchainApi {} | ||
impl<Api> TxToSpecified<TxScEnv<Api>> for ToSelf where Api: CallTypeApi + BlockchainApi {} |
Oops, something went wrong.