Skip to content

Commit fba1aca

Browse files
authored
Add parity-scale-codec and borsh for IbcEvent (#321)
* add parity-scale-codec and borsh for IbcEvent * Create 320-add-borsh-and-scale-codec-for-ibcevent.md * Update no-std-check ibc-proto dep * Add patch ibc-proto for no-std-check * Update ibc-proto patch * Update Cargo.toml * Update ibc-proto version and Add serde feature Signed-off-by: Davirain <[email protected]>
1 parent 264b5be commit fba1aca

File tree

12 files changed

+633
-61
lines changed

12 files changed

+633
-61
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add parity-scale-codec and borsh for ibc::events::IbcEvent
2+
([#320](https://github.com/cosmos/ibc-rs/issues/320))

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ members = [
88

99
exclude = [
1010
"ci/no-std-check",
11-
]
11+
]

ci/no-std-check/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ resolver = "2"
66

77
[dependencies]
88
ibc = { path = "../../crates/ibc", default-features = false, features = ["mocks-no-std"] }
9-
ibc-proto = { version = "0.24.0", default-features = false }
9+
ibc-proto = { version = "0.24.1", default-features = false, features = ["parity-scale-codec", "borsh"]}
1010
tendermint = { version = "0.28.0", default-features = false }
1111
tendermint-proto = { version = "0.28.0", default-features = false }
1212
tendermint-light-client-verifier = { version = "0.28.0", default-features = false }
@@ -29,4 +29,4 @@ substrate-std = [
2929
"sp-io/std",
3030
"sp-runtime/std",
3131
"sp-std/std",
32-
]
32+
]

crates/ibc/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ val_exec_ctx = []
4646
# Depends on the `testgen` suite for generating Tendermint light blocks.
4747
mocks = ["tendermint-testgen", "tendermint/clock", "cfg-if", "parking_lot"]
4848
mocks-no-std = ["cfg-if"]
49+
serde = []
4950

5051
[dependencies]
5152
# Proto definitions for all IBC-related interfaces, e.g., connections or channels.
52-
ibc-proto = { version = "0.24.0", default-features = false }
53+
ibc-proto = { version = "0.24.1", default-features = false, features = ["parity-scale-codec", "borsh"] }
5354
ics23 = { version = "0.9.0", default-features = false, features = ["host-functions"] }
5455
time = { version = ">=0.3.0, <0.3.18", default-features = false }
5556
serde_derive = { version = "1.0.104", default-features = false }

crates/ibc/src/core/ics02_client/events.rs

Lines changed: 126 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,20 @@ pub const CONSENSUS_HEIGHTS_ATTRIBUTE_KEY: &str = "consensus_heights";
2525
/// The content of the `key` field for the header in update client event.
2626
pub const HEADER_ATTRIBUTE_KEY: &str = "header";
2727

28-
#[derive(Debug, From)]
28+
#[cfg_attr(
29+
feature = "parity-scale-codec",
30+
derive(
31+
parity_scale_codec::Encode,
32+
parity_scale_codec::Decode,
33+
scale_info::TypeInfo
34+
)
35+
)]
36+
#[cfg_attr(
37+
feature = "borsh",
38+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
39+
)]
40+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
41+
#[derive(Clone, Debug, From, PartialEq, Eq)]
2942
struct ClientIdAttribute {
3043
client_id: ClientId,
3144
}
@@ -36,7 +49,20 @@ impl From<ClientIdAttribute> for abci::EventAttribute {
3649
}
3750
}
3851

39-
#[derive(Debug, From)]
52+
#[cfg_attr(
53+
feature = "parity-scale-codec",
54+
derive(
55+
parity_scale_codec::Encode,
56+
parity_scale_codec::Decode,
57+
scale_info::TypeInfo
58+
)
59+
)]
60+
#[cfg_attr(
61+
feature = "borsh",
62+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
63+
)]
64+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
65+
#[derive(Clone, Debug, From, PartialEq, Eq)]
4066
struct ClientTypeAttribute {
4167
client_type: ClientType,
4268
}
@@ -47,7 +73,20 @@ impl From<ClientTypeAttribute> for abci::EventAttribute {
4773
}
4874
}
4975

