Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1efa953

Browse files
committedJan 15, 2025··
Compiles and nits done
1 parent 2b8f4ba commit 1efa953

File tree

11 files changed

+148
-24
lines changed

11 files changed

+148
-24
lines changed
 

‎Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ tracing = { version = "0.1.40", default-features = false }
338338
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "ansi"] }
339339
typenum = { version = "1.17.0", default-features = false }
340340

341+
cw-orch = "0.27.0"
342+
341343
[patch."crates-io"]
342344
arbitrary = { git = "https://github.com/unionlabs/arbitrary" }
343345
# parity-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" }

‎cosmwasm/ibc-union/core/Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ workspace = true
1313
crate-type = ["cdylib", "rlib"]
1414

1515
[features]
16-
library = []
16+
cw-orch-interface = ["dep:cosmwasm-schema", "dep:cw-orch"]
17+
library = []
1718

1819
[dependencies]
1920
alloy = { workspace = true, features = ["sol-types"] }
@@ -28,5 +29,6 @@ serde_json = { workspace = true }
2829
strum = { version = "0.26.3", features = ["derive"] }
2930
thiserror = { workspace = true }
3031
unionlabs = { workspace = true, features = ["ethabi"] }
31-
cw-orch = "0.27.0"
32-
cosmwasm-schema = { workspace = true }
32+
33+
cosmwasm-schema = { workspace = true, optional = true }
34+
cw-orch = { workspace = true, optional = true }

‎cosmwasm/ibc-union/core/msg/Cargo.toml

+17-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,24 @@ version = "1.0.0"
99
[lints]
1010
workspace = true
1111

12+
[features]
13+
cw-orch-interface = [
14+
"dep:cw-orch",
15+
"dep:schemars",
16+
"dep:cosmwasm-std",
17+
"dep:cosmwasm-schema",
18+
"unionlabs-primitives/schemars",
19+
"ibc-solidity/schemars",
20+
]
21+
schemars = []
22+
1223
[dependencies]
1324
ibc-solidity = { workspace = true, features = ["serde"] }
1425
serde = { workspace = true, features = ["derive"] }
1526
unionlabs-primitives = { workspace = true, features = ["serde"] }
16-
cosmwasm-std = { workspace = true }
17-
cosmwasm-schema = { workspace = true }
18-
cw-orch = "0.27.0"
27+
28+
29+
cosmwasm-schema = { workspace = true, optional = true }
30+
cosmwasm-std = { workspace = true, optional = true }
31+
cw-orch = { workspace = true, optional = true }
32+
schemars = { workspace = true, optional = true }

‎cosmwasm/ibc-union/core/msg/src/lightclient.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use unionlabs_primitives::Bytes;
22

