Skip to content

Commit

Permalink
Merge pull request #10 from AbstractSDK/howard/cleanup
Browse files Browse the repository at this point in the history
Updates to APIs and cleanup
  • Loading branch information
CyberHoward authored May 28, 2024
2 parents fa63baf + d8bb475 commit 2c9f114
Show file tree
Hide file tree
Showing 99 changed files with 14,050 additions and 573 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: gh-pages-deploy

on:
push:
branches: [main]
paths:
- "docs/**"
tags:
- "v[0-9]+.[0-9]+.[0-9]+" # Push events to matching v*, i.e. v1.0, v20.15.10
- "v[0-9]+.[0-9]+.[0-9]+-rc*" # Push events to matching v*, i.e. v1.0-rc1, v20.15.10-rc5
- "v[0-9]+.[0-9]+.[0-9]+-beta*" # Push events to matching v*, i.e. v1.0-rc1, v20.15.10-rc5

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎
uses: actions/checkout@v3

- name: Setup | Rust
id: rustup
uses: dtolnay/rust-toolchain@stable

- name: Setup | Just
id: just
uses: extractions/setup-just@v1

- name: Install static-sitemap-cli
run: npm install static-sitemap-cli

- name: Install dependencies 🔧
run: just docs-install
- name: Build 🏗️
run: just docs-build

- name: Upload artifact
if: ${{ github.event_name != 'pull_request' }}
uses: actions/upload-pages-artifact@v1
with:
# Upload book repository
path: './docs/book'

# Deploy job
deploy:
if: ${{ github.event_name != 'pull_request' }}
# Add a dependency to the build job
needs: build

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

# Specify runner + deployment step
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
61 changes: 23 additions & 38 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,56 +1,41 @@
[workspace]
members = ["contracts/*", "packages/ibcmail"]
members = ["contracts/*", "packages/ibcmail", "tests"]
resolver = "2"

[profile.release]
rpath = false
lto = true
overflow-checks = true
opt-level = 3
debug = false
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false
[workspace.package]
version = "0.2.0"

[workspace.dependencies]
cosmwasm-std = { version = "1.5.3" }
cosmwasm-schema = { version = "1.5.3" }
cw-controllers = { version = "1.1.2" }
cosmwasm-std = "1.5.3"
cosmwasm-schema = "1.5.3"
cw-controllers = "1.1.2"
cw-storage-plus = "1.2.0"
thiserror = { version = "1.0.50" }
thiserror = "1.0.50"
cw-paginate = "0.2.1"
schemars = "0.8"
cw-asset = { version = "3.0.0" }
abstract-app = { version = "0.22.1" }
abstract-adapter = { version = "0.22.1" }
abstract-std = { version = "0.22.1" }
abstract-interface = { version = "0.22.1" }
abstract-sdk = { version = "0.22.1" }
lazy_static = "1.4.0"
cw-asset = "3.0.0"
cw-semver = { version = "1.0", features = ["serde"] }
cw-orch = { package = "cw-orch-interchain", git = "ssh://[email protected]/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" }
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-client = { version = "0.22.1" }
abstract-client = "0.22.1"
speculoos = "0.11.0"
semver = "1.0"
dotenv = "0.15.0"
env_logger = "0.10.0"
clap = { version = "4.3.7" }
clap = "4.3.7"
const_format = "0.2.32"

# We have to patch everything because of abstract-interchain-tests
[patch.crates-io]
#abstract-money-market-standard = { git = "https://github.com/AbstractSDK/abstract", version = "0.22.1", tag = "v0.22.1" }
#abstract-money-market-adapter = { git = "https://github.com/AbstractSDK/abstract", version = "0.22.1", branch = "removemm" }
#abstract-money-market-adapter = { git = "https://github.com/AbstractSDK/abstract", version = "0.22.1", rev = "985c558d90e38817fceb3681272b788607608689" }
#abstract-adapter = { git = "https://github.com/AbstractSDK/abstract", version = "0.22.1", tag = "v0.22.1" }
#abstract-std = { git = "https://github.com/AbstractSDK/abstract", version = "0.22.1", tag = "v0.22.1" }
#abstract-sdk = { git = "https://github.com/AbstractSDK/abstract", version = "0.22.1", tag = "v0.22.1" }
[profile.release]
rpath = false
lto = true
overflow-checks = true
opt-level = 3
debug = false
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false

