Skip to content

Commit

Permalink
Added function to check if the first phase is completed
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Baltariu <[email protected]>
  • Loading branch information
andreiblt1304 committed Dec 3, 2024
1 parent e03a74f commit 41ab7e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
20 changes: 8 additions & 12 deletions sovereign-forge/src/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<M: ManagedTypeApi> {
Expand Down Expand Up @@ -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");

Check warning on line 47 in sovereign-forge/src/common/utils.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] sovereign-forge/src/common/utils.rs#L47

warning: this expression creates a reference which is immediately dereferenced by the compiler --> sovereign-forge/src/common/utils.rs:47:41 | 47 | self.check_if_contract_deployed(&caller, ScArray::ChainConfig, b"ChainConfig"); | ^^^^^^^ help: change this to: `caller` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
Raw output
sovereign-forge/src/common/utils.rs:47:41:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> sovereign-forge/src/common/utils.rs:47:41
   |
47 |         self.check_if_contract_deployed(&caller, ScArray::ChainConfig, b"ChainConfig");
   |                                         ^^^^^^^ help: change this to: `caller`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
   = note: `#[warn(clippy::needless_borrow)]` on by default


__END__

Check warning on line 47 in sovereign-forge/src/common/utils.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] sovereign-forge/src/common/utils.rs#L47

warning: this expression creates a reference which is immediately dereferenced by the compiler --> sovereign-forge/src/common/utils.rs:47:41 | 47 | self.check_if_contract_deployed(&caller, ScArray::ChainConfig, b"ChainConfig"); | ^^^^^^^ help: change this to: `caller` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
Raw output
sovereign-forge/src/common/utils.rs:47:41:w:warning: this expression creates a reference which is immediately dereferenced by the compiler
  --> sovereign-forge/src/common/utils.rs:47:41
   |
47 |         self.check_if_contract_deployed(&caller, ScArray::ChainConfig, b"ChainConfig");
   |                                         ^^^^^^^ help: change this to: `caller`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
   = note: `#[warn(clippy::needless_borrow)]` on by default


__END__
}

fn check_if_contract_deployed(
&self,
sovereign_creator: &ManagedAddress,
Expand Down Expand Up @@ -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<Self::Api> {
let sovereign_mapper = self.sovereigns_mapper(sovereign_creator);
require!(
!sovereign_mapper.is_empty(),
"There is no sovereign created by this address"
);

sovereign_mapper.get()
}
}
5 changes: 2 additions & 3 deletions sovereign-forge/src/phases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 41ab7e0

Please sign in to comment.