From 340224b525c7cece0cdff0c72ba918ac26750c5c Mon Sep 17 00:00:00 2001 From: Adi Seredinschi Date: Mon, 3 May 2021 11:39:54 +0200 Subject: [PATCH] Fix for `chain_version` parsing when chain identifier has multiple dashes (#884) * Solution: use the last digit (fix #878) (#879) use expect Co-authored-by: jongwhan lee * Doc tests and FMT * Changelog Co-authored-by: Jongwhan Lee <51560997+leejw51crypto@users.noreply.github.com> Co-authored-by: jongwhan lee --- CHANGELOG.md | 7 +++++++ modules/src/ics24_host/identifier.rs | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1935f17302..a015ad7e33 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] ### FEATURES @@ -18,6 +21,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]) @@ -41,6 +47,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 diff --git a/modules/src/ics24_host/identifier.rs b/modules/src/ics24_host/identifier.rs index 9d178d7fd2..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[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