Skip to content

Commit

Permalink
Merge pull request #221 from multiversx/header-endpoints
Browse files Browse the repository at this point in the history
Header-Verifier endpoints
  • Loading branch information
andreiblt1304 authored Jan 17, 2025
2 parents 774f122 + 999e4a1 commit 94f29c9
Show file tree
Hide file tree
Showing 30 changed files with 445 additions and 50 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.

3 changes: 2 additions & 1 deletion chain-factory/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ pub trait FactoryModule: only_admin::OnlyAdminModule {
#[endpoint(deployHeaderVerifier)]
fn deploy_header_verifier(
&self,
chain_config_address: ManagedAddress,
bls_pub_keys: MultiValueEncoded<ManagedBuffer>,
) -> ManagedAddress {
let source_address = self.header_verifier_template().get();
let metadata = self.blockchain().get_code_metadata(&source_address);

self.tx()
.typed(HeaderverifierProxy)
.init(bls_pub_keys)
.init(chain_config_address, bls_pub_keys)
.gas(60_000_000)
.from_source(source_address)
.code_metadata(metadata)
Expand Down
8 changes: 6 additions & 2 deletions common/operation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ pub const MIN_BLOCKS_FOR_FINALITY: u64 = 10;
const DEFAULT_MAX_TX_GAS_LIMIT: u64 = 300_000_000;

#[type_abi]
#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, ManagedVecItem, Clone)]
#[derive(
TopEncode, TopDecode, NestedEncode, NestedDecode, ManagedVecItem, Clone, Debug, PartialEq,
)]
pub struct StakeArgs<M: ManagedTypeApi> {
pub token_id: TokenIdentifier<M>,
pub amount: BigUint<M>,
Expand All @@ -25,7 +27,9 @@ impl<M: ManagedTypeApi> StakeArgs<M> {
}

#[type_abi]
#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, ManagedVecItem, Clone)]
#[derive(
TopEncode, TopDecode, NestedEncode, NestedDecode, ManagedVecItem, Clone, Debug, PartialEq,
)]
pub struct SovereignConfig<M: ManagedTypeApi> {
pub min_validators: u64,
pub max_validators: u64,
Expand Down
7 changes: 5 additions & 2 deletions common/proxies/src/chain_factory_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,17 @@ where
}

pub fn deploy_header_verifier<
Arg0: ProxyArg<MultiValueEncoded<Env::Api, ManagedBuffer<Env::Api>>>,
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<MultiValueEncoded<Env::Api, ManagedBuffer<Env::Api>>>,
>(
self,
bls_pub_keys: Arg0,
chain_config_address: Arg0,
bls_pub_keys: Arg1,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ManagedAddress<Env::Api>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("deployHeaderVerifier")
.argument(&chain_config_address)
.argument(&bls_pub_keys)
.original_result()
}
Expand Down
33 changes: 31 additions & 2 deletions common/proxies/src/header_verifier_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ where
Gas: TxGas<Env>,
{
pub fn init<
Arg0: ProxyArg<MultiValueEncoded<Env::Api, ManagedBuffer<Env::Api>>>,
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<MultiValueEncoded<Env::Api, ManagedBuffer<Env::Api>>>,
>(
self,
bls_pub_keys: Arg0,
chain_config_address: Arg0,
bls_pub_keys: Arg1,
) -> TxTypedDeploy<Env, From, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_deploy()
.argument(&chain_config_address)
.argument(&bls_pub_keys)
.original_result()
}
Expand Down Expand Up @@ -149,6 +152,32 @@ where
.original_result()
}

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

pub fn update_config<
Arg0: ProxyArg<operation::SovereignConfig<Env::Api>>,
>(
self,
new_config: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("updateConfig")
.argument(&new_config)
.original_result()
}

