cuprate_helper::map

Function u64_to_timelock

Source
pub const fn u64_to_timelock(u: u64) -> Timelock
Expand description

Map a u64 to a Timelock.

Height/time is not differentiated via type, but rather: “height is any value less than MAX_BLOCK_HEIGHT and timestamp is any value above” so the u64/usize is stored without any tag.

See timelock_to_u64 for the inverse function.

use cuprate_constants::block::{MAX_BLOCK_HEIGHT, MAX_BLOCK_HEIGHT_USIZE};
assert_eq!(u64_to_timelock(0), Timelock::None);
assert_eq!(u64_to_timelock(MAX_BLOCK_HEIGHT-1), Timelock::Block(MAX_BLOCK_HEIGHT_USIZE-1));
assert_eq!(u64_to_timelock(MAX_BLOCK_HEIGHT), Timelock::Time(MAX_BLOCK_HEIGHT));