Skip to content

Commit

Permalink
Merge pull request #197 from multiversx/phase-two
Browse files Browse the repository at this point in the history
Phase two
  • Loading branch information
andreiblt1304 authored Dec 4, 2024
2 parents c888c6b + ca44ef2 commit b3622f9
Show file tree
Hide file tree
Showing 24 changed files with 254 additions and 86 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions common/proxies/src/header_verifier_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,13 @@ where
.argument(&operation_hash)
.original_result()
}

pub fn complete_setup_phase(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("completeSetupPhase")
.original_result()
}
}
6 changes: 5 additions & 1 deletion common/proxies/src/sovereign_forge_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,16 @@ where
.original_result()
}

pub fn deploy_phase_two(
pub fn deploy_phase_two<
Arg0: ProxyArg<MultiValueEncoded<Env::Api, ManagedBuffer<Env::Api>>>,
>(
self,
bls_keys: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("deployPhaseTwo")
.argument(&bls_keys)
.original_result()
}

Expand Down
15 changes: 5 additions & 10 deletions enshrine-esdt-safe/interactor/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
use serde::Deserialize;
use std::io::Read;


/// Config file
const CONFIG_FILE: &str = "config.toml";


#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ChainType {
Real,
Simulator,
}
}

/// Contract Interact configuration
#[derive(Debug, Deserialize)]
pub struct Config {
pub gateway_uri: String,
pub chain_type: ChainType,
}

}

impl Config {
// Deserializes config from file
Expand All @@ -36,7 +33,7 @@ impl Config {
Config {
gateway_uri: "http://localhost:8085".to_owned(),
chain_type: ChainType::Simulator,
}
}
}

// Returns the gateway URI
Expand All @@ -49,8 +46,6 @@ impl Config {
match self.chain_type {
ChainType::Real => false,
ChainType::Simulator => true,
}
}
}
}


}
1 change: 1 addition & 0 deletions enshrine-esdt-safe/wasm-enshrine-esdt-safe-full/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions enshrine-esdt-safe/wasm-enshrine-esdt-safe-view/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions enshrine-esdt-safe/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions esdt-safe/wasm-esdt-safe-full/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions esdt-safe/wasm-esdt-safe-view/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions esdt-safe/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions header-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ path = "../common/transaction"
[dependencies.proxies]
path = "../common/proxies"

[dependencies.setup-phase]
path = "../common/setup-phase"

[dev-dependencies]
num-bigint = "0.4.2"

Expand Down
35 changes: 34 additions & 1 deletion header-verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum OperationHashStatus {
}

