-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
system sc interaction and proxy, modify creator tests, set token type
- Loading branch information
1 parent
e8dfee4
commit 675066c
Showing
8 changed files
with
278 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
mod esdt_system_sc_address; | ||
mod gas_left; | ||
mod system_sc_address; | ||
mod to_caller; | ||
mod to_self; | ||
|
||
pub use esdt_system_sc_address::ESDTSystemSCAddress; | ||
pub use gas_left::GasLeft; | ||
pub use system_sc_address::SystemSCAddress; | ||
pub use to_caller::ToCaller; | ||
pub use to_self::ToSelf; |
75 changes: 75 additions & 0 deletions
75
framework/base/src/types/interaction/markers/system_sc_address.rs
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,75 @@ | ||
use hex_literal::hex; | ||
use multiversx_chain_core::types::Address; | ||
use multiversx_sc_codec::{EncodeErrorHandler, TopEncode, TopEncodeOutput}; | ||
|
||
use crate::{ | ||
abi::TypeAbiFrom, | ||
api::ManagedTypeApi, | ||
types::{AnnotatedValue, ManagedAddress, ManagedBuffer, TxEnv, TxTo, TxToSpecified}, | ||
}; | ||
|
||
/// Address of the system smart contract that manages ESDT. | ||
const SYSTEM_SC_ADDRESS_BYTES: [u8; 32] = | ||
hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01"); | ||
const SYSTEM_SC_ADDRESS_BECH32: &str = | ||
"erd1llllllllllllllllllllllllllllllllllllllllllllllllluqsl6e366"; | ||
const SYSTEM_SC_ADDRESS_ANNOTATION: &str = | ||
"bech32:erd1llllllllllllllllllllllllllllllllllllllllllllllllluqsl6e366"; | ||
|
||
/// Indicates the system SC address, which is the same on any MultiversX blockchain. | ||
pub struct SystemSCAddress; | ||
|
||
impl SystemSCAddress { | ||
pub fn to_managed_address<Api>(self) -> ManagedAddress<Api> | ||
where | ||
Api: ManagedTypeApi, | ||
{ | ||
ManagedAddress::from(SYSTEM_SC_ADDRESS_BYTES) | ||
} | ||
|
||
pub fn to_address(&self) -> Address { | ||
SYSTEM_SC_ADDRESS_BYTES.into() | ||
} | ||
|
||
pub fn to_bech32_str(&self) -> &str { | ||
SYSTEM_SC_ADDRESS_BECH32 | ||
} | ||
|
||
pub fn to_bech32_string(&self) -> alloc::string::String { | ||
SYSTEM_SC_ADDRESS_BECH32.into() | ||
} | ||
} | ||
|
||
impl<Env> AnnotatedValue<Env, ManagedAddress<Env::Api>> for SystemSCAddress | ||
where | ||
Env: TxEnv, | ||
{ | ||
fn annotation(&self, _env: &Env) -> ManagedBuffer<Env::Api> { | ||
ManagedBuffer::from(SYSTEM_SC_ADDRESS_ANNOTATION) | ||
} | ||
|
||
fn to_value(&self, _env: &Env) -> ManagedAddress<Env::Api> { | ||
SystemSCAddress.to_managed_address() | ||
} | ||
} | ||
|
||
impl<Env> TxTo<Env> for SystemSCAddress where Env: TxEnv {} | ||
impl<Env> TxToSpecified<Env> for SystemSCAddress where Env: TxEnv {} | ||
|
||
impl TopEncode for SystemSCAddress { | ||
fn top_encode_or_handle_err<O, H>(&self, output: O, h: H) -> Result<(), H::HandledErr> | ||
where | ||
O: TopEncodeOutput, | ||
H: EncodeErrorHandler, | ||
{ | ||
SYSTEM_SC_ADDRESS_BYTES.top_encode_or_handle_err(output, h) | ||
} | ||
} | ||
|
||
impl<M> TypeAbiFrom<SystemSCAddress> for ManagedAddress<M> where M: ManagedTypeApi {} | ||
|
||
impl core::fmt::Display for SystemSCAddress { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
f.write_str(SYSTEM_SC_ADDRESS_BECH32) | ||
} | ||
} |
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,9 +1,11 @@ | ||
mod builtin_func_proxy; | ||
mod esdt_system_sc_proxy; | ||
mod legacy_system_sc_proxy; | ||
mod system_sc_proxy; | ||
pub(crate) mod token_properties; | ||
|
||
pub use builtin_func_proxy::*; | ||
pub use esdt_system_sc_proxy::{ESDTSystemSCProxy, ESDTSystemSCProxyMethods, IssueCall}; | ||
pub use legacy_system_sc_proxy::ESDTSystemSmartContractProxy; | ||
pub use system_sc_proxy::{SystemSCProxy, SystemSCProxyMethods}; | ||
pub use token_properties::*; |
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
61 changes: 61 additions & 0 deletions
61
framework/base/src/types/interaction/system_proxy/system_sc_proxy.rs
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,61 @@ | ||
use multiversx_chain_core::builtin_func_names::ESDT_SET_TOKEN_TYPE_FUNC_NAME; | ||
|
||
use crate::types::{ | ||
EsdtTokenType, NotPayable, ProxyArg, TokenIdentifier, Tx, TxEnv, TxFrom, TxGas, TxProxyTrait, | ||
TxTo, TxTypedCall, | ||
}; | ||
|
||
/// Proxy for the system smart contract. | ||
pub struct SystemSCProxy; | ||
|
||
impl<Env, From, To, Gas> TxProxyTrait<Env, From, To, Gas> for SystemSCProxy | ||
where | ||
Env: TxEnv, | ||
From: TxFrom<Env>, | ||
To: TxTo<Env>, | ||
Gas: TxGas<Env>, | ||
{ | ||
type TxProxyMethods = SystemSCProxyMethods<Env, From, To, Gas>; | ||
|
||
fn proxy_methods(self, tx: Tx<Env, From, To, (), Gas, (), ()>) -> Self::TxProxyMethods { | ||
SystemSCProxyMethods { wrapped_tx: tx } | ||
} | ||
} | ||
|
||
/// Method container of the ESDT system smart contract proxy. | ||
pub struct SystemSCProxyMethods<Env, From, To, Gas> | ||
where | ||
Env: TxEnv, | ||
From: TxFrom<Env>, | ||
To: TxTo<Env>, | ||
Gas: TxGas<Env>, | ||
{ | ||
wrapped_tx: Tx<Env, From, To, (), Gas, (), ()>, | ||
} | ||
|
||
impl<Env, From, To, Gas> SystemSCProxyMethods<Env, From, To, Gas> | ||
where | ||
Env: TxEnv, | ||
From: TxFrom<Env>, | ||
To: TxTo<Env>, | ||
Gas: TxGas<Env>, | ||
{ | ||
/// Sets the token type for a specific token. | ||
pub fn esdt_set_token_type< | ||
Arg0: ProxyArg<TokenIdentifier<Env::Api>>, | ||
Arg1: ProxyArg<EsdtTokenType>, | ||
>( | ||
self, | ||
token_id: Arg0, | ||
token_type: Arg1, | ||
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> { | ||
let tx = self | ||
.wrapped_tx | ||
.payment(NotPayable) | ||
.raw_call(ESDT_SET_TOKEN_TYPE_FUNC_NAME) | ||
.argument(&token_id) | ||
.argument(&token_type); | ||
|
||
tx.original_result() | ||
} | ||
} |
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
Oops, something went wrong.