Skip to content

Commit

Permalink
Better API and avoid exposing un-necessary dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayanski committed Sep 9, 2024
1 parent 68f1715 commit 4b88338
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
26 changes: 18 additions & 8 deletions cw-orch-daemon/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,24 @@ impl<Sender: TxSender> DaemonAsyncBase<Sender> {
wasm_byte_code,
instantiate_permission: access
.map(|a| {
Ok::<_, DaemonError>(cosmrs::cosmwasm::AccessConfig {
permission: a.permission.try_into().unwrap(),
addresses: a
.addresses
.into_iter()
.map(|a| a.parse())
.collect::<Result<_, _>>()?,
})
let response = match a {
AccessConfig::Nobody => cosmrs::cosmwasm::AccessConfig {
permission: cosmrs::cosmwasm::AccessType::Nobody,
addresses: vec![],
},
AccessConfig::Everybody => cosmrs::cosmwasm::AccessConfig {
permission: cosmrs::cosmwasm::AccessType::Everybody,
addresses: vec![],
},
AccessConfig::AnyOfAddresses(addresses) => cosmrs::cosmwasm::AccessConfig {
permission: cosmrs::cosmwasm::AccessType::AnyOfAddresses,
addresses: addresses
.into_iter()
.map(|a| a.parse())
.collect::<Result<_, _>>()?,
},
};
Ok::<_, DaemonError>(response)
})
.transpose()?,
};
Expand Down
5 changes: 3 additions & 2 deletions cw-orch/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ pub use crate::environment::IndexResponse;

// Environment
pub use crate::environment::{
BankQuerier, BankSetter, CwEnv, DefaultQueriers, EnvironmentInfo, EnvironmentQuerier,
NodeQuerier, QuerierGetter, QueryHandler, TxHandler, TxResponse, WasmQuerier,
AccessConfig, BankQuerier, BankSetter, CwEnv, DefaultQueriers, EnvironmentInfo,
EnvironmentQuerier, NodeQuerier, QuerierGetter, QueryHandler, TxHandler, TxResponse,
WasmQuerier,
};

pub use cw_orch_core::environment::Environment;
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-orch-core/src/contract/contract_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::{
log::{contract_target, transaction_target},
};

use crate::environment::AccessConfig;
use crate::environment::QueryHandler;
use cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig;
use cosmwasm_std::{Addr, Binary, Coin};
use serde::{de::DeserializeOwned, Serialize};
use std::fmt::Debug;
Expand Down
2 changes: 1 addition & 1 deletion packages/cw-orch-core/src/contract/interface_traits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{Contract, WasmPath};
use crate::environment::AccessConfig;
use crate::{
environment::{
AsyncWasmQuerier, ChainInfoOwned, ChainState, CwEnv, Environment, QueryHandler, TxHandler,
Expand All @@ -7,7 +8,6 @@ use crate::{
error::CwEnvError,
log::contract_target,
};
use cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig;
use cosmwasm_std::{Addr, Binary, Coin, Empty};
use cw_multi_test::Contract as MockContract;
use cw_storage_plus::{Item, Map, PrimaryKey};
Expand Down
30 changes: 28 additions & 2 deletions packages/cw-orch-core/src/environment/tx_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use cosmwasm_std::{Addr, Binary, Coin};
use serde::Serialize;
use std::fmt::Debug;

pub use cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig;

/// Response type for actions on an environment
pub type TxResponse<Chain> = <Chain as TxHandler>::Response;

Expand Down Expand Up @@ -90,6 +88,34 @@ pub trait TxHandler: ChainState + Clone {
}
}

pub enum AccessConfig {
Nobody,
Everybody,
AnyOfAddresses(Vec<String>),
}

impl From<AccessConfig> for cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig {
fn from(val: AccessConfig) -> Self {
match val {
AccessConfig::Nobody => cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig {
permission: cosmos_sdk_proto::cosmwasm::wasm::v1::AccessType::Nobody.into(),
addresses: vec![],
},
AccessConfig::Everybody => cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig {
permission: cosmos_sdk_proto::cosmwasm::wasm::v1::AccessType::Everybody.into(),
addresses: vec![],
},
AccessConfig::AnyOfAddresses(addresses) => {
cosmos_sdk_proto::cosmwasm::wasm::v1::AccessConfig {
permission: cosmos_sdk_proto::cosmwasm::wasm::v1::AccessType::AnyOfAddresses
.into(),
addresses,
}
}
}
}
}

// TODO: Perfect test candidate for `trybuild`
#[cfg(test)]
mod tests {
Expand Down

0 comments on commit 4b88338

Please sign in to comment.