From 46288c9ac9c8433cfbaa2ea7f10d3a053b8ee35e Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Wed, 10 Apr 2024 01:59:46 +0300 Subject: [PATCH] ESDTSystemSCAddress used in interactors directly --- .../interact/src/multisig_interact.rs | 3 --- .../interact/src/multisig_interact_nfts.rs | 8 +++---- .../interact-rs/src/interactor_main.rs | 1 - .../markers/esdt_system_sc_address.rs | 21 +++++++++++++++++++ .../scenario/model/transaction/tx_response.rs | 6 ++---- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/contracts/examples/multisig/interact/src/multisig_interact.rs b/contracts/examples/multisig/interact/src/multisig_interact.rs index 5975c7299c..48cfb05a6d 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact.rs @@ -11,7 +11,6 @@ use multisig_interact_state::State; use multiversx_sc_snippets::imports::*; -const SYSTEM_SC_BECH32: &str = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"; const INTERACTOR_SCENARIO_TRACE_PATH: &str = "interactor_trace.scen.json"; #[tokio::main] @@ -77,7 +76,6 @@ async fn main() { struct MultisigInteract { interactor: Interactor, wallet_address: Bech32Address, - system_sc_address: Address, collection_token_identifier: String, multisig_code: BytesValue, state: State, @@ -99,7 +97,6 @@ impl MultisigInteract { Self { interactor, wallet_address: wallet_address.into(), - system_sc_address: bech32::decode(SYSTEM_SC_BECH32), collection_token_identifier: String::new(), multisig_code, state: State::load_state(), diff --git a/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs b/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs index ebc30300ef..2efda8e4d6 100644 --- a/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs +++ b/contracts/examples/multisig/interact/src/multisig_interact_nfts.rs @@ -33,7 +33,6 @@ impl MultisigInteract { } pub async fn propose_issue_collection_with_all_roles(&mut self) -> usize { - let system_sc_address = bech32::decode(SYSTEM_SC_BECH32); let action_id = self .interactor .tx() @@ -42,7 +41,7 @@ impl MultisigInteract { .gas(NumExpr("10,000,000")) .typed(multisig_proxy::MultisigProxy) .propose_async_call( - system_sc_address, + ESDTSystemSCAddress, ISSUE_COST, FunctionCall::new("registerAndSetAllRoles") .argument(&COLLECTION_NAME) @@ -88,7 +87,6 @@ impl MultisigInteract { } pub async fn propose_issue_collection(&mut self) -> usize { - let system_sc_address = bech32::decode(SYSTEM_SC_BECH32); let action_id = self .interactor .tx() @@ -97,7 +95,7 @@ impl MultisigInteract { .gas(NumExpr("10,000,000")) .typed(multisig_proxy::MultisigProxy) .propose_async_call( - system_sc_address, + ESDTSystemSCAddress, ISSUE_COST, FunctionCall::new("issueNonFungible") .argument(&COLLECTION_NAME) @@ -150,7 +148,7 @@ impl MultisigInteract { .gas(NumExpr("10,000,000")) .typed(multisig_proxy::MultisigProxy) .propose_async_call( - &self.system_sc_address, + ESDTSystemSCAddress, 0u64, FunctionCall::new("setSpecialRole") .argument(&self.collection_token_identifier) diff --git a/contracts/feature-tests/rust-snippets-generator-test/interact-rs/src/interactor_main.rs b/contracts/feature-tests/rust-snippets-generator-test/interact-rs/src/interactor_main.rs index 92d00a227d..389c717f2c 100644 --- a/contracts/feature-tests/rust-snippets-generator-test/interact-rs/src/interactor_main.rs +++ b/contracts/feature-tests/rust-snippets-generator-test/interact-rs/src/interactor_main.rs @@ -8,7 +8,6 @@ const GATEWAY: &str = sdk::blockchain::DEVNET_GATEWAY; const PEM: &str = "alice.pem"; const SC_ADDRESS: &str = ""; -const SYSTEM_SC_BECH32: &str = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"; const DEFAULT_ADDRESS_EXPR: &str = "0x0000000000000000000000000000000000000000000000000000000000000000"; const TOKEN_ISSUE_COST: u64 = 50_000_000_000_000_000; diff --git a/framework/base/src/types/interaction/markers/esdt_system_sc_address.rs b/framework/base/src/types/interaction/markers/esdt_system_sc_address.rs index de8aadb1b6..e43ee5f2ce 100644 --- a/framework/base/src/types/interaction/markers/esdt_system_sc_address.rs +++ b/framework/base/src/types/interaction/markers/esdt_system_sc_address.rs @@ -1,4 +1,5 @@ use hex_literal::hex; +use multiversx_sc_codec::{CodecFrom, EncodeErrorHandler, TopEncode, TopEncodeOutput}; use crate::{ api::{ @@ -14,6 +15,8 @@ use crate::{ /// Address of the system smart contract that manages ESDT. const SYSTEM_SC_ADDRESS_BYTES: [u8; 32] = hex!("000000000000000000010000000000000000000000000000000000000002ffff"); +const SYSTEM_SC_ADDRESS_BECH32: &str = + "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"; const SYSTEM_SC_ADDRESS_ANNOTATION: &str = "bech32:erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"; @@ -44,3 +47,21 @@ where impl TxTo> for ESDTSystemSCAddress where Api: CallTypeApi {} impl TxToSpecified> for ESDTSystemSCAddress where Api: CallTypeApi {} + +impl TopEncode for ESDTSystemSCAddress { + fn top_encode_or_handle_err(&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 CodecFrom for ManagedAddress where M: ManagedTypeApi {} + +impl core::fmt::Display for ESDTSystemSCAddress { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str(SYSTEM_SC_ADDRESS_BECH32) + } +} diff --git a/framework/scenario/src/scenario/model/transaction/tx_response.rs b/framework/scenario/src/scenario/model/transaction/tx_response.rs index ee844865bc..a2dbed5f5a 100644 --- a/framework/scenario/src/scenario/model/transaction/tx_response.rs +++ b/framework/scenario/src/scenario/model/transaction/tx_response.rs @@ -1,5 +1,5 @@ use multiversx_chain_vm::{crypto_functions::keccak256, tx_mock::TxResult}; -use multiversx_sc::types::Address; +use multiversx_sc::types::{Address, ESDTSystemSCAddress}; use multiversx_sdk::{ data::transaction::{ApiLogs, ApiSmartContractResult, Events, TransactionOnNetwork}, utils::base64_decode, @@ -12,8 +12,6 @@ use super::{ const SC_DEPLOY_PROCESSING_TYPE: &str = "SCDeployment"; const LOG_IDENTIFIER_SIGNAL_ERROR: &str = "signalError"; -const SYSTEM_SC_BECH32: &str = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"; - #[derive(Debug, Default, Clone)] /// The response of a transaction. pub struct TxResponse { @@ -196,7 +194,7 @@ impl TxResponse { fn process_new_issued_token_identifier(mut self) -> Self { for scr in self.api_scrs.iter() { - if scr.sender.to_string() != SYSTEM_SC_BECH32 { + if scr.sender.to_string() != ESDTSystemSCAddress.to_string() { continue; }