From 41ab7e0a964ec42ca05a2beeb0295be24d5e9c74 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Tue, 3 Dec 2024 16:14:49 +0200 Subject: [PATCH] Added function to check if the first phase is completed Signed-off-by: Andrei Baltariu --- sovereign-forge/src/common/utils.rs | 20 ++++++++------------ sovereign-forge/src/phases.rs | 5 ++--- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/sovereign-forge/src/common/utils.rs b/sovereign-forge/src/common/utils.rs index d1602ee9..997ff967 100644 --- a/sovereign-forge/src/common/utils.rs +++ b/sovereign-forge/src/common/utils.rs @@ -11,8 +11,6 @@ const CHARSET: &[u8] = b"0123456789abcdefghijklmnopqrstuvwxyz"; use crate::err_msg; -use super::storage::ChainId; - #[type_abi] #[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, ManagedVecItem)] pub struct ContractInfo { @@ -41,6 +39,14 @@ pub enum ScArray { #[multiversx_sc::module] pub trait UtilsModule: super::storage::StorageModule { + fn require_phase_1_completed(&self, caller: &ManagedAddress) { + require!( + self.sovereigns_mapper(caller).is_empty(), + "The current caller has not deployed any Sovereign Chain" + ); + self.check_if_contract_deployed(&caller, ScArray::ChainConfig, b"ChainConfig"); + } + fn check_if_contract_deployed( &self, sovereign_creator: &ManagedAddress, @@ -101,14 +107,4 @@ pub trait UtilsModule: super::storage::StorageModule { self.chain_factories(shard_id).get() } - - fn get_sovereign_chain_id(&self, sovereign_creator: &ManagedAddress) -> ChainId { - let sovereign_mapper = self.sovereigns_mapper(sovereign_creator); - require!( - !sovereign_mapper.is_empty(), - "There is no sovereign created by this address" - ); - - sovereign_mapper.get() - } } diff --git a/sovereign-forge/src/phases.rs b/sovereign-forge/src/phases.rs index 620f1562..9ca79248 100644 --- a/sovereign-forge/src/phases.rs +++ b/sovereign-forge/src/phases.rs @@ -93,15 +93,14 @@ pub trait PhasesModule: let blockchain_api = self.blockchain(); let caller = blockchain_api.get_caller(); - self.check_if_contract_deployed(&caller, ScArray::ChainConfig, b"ChainConfig"); + self.require_phase_1_completed(&caller); let header_verifier_address = self.deploy_header_verifier(bls_keys); let header_verifier_contract_info = ContractInfo::new(ScArray::HeaderVerifier, header_verifier_address); - let chain_id = self.get_sovereign_chain_id(&caller); - self.sovereign_deployed_contracts(&chain_id) + self.sovereign_deployed_contracts(&self.sovereigns_mapper(&caller).get()) .insert(header_verifier_contract_info); } }