Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format/further cleanup #11

Open
wants to merge 3 commits into
base: howard/cleanup
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ cw-orch = "0.22"
ibcmail = { path = "packages/ibcmail", package = "ibcmail" }
client = { path = "contracts/client", package = "ibcmail-client" }
server = { path = "contracts/server", package = "ibcmail-server" }
abstract-app = { version = "0.22.2" }
abstract-adapter = { version = "0.22.2" }
abstract-client = "0.22.1"
speculoos = "0.11.0"
semver = "1.0"
Expand All @@ -38,4 +40,3 @@ debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false

11 changes: 4 additions & 7 deletions contracts/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ required-features = ["daemon"]
default = ["export"]
export = []
schema = ["abstract-app/schema"]
interface = [
"export",
"dep:cw-orch",
]
interface = ["export", "dep:cw-orch"]
daemon = ["interface", "cw-orch/daemon"]

[dependencies]
Expand All @@ -49,10 +46,10 @@ cw-storage-plus = { workspace = true }
thiserror = { workspace = true }
schemars = { workspace = true }
cw-asset = { workspace = true }
abstract-app = "0.22"
abstract-app = { workspace = true }
ibcmail = { workspace = true }
cw-paginate = { workspace = true }
base64 = { version = "0.22.1", default-features = false }
base64 = { version = "0.22.1", default-features = false, features = ["alloc"] }

# Dependencies for interface
cw-orch = { workspace = true, optional = true }
Expand All @@ -62,7 +59,7 @@ sha2 = { version = "0.10.8", default-features = false }
client = { workspace = true, features = ["interface"] }
server = { workspace = true, features = ["interface"] }
abstract-client = { workspace = true }
abstract-app = { version = "0.22", features = ["test-utils"] }
abstract-app = { workspace = true, features = ["test-utils"] }
semver = { workspace = true }
dotenv = { workspace = true }
env_logger = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions contracts/client/src/dependencies.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use abstract_app::objects::dependency::StaticDependency;
#[cfg(feature = "interface")]
use abstract_app::{objects::module::ModuleInfo, std::manager::ModuleInstallConfig};
use ibcmail::IBCMAIL_SERVER_ID;
use ibcmail::{EMAIL_VERSION, IBCMAIL_SERVER_ID};

pub const MAIL_SERVER_DEP: StaticDependency =
StaticDependency::new(IBCMAIL_SERVER_ID, &[">=0.0.1"]);
StaticDependency::new(IBCMAIL_SERVER_ID, &[EMAIL_VERSION]);

