abstract_client/
infrastructure.rs

1//! # Represents chain infrastructure
2//!
3//! [`Environment`] allows you to get the execution environment of the object.
4//!
5//! You might want to do this to get the cw-orchestrator type of the infrastructure which enables you to
6//! call some environment-specific methods or do low-level operations.
7//!
8//! You also sometimes need to provide the environment as a parameter to some methods, e.g. when you want to deploy a contract.
9
10use abstract_interface::{Abstract, AbstractInterfaceError};
11use cw_orch::prelude::*;
12
13use crate::{account::Account, AbstractClient};
14
15use cw_orch::environment::Environment as _;
16
17/// Trait for retrieving the CosmWasm environment that is being used.
18pub trait Environment<Chain: CwEnv> {
19    /// Get the execution environment
20    fn environment(&self) -> Chain;
21}
22
23pub(crate) trait Infrastructure<Chain: CwEnv>: Environment<Chain> {
24    /// Get the infrastructure on the execution environment
25    fn infrastructure(&self) -> Result<Abstract<Chain>, AbstractInterfaceError> {
26        let chain = self.environment();
27        Abstract::load_from(chain)
28    }
29}
30
31impl<Chain: CwEnv, T> Infrastructure<Chain> for T where T: Environment<Chain> {}
32
33impl<Chain: CwEnv> Environment<Chain> for Account<Chain> {
34    fn environment(&self) -> Chain {
35        self.abstr_account.environment().clone()
36    }
37}
38
39impl<Chain: CwEnv> Environment<Chain> for AbstractClient<Chain> {
40    fn environment(&self) -> Chain {
41        self.abstr.registry.environment().clone()
42    }
43}