-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(relayer): use starknet block timestamp (#244)
* use starknet block timestamp * use ibc-rs timestamp * refactor for timestamp * src chan id is of a * avoid using expect in hermes components * fix error message * avoid expect in relayer comps
- Loading branch information
Showing
10 changed files
with
69 additions
and
56 deletions.
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
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
51 changes: 25 additions & 26 deletions
51
relayer/crates/starknet-chain-components/src/types/cosmos/timestamp.rs
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,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 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