Skip to content

Commit

Permalink
Compiles and nits done
Browse files Browse the repository at this point in the history
  • Loading branch information
Kayanski committed Jan 15, 2025
1 parent 2b8f4ba commit 1efa953
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 24 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,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
8 changes: 5 additions & 3 deletions cosmwasm/ibc-union/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ workspace = true
crate-type = ["cdylib", "rlib"]

[features]
library = []
cw-orch-interface = ["dep:cosmwasm-schema", "dep:cw-orch"]
library = []

[dependencies]
alloy = { workspace = true, features = ["sol-types"] }
Expand All @@ -28,5 +29,6 @@ serde_json = { workspace = true }
strum = { version = "0.26.3", features = ["derive"] }
thiserror = { workspace = true }
unionlabs = { workspace = true, features = ["ethabi"] }
cw-orch = "0.27.0"
cosmwasm-schema = { workspace = true }

cosmwasm-schema = { workspace = true, optional = true }
cw-orch = { workspace = true, optional = true }
20 changes: 17 additions & 3 deletions cosmwasm/ibc-union/core/msg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,24 @@ version = "1.0.0"
[lints]
workspace = true

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

[dependencies]
ibc-solidity = { workspace = true, features = ["serde"] }
serde = { workspace = true, features = ["derive"] }
unionlabs-primitives = { workspace = true, features = ["serde"] }
cosmwasm-std = { workspace = true }
cosmwasm-schema = { workspace = true }
cw-orch = "0.27.0"


cosmwasm-schema = { workspace = true, optional = true }
cosmwasm-std = { workspace = true, optional = true }
cw-orch = { workspace = true, optional = true }
schemars = { workspace = true, optional = true }
1 change: 1 addition & 0 deletions 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, Debug)]
#[cfg_attr(feature = "cw-orch-interface", derive(schemars::JsonSchema))]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
pub enum Status {
Active,
Expand Down
2 changes: 1 addition & 1 deletion cosmwasm/ibc-union/core/msg/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct MsgRegisterClient {

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

#[derive(serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields, rename_all = "snake_case")]
#[derive(cosmwasm_schema::QueryResponses, cw_orch::QueryFns)]
#[cfg_attr(
feature = "cw-orch-interface",
derive(
cosmwasm_schema::QueryResponses,
cw_orch::QueryFns,
schemars::JsonSchema
)
)]
pub enum QueryMsg {
#[returns(u64)]
#[cfg_attr(feature = "cw-orch-interface", returns(u64))]
GetTimestampAtHeight { client_id: u32, height: u64 },
#[returns(u64)]
#[cfg_attr(feature = "cw-orch-interface", returns(u64))]
GetLatestHeight { client_id: u32 },
#[returns(cosmwasm_std::Binary)]
#[cfg_attr(feature = "cw-orch-interface", returns(cosmwasm_std::Binary))]
GetClientState { client_id: u32 },
#[returns(cosmwasm_std::Binary)]
#[cfg_attr(feature = "cw-orch-interface", returns(cosmwasm_std::Binary))]
GetConsensusState { client_id: u32, height: u64 },
#[returns(crate::lightclient::Status)]
#[cfg_attr(feature = "cw-orch-interface", returns(crate::lightclient::Status))]
GetStatus { client_id: u32 },
#[returns(u64)]
#[cfg_attr(feature = "cw-orch-interface", returns(u64))]
GetClientType { client_id: u32 },
#[returns(ibc_solidity::Connection)]
#[cfg_attr(feature = "cw-orch-interface", returns(ibc_solidity::Connection))]
GetConnection { connection_id: u32 },
#[returns(ibc_solidity::Channel)]
#[cfg_attr(feature = "cw-orch-interface", returns(ibc_solidity::Channel))]
GetChannel { channel_id: u32 },
#[returns(BTreeSet<u32>)]
#[cfg_attr(feature = "cw-orch-interface", returns(std::collections::BTreeSet<u32>))]
GetChannels { contract: String },
#[returns(Option<H256>)]
#[cfg_attr(feature = "cw-orch-interface", returns(Option<Vec<u8>>))]
GetBatchPackets { channel_id: u32, batch_hash: H256 },
#[returns(Option<H256>)]
#[cfg_attr(feature = "cw-orch-interface", returns(Option<Vec<u8>>))]
GetBatchReceipts { channel_id: u32, batch_hash: H256 },
}
3 changes: 2 additions & 1 deletion cosmwasm/ibc-union/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#![cfg_attr(not(test), warn(clippy::unwrap_used))]

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

