Skip to content

Commit

Permalink
feat(ibc-union): implement QueryResponses and cw-orch function genera…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
adairrr committed Feb 21, 2025
1 parent d5c4aeb commit 4abb9e3
Show file tree
Hide file tree
Showing 10 changed files with 2,054 additions and 1,260 deletions.
3,235 changes: 1,981 additions & 1,254 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ tracing = { version = "0.1.40", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "ansi"] }
typenum = { version = "1.17.0", default-features = false }

cw-orch = "0.27.0"

[patch."crates-io"]
arbitrary = { git = "https://github.com/unionlabs/arbitrary" }
# parity-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" }
Expand Down
4 changes: 3 additions & 1 deletion cosmwasm/ibc-union/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ workspace = true
crate-type = ["cdylib", "rlib"]

[features]
library = []
cw-orch-interface = ["dep:cw-orch", "ibc-union-msg/cw-orch-interface"]
library = []

[dependencies]
alloy = { workspace = true, features = ["sol-types"] }
Expand All @@ -32,3 +33,4 @@ strum = { version = "0.26.3", features = ["derive"] }
thiserror = { workspace = true }
unionlabs = { workspace = true, features = ["ethabi"] }
unionlabs-cosmwasm-upgradable = { workspace = true }
cw-orch = { workspace = true, optional = true }
9 changes: 9 additions & 0 deletions cosmwasm/ibc-union/core/msg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ repository = { workspace = true }
[lints]
workspace = true

[features]
cw-orch-interface = ["schemars", "dep:cw-orch", "dep:cosmwasm-std", "dep:cosmwasm-schema"]
schemars = ["dep:schemars", "unionlabs-primitives/schemars", "ibc-union-spec/schemars"]

[dependencies]
ibc-union-spec = { workspace = true, features = ["serde"] }
serde = { workspace = true, features = ["derive"] }
unionlabs-primitives = { workspace = true, features = ["serde"] }

cosmwasm-schema = { workspace = true, optional = true }
cosmwasm-std = { workspace = true, optional = true }
cw-orch = { workspace = true, optional = true }
schemars = { workspace = true, optional = true }
3 changes: 2 additions & 1 deletion cosmwasm/ibc-union/core/msg/src/lightclient.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use unionlabs_primitives::Bytes;

#[derive(serde::Serialize, serde::Deserialize)]
#[derive(serde::Serialize, serde::Deserialize, Debug)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub enum Status {
Active,
Expand Down
3 changes: 2 additions & 1 deletion cosmwasm/ibc-union/core/msg/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use ibc_union_spec::types::Packet;
use unionlabs_primitives::Bytes;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub enum IbcUnionMsg {
OnChannelOpenInit {
connection_id: u32,
Expand Down
3 changes: 2 additions & 1 deletion cosmwasm/ibc-union/core/msg/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ibc_union_spec::types::{Channel, Packet};
use serde::{Deserialize, Serialize};
use unionlabs_primitives::Bytes;

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct InitMsg {}

Expand All @@ -15,6 +15,7 @@ pub struct MsgRegisterClient {

#[derive(Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
#[cfg_attr(feature = "cw-orch-interface", derive(cw_orch::ExecuteFns))]
pub enum ExecuteMsg {
RegisterClient(MsgRegisterClient),
CreateClient(MsgCreateClient),
Expand Down
24 changes: 22 additions & 2 deletions cosmwasm/ibc-union/core/msg/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
use unionlabs_primitives::H256;

#[derive(serde::Serialize, serde::Deserialize)]
#[derive(serde::Serialize, serde::Deserialize, Debug)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(
feature = "cw-orch-interface",
derive(cosmwasm_schema::QueryResponses, cw_orch::QueryFns)
)]
pub enum QueryMsg {
#[cfg_attr(feature = "cw-orch-interface", returns(u64))]
GetTimestampAtHeight { client_id: u32, height: u64 },
#[cfg_attr(feature = "cw-orch-interface", returns(u64))]
GetLatestHeight { client_id: u32 },
#[cfg_attr(feature = "cw-orch-interface", returns(cosmwasm_std::Binary))]
GetClientState { client_id: u32 },
#[cfg_attr(feature = "cw-orch-interface", returns(cosmwasm_std::Binary))]
GetConsensusState { client_id: u32, height: u64 },
#[cfg_attr(feature = "cw-orch-interface", returns(crate::lightclient::Status))]
GetStatus { client_id: u32 },
#[cfg_attr(feature = "cw-orch-interface", returns(u64))]
GetClientType { client_id: u32 },
#[cfg_attr(
feature = "cw-orch-interface",
returns(ibc_union_spec::types::Connection)
)]
GetConnection { connection_id: u32 },
#[cfg_attr(feature = "cw-orch-interface", returns(ibc_union_spec::types::Channel))]
GetChannel { channel_id: u32 },
#[cfg_attr(feature = "cw-orch-interface", returns(std::collections::BTreeSet<u32>))]
GetChannels { contract: String },
#[cfg_attr(feature = "cw-orch-interface", returns(Option<Vec<u8>>))]
GetBatchPackets { channel_id: u32, batch_hash: H256 },
#[cfg_attr(feature = "cw-orch-interface", returns(Option<Vec<u8>>))]
GetBatchReceipts { channel_id: u32, batch_hash: H256 },
#[cfg_attr(feature = "cw-orch-interface", returns(cosmwasm_std::Addr))]
GetClientImpl { client_id: u32 },
#[cfg_attr(feature = "cw-orch-interface", returns(cosmwasm_std::Addr))]
GetRegisteredClientType { client_type: String },
}
29 changes: 29 additions & 0 deletions cosmwasm/ibc-union/core/src/interface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pub const IBC_UNION: &str = "union:ibc-union";

#[cw_orch::interface(
ibc_union_msg::msg::InitMsg,
ibc_union_msg::msg::ExecuteMsg,
ibc_union_msg::query::QueryMsg,
crate::contract::IbcUnionMigrateMsg,
id = IBC_UNION
)]
pub struct IbcUnion<Chain>;

#[cfg(not(target_arch = "wasm32"))]
use cw_orch::prelude::*;

#[cfg(not(target_arch = "wasm32"))]
impl<Chain: CwEnv> Uploadable for IbcUnion<Chain> {
fn wasm(_chain_info: &ChainInfoOwned) -> WasmPath {
artifacts_dir_from_workspace!()
.find_wasm_path("ibc_union")
.unwrap()
}
fn wrapper() -> <Mock as TxHandler>::ContractSource {
Box::new(ContractWrapper::new(
crate::contract::execute,
crate::contract::instantiate,
crate::contract::query,
))
}
}
2 changes: 2 additions & 0 deletions cosmwasm/ibc-union/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![cfg_attr(not(test), warn(clippy::unwrap_used))]

pub mod contract;
#[cfg(feature = "cw-orch-interface")]
pub mod interface;
pub mod state;

#[cfg(test)]
Expand Down

0 comments on commit 4abb9e3

Please sign in to comment.