-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1627 from multiversx/composability-interact
composability interact migration
- Loading branch information
Showing
12 changed files
with
639 additions
and
193 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 39 additions & 74 deletions
113
contracts/feature-tests/composability/interact/src/call_tree_deploy.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,65 @@ | ||
use crate::{call_tree::CallState, comp_interact_controller::ComposabilityInteract}; | ||
|
||
use forwarder_queue::ProxyTrait as _; | ||
use vault::ProxyTrait as _; | ||
use crate::{ | ||
call_tree::CallState, comp_interact_controller::ComposabilityInteract, forwarder_queue_proxy, vault_proxy | ||
}; | ||
|
||
use multiversx_sc_snippets::imports::*; | ||
|
||
impl ComposabilityInteract { | ||
pub async fn deploy_call_tree_contracts(&mut self, call_state: &CallState) { | ||
let mut typed_vault_deploys = self.typed_sc_deploy_vault(call_state).await; | ||
let mut typed_forwarder_deploys = self.typed_sc_deploy_forwarder_queue(call_state).await; | ||
|
||
let mut steps = Vec::new(); | ||
for typed_sc_deploy in &mut typed_vault_deploys { | ||
steps.push(typed_sc_deploy.as_mut()); | ||
} | ||
for typed_sc_deploy in &mut typed_forwarder_deploys { | ||
steps.push(typed_sc_deploy.as_mut()); | ||
} | ||
|
||
self.interactor | ||
.multi_sc_exec(StepBuffer::from_sc_deploy_vec(&mut steps)) | ||
.await; | ||
let vault_deploy_addresses = self.typed_sc_deploy_vault(call_state).await; | ||
let forwarder_deploy_addresses = self.typed_sc_deploy_forwarder_queue(call_state).await; | ||
|
||
let mut vault_iter = call_state.vaults.iter(); | ||
for step in typed_vault_deploys.iter() { | ||
if let Some(new_address) = step.response().new_deployed_address.clone() { | ||
let new_address_bech32 = bech32::encode(&new_address); | ||
let rc_vault = vault_iter.next().unwrap(); | ||
let mut vault = rc_vault.borrow_mut(); | ||
println!( | ||
"New vault {0} deployed address: {1}", | ||
vault.name, new_address_bech32 | ||
); | ||
for address in vault_deploy_addresses.iter() { | ||
let rc_vault = vault_iter.next().unwrap(); | ||
let mut vault = rc_vault.borrow_mut(); | ||
println!("New vault {0} deployed address: {1}", vault.name, address); | ||
|
||
vault.address = Some(new_address); | ||
} else { | ||
println!("deploy failed"); | ||
return; | ||
} | ||
vault.address = Some(address.to_address()); | ||
} | ||
|
||
let mut fwd_iter = call_state.forwarders.iter(); | ||
for step in typed_forwarder_deploys.iter() { | ||
if let Some(new_address) = step.response().new_deployed_address.clone() { | ||
let new_address_bech32 = bech32::encode(&new_address); | ||
let rc_fwd = fwd_iter.next().unwrap(); | ||
let mut fwd = rc_fwd.borrow_mut(); | ||
println!( | ||
"New forwarder {0} deployed address: {1}", | ||
fwd.name, new_address_bech32 | ||
); | ||
for address in forwarder_deploy_addresses.iter() { | ||
let rc_fwd = fwd_iter.next().unwrap(); | ||
let mut fwd = rc_fwd.borrow_mut(); | ||
println!("New forwarder {0} deployed address: {1}", fwd.name, address); | ||
|
||
fwd.address = Some(new_address); | ||
} else { | ||
println!("deploy failed"); | ||
return; | ||
} | ||
fwd.address = Some(address.to_address()); | ||
} | ||
} | ||
|
||
pub async fn typed_sc_deploy_vault( | ||
&mut self, | ||
call_state: &CallState, | ||
) -> Vec<TypedScDeploy<OptionalValue<ManagedBuffer<StaticApi>>>> { | ||
let mut typed_vault_deploys = Vec::new(); | ||
pub async fn typed_sc_deploy_vault(&mut self, call_state: &CallState) -> Vec<Bech32Address> { | ||
let mut buffer = self.interactor.homogenous_call_buffer(); | ||
for _ in call_state.vaults.iter() { | ||
let typed_sc_deploy = ScDeployStep::new() | ||
.call( | ||
self.state | ||
.default_vault_address() | ||
.init(OptionalValue::<BoxedBytes>::None), | ||
) | ||
.from(&self.wallet_address) | ||
.code(&self.vault_code) | ||
.gas_limit("70,000,000"); | ||
|
||
typed_vault_deploys.push(typed_sc_deploy); | ||
buffer.push_tx(|tx| { | ||
tx.from(&self.wallet_address) | ||
.typed(vault_proxy::VaultProxy) | ||
.init(OptionalValue::<BoxedBytes>::None) | ||
.code(&self.vault_code) | ||
.gas(NumExpr("70,000,000")) | ||
.returns(ReturnsNewBech32Address) | ||
}); | ||
} | ||
typed_vault_deploys | ||
|
||
buffer.run().await | ||
} | ||
|
||
pub async fn typed_sc_deploy_forwarder_queue( | ||
&mut self, | ||
call_state: &CallState, | ||
) -> Vec<TypedScDeploy<()>> { | ||
let mut typed_forwarder_deploys = Vec::new(); | ||
|
||
) -> Vec<Bech32Address> { | ||
let mut buffer = self.interactor.homogenous_call_buffer(); | ||
for _ in call_state.forwarders.iter() { | ||
let typed_sc_deploy = ScDeployStep::new() | ||
.call(self.state.default_forwarder_queue_address().init()) | ||
.from(&self.wallet_address) | ||
.code(&self.forw_queue_code) | ||
.gas_limit("70,000,000"); | ||
|
||
typed_forwarder_deploys.push(typed_sc_deploy); | ||
buffer.push_tx(|tx| { | ||
tx.from(&self.wallet_address) | ||
.typed(forwarder_queue_proxy::ForwarderQueueProxy) | ||
.init() | ||
.code(&self.forw_queue_code) | ||
.gas(NumExpr("70,000,000")) | ||
.returns(ReturnsNewBech32Address) | ||
}); | ||
} | ||
typed_forwarder_deploys | ||
|
||
buffer.run().await | ||
} | ||
} |
Oops, something went wrong.