50-
#[derive(Debug, From)]
76+
#[cfg_attr(
77+
feature = "parity-scale-codec",
78+
derive(
79+
parity_scale_codec::Encode,
80+
parity_scale_codec::Decode,
81+
scale_info::TypeInfo
82+
)
83+
)]
84+
#[cfg_attr(
85+
feature = "borsh",
86+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
87+
)]
88+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
89+
#[derive(Clone, Debug, From, PartialEq, Eq)]
5190
struct ConsensusHeightAttribute {
5291
consensus_height: Height,
5392
}
@@ -58,7 +97,20 @@ impl From<ConsensusHeightAttribute> for abci::EventAttribute {
5897
}
5998
}
6099

61-
#[derive(Debug, From)]
100+
#[cfg_attr(
101+
feature = "parity-scale-codec",
102+
derive(
103+
parity_scale_codec::Encode,
104+
parity_scale_codec::Decode,
105+
scale_info::TypeInfo
106+
)
107+
)]
108+
#[cfg_attr(
109+
feature = "borsh",
110+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
111+
)]
112+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
113+
#[derive(Clone, Debug, From, PartialEq, Eq)]
62114
struct ConsensusHeightsAttribute {
63115
consensus_heights: Vec<Height>,
64116
}
@@ -74,7 +126,20 @@ impl From<ConsensusHeightsAttribute> for abci::EventAttribute {
74126
}
75127
}
76128

77-
#[derive(Debug, From)]
129+
#[cfg_attr(
130+
feature = "parity-scale-codec",
131+
derive(
132+
parity_scale_codec::Encode,
133+
parity_scale_codec::Decode,
134+
scale_info::TypeInfo
135+
)
136+
)]
137+
#[cfg_attr(
138+
feature = "borsh",
139+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
140+
)]
141+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
142+
#[derive(Clone, Debug, From, PartialEq, Eq)]
78143
struct HeaderAttribute {
79144
header: Any,
80145
}
@@ -90,7 +155,20 @@ impl From<HeaderAttribute> for abci::EventAttribute {
90155
}
91156

92157
/// CreateClient event signals the creation of a new on-chain client (IBC client).
93-
#[derive(Debug)]
158+
#[cfg_attr(
159+
feature = "parity-scale-codec",
160+
derive(
161+
parity_scale_codec::Encode,
162+
parity_scale_codec::Decode,
163+
scale_info::TypeInfo
164+
)
165+
)]
166+
#[cfg_attr(
167+
feature = "borsh",
168+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
169+
)]
170+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
171+
#[derive(Clone, Debug, PartialEq, Eq)]
94172
pub struct CreateClient {
95173
client_id: ClientIdAttribute,
96174
client_type: ClientTypeAttribute,
@@ -133,7 +211,20 @@ impl From<CreateClient> for abci::Event {
133211
}
134212

135213
/// UpdateClient event signals a recent update of an on-chain client (IBC Client).
136-
#[derive(Debug)]
214+
#[cfg_attr(
215+
feature = "parity-scale-codec",
216+
derive(
217+
parity_scale_codec::Encode,
218+
parity_scale_codec::Decode,
219+
scale_info::TypeInfo
220+
)
221+
)]
222+
#[cfg_attr(
223+
feature = "borsh",
224+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
225+
)]
226+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
227+
#[derive(Clone, Debug, PartialEq, Eq)]
137228
pub struct UpdateClient {
138229
client_id: ClientIdAttribute,
139230
client_type: ClientTypeAttribute,
@@ -199,7 +290,20 @@ impl From<UpdateClient> for abci::Event {
199290

200291
/// ClientMisbehaviour event signals the update of an on-chain client (IBC Client) with evidence of
201292
/// misbehaviour.
202-
#[derive(Debug)]
293+
#[cfg_attr(
294+
feature = "parity-scale-codec",
295+
derive(
296+
parity_scale_codec::Encode,
297+
parity_scale_codec::Decode,
298+
scale_info::TypeInfo
299+
)
300+
)]
301+
#[cfg_attr(
302+
feature = "borsh",
303+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
304+
)]
305+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
306+
#[derive(Clone, Debug, PartialEq, Eq)]
203307
pub struct ClientMisbehaviour {
204308
client_id: ClientIdAttribute,
205309
client_type: ClientTypeAttribute,
@@ -232,7 +336,20 @@ impl From<ClientMisbehaviour> for abci::Event {
232336
}
233337

234338
/// Signals a recent upgrade of an on-chain client (IBC Client).
235-
#[derive(Debug)]
339+
#[cfg_attr(
340+
feature = "parity-scale-codec",
341+
derive(
342+
parity_scale_codec::Encode,
343+
parity_scale_codec::Decode,
344+
scale_info::TypeInfo
345+
)
346+
)]
347+
#[cfg_attr(
348+
feature = "borsh",
349+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
350+
)]
351+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
352+
#[derive(Clone, Debug, PartialEq, Eq)]
236353
pub struct UpgradeClient {
237354
client_id: ClientIdAttribute,
238355
client_type: ClientTypeAttribute,

crates/ibc/src/core/ics03_connection/events.rs

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Types for the IBC events emitted from Tendermint Websocket by the connection module.
22
3-
use serde_derive::{Deserialize, Serialize};
43
use tendermint::abci;
54

65
use crate::core::ics24_host::identifier::{ClientId, ConnectionId};
@@ -13,7 +12,20 @@ pub const CLIENT_ID_ATTRIBUTE_KEY: &str = "client_id";
1312
pub const COUNTERPARTY_CONN_ID_ATTRIBUTE_KEY: &str = "counterparty_connection_id";
1413
pub const COUNTERPARTY_CLIENT_ID_ATTRIBUTE_KEY: &str = "counterparty_client_id";
1514

16-
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
15+
#[cfg_attr(
16+
feature = "parity-scale-codec",
17+
derive(
18+
parity_scale_codec::Encode,
19+
parity_scale_codec::Decode,
20+
scale_info::TypeInfo
21+
)
22+
)]
23+
#[cfg_attr(
24+
feature = "borsh",
25+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
26+
)]
27+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
28+
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
1729
struct Attributes {
1830
pub connection_id: ConnectionId,
1931
pub client_id: ClientId,
@@ -51,7 +63,20 @@ impl From<Attributes> for Vec<abci::EventAttribute> {
5163
}
5264
}
5365

