Skip to content

Commit

Permalink
ESDTSystemSCAddress used in interactors directly
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Apr 10, 2024
1 parent 9db6c73 commit 46288c9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
3 changes: 0 additions & 3 deletions contracts/examples/multisig/interact/src/multisig_interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use hex_literal::hex;
use multiversx_sc_codec::{CodecFrom, EncodeErrorHandler, TopEncode, TopEncodeOutput};

use crate::{
api::{
Expand All @@ -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";

Expand Down Expand Up @@ -44,3 +47,21 @@ where

impl<Api> TxTo<TxScEnv<Api>> for ESDTSystemSCAddress where Api: CallTypeApi {}
impl<Api> TxToSpecified<TxScEnv<Api>> for ESDTSystemSCAddress where Api: CallTypeApi {}

impl TopEncode for ESDTSystemSCAddress {
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> CodecFrom<ESDTSystemSCAddress> for ManagedAddress<M> 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)
}
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 46288c9

Please sign in to comment.