#[multiversx_sc::contract]
pub trait Headerverifier {
pub trait Headerverifier: setup_phase::SetupPhaseModule {
#[init]
fn init(&self, bls_pub_keys: MultiValueEncoded<ManagedBuffer>) {
for pub_key in bls_pub_keys {
Expand Down Expand Up @@ -90,6 +90,33 @@ pub trait Headerverifier {
}
}

#[only_owner]
#[endpoint(completeSetupPhase)]
fn complete_setup_phase(&self) {
if self.is_setup_phase_complete() {
return;
}

let chain_config_mapper = self.chain_config_address();
require!(
!chain_config_mapper.is_empty(),
"The Chain-Config address is not set"
);

let chain_config_address = chain_config_mapper.get();
let min_validators = self.min_validators(chain_config_address).get();
let number_of_validators = self.bls_pub_keys().len() as u32;

require!(
number_of_validators > min_validators,
"There should be at least {} more validators so the setup phase can be completed",
(number_of_validators - min_validators)
);

// change ownership
self.setup_phase_complete().set(true);
}

fn require_caller_esdt_safe(&self) {
let esdt_safe_mapper = self.esdt_safe_address();

Expand Down Expand Up @@ -155,4 +182,10 @@ pub trait Headerverifier {

#[storage_mapper("esdtSafeAddress")]
fn esdt_safe_address(&self) -> SingleValueMapper<ManagedAddress>;

#[storage_mapper("chainConfigAddress")]
fn chain_config_address(&self) -> SingleValueMapper<ManagedAddress>;

#[storage_mapper_from_address("minValidators")]
fn min_validators(&self, sc_address: ManagedAddress) -> SingleValueMapper<u32, ManagedAddress>;
}
8 changes: 8 additions & 0 deletions header-verifier/wasm-header-verifier-full/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions header-verifier/wasm-header-verifier-full/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 4
// Endpoints: 5
// Async Callback (empty): 1
// Total number of exported functions: 7
// Total number of exported functions: 8

#![no_std]

Expand All @@ -24,6 +24,7 @@ multiversx_sc_wasm_adapter::endpoints! {
setEsdtSafeAddress => set_esdt_safe_address
removeExecutedHash => remove_executed_hash
lockOperationHash => lock_operation_hash
completeSetupPhase => complete_setup_phase
)
}

Expand Down
8 changes: 8 additions & 0 deletions header-verifier/wasm-multisig-view/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions header-verifier/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions header-verifier/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 4
// Endpoints: 5
// Async Callback (empty): 1
// Total number of exported functions: 7
// Total number of exported functions: 8

#![no_std]

Expand All @@ -24,6 +24,7 @@ multiversx_sc_wasm_adapter::endpoints! {
setEsdtSafeAddress => set_esdt_safe_address
removeExecutedHash => remove_executed_hash
lockOperationHash => lock_operation_hash
completeSetupPhase => complete_setup_phase
)
}

Expand Down
1 change: 1 addition & 0 deletions sovereign-forge/src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod sc_deploy;
pub mod storage;
pub mod utils;
48 changes: 48 additions & 0 deletions sovereign-forge/src/common/sc_deploy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use crate::err_msg;
use multiversx_sc::types::{MultiValueEncoded, ReturnsResult};
use proxies::chain_factory_proxy::ChainFactoryContractProxy;
use transaction::StakeMultiArg;

#[multiversx_sc::module]
pub trait ScDeployModule: super::utils::UtilsModule + super::storage::StorageModule {
#[inline]
fn deploy_chain_config(
&self,
min_validators: u64,
max_validators: u64,
min_stake: BigUint,
additional_stake_required: MultiValueEncoded<StakeMultiArg<Self::Api>>,
) -> ManagedAddress {
self.tx()
.to(self.get_chain_factory_address())
.typed(ChainFactoryContractProxy)
.deploy_sovereign_chain_config_contract(
min_validators,
max_validators,
min_stake,
additional_stake_required,
)
.returns(ReturnsResult)
.sync_call()
}

#[inline]
fn deploy_header_verifier(&self, bls_keys: MultiValueEncoded<ManagedBuffer>) -> ManagedAddress {
self.tx()
.to(self.get_chain_factory_address())
.typed(ChainFactoryContractProxy)
.deploy_header_verifier(bls_keys)
.returns(ReturnsResult)
.sync_call()
}

#[inline]
fn deploy_esdt_safe(&self, is_sovereign_chain: bool) -> ManagedAddress {
self.tx()
.to(self.get_chain_factory_address())
.typed(ChainFactoryContractProxy)
.deploy_esdt_safe(is_sovereign_chain)
.returns(ReturnsResult)
.sync_call()
}
}
11 changes: 8 additions & 3 deletions sovereign-forge/src/common/storage.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
use multiversx_sc::imports::{SingleValueMapper, UnorderedSetMapper};
use multiversx_sc::{
imports::{SingleValueMapper, UnorderedSetMapper},
types::ManagedBuffer,
};

use super::utils::ContractInfo;

pub type ChainId<M> = ManagedBuffer<M>;

#[multiversx_sc::module]
pub trait StorageModule {
#[storage_mapper("sovereignsMapper")]
fn sovereigns_mapper(
&self,
sovereign_creator: &ManagedAddress,
) -> SingleValueMapper<ManagedBuffer>;
) -> SingleValueMapper<ChainId<Self::Api>>;

#[storage_mapper("sovereignDeployedContracts")]
fn sovereign_deployed_contracts(
&self,
chain_id: &ManagedBuffer,
chain_id: &ChainId<Self::Api>,
) -> UnorderedSetMapper<ContractInfo<Self::Api>>;

#[view(getChainFactoryAddress)]
Expand Down
Loading

0 comments on commit b3622f9

Please sign in to comment.