use cosmwasm_std::{Addr, StdError};
use ibc_solidity::{ChannelState, ConnectionState};
Expand Down
67 changes: 67 additions & 0 deletions lib/ibc-solidity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ maybe_sol_attr! {
feature = "serde", derive(serde::Serialize, serde::Deserialize),
serde(deny_unknown_fields)
)]
#[cfg_attr(
feature = "schemars", derive(schemars::JsonSchema),
)]
enum ConnectionState {
Unspecified,
Init,
Expand All @@ -355,6 +358,9 @@ maybe_sol_attr! {
feature = "serde", derive(serde::Serialize, serde::Deserialize),
serde(deny_unknown_fields)
)]
#[cfg_attr(
feature = "schemars", derive(schemars::JsonSchema),
)]
struct Connection {
ConnectionState state;
uint32 client_id;
Expand All @@ -366,6 +372,9 @@ maybe_sol_attr! {
feature = "serde", derive(serde::Serialize, serde::Deserialize),
serde(deny_unknown_fields)
)]
#[cfg_attr(
feature = "schemars", derive(schemars::JsonSchema),
)]
enum ChannelState {
Unspecified,
Init,
Expand Down Expand Up @@ -613,6 +622,64 @@ maybe_sol_attr! {
}
}

#[cfg(feature = "schemars")]
/// We need a custom implementation because alloy::Bytes doesn't implement JsonSchema
impl schemars::JsonSchema for Channel {
fn schema_name() -> String {
"Channel".to_string()
}
fn schema_id() -> std::borrow::Cow<'static, str> {
std::borrow::Cow::Borrowed("ibc_solidity::Channel")
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
let mut schema_object = schemars::schema::SchemaObject {
instance_type: Some(schemars::schema::InstanceType::Object.into()),
..Default::default()
};
let object_validation = schema_object.object();
{
schemars::_private::insert_object_property::<ChannelState>(
object_validation,
"state",
false,
true,
gen.subschema_for::<ChannelState>(),
);
schemars::_private::insert_object_property::<u32>(
object_validation,
"connection_id",
false,
true,
gen.subschema_for::<u32>(),
);
schemars::_private::insert_object_property::<u32>(
object_validation,
"counterparty_channel_id",
false,
true,
gen.subschema_for::<u32>(),
);
schemars::_private::insert_object_property::<Vec<u8>>(
object_validation,
"counterparty_port_id",
false,
true,
gen.subschema_for::<Vec<u8>>(),
);
schemars::_private::insert_object_property::<String>(
object_validation,
"version",
false,
true,
gen.subschema_for::<String>(),
);
}

schemars::schema::Schema::Object(schema_object)
}
}

impl Clone for Ibc::IbcEvents {
fn clone(&self) -> Self {
match self {
Expand Down
10 changes: 6 additions & 4 deletions lib/unionlabs-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ generic-array = { workspace = true, optional = true }
hex = { workspace = true, features = ["std"] }
primitive-types = { workspace = true, optional = true }
rlp = { workspace = true, optional = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"], optional = true }
serde_bytes = { version = "0.11.15", optional = true }
thiserror = { workspace = true }
Expand All @@ -24,10 +25,11 @@ workspace = true
[features]
default = ["serde", "base64"]

base64 = ["dep:base64"]
bincode = ["dep:bincode"]
rlp = ["dep:rlp"]
serde = ["dep:serde", "dep:serde_bytes"]
base64 = ["dep:base64"]
bincode = ["dep:bincode"]
rlp = ["dep:rlp"]
schemars = ["dep:schemars"]
serde = ["dep:serde", "dep:serde_bytes"]

alloy-primitives-compat = ["dep:alloy-primitives"]
generic-array-compat = ["dep:generic-array", "dep:typenum", "typenum/const-generics"]
Expand Down
26 changes: 26 additions & 0 deletions lib/unionlabs-primitives/src/fixed_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,32 @@ impl<'de, const BYTES: usize, E: Encoding> serde::Deserialize<'de> for FixedByte
}
}

#[cfg(feature = "schemars")]
impl<const BYTES: usize, E: Encoding> schemars::JsonSchema for FixedBytes<BYTES, E> {
fn schema_name() -> String {
"Hash".to_string()
}

/// The `FixedBytes` object is serialized as an array in JSON
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
let mut schema_object = schemars::schema::SchemaObject {
instance_type: Some(schemars::schema::InstanceType::Array.into()),
..Default::default()
};

schema_object.array = Some(Box::new(schemars::schema::ArrayValidation {
items: Some(schemars::schema::SingleOrVec::Single(Box::new(
gen.subschema_for::<u8>(),
))),
min_items: Some(BYTES.try_into().unwrap()),
max_items: Some(BYTES.try_into().unwrap()),
..Default::default()
}));

schemars::schema::Schema::Object(schema_object)
}
}

impl<const BYTES: usize, E: Encoding> FromStr for FixedBytes<BYTES, E> {
type Err = E::Error;

Expand Down

0 comments on commit 1efa953

Please sign in to comment.