mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 04:41:03 +00:00
add RelaychainBlockNumberProvider (#515)
* add RelaychainBlockNumberProvider * add docs
This commit is contained in:
@@ -51,6 +51,7 @@ use sp_runtime::{
|
||||
InvalidTransaction, TransactionLongevity, TransactionSource, TransactionValidity,
|
||||
ValidTransaction,
|
||||
},
|
||||
offchain::storage_lock::BlockNumberProvider,
|
||||
};
|
||||
use sp_std::{cmp, collections::btree_map::BTreeMap, prelude::*};
|
||||
|
||||
@@ -1038,3 +1039,18 @@ pub trait CheckInherents<Block: BlockT> {
|
||||
validation_data: &RelayChainStateProof,
|
||||
) -> frame_support::inherent::CheckInherentsResult;
|
||||
}
|
||||
|
||||
/// Implements [`BlockNumberProvider`] that returns relaychain block number fetched from
|
||||
/// validation data.
|
||||
/// NTOE: When validation data is not available (e.g. within on_initialize), 0 will be returned.
|
||||
pub struct RelaychainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);
|
||||
|
||||
impl<T: Config> BlockNumberProvider for RelaychainBlockNumberProvider<T> {
|
||||
type BlockNumber = relay_chain::BlockNumber;
|
||||
|
||||
fn current_block_number() -> relay_chain::BlockNumber {
|
||||
Pallet::<T>::validation_data()
|
||||
.map(|d| d.relay_parent_number)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user