chore: ShardedKey::last helper methods (#3352)

This commit is contained in:
Roman Krasiuk
2023-06-23 14:15:50 +03:00
committed by GitHub
parent a66a350cf0
commit f4d7a6a369
2 changed files with 16 additions and 1 deletions

View File

@ -29,6 +29,12 @@ impl<T> ShardedKey<T> {
pub fn new(key: T, highest_block_number: BlockNumber) -> Self {
ShardedKey { key, highest_block_number }
}
/// Creates a new key with the highest block number set to maximum.
/// This is useful when we want to search the last value for a given key.
pub fn last(key: T) -> Self {
Self { key, highest_block_number: u64::MAX }
}
}
impl<T> Encode for ShardedKey<T>

View File

@ -1,4 +1,4 @@
//! Sharded key
//! Storage sharded key
use crate::{
table::{Decode, Encode},
@ -32,6 +32,15 @@ impl StorageShardedKey {
pub fn new(address: H160, storage_key: H256, highest_block_number: BlockNumber) -> Self {
Self { address, sharded_key: ShardedKey { key: storage_key, highest_block_number } }
}
/// Creates a new key with the highest block number set to maximum.
/// This is useful when we want to search the last value for a given key.
pub fn last(address: H160, storage_key: H256) -> Self {
Self {
address,
sharded_key: ShardedKey { key: storage_key, highest_block_number: u64::MAX },
}
}
}
impl Encode for StorageShardedKey {