#[cfg(feature = "interface")]
impl<Chain: cw_orch::environment::CwEnv> abstract_app::abstract_interface::DependencyCreation
Expand Down
7 changes: 2 additions & 5 deletions contracts/client/src/handlers/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,12 @@ fn send_msg(
app: ClientApp,
) -> ClientResult {
// validate basic fields of message, construct message to send to server
let to_hash = format!("{:?}{:?}{:?}", env.block.time, msg.subject, msg.recipient);
let to_hash = format!("{}{}{:?}", env.block.time, msg.subject, msg.recipient);
let hash = <sha2::Sha256 as sha2::Digest>::digest(to_hash);
let base_64_hash = BASE64_STANDARD.encode(hash);
let to_send = IbcMailMessage {
id: base_64_hash,
sender: Sender::account(
app.account_id(deps.as_ref()).unwrap(),
Some(ChainName::new(&env)),
),
sender: Sender::account(app.account_id(deps.as_ref())?, Some(ChainName::new(&env))),
message: Message {
recipient: msg.recipient,
subject: msg.subject,
Expand Down
7 changes: 2 additions & 5 deletions contracts/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@ required-features = ["daemon"]
default = ["export"]
export = []
schema = ["abstract-adapter/schema"]
interface = [
"export",
"dep:cw-orch",
]
interface = ["export", "dep:cw-orch"]
daemon = ["interface", "cw-orch/daemon"]

[dependencies]
abstract-adapter = "0.22"
abstract-adapter = { workspace = true }
ibcmail = { workspace = true }

cosmwasm-std = { workspace = true }
Expand Down
4 changes: 3 additions & 1 deletion contracts/server/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use cosmwasm_std::Response;
pub use ibcmail::server::ServerAdapter as Adapter;
use ibcmail::EMAIL_VERSION;
use ibcmail::{server::error::ServerError, IBCMAIL_SERVER_ID};
use ibcmail::{server::msg::ServerInstantiateMsg, IBCMAIL_CLIENT_ID};

use crate::{handlers, APP_VERSION};

use abstract_adapter::objects::dependency::StaticDependency;

pub const MAIL_CLIENT: StaticDependency = StaticDependency::new(IBCMAIL_CLIENT_ID, &[]);
pub const MAIL_CLIENT: StaticDependency =
StaticDependency::new(IBCMAIL_CLIENT_ID, &[EMAIL_VERSION]);

/// The type of the result returned by your client's entry points.
pub type ServerResult<T = Response> = Result<T, ServerError>;
Expand Down
40 changes: 19 additions & 21 deletions contracts/server/src/handlers/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use abstract_adapter::traits::AbstractResponse;
use cosmwasm_std::{to_json_binary, wasm_execute, CosmosMsg, Deps, DepsMut, Env, MessageInfo};
use ibcmail::{
client::api::ClientInterface,
server::{
msg::{ServerExecuteMsg, ServerIbcMessage},
ServerAdapter,
},
server::msg::{ServerExecuteMsg, ServerIbcMessage},
Header, IbcMailMessage, Recipient, Route,
};

Expand All @@ -27,12 +24,12 @@ pub fn execute_handler(
deps: DepsMut,
env: Env,
info: MessageInfo,
app: Adapter,
adapter: Adapter,
msg: ServerExecuteMsg,
) -> ServerResult {
match msg {
ServerExecuteMsg::ProcessMessage { msg, route } => {
process_message(deps, env, info, msg, route, app)
process_message(deps, env, info, msg, route, adapter)
}
}
}
Expand All @@ -43,7 +40,7 @@ fn process_message(
_info: MessageInfo,
msg: IbcMailMessage,
route: Option<Route>,
mut app: Adapter,
mut adapter: Adapter,
) -> ServerResult {
println!("processing message: {:?} with route {:?}", msg, route);

Expand Down Expand Up @@ -84,30 +81,31 @@ fn process_message(
route,
};

let msg = route_msg(deps, msg, metadata, &mut app)?;
let msg = route_msg(deps, msg, metadata, &mut adapter)?;

Ok(app.response("route").add_message(msg))
Ok(adapter.response("route").add_message(msg))
}

pub(crate) fn route_msg(
deps: DepsMut,
msg: IbcMailMessage,
header: Header,
app: &mut ServerAdapter,
adapter: &mut Adapter,
) -> ServerResult<CosmosMsg> {
println!("routing message: {:?}, metadata: {:?}", msg, header);

match header.route {
AccountTrace::Local => route_to_local_account(deps.as_ref(), msg, header, app),
AccountTrace::Local => route_to_local_account(deps.as_ref(), msg, header, adapter),
AccountTrace::Remote(ref chains) => {
println!("routing to chains: {:?}", chains);
// check index of hop. If we are on the final hop, route to local account
if header.current_hop == chains.len() as u32 {
return route_to_local_account(deps.as_ref(), msg.clone(), header, app);
return route_to_local_account(deps.as_ref(), msg.clone(), header, adapter);
}
// TODO verify that the chain is a valid chain
// TODO: verify that the chain is a valid chain

let current_module_info = ModuleInfo::from_id(app.module_id(), app.version().into())?;
let current_module_info =
ModuleInfo::from_id(adapter.module_id(), adapter.version().into())?;

let dest_chain = chains
.get(header.current_hop as usize)
Expand All @@ -132,14 +130,14 @@ pub(crate) fn route_msg(
// TODO: We could additionally have something like to avoid having to create the module info object
// let ibc_msg = app.ibc_client().self_module_ibc_action(chain, msg, callback)

let ibc_client_addr = app
let ibc_client_addr = adapter
.module_registry(deps.as_ref())?
.query_module(ModuleInfo::from_id_latest(IBC_CLIENT)?)?
.reference
.unwrap_native()?;
let exec_msg = wasm_execute(ibc_client_addr, &ibc_msg, vec![])?.into();

Ok::<CosmosMsg, ServerError>(exec_msg)
Ok(exec_msg)
}
}
}
Expand All @@ -148,7 +146,7 @@ fn route_to_local_account(
deps: Deps,
msg: IbcMailMessage,
header: Header,
app: &mut ServerAdapter,
adapter: &mut Adapter,
) -> ServerResult<CosmosMsg> {
println!("routing to local account: {:?}", msg.message.recipient);
// This is a local message
Expand All @@ -160,7 +158,7 @@ fn route_to_local_account(
Recipient::Namespace { namespace, .. } => {
// TODO: this only allows for addressing recipients via namespace of their email account directly.
// If they have the email application installed on a sub-account, this will not be able to identify the sub-account.
let namespace_status = app
let namespace_status = adapter
.module_registry(deps)?
.query_namespace(namespace.clone())?;
match namespace_status {
Expand All @@ -175,10 +173,10 @@ fn route_to_local_account(
)),
}?;

let acc_base = app.account_registry(deps)?.account_base(&account_id)?;
(*app).target_account = Some(acc_base);
let acc_base = adapter.account_registry(deps)?.account_base(&account_id)?;
adapter.target_account = Some(acc_base);

let mail_client = app.mail_client(deps);
let mail_client = adapter.mail_client(deps);

Ok(mail_client.receive_msg(msg, header)?)
}
6 changes: 3 additions & 3 deletions contracts/server/src/handlers/module_ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{contract::ServerResult, handlers::execute::route_msg};
pub fn module_ibc_handler(
deps: DepsMut,
_env: Env,
mut app: ServerAdapter,
mut adapter: ServerAdapter,
ibc_msg: ModuleIbcMsg,
) -> ServerResult {
println!("module_ibc_handler 1 : {:?}", ibc_msg);
Expand All @@ -31,11 +31,11 @@ pub fn module_ibc_handler(
ServerIbcMessage::RouteMessage { msg, mut header } => {
// We've hopped one more time
header.current_hop += 1;
let msg = dbg!(route_msg(deps, msg, header, &mut app))?;
let msg = dbg!(route_msg(deps, msg, header, &mut adapter))?;

println!("routed_msg: {:?}", msg);

Ok(app.response("module_ibc").add_message(msg))
Ok(adapter.response("module_ibc").add_message(msg))
}
_ => Err(ServerError::UnauthorizedIbcMessage {}),
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ibcmail/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ default = []
cosmwasm-std = { workspace = true }
cosmwasm-schema = { workspace = true }
cw-storage-plus = { workspace = true }
abstract-app = { version = "0.22"}
abstract-adapter = { version = "0.22"}
abstract-app = { workspace = true }
abstract-adapter = { workspace = true }
cw-orch = { workspace = true }
thiserror = { workspace = true }
cw-asset = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
default = []

[dependencies]
abstract-app = { version = "0.22", features = ["test-utils"] }
abstract-app = { workspace = true, features = ["test-utils"] }
abstract-cw-orch-polytone = "2.0.0"
abstract-interchain-tests = { git = "https://github.com/AbstractSDK/abstract", version = "0.22.1", branch = "removemm" }
cw-orch = { package = "cw-orch-interchain", git = "ssh://[email protected]/AbstractSDK/cw-orch-interchain.git", tag = "v0.22.0" }
Expand All @@ -23,4 +23,4 @@ cw-asset = { workspace = true }
client = { workspace = true, features = ["interface"] }
speculoos = { workspace = true }
server = { workspace = true, features = ["interface"] }
abstract-client = { workspace = true }
abstract-client = { workspace = true }
Loading