From 38ee7a4b30bbdcbfb8ac1a085c672a296a29b016 Mon Sep 17 00:00:00 2001 From: Jongwhan Lee <51560997+leejw51crypto@users.noreply.github.com> Date: Sat, 1 May 2021 01:18:40 +0800 Subject: [PATCH 1/3] Solution: use the last digit (fix #878) (#879) use expect Co-authored-by: jongwhan lee --- modules/src/ics24_host/identifier.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/ics24_host/identifier.rs b/modules/src/ics24_host/identifier.rs index 9d178d7fd2..b426f31a41 100644 --- a/modules/src/ics24_host/identifier.rs +++ b/modules/src/ics24_host/identifier.rs @@ -59,7 +59,7 @@ impl ChainId { } let split: Vec<_> = chain_id.split('-').collect(); - split[1].parse().unwrap_or(0) + split.last().expect("get revision number from chain_id").parse().unwrap_or(0) } /// is_epoch_format() checks if a chain_id is in the format required for parsing epochs From 4b299973a8f1ff8d40841d08a86957fe2f72a640 Mon Sep 17 00:00:00 2001 From: Adi Seredinschi Date: Fri, 30 Apr 2021 19:35:09 +0200 Subject: [PATCH 2/3] Doc tests and FMT --- modules/src/ics24_host/identifier.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/src/ics24_host/identifier.rs b/modules/src/ics24_host/identifier.rs index b426f31a41..cf6b969c29 100644 --- a/modules/src/ics24_host/identifier.rs +++ b/modules/src/ics24_host/identifier.rs @@ -53,13 +53,25 @@ impl ChainId { } /// Extract the version from the given chain identifier. + /// ``` + /// use ibc::ics24_host::identifier::ChainId; + /// + /// assert_eq!(ChainId::chain_version("chain--a-0"), 0); + /// assert_eq!(ChainId::chain_version("ibc-10"), 10); + /// assert_eq!(ChainId::chain_version("cosmos-hub-97"), 97); + /// assert_eq!(ChainId::chain_version("testnet-helloworld-2"), 2); + /// ``` pub fn chain_version(chain_id: &str) -> u64 { if !ChainId::is_epoch_format(chain_id) { return 0; } let split: Vec<_> = chain_id.split('-').collect(); - split.last().expect("get revision number from chain_id").parse().unwrap_or(0) + split + .last() + .expect("get revision number from chain_id") + .parse() + .unwrap_or(0) } /// is_epoch_format() checks if a chain_id is in the format required for parsing epochs From cdcc221792ea1837577abc1fd811c869a5210fe6 Mon Sep 17 00:00:00 2001 From: Adi Seredinschi Date: Fri, 30 Apr 2021 19:37:45 +0200 Subject: [PATCH 3/3] Changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 036dceee46..9092ab5c37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Unreleased +Special thanks to external contributors: +Jongwhan Lee (@leejw51crypto) ([#878]). + > [TODO: high level summary] ### IMPROVEMENTS @@ -13,6 +16,9 @@ ### BUG FIXES +- [ibc] + - Fix parsing in `chain_version` when chain identifier has multiple dashes ([#878]) + - [ibc-relayer] - Fix pagination in gRPC query for clients ([#811]) - Fix relayer crash when hermes starts in the same time as packets are being sent ([#851]) @@ -35,6 +41,7 @@ [#854]: https://github.com/informalsystems/ibc-rs/issues/854 [#861]: https://github.com/informalsystems/ibc-rs/issues/861 [#869]: https://github.com/informalsystems/ibc-rs/issues/869 +[#878]: https://github.com/informalsystems/ibc-rs/issues/878 ## v0.2.0