diff --git a/Cargo.toml b/Cargo.toml index 871be2c..5da8597 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ cw-semver = { version = "1.0", features = ["serde" ]} cw-orch = { package = "cw-orch-interchain", git = "ssh://git@github.com/AbstractSDK/cw-orch-interchain.git", tag = "v0.22.0" } abstract-cw-orch-polytone = "2.0.0" abstract-interchain-tests = { git = "https://github.com/AbstractSDK/abstract", version = "0.22.1", branch = "removemm" } +cw-paginate = "0.2.1" # TODO: cannot use this because of money-market adapter trait issue #abstract-interchain-tests = { git = "https://github.com/AbstractSDK/abstract", version = "0.22.1", tag = "v0.22.1" } diff --git a/contracts/client/Cargo.toml b/contracts/client/Cargo.toml index 391dfc9..05de687 100644 --- a/contracts/client/Cargo.toml +++ b/contracts/client/Cargo.toml @@ -49,6 +49,7 @@ cw-asset = { workspace = true } abstract-app = { workspace = true } ibcmail = { workspace = true } abstract-interface = { workspace = true, optional = true } +cw-paginate = { workspace = true } # Dependencies for interface cw-orch = { workspace = true, optional = true } diff --git a/contracts/client/src/handlers/execute.rs b/contracts/client/src/handlers/execute.rs index 44092f3..75c710e 100644 --- a/contracts/client/src/handlers/execute.rs +++ b/contracts/client/src/handlers/execute.rs @@ -55,7 +55,10 @@ fn receive_msg(deps: DepsMut, info: MessageInfo, msg: Message, app: App) -> Clie match msg.recipient { Recipient::Account { id: ref account_id, .. } => { + + println!("account_id: {:?}", account_id); let our_id = app.account_id(deps.as_ref())?; + println!("our_id: {:?}", our_id); // check that the recipient is the current account ensure_eq!(account_id, &our_id, ClientError::NotRecipient {} ); } diff --git a/contracts/client/src/handlers/query.rs b/contracts/client/src/handlers/query.rs index 15192ce..e4b1459 100644 --- a/contracts/client/src/handlers/query.rs +++ b/contracts/client/src/handlers/query.rs @@ -2,14 +2,34 @@ use crate::contract::{App, ClientResult}; use crate::msg::{ClientQueryMsg, ConfigResponse}; use crate::state::{CONFIG}; use cosmwasm_std::{to_json_binary, Binary, Deps, Env, StdResult}; +use cw_storage_plus::Bound; +use ibcmail::client::error::ClientError; +use ibcmail::client::msg::{MessageFilter, MessagesResponse}; +use ibcmail::client::state::RECEIVED; +use ibcmail::MessageId; + +pub const DEFAULT_LIMIT: u32 = 50; pub fn query_handler(deps: Deps, _env: Env, _app: &App, msg: ClientQueryMsg) -> ClientResult { match msg { ClientQueryMsg::Config {} => to_json_binary(&query_config(deps)?), + ClientQueryMsg::Messages { filter, start_after, limit } => to_json_binary(&query_messages(deps, filter, start_after, limit)?), } .map_err(Into::into) } +fn query_messages(deps: Deps, filter: Option, start: Option, limit: Option) -> ClientResult { + let messages = cw_paginate::paginate_map( + &RECEIVED, + deps.storage, + start.as_ref().map(Bound::exclusive), + limit, + |_id, message| Ok::<_, ClientError>(message), + )?; + + Ok(MessagesResponse { messages }) +} + fn query_config(deps: Deps) -> StdResult { let _config = CONFIG.load(deps.storage)?; Ok(ConfigResponse {}) diff --git a/contracts/client/tests/integration.rs b/contracts/client/tests/integration.rs index 7786ac5..54c0d06 100644 --- a/contracts/client/tests/integration.rs +++ b/contracts/client/tests/integration.rs @@ -118,11 +118,19 @@ mod receive_msg { let server_account_id = app.account().id().unwrap(); let app_account_id = app.account().id().unwrap(); + println!("server_account_id: {:?}, app_account_id: {:?}", server_account_id, app_account_id); + let msg = create_test_message(server_account_id.clone(), app_account_id.clone()); - let server_adr = app.account().module_addresses(vec![IBCMAIL_SERVER_ID.into()])?.modules[0].1.clone(); - let res = app.call_as(&server_adr).receive_message(msg); + let server_addr = app.account().module_addresses(vec![IBCMAIL_SERVER_ID.into()])?.modules[0].1.clone(); + + println!("app_account_id: {:?}", app.account().id()); + let res = app.call_as(&server_addr).receive_message(msg); assert_that!(res).is_ok(); + + let messages = app.messages(None, None, None)?; + assert_that!(messages.messages).has_length(1); + Ok(()) } @@ -199,6 +207,12 @@ mod send_msg { assert_that!(res).is_ok(); + let myos_messages = myos_client.messages(None, None, None)?; + assert_that!(myos_messages.messages).is_empty(); + + let juno_messages = juno_client.messages(None, None, None)?; + assert_that!(juno_messages.messages).has_length(1); + Ok(()) } } \ No newline at end of file diff --git a/packages/ibcmail/src/client/msg.rs b/packages/ibcmail/src/client/msg.rs index a663dc7..02a53cd 100644 --- a/packages/ibcmail/src/client/msg.rs +++ b/packages/ibcmail/src/client/msg.rs @@ -1,7 +1,7 @@ use cosmwasm_schema::QueryResponses; use crate::client::ClientApp; -use crate::{Message, NewMessage}; +use crate::{Message, MessageId, NewMessage, Recipient, Sender}; // This is used for type safety and re-exporting the contract endpoint structs. @@ -25,19 +25,35 @@ pub enum ClientExecuteMsg { UpdateConfig {}, } -#[cosmwasm_schema::cw_serde] -pub struct AppMigrateMsg {} - - /// App query messages #[cosmwasm_schema::cw_serde] #[cfg_attr(feature = "interface", derive(cw_orch::QueryFns))] #[cfg_attr(feature = "interface", impl_into(QueryMsg))] #[derive(QueryResponses)] pub enum ClientQueryMsg { + #[returns(MessagesResponse)] + Messages { + filter: Option, + limit: Option, + start_after: Option, + }, #[returns(ConfigResponse)] Config {}, } +#[cosmwasm_schema::cw_serde] +pub struct MessageFilter { + pub from: Option, +} + +#[cosmwasm_schema::cw_serde] +pub struct AppMigrateMsg {} + + #[cosmwasm_schema::cw_serde] pub struct ConfigResponse {} + +#[cosmwasm_schema::cw_serde] +pub struct MessagesResponse { + pub messages: Vec, +} \ No newline at end of file diff --git a/packages/ibcmail/src/lib.rs b/packages/ibcmail/src/lib.rs index da422cd..cab0a5c 100644 --- a/packages/ibcmail/src/lib.rs +++ b/packages/ibcmail/src/lib.rs @@ -58,4 +58,13 @@ impl Recipient { chain: chain_name } } +} + +#[non_exhaustive] +#[cosmwasm_schema::cw_serde] +pub enum Sender { + Account { + id: AccountId, + chain: Option + } } \ No newline at end of file