pub fn complete_setup_phase(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ impl ContractInteract {
let mut bls_pub_keys = MultiValueEncoded::new();
bls_pub_keys.push(bls_pub_key);
let header_verifier_code_path = MxscPath::new(&self.header_verifier_code);
let chain_config_address = Bech32Address::from_bech32_string("chain_config".to_string());

let new_address = self
.interactor
.tx()
.from(&self.wallet_address)
.gas(100_000_000u64)
.typed(header_verifier_proxy::HeaderverifierProxy)
.init(bls_pub_keys)
.init(chain_config_address, bls_pub_keys)
.code(header_verifier_code_path)
.returns(ReturnsNewAddress)
.run()
Expand Down
4 changes: 3 additions & 1 deletion enshrine-esdt-safe/tests/enshrine_esdt_safe_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const TOKEN_HANDLER_CODE_PATH: MxscPath =
const FEE_MARKET_ADDRESS: TestSCAddress = TestSCAddress::new("fee-market");
const FEE_MARKET_CODE_PATH: MxscPath = MxscPath::new("../fee-market/output/fee-market.mxsc.json");

const CHAIN_CONFIG_ADDRESS: TestSCAddress = TestSCAddress::new("chain-config");

const USER_ADDRESS: TestAddress = TestAddress::new("user");
const INSUFFICIENT_WEGLD_ADDRESS: TestAddress = TestAddress::new("insufficient_wegld");
const RECEIVER_ADDRESS: TestAddress = TestAddress::new("receiver");
Expand Down Expand Up @@ -169,7 +171,7 @@ impl EnshrineTestState {
.tx()
.from(ENSHRINE_ESDT_OWNER_ADDRESS)
.typed(HeaderverifierProxy)
.init(bls_pub_keys)
.init(CHAIN_CONFIG_ADDRESS, bls_pub_keys)
.code(HEADER_VERIFIER_CODE_PATH)
.new_address(HEADER_VERIFIER_ADDRESS)
.run();
Expand Down
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.

9 changes: 5 additions & 4 deletions esdt-safe/interactor/src/esdt_safe_interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use multiversx_sc_scenario::multiversx_chain_vm::crypto_functions::{sha256, SHA2
use multiversx_sc_scenario::scenario_model::TxResponseStatus;
use multiversx_sc_snippets::imports::*;
use multiversx_sc_snippets::sdk::{self};
use operation::aliases::{OptionalTransferData, PaymentsVec};
use operation::{Operation, OperationData};
use operation::{OperationEsdtPayment, TransferData};
use proxies::esdt_safe_proxy::EsdtSafeProxy;
use proxies::fee_market_proxy::{FeeMarketProxy, FeeStruct, FeeType};
use proxies::header_verifier_proxy::HeaderverifierProxy;
use proxies::testing_sc_proxy::TestingScProxy;
use operation::aliases::{OptionalTransferData, PaymentsVec};
use operation::{Operation, OperationData};
use operation::{OperationEsdtPayment, TransferData};

const FEE_MARKET_CODE_PATH: &str = "../../fee-market/output/fee-market.mxsc.json";
const HEADER_VERIFIER_CODE_PATH: &str = "../../header-verifier/output/header-verifier.mxsc.json";
Expand Down Expand Up @@ -151,14 +151,15 @@ impl ContractInteract {

pub async fn deploy_header_verifier_contract(&mut self) {
let header_verifier_code_path = MxscPath::new(&self.header_verifier_code);
let chain_config_address = Bech32Address::from_bech32_string("chain_config".to_string());

let new_address = self
.interactor
.tx()
.from(&self.wallet_address)
.gas(100_000_000u64)
.typed(HeaderverifierProxy)
.init(MultiValueEncoded::new())
.init(chain_config_address, MultiValueEncoded::new())
.code(header_verifier_code_path)
.returns(ReturnsNewAddress)
.run()
Expand Down
6 changes: 4 additions & 2 deletions esdt-safe/tests/bridge_blackbox_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use multiversx_sc_scenario::multiversx_chain_vm::crypto_functions::sha256;
use multiversx_sc_scenario::{
api::StaticApi, imports::MxscPath, ExpectError, ScenarioTxRun, ScenarioWorld,
};
use operation::{Operation, OperationData, OperationEsdtPayment};
use proxies::esdt_safe_proxy::EsdtSafeProxy;
use proxies::fee_market_proxy::{FeeMarketProxy, FeeStruct, FeeType};
use proxies::header_verifier_proxy::HeaderverifierProxy;
use operation::{Operation, OperationData, OperationEsdtPayment};

const BRIDGE_ADDRESS: TestSCAddress = TestSCAddress::new("bridge");
const BRIDGE_CODE_PATH: MxscPath = MxscPath::new("output/esdt-safe.mxsc.json");
Expand All @@ -27,6 +27,8 @@ const HEADER_VERIFIER_ADDRESS: TestSCAddress = TestSCAddress::new("header_verifi
const HEADER_VERIFIER_CODE_PATH: MxscPath =
MxscPath::new("../header-verifier/output/header-verifier.mxsc.json");

const CHAIN_CONFIG_ADDRESS: TestSCAddress = TestSCAddress::new("chain-config");

const USER_ADDRESS: TestAddress = TestAddress::new("user");
const RECEIVER_ADDRESS: TestAddress = TestAddress::new("receiver");

Expand Down Expand Up @@ -114,7 +116,7 @@ impl BridgeTestState {
.tx()
.from(BRIDGE_OWNER_ADDRESS)
.typed(HeaderverifierProxy)
.init(bls_pub_keys)
.init(CHAIN_CONFIG_ADDRESS, bls_pub_keys)
.code(HEADER_VERIFIER_CODE_PATH)
.new_address(HEADER_VERIFIER_ADDRESS)
.run();
Expand Down
12 changes: 12 additions & 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.

12 changes: 12 additions & 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.

12 changes: 12 additions & 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 @@ -11,6 +11,9 @@ path = "src/lib.rs"
[dependencies.multiversx-sc]
version = "=0.55.0"

[dependencies.chain-config]
path = "../chain-config"

[dependencies.operation]
path = "../common/operation"

Expand Down
Loading

0 comments on commit 94f29c9

Please sign in to comment.