54-
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
66+
#[cfg_attr(
67+
feature = "parity-scale-codec",
68+
derive(
69+
parity_scale_codec::Encode,
70+
parity_scale_codec::Decode,
71+
scale_info::TypeInfo
72+
)
73+
)]
74+
#[cfg_attr(
75+
feature = "borsh",
76+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
77+
)]
78+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
79+
#[derive(Clone, Debug, PartialEq, Eq)]
5580
pub struct OpenInit(Attributes);
5681

5782
impl OpenInit {
@@ -92,7 +117,20 @@ impl From<OpenInit> for abci::Event {
92117
}
93118
}
94119

95-
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
120+
#[cfg_attr(
121+
feature = "parity-scale-codec",
122+
derive(
123+
parity_scale_codec::Encode,
124+
parity_scale_codec::Decode,
125+
scale_info::TypeInfo
126+
)
127+
)]
128+
#[cfg_attr(
129+
feature = "borsh",
130+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
131+
)]
132+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
133+
#[derive(Clone, Debug, PartialEq, Eq)]
96134
pub struct OpenTry(Attributes);
97135

98136
impl OpenTry {
@@ -133,8 +171,20 @@ impl From<OpenTry> for abci::Event {
133171
}
134172
}
135173
}
136-
137-
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
174+
#[cfg_attr(
175+
feature = "parity-scale-codec",
176+
derive(
177+
parity_scale_codec::Encode,
178+
parity_scale_codec::Decode,
179+
scale_info::TypeInfo
180+
)
181+
)]
182+
#[cfg_attr(
183+
feature = "borsh",
184+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
185+
)]
186+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
187+
#[derive(Clone, Debug, PartialEq, Eq)]
138188
pub struct OpenAck(Attributes);
139189

140190
impl OpenAck {
@@ -176,7 +226,20 @@ impl From<OpenAck> for abci::Event {
176226
}
177227
}
178228

179-
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
229+
#[cfg_attr(
230+
feature = "parity-scale-codec",
231+
derive(
232+
parity_scale_codec::Encode,
233+
parity_scale_codec::Decode,
234+
scale_info::TypeInfo
235+
)
236+
)]
237+
#[cfg_attr(
238+
feature = "borsh",
239+
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
240+
)]
241+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
242+
#[derive(Clone, Debug, PartialEq, Eq)]
180243
pub struct OpenConfirm(Attributes);
181244

182245
impl OpenConfirm {

0 commit comments

Comments
 (0)