-
Notifications
You must be signed in to change notification settings - Fork 4
fix(relayer): use starknet block timestamp #244
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6079efc
use starknet block timestamp
rnbguy 553dcba
use ibc-rs timestamp
rnbguy 08d1156
refactor for timestamp
rnbguy b3d6706
src chan id is of a
rnbguy 91f3ff3
avoid using expect in hermes components
rnbguy feb5c16
fix error message
rnbguy d425ba7
avoid expect in relayer comps
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
51 changes: 25 additions & 26 deletions
51
relayer/crates/starknet-chain-components/src/types/cosmos/timestamp.rs
This file contains hidden or 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,35 +1,34 @@ | ||
| use cgp::core::component::UseContext; | ||
| use cgp::prelude::*; | ||
| use hermes_encoding_components::impls::encode_mut::combine::CombineEncoders; | ||
| use hermes_encoding_components::impls::encode_mut::field::EncodeField; | ||
| use hermes_encoding_components::impls::encode_mut::from::DecodeFrom; | ||
| use hermes_encoding_components::traits::decode_mut::MutDecoderComponent; | ||
| use hermes_encoding_components::traits::encode_mut::MutEncoderComponent; | ||
| use hermes_encoding_components::traits::transform::Transformer; | ||
|
|
||
| #[derive(Debug, Clone, HasField)] | ||
| pub struct Timestamp { | ||
| pub timestamp: u64, | ||
| } | ||
| use hermes_encoding_components::traits::decode_mut::{CanDecodeMut, MutDecoder}; | ||
| use hermes_encoding_components::traits::encode_mut::{CanEncodeMut, MutEncoder}; | ||
| pub use ibc::primitives::Timestamp; | ||
|
|
||
| pub struct EncodeTimestamp; | ||
|
|
||
| delegate_components! { | ||
| EncodeTimestamp { | ||
| MutEncoderComponent: CombineEncoders< | ||
| Product![ | ||
| EncodeField<symbol!("timestamp"), UseContext>, | ||
| ], | ||
| >, | ||
| MutDecoderComponent: DecodeFrom<Self, UseContext>, | ||
| impl<Encoding, Strategy> MutEncoder<Encoding, Strategy, Timestamp> for EncodeTimestamp | ||
| where | ||
| Encoding: CanEncodeMut<Strategy, Product![u64]>, | ||
| { | ||
| fn encode_mut( | ||
| encoding: &Encoding, | ||
| value: &Timestamp, | ||
| buffer: &mut Encoding::EncodeBuffer, | ||
| ) -> Result<(), Encoding::Error> { | ||
| let unix_secs = value.nanoseconds() / 1_000_000_000; | ||
| encoding.encode_mut(&product![unix_secs], buffer)?; | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl Transformer for EncodeTimestamp { | ||
| type From = u64; | ||
| type To = Timestamp; | ||
|
|
||
| fn transform(timestamp: Self::From) -> Timestamp { | ||
| Timestamp { timestamp } | ||
| impl<Encoding, Strategy> MutDecoder<Encoding, Strategy, Timestamp> for EncodeTimestamp | ||
| where | ||
| Encoding: CanDecodeMut<Strategy, Product![u64]>, | ||
| { | ||
| fn decode_mut<'a>( | ||
| encoding: &Encoding, | ||
| buffer: &mut Encoding::DecodeBuffer<'a>, | ||
| ) -> Result<Timestamp, Encoding::Error> { | ||
| let product![unix_secs] = encoding.decode_mut(buffer)?; | ||
| Ok(Timestamp::from_nanoseconds(unix_secs * 1_000_000_000)) | ||
| } | ||
| } |
This file contains hidden or 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
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.
The error should probably be "invalid" instead of "valid". We could also use
CanRaiseError<ParseIntError>for this case.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.
nice catch. fixed at feb5c16