33
#[derive(serde::Serialize, serde::Deserialize, Debug)]
4+
#[cfg_attr(feature = "cw-orch-interface", derive(schemars::JsonSchema))]
45
#[serde(deny_unknown_fields, rename_all = "snake_case")]
56
pub enum Status {
67
Active,

‎cosmwasm/ibc-union/core/msg/src/msg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct MsgRegisterClient {
1414

1515
#[derive(Debug, serde::Serialize, serde::Deserialize)]
1616
#[serde(deny_unknown_fields, rename_all = "snake_case")]
17-
#[derive(cw_orch::ExecuteFns)] // cw-orch automatic
17+
#[cfg_attr(feature = "cw-orch-interface", derive(cw_orch::ExecuteFns))]
1818
pub enum ExecuteMsg {
1919
RegisterClient(MsgRegisterClient),
2020
CreateClient(MsgCreateClient),

‎cosmwasm/ibc-union/core/msg/src/query.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,35 @@ use unionlabs_primitives::H256;
22

33
#[derive(serde::Serialize, serde::Deserialize)]
44
#[serde(deny_unknown_fields, rename_all = "snake_case")]
5-
#[derive(cosmwasm_schema::QueryResponses, cw_orch::QueryFns)]
5+
#[cfg_attr(
6+
feature = "cw-orch-interface",
7+
derive(
8+
cosmwasm_schema::QueryResponses,
9+
cw_orch::QueryFns,
10+
schemars::JsonSchema
11+
)
12+
)]
613
pub enum QueryMsg {
7-
#[returns(u64)]
14+
#[cfg_attr(feature = "cw-orch-interface", returns(u64))]
815
GetTimestampAtHeight { client_id: u32, height: u64 },
9-
#[returns(u64)]
16+
#[cfg_attr(feature = "cw-orch-interface", returns(u64))]
1017
GetLatestHeight { client_id: u32 },
11-
#[returns(cosmwasm_std::Binary)]
18+
#[cfg_attr(feature = "cw-orch-interface", returns(cosmwasm_std::Binary))]
1219
GetClientState { client_id: u32 },
13-
#[returns(cosmwasm_std::Binary)]
20+
#[cfg_attr(feature = "cw-orch-interface", returns(cosmwasm_std::Binary))]
1421
GetConsensusState { client_id: u32, height: u64 },
15-
#[returns(crate::lightclient::Status)]
22+
#[cfg_attr(feature = "cw-orch-interface", returns(crate::lightclient::Status))]
1623
GetStatus { client_id: u32 },
17-
#[returns(u64)]
24+
#[cfg_attr(feature = "cw-orch-interface", returns(u64))]
1825
GetClientType { client_id: u32 },
19-
#[returns(ibc_solidity::Connection)]
26+
#[cfg_attr(feature = "cw-orch-interface", returns(ibc_solidity::Connection))]
2027
GetConnection { connection_id: u32 },
21-
#[returns(ibc_solidity::Channel)]
28+
#[cfg_attr(feature = "cw-orch-interface", returns(ibc_solidity::Channel))]
2229
GetChannel { channel_id: u32 },
23-
#[returns(BTreeSet<u32>)]
30+
#[cfg_attr(feature = "cw-orch-interface", returns(std::collections::BTreeSet<u32>))]
2431
GetChannels { contract: String },
25-
#[returns(Option<H256>)]
32+
#[cfg_attr(feature = "cw-orch-interface", returns(Option<Vec<u8>>))]
2633
GetBatchPackets { channel_id: u32, batch_hash: H256 },
27-
#[returns(Option<H256>)]
34+
#[cfg_attr(feature = "cw-orch-interface", returns(Option<Vec<u8>>))]
2835
GetBatchReceipts { channel_id: u32, batch_hash: H256 },
2936
}

‎cosmwasm/ibc-union/core/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#![cfg_attr(not(test), warn(clippy::unwrap_used))]
22

33
pub mod contract;
4-
pub mod state;
4+
#[cfg(feature = "cw-orch-interface")]
55
pub mod interface;
6+
pub mod state;
67

78
use cosmwasm_std::{Addr, StdError};
89
use ibc_solidity::{ChannelState, ConnectionState};

‎lib/ibc-solidity/src/lib.rs

+67
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ maybe_sol_attr! {
344344
feature = "serde", derive(serde::Serialize, serde::Deserialize),
345345
serde(deny_unknown_fields)
346346
)]
347+
#[cfg_attr(
348+
feature = "schemars", derive(schemars::JsonSchema),
349+
)]
347350
enum ConnectionState {
348351
Unspecified,
349352
Init,
@@ -355,6 +358,9 @@ maybe_sol_attr! {
355358
feature = "serde", derive(serde::Serialize, serde::Deserialize),
356359
serde(deny_unknown_fields)
357360
)]
361+
#[cfg_attr(
362+
feature = "schemars", derive(schemars::JsonSchema),
363+
)]
358364
struct Connection {
359365
ConnectionState state;
360366
uint32 client_id;
@@ -366,6 +372,9 @@ maybe_sol_attr! {
366372
feature = "serde", derive(serde::Serialize, serde::Deserialize),
367373
serde(deny_unknown_fields)
368374
)]
375+
#[cfg_attr(
376+
feature = "schemars", derive(schemars::JsonSchema),
377+
)]
369378
enum ChannelState {
370379
Unspecified,
371380
Init,
@@ -613,6 +622,64 @@ maybe_sol_attr! {
613622
}
614623
}
615624

