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