Skip to content

Commit

Permalink
fix: 50 seperate query to a seperate function
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonAndell committed Nov 6, 2023
1 parent 8472f6f commit b1e7828
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions contracts/core-contracts/cw-asset-manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ mod exec {

use super::*;

fn query_network_address(
deps: &DepsMut,
x_call_addr: &Addr,
) -> Result<NetworkAddress, ContractError> {
let query_msg = GetNetworkAddress {};
let query = QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: x_call_addr.to_string(),
msg: to_binary(&query_msg).map_err(ContractError::Std)?,
});

deps.querier.query(&query).map_err(ContractError::Std)
}

pub fn setup(
deps: DepsMut,
source_xcall: String,
Expand All @@ -132,14 +145,7 @@ mod exec {
.addr_validate(&source_xcall)
.map_err(ContractError::Std)?;

// query network address of xcall
let query_msg = GetNetworkAddress {};
let query = QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: x_call_addr.to_string(),
msg: to_binary(&query_msg).map_err(ContractError::Std)?,
});

let xcall_network_address: NetworkAddress = deps.querier.query(&query)?;
let xcall_network_address: NetworkAddress = query_network_address(&deps, &x_call_addr)?;

if xcall_network_address.to_string().is_empty() {
return Err(ContractError::XAddressNotFound);
Expand Down

0 comments on commit b1e7828

Please sign in to comment.