|
1 |
| -use alloc::borrow::ToOwned; |
2 | 1 | use ibc_types_core_connection::ConnectionId;
|
3 | 2 | use tendermint::abci::{Event, TypedEvent};
|
4 | 3 |
|
| 4 | +use crate::prelude::*; |
5 | 5 | use crate::{ChannelId, PortId, Version};
|
6 | 6 |
|
7 | 7 | use super::Error;
|
@@ -56,23 +56,32 @@ impl TryFrom<Event> for OpenInit {
|
56 | 56 | let mut version = None;
|
57 | 57 |
|
58 | 58 | for attr in event.attributes {
|
59 |
| - match attr.key.as_ref() { |
60 |
| - "port_id" => { |
61 |
| - port_id = Some(PortId(attr.value)); |
| 59 | + match attr.key_bytes() { |
| 60 | + b"port_id" => { |
| 61 | + port_id = Some(PortId(String::from_utf8_lossy(attr.value_bytes()).into())); |
62 | 62 | }
|
63 |
| - "channel_id" => { |
64 |
| - channel_id = Some(ChannelId(attr.value)); |
| 63 | + b"channel_id" => { |
| 64 | + channel_id = Some(ChannelId( |
| 65 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 66 | + )); |
65 | 67 | }
|
66 |
| - "counterparty_port_id" => { |
67 |
| - counterparty_port_id = Some(PortId(attr.value)); |
| 68 | + b"counterparty_port_id" => { |
| 69 | + counterparty_port_id = |
| 70 | + Some(PortId(String::from_utf8_lossy(attr.value_bytes()).into())); |
68 | 71 | }
|
69 |
| - "connection_id" => { |
70 |
| - connection_id = Some(ConnectionId(attr.value)); |
| 72 | + b"connection_id" => { |
| 73 | + connection_id = Some(ConnectionId( |
| 74 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 75 | + )); |
71 | 76 | }
|
72 |
| - "version" => { |
73 |
| - version = Some(Version(attr.value)); |
| 77 | + b"version" => { |
| 78 | + version = Some(Version(String::from_utf8_lossy(attr.value_bytes()).into())); |
| 79 | + } |
| 80 | + unknown => { |
| 81 | + return Err(Error::UnexpectedAttribute( |
| 82 | + String::from_utf8_lossy(unknown).into(), |
| 83 | + )) |
74 | 84 | }
|
75 |
| - unknown => return Err(Error::UnexpectedAttribute(unknown.to_owned())), |
76 | 85 | }
|
77 | 86 | }
|
78 | 87 |
|
@@ -136,26 +145,37 @@ impl TryFrom<Event> for OpenTry {
|
136 | 145 | let mut version = None;
|
137 | 146 |
|
138 | 147 | for attr in event.attributes {
|
139 |
| - match attr.key.as_ref() { |
140 |
| - "port_id" => { |
141 |
| - port_id = Some(PortId(attr.value)); |
| 148 | + match attr.key_bytes() { |
| 149 | + b"port_id" => { |
| 150 | + port_id = Some(PortId(String::from_utf8_lossy(attr.value_bytes()).into())); |
| 151 | + } |
| 152 | + b"channel_id" => { |
| 153 | + channel_id = Some(ChannelId( |
| 154 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 155 | + )); |
142 | 156 | }
|
143 |
| - "channel_id" => { |
144 |
| - channel_id = Some(ChannelId(attr.value)); |
| 157 | + b"counterparty_port_id" => { |
| 158 | + counterparty_port_id = |
| 159 | + Some(PortId(String::from_utf8_lossy(attr.value_bytes()).into())); |
145 | 160 | }
|
146 |
| - "counterparty_port_id" => { |
147 |
| - counterparty_port_id = Some(PortId(attr.value)); |
| 161 | + b"counterparty_channel_id" => { |
| 162 | + counterparty_channel_id = Some(ChannelId( |
| 163 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 164 | + )); |
148 | 165 | }
|
149 |
| - "counterparty_channel_id" => { |
150 |
| - counterparty_channel_id = Some(ChannelId(attr.value)); |
| 166 | + b"connection_id" => { |
| 167 | + connection_id = Some(ConnectionId( |
| 168 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 169 | + )); |
151 | 170 | }
|
152 |
| - "connection_id" => { |
153 |
| - connection_id = Some(ConnectionId(attr.value)); |
| 171 | + b"version" => { |
| 172 | + version = Some(Version(String::from_utf8_lossy(attr.value_bytes()).into())); |
154 | 173 | }
|
155 |
| - "version" => { |
156 |
| - version = Some(Version(attr.value)); |
| 174 | + unknown => { |
| 175 | + return Err(Error::UnexpectedAttribute( |
| 176 | + String::from_utf8_lossy(unknown).into(), |
| 177 | + )) |
157 | 178 | }
|
158 |
| - unknown => return Err(Error::UnexpectedAttribute(unknown.to_owned())), |
159 | 179 | }
|
160 | 180 | }
|
161 | 181 |
|
@@ -218,23 +238,34 @@ impl TryFrom<Event> for OpenAck {
|
218 | 238 | let mut connection_id = None;
|
219 | 239 |
|
220 | 240 | for attr in event.attributes {
|
221 |
| - match attr.key.as_ref() { |
222 |
| - "port_id" => { |
223 |
| - port_id = Some(PortId(attr.value)); |
| 241 | + match attr.key_bytes() { |
| 242 | + b"port_id" => { |
| 243 | + port_id = Some(PortId(String::from_utf8_lossy(attr.value_bytes()).into())); |
| 244 | + } |
| 245 | + b"channel_id" => { |
| 246 | + channel_id = Some(ChannelId( |
| 247 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 248 | + )); |
224 | 249 | }
|
225 |
| - "channel_id" => { |
226 |
| - channel_id = Some(ChannelId(attr.value)); |
| 250 | + b"counterparty_port_id" => { |
| 251 | + counterparty_port_id = |
| 252 | + Some(PortId(String::from_utf8_lossy(attr.value_bytes()).into())); |
227 | 253 | }
|
228 |
| - "counterparty_port_id" => { |
229 |
| - counterparty_port_id = Some(PortId(attr.value)); |
| 254 | + b"counterparty_channel_id" => { |
| 255 | + counterparty_channel_id = Some(ChannelId( |
| 256 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 257 | + )); |
230 | 258 | }
|
231 |
| - "counterparty_channel_id" => { |
232 |
| - counterparty_channel_id = Some(ChannelId(attr.value)); |
| 259 | + b"connection_id" => { |
| 260 | + connection_id = Some(ConnectionId( |
| 261 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 262 | + )); |
233 | 263 | }
|
234 |
| - "connection_id" => { |
235 |
| - connection_id = Some(ConnectionId(attr.value)); |
| 264 | + unknown => { |
| 265 | + return Err(Error::UnexpectedAttribute( |
| 266 | + String::from_utf8_lossy(unknown).into(), |
| 267 | + )) |
236 | 268 | }
|
237 |
| - unknown => return Err(Error::UnexpectedAttribute(unknown.to_owned())), |
238 | 269 | }
|
239 | 270 | }
|
240 | 271 |
|
@@ -296,23 +327,34 @@ impl TryFrom<Event> for OpenConfirm {
|
296 | 327 | let mut connection_id = None;
|
297 | 328 |
|
298 | 329 | for attr in event.attributes {
|
299 |
| - match attr.key.as_ref() { |
300 |
| - "port_id" => { |
301 |
| - port_id = Some(PortId(attr.value)); |
| 330 | + match attr.key_bytes() { |
| 331 | + b"port_id" => { |
| 332 | + port_id = Some(PortId(String::from_utf8_lossy(attr.value_bytes()).into())); |
302 | 333 | }
|
303 |
| - "channel_id" => { |
304 |
| - channel_id = Some(ChannelId(attr.value)); |
| 334 | + b"channel_id" => { |
| 335 | + channel_id = Some(ChannelId( |
| 336 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 337 | + )); |
305 | 338 | }
|
306 |
| - "counterparty_port_id" => { |
307 |
| - counterparty_port_id = Some(PortId(attr.value)); |
| 339 | + b"counterparty_port_id" => { |
| 340 | + counterparty_port_id = |
| 341 | + Some(PortId(String::from_utf8_lossy(attr.value_bytes()).into())); |
308 | 342 | }
|
309 |
| - "counterparty_channel_id" => { |
310 |
| - counterparty_channel_id = Some(ChannelId(attr.value)); |
| 343 | + b"counterparty_channel_id" => { |
| 344 | + counterparty_channel_id = Some(ChannelId( |
| 345 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 346 | + )); |
311 | 347 | }
|
312 |
| - "connection_id" => { |
313 |
| - connection_id = Some(ConnectionId(attr.value)); |
| 348 | + b"connection_id" => { |
| 349 | + connection_id = Some(ConnectionId( |
| 350 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 351 | + )); |
| 352 | + } |
| 353 | + unknown => { |
| 354 | + return Err(Error::UnexpectedAttribute( |
| 355 | + String::from_utf8_lossy(unknown).into(), |
| 356 | + )) |
314 | 357 | }
|
315 |
| - unknown => return Err(Error::UnexpectedAttribute(unknown.to_owned())), |
316 | 358 | }
|
317 | 359 | }
|
318 | 360 |
|
@@ -374,23 +416,34 @@ impl TryFrom<Event> for CloseInit {
|
374 | 416 | let mut connection_id = None;
|
375 | 417 |
|
376 | 418 | for attr in event.attributes {
|
377 |
| - match attr.key.as_ref() { |
378 |
| - "port_id" => { |
379 |
| - port_id = Some(PortId(attr.value)); |
| 419 | + match attr.key_bytes() { |
| 420 | + b"port_id" => { |
| 421 | + port_id = Some(PortId(String::from_utf8_lossy(attr.value_bytes()).into())); |
| 422 | + } |
| 423 | + b"channel_id" => { |
| 424 | + channel_id = Some(ChannelId( |
| 425 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 426 | + )); |
380 | 427 | }
|
381 |
| - "channel_id" => { |
382 |
| - channel_id = Some(ChannelId(attr.value)); |
| 428 | + b"counterparty_port_id" => { |
| 429 | + counterparty_port_id = |
| 430 | + Some(PortId(String::from_utf8_lossy(attr.value_bytes()).into())); |
383 | 431 | }
|
384 |
| - "counterparty_port_id" => { |
385 |
| - counterparty_port_id = Some(PortId(attr.value)); |
| 432 | + b"counterparty_channel_id" => { |
| 433 | + counterparty_channel_id = Some(ChannelId( |
| 434 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 435 | + )); |
386 | 436 | }
|
387 |
| - "counterparty_channel_id" => { |
388 |
| - counterparty_channel_id = Some(ChannelId(attr.value)); |
| 437 | + b"connection_id" => { |
| 438 | + connection_id = Some(ConnectionId( |
| 439 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 440 | + )); |
389 | 441 | }
|
390 |
| - "connection_id" => { |
391 |
| - connection_id = Some(ConnectionId(attr.value)); |
| 442 | + unknown => { |
| 443 | + return Err(Error::UnexpectedAttribute( |
| 444 | + String::from_utf8_lossy(unknown).into(), |
| 445 | + )) |
392 | 446 | }
|
393 |
| - unknown => return Err(Error::UnexpectedAttribute(unknown.to_owned())), |
394 | 447 | }
|
395 | 448 | }
|
396 | 449 |
|
@@ -452,23 +505,34 @@ impl TryFrom<Event> for CloseConfirm {
|
452 | 505 | let mut connection_id = None;
|
453 | 506 |
|
454 | 507 | for attr in event.attributes {
|
455 |
| - match attr.key.as_ref() { |
456 |
| - "port_id" => { |
457 |
| - port_id = Some(PortId(attr.value)); |
| 508 | + match attr.key_bytes() { |
| 509 | + b"port_id" => { |
| 510 | + port_id = Some(PortId(String::from_utf8_lossy(attr.value_bytes()).into())); |
| 511 | + } |
| 512 | + b"channel_id" => { |
| 513 | + channel_id = Some(ChannelId( |
| 514 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 515 | + )); |
458 | 516 | }
|
459 |
| - "channel_id" => { |
460 |
| - channel_id = Some(ChannelId(attr.value)); |
| 517 | + b"counterparty_port_id" => { |
| 518 | + counterparty_port_id = |
| 519 | + Some(PortId(String::from_utf8_lossy(attr.value_bytes()).into())); |
461 | 520 | }
|
462 |
| - "counterparty_port_id" => { |
463 |
| - counterparty_port_id = Some(PortId(attr.value)); |
| 521 | + b"counterparty_channel_id" => { |
| 522 | + counterparty_channel_id = Some(ChannelId( |
| 523 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 524 | + )); |
464 | 525 | }
|
465 |
| - "counterparty_channel_id" => { |
466 |
| - counterparty_channel_id = Some(ChannelId(attr.value)); |
| 526 | + b"connection_id" => { |
| 527 | + connection_id = Some(ConnectionId( |
| 528 | + String::from_utf8_lossy(attr.value_bytes()).into(), |
| 529 | + )); |
467 | 530 | }
|
468 |
| - "connection_id" => { |
469 |
| - connection_id = Some(ConnectionId(attr.value)); |
| 531 | + unknown => { |
| 532 | + return Err(Error::UnexpectedAttribute( |
| 533 | + String::from_utf8_lossy(unknown).into(), |
| 534 | + )) |
470 | 535 | }
|
471 |
| - unknown => return Err(Error::UnexpectedAttribute(unknown.to_owned())), |
472 | 536 | }
|
473 | 537 | }
|
474 | 538 |
|
|
0 commit comments