Skip to content

Commit

Permalink
Fix for chain_version parsing when chain identifier has multiple da…
Browse files Browse the repository at this point in the history
…shes (#884)

* Solution: use the last digit (fix #878) (#879)

use expect

Co-authored-by: jongwhan lee <leejw51@gmail.com>

* Doc tests and FMT

* Changelog

Co-authored-by: Jongwhan Lee <51560997+leejw51crypto@users.noreply.github.com>
Co-authored-by: jongwhan lee <leejw51@gmail.com>
  • Loading branch information
3 people authored May 3, 2021
1 parent 7230c1d commit 340224b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Unreleased

Special thanks to external contributors:
Jongwhan Lee (@leejw51crypto) ([#878]).

> [TODO: high level summary]
### FEATURES
Expand All @@ -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])
Expand All @@ -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
Expand Down
14 changes: 13 additions & 1 deletion modules/src/ics24_host/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 340224b

Please sign in to comment.