625+
#[cfg(feature = "schemars")]
626+
/// We need a custom implementation because alloy::Bytes doesn't implement JsonSchema
627+
impl schemars::JsonSchema for Channel {
628+
fn schema_name() -> String {
629+
"Channel".to_string()
630+
}
631+
fn schema_id() -> std::borrow::Cow<'static, str> {
632+
std::borrow::Cow::Borrowed("ibc_solidity::Channel")
633+
}
634+
635+
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
636+
let mut schema_object = schemars::schema::SchemaObject {
637+
instance_type: Some(schemars::schema::InstanceType::Object.into()),
638+
..Default::default()
639+
};
640+
let object_validation = schema_object.object();
641+
{
642+
schemars::_private::insert_object_property::<ChannelState>(
643+
object_validation,
644+
"state",
645+
false,
646+
true,
647+
gen.subschema_for::<ChannelState>(),
648+
);
649+
schemars::_private::insert_object_property::<u32>(
650+
object_validation,
651+
"connection_id",
652+
false,
653+
true,
654+
gen.subschema_for::<u32>(),
655+
);
656+
schemars::_private::insert_object_property::<u32>(
657+
object_validation,
658+
"counterparty_channel_id",
659+
false,
660+
true,
661+
gen.subschema_for::<u32>(),
662+
);
663+
schemars::_private::insert_object_property::<Vec<u8>>(
664+
object_validation,
665+
"counterparty_port_id",
666+
false,
667+
true,
668+
gen.subschema_for::<Vec<u8>>(),
669+
);
670+
schemars::_private::insert_object_property::<String>(
671+
object_validation,
672+
"version",
673+
false,
674+
true,
675+
gen.subschema_for::<String>(),
676+
);
677+
}
678+
679+
schemars::schema::Schema::Object(schema_object)
680+
}
681+
}
682+
616683
impl Clone for Ibc::IbcEvents {
617684
fn clone(&self) -> Self {
618685
match self {

‎lib/unionlabs-primitives/Cargo.toml

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ generic-array = { workspace = true, optional = true }
1313
hex = { workspace = true, features = ["std"] }
1414
primitive-types = { workspace = true, optional = true }
1515
rlp = { workspace = true, optional = true }
16+
schemars = { workspace = true, optional = true }
1617
serde = { workspace = true, features = ["derive"], optional = true }
1718
serde_bytes = { version = "0.11.15", optional = true }
1819
thiserror = { workspace = true }
@@ -24,10 +25,11 @@ workspace = true
2425
[features]
2526
default = ["serde", "base64"]
2627

27-
base64 = ["dep:base64"]
28-
bincode = ["dep:bincode"]
29-
rlp = ["dep:rlp"]
30-
serde = ["dep:serde", "dep:serde_bytes"]
28+
base64 = ["dep:base64"]
29+
bincode = ["dep:bincode"]
30+
rlp = ["dep:rlp"]
31+
schemars = ["dep:schemars"]
32+
serde = ["dep:serde", "dep:serde_bytes"]
3133

3234
alloy-primitives-compat = ["dep:alloy-primitives"]
3335
generic-array-compat = ["dep:generic-array", "dep:typenum", "typenum/const-generics"]

‎lib/unionlabs-primitives/src/fixed_bytes.rs

+26
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,32 @@ impl<'de, const BYTES: usize, E: Encoding> serde::Deserialize<'de> for FixedByte
236236
}
237237
}
238238

239+
#[cfg(feature = "schemars")]
240+
impl<const BYTES: usize, E: Encoding> schemars::JsonSchema for FixedBytes<BYTES, E> {
241+
fn schema_name() -> String {
242+
"Hash".to_string()
243+
}
244+
245+
/// The `FixedBytes` object is serialized as an array in JSON
246+
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
247+
let mut schema_object = schemars::schema::SchemaObject {
248+
instance_type: Some(schemars::schema::InstanceType::Array.into()),
249+
..Default::default()
250+
};
251+
252+
schema_object.array = Some(Box::new(schemars::schema::ArrayValidation {
253+
items: Some(schemars::schema::SingleOrVec::Single(Box::new(
254+
gen.subschema_for::<u8>(),
255+
))),
256+
min_items: Some(BYTES.try_into().unwrap()),
257+
max_items: Some(BYTES.try_into().unwrap()),
258+
..Default::default()
259+
}));
260+
261+
schemars::schema::Schema::Object(schema_object)
262+
}
263+
}
264+
239265
impl<const BYTES: usize, E: Encoding> FromStr for FixedBytes<BYTES, E> {
240266
type Err = E::Error;
241267

0 commit comments

Comments
 (0)
Please sign in to comment.