-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
76 additions
and
34 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! This file is copied from Godwoken `crates/types/src/core.rs`. | ||
/// Timepoint encodes in the below layout into u64 in order to support representing two kinds of | ||
/// time points, block number and timestamp. | ||
/// - the highest 1 bit represent whether the time point is block-number-based or timestamp-based | ||
/// - the rest 63 bits represent the value of time point | ||
pub enum Timepoint { | ||
BlockNumber(u64), | ||
Timestamp(u64), | ||
} | ||
|
||
impl Timepoint { | ||
const MASK: u64 = 1 << 63; | ||
|
||
pub fn from_block_number(block_number: u64) -> Self { | ||
Timepoint::BlockNumber(block_number) | ||
} | ||
|
||
pub fn from_timestamp(timestamp: u64) -> Self { | ||
Timepoint::Timestamp(timestamp) | ||
} | ||
|
||
pub fn from_full_value(full_value: u64) -> Self { | ||
let is_block_number = (Self::MASK & full_value) == 0; | ||
if is_block_number { | ||
Timepoint::BlockNumber(full_value) | ||
} else { | ||
Timepoint::Timestamp(Self::MASK ^ full_value) | ||
} | ||
} | ||
|
||
pub fn full_value(&self) -> u64 { | ||
match self { | ||
Timepoint::BlockNumber(block_number) => *block_number, | ||
Timepoint::Timestamp(timestamp) => Self::MASK | *timestamp, | ||
} | ||
} | ||
} |
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