Skip to content

Commit

Permalink
Updated polytone to use new cw-orch patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayanski committed Oct 21, 2024
1 parent 3fb6f1a commit f6ba0e6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions packages/cw-orch-polytone/src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ impl<Chain: CwEnv> DeployedChains<Chain> for Polytone<Chain> {
// We try to get the code_id for the contract
if contract.code_id().is_err() {
let code_id = state
.get(env_info.chain_name.clone())
.unwrap_or(&Value::Null)
.get(env_info.chain_id.to_string())
.unwrap_or(&Value::Null)
.get("code_ids")
Expand Down
52 changes: 49 additions & 3 deletions packages/cw-orch-polytone/src/interchain.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use cosmwasm_std::{CosmosMsg, Uint64};
use cw_orch::prelude::*;
use cw_orch::{core::serde_json::Value, daemon::DeployedChains, prelude::*};
use cw_orch_interchain::core::{IbcQueryHandler, InterchainEnv, InterchainError};
use polytone_note::msg::ExecuteMsgFns;

use crate::{
deploy::{POLYTONE_NOTE, POLYTONE_PROXY, POLYTONE_VOICE},
utils::read_json,
Polytone, PolytoneNote, PolytoneProxy, PolytoneVoice,
};

Expand All @@ -20,9 +21,9 @@ pub struct PolytoneConnection<Chain: CwEnv> {
pub proxy: PolytoneProxy<Chain>, // This contract doesn't have an address, it's only a code id used for instantiating
}

impl<Chain: CwEnv> PolytoneConnection<Chain> {
impl<Chain: IbcQueryHandler> PolytoneConnection<Chain> {
pub fn load_from(src_chain: Chain, dst_chain: Chain) -> PolytoneConnection<Chain> {
PolytoneConnection {
let mut connection = PolytoneConnection {
note: PolytoneNote::new(
format!(
"{POLYTONE_NOTE}{DELIMITER}{}",
Expand All @@ -39,6 +40,47 @@ impl<Chain: CwEnv> PolytoneConnection<Chain> {
),
// Proxy doesn't have a specific address in deployments, so we don't load a specific suffixed proxy
proxy: PolytoneProxy::new(POLYTONE_PROXY, dst_chain),
};
connection.set_contracts_addresses();
connection
}

/// This allows loading only the addresses from the state, because code_ids are not relevant for this Structure
fn set_contracts_addresses(&mut self) {
let state;

let state_file = Polytone::<Chain>::deployed_state_file_path();
if let Some(state_file) = state_file {
if let Ok(module_state_json) = read_json(&state_file) {
state = module_state_json;
} else {
return;
}
} else {
return;
}

let all_contracts = self.get_contracts_mut();

for contract in all_contracts {
// We set the code_id and/or address of the contract in question if they are not present already
let env_info = contract.environment().env_info();
// We try to get the address for the contract
if contract.address().is_err() {
// Try and get the code id from file
let address = state
.get(env_info.chain_id.to_string())
.unwrap_or(&Value::Null)
.get(env_info.deployment_id)
.unwrap_or(&Value::Null)
.get(contract.id());

if let Some(address) = address {
if address.is_string() {
contract.set_default_address(&Addr::unchecked(address.as_str().unwrap()))
}
}
}
}
}

Expand Down Expand Up @@ -75,4 +117,8 @@ impl<Chain: IbcQueryHandler> PolytoneConnection<Chain> {

src_polytone.connect_if_needed(&dst_polytone, interchain)
}

fn get_contracts_mut(&mut self) -> Vec<&mut dyn cw_orch::prelude::ContractInstance<Chain>> {
vec![&mut self.note, &mut self.voice, &mut self.proxy]
}
}

0 comments on commit f6ba0e6

Please sign in to comment.