-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cw-context): encoding, decoding and iteration of ConsensusState
heights
#1176
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5e1ec84
only consider ITERATE_CONSENSUS_STATE_PREFIX keys
rnbguy db93358
use proto codec
rnbguy 8aa653b
refactor with updated parse_height type sig
rnbguy b88734b
encode and decode height funcs
rnbguy ebfbb7b
fix clippy
rnbguy 4de6db9
rm redundant type annotation
rnbguy f5bc322
add changelog entry
rnbguy 94683f4
correct link on changelog
rnbguy 7a10782
rm changelog entry
rnbguy 5133dfb
handle missing case
rnbguy 9c76cc8
use cw_storage_plus::Map
rnbguy edcaab3
store or delete height keys at cw_storage_plus::Map
rnbguy c6331d5
use cw_storage_plus::Map range or keys
rnbguy 7aa0c57
rm redundant encode_height and decode_height
rnbguy b442f93
add comment
rnbguy 41bed59
use imports
rnbguy 4a4679c
cargo format
rnbguy b082200
deserialized result must be handled
rnbguy 6dc68cf
update doc string
rnbguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,6 @@ | |
)] | ||
#![forbid(unsafe_code)] | ||
|
||
extern crate alloc; | ||
|
||
pub mod api; | ||
pub mod context; | ||
pub mod handlers; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,3 @@ | ||
mod codec; | ||
|
||
pub use codec::*; | ||
use ibc_core::client::types::error::ClientError; | ||
use ibc_core::client::types::{Height, HeightError}; | ||
|
||
/// Decodes a `Height` from a UTF-8 encoded byte array. | ||
pub fn parse_height(encoded_height: Vec<u8>) -> Result<Option<Height>, ClientError> { | ||
let height_str = match alloc::str::from_utf8(encoded_height.as_slice()) { | ||
Ok(s) => s, | ||
// In cases where the height is unavailable, the encoded representation | ||
// might not be valid UTF-8, resulting in an invalid string. In such | ||
// instances, we return None. | ||
Err(_) => return Ok(None), | ||
}; | ||
match Height::try_from(height_str) { | ||
Ok(height) => Ok(Some(height)), | ||
// This is a valid case, as the key may contain other data. We just skip | ||
// it. | ||
Err(HeightError::InvalidFormat { .. }) => Ok(None), | ||
Err(e) => Err(ClientError::Other { | ||
description: e.to_string(), | ||
}), | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started using this for a better interface. I am curious - if anything breaks if I do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. We should be good as long as the key produced by the
Map
matches theiteration_key()
(?)Specifically, we only need to use the
iteration_key
here. (Connected to your question below)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized in the old implementation, we should have used this
range_with_prefix
from cw-storage-plus. Note the trick forNone
and exclusive or inclusive cases incalc_start_bound
andcalc_end_bound
.Since this brings
cw-storage-plus
dependency anyway, it's best to use their storage abstractions, built on top of these low-level functions.