15 changes: 4 additions & 11 deletions contracts/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ibcmail-client"
version = "0.1.1"
version.workspace = true
authors = [
"CyberHoward <[email protected]>",
"Adair <[email protected]>",
Expand Down Expand Up @@ -37,9 +37,7 @@ export = []
schema = ["abstract-app/schema"]
interface = [
"export",
"dep:abstract-interface",
"dep:cw-orch",
"ibcmail/interface",
]
daemon = ["interface", "cw-orch/daemon"]

Expand All @@ -51,27 +49,22 @@ cw-storage-plus = { workspace = true }
thiserror = { workspace = true }
schemars = { workspace = true }
cw-asset = { workspace = true }
abstract-app = { workspace = true }
abstract-app = "0.22"
ibcmail = { workspace = true }
abstract-interface = { workspace = true, optional = true }
cw-paginate = { workspace = true }
base64 = { version = "0.22.1", default-features = false }

# Dependencies for interface
cw-orch = { workspace = true, optional = true }
sha2 = { version = "0.10.8", default-features = false }
#client = { workspace = true, optional = true }

[dev-dependencies]
client = { workspace = true, features = ["interface"] }
server = { workspace = true, features = ["interface"] }
abstract-client = { workspace = true }
abstract-app = { workspace = true, features = ["test-utils"] }
speculoos = { workspace = true }
abstract-app = { version = "0.22", features = ["test-utils"] }
semver = { workspace = true }
dotenv = { workspace = true }
env_logger = { workspace = true }
cw-orch = { workspace = true }
clap = { workspace = true, features = ["derive"] }
abstract-cw-orch-polytone = { workspace = true }
abstract-interchain-tests = { workspace = true }
#abstract-scripts = { workspace = true }
1 change: 0 additions & 1 deletion contracts/client/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{dependencies::MAIL_SERVER_DEP, error::ClientError, handlers, APP_VER
pub type ClientResult<T = Response> = Result<T, ClientError>;

const APP: App = App::new(IBCMAIL_CLIENT_ID, APP_VERSION, None)
.with_instantiate(handlers::instantiate_handler)
.with_execute(handlers::execute_handler)
.with_query(handlers::query_handler)
.with_migrate(handlers::migrate_handler)
Expand Down
5 changes: 3 additions & 2 deletions contracts/client/src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ pub const MAIL_SERVER_DEP: StaticDependency =
StaticDependency::new(IBCMAIL_SERVER_ID, &[">=0.0.1"]);

#[cfg(feature = "interface")]
impl<Chain: cw_orch::environment::CwEnv> abstract_interface::DependencyCreation
impl<Chain: cw_orch::environment::CwEnv> abstract_app::abstract_interface::DependencyCreation
for crate::ClientInterface<Chain>
{
type DependenciesConfig = cosmwasm_std::Empty;

fn dependency_install_configs(
_configuration: Self::DependenciesConfig,
) -> Result<Vec<ModuleInstallConfig>, abstract_interface::AbstractInterfaceError> {
) -> Result<Vec<ModuleInstallConfig>, abstract_app::abstract_interface::AbstractInterfaceError>
{
let adapter_install_config = ModuleInstallConfig::new(
ModuleInfo::from_id(ibcmail::IBCMAIL_SERVER_ID, crate::APP_VERSION.into())?,
None,
Expand Down
63 changes: 23 additions & 40 deletions contracts/client/src/handlers/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,82 +3,80 @@ use abstract_app::{
sdk::ModuleRegistryInterface,
traits::{AbstractResponse, AccountIdentification},
};
use cosmwasm_std::{ensure_eq, Deps, DepsMut, Env, MessageInfo, Order};
use base64::prelude::*;
use cosmwasm_std::{ensure_eq, CosmosMsg, Deps, DepsMut, Env, MessageInfo};
use ibcmail::{
client::{
state::{RECEIVED, SENT},
ClientApp,
},
server::api::ServerInterface,
Message, NewMessage, Recipient, Route, Sender, IBCMAIL_SERVER_ID,
server::api::{MailServer, ServerInterface},
IbcMailMessage, Message, Recipient, Route, Sender, IBCMAIL_SERVER_ID,
};

use crate::{
contract::{App, ClientResult},
error::ClientError,
msg::ClientExecuteMsg,
state::CONFIG,
};

// # ANCHOR: execute_handler
pub fn execute_handler(
deps: DepsMut,
env: Env,
info: MessageInfo,
app: App,
msg: ClientExecuteMsg,
) -> ClientResult {
println!("Env: {:?}", env);
match msg {
ClientExecuteMsg::SendMessage { message, route } => {
send_msg(deps, env, info, message, route, app)
}
ClientExecuteMsg::ReceiveMessage(message) => receive_msg(deps, info, message, app),
ClientExecuteMsg::UpdateConfig {} => update_config(deps, info, app),
_ => Err(ClientError::NotImplemented("execute".to_string())),
}
}
// # ANCHOR_END: execute_handler

// # ANCHOR: send_msg
fn send_msg(
deps: DepsMut,
env: Env,
_info: MessageInfo,
msg: NewMessage,
msg: Message,
route: Option<Route>,
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 hash = <sha2::Sha256 as sha2::Digest>::digest(to_hash);

let to_send = Message {
// TODO: base64 encode this
id: format!("{:x}", 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)),
),
recipient: msg.recipient,
subject: msg.subject,
body: msg.body,
message: Message {
recipient: msg.recipient,
subject: msg.subject,
body: msg.body,
},
timestamp: env.block.time,
version: app.version().to_string(),
};

SENT.save(deps.storage, to_send.id.clone(), &to_send)?;

let server = app.mail_server(deps.as_ref());
let route_msg = server.process_msg(to_send, route)?;
let server: MailServer<_> = app.mail_server(deps.as_ref());
let route_msg: CosmosMsg = server.process_msg(to_send, route)?;

Ok(app.response("send").add_message(route_msg))
}
// # ANCHOR_END: send_msg

/// Receive a message from the server
fn receive_msg(deps: DepsMut, info: MessageInfo, msg: Message, app: App) -> ClientResult {
// TODO: remove print
println!("Received message: {:?}", msg);
// check that the message sender is the server... this requires the server to be the proper version
// TODO, should we have a function that is able to check against a module ID directly in the SDK ?
// # ANCHOR: receive_msg
fn receive_msg(deps: DepsMut, info: MessageInfo, msg: IbcMailMessage, app: App) -> ClientResult {
let sender_module = app
.module_registry(deps.as_ref())?
.module_info(info.sender)
Expand All @@ -89,32 +87,26 @@ fn receive_msg(deps: DepsMut, info: MessageInfo, msg: Message, app: App) -> Clie
ClientError::NotMailServer {}
);

ensure_correct_recipient(deps.as_ref(), &msg.recipient, &app)?;
ensure_correct_recipient(deps.as_ref(), &msg.message.recipient, &app)?;

RECEIVED.save(deps.storage, msg.id.clone(), &msg)?;
// TODO: remove, could run out of gas!!
let len = RECEIVED
.keys(deps.storage, None, None, Order::Ascending)
.count();
println!("Received length: {:?}", len);

Ok(app
.response("received")
.add_attribute("message_id", &msg.id))
}
// # ANCHOR_END: receive_msg

fn ensure_correct_recipient(
deps: Deps,
recipient: &Recipient,
app: &ClientApp,
) -> ClientResult<()> {
println!("Checking recipient: {:?}", recipient);
match recipient {
Recipient::Account {
id: ref account_id, ..
} => {
let our_id = app.account_id(deps)?;
println!("recipient_id: {:?}, our_id: {:?}", account_id, our_id);

// check that the recipient is the current account
ensure_eq!(account_id, &our_id, ClientError::NotRecipient {});
Expand All @@ -131,12 +123,3 @@ fn ensure_correct_recipient(
}
Ok(())
}

/// Update the configuration of the client
fn update_config(deps: DepsMut, msg_info: MessageInfo, app: App) -> ClientResult {
// Only the admin should be able to call this
app.admin.assert_admin(deps.as_ref(), &msg_info.sender)?;
let mut _config = CONFIG.load(deps.storage)?;

Ok(app.response("update_config"))
}
Loading

0 comments on commit 2c9f114

Please sign in to comment.