[BridgeHub] Added best_finalized runtime apis

This commit is contained in:
Branislav Kontur
2022-08-28 22:32:58 +02:00
parent 69f2159c01
commit 0373bfbe53
2 changed files with 23 additions and 0 deletions
@@ -69,6 +69,7 @@ parachains-common = { path = "../../../../parachains/common", default-features =
# Bridges
bp-polkadot-core = { path = "../../../../bridges/primitives/polkadot-core", default-features = false }
bp-runtime = { path = "../../../../bridges/primitives/runtime", default-features = false }
bp-rococo = { path = "../../../../bridges/primitives/chain-rococo", default-features = false }
bp-wococo = { path = "../../../../bridges/primitives/chain-wococo", default-features = false }
pallet-bridge-grandpa = { path = "../../../../bridges/modules/grandpa", default-features = false }
@@ -83,6 +84,7 @@ default = [
]
std = [
"bp-polkadot-core/std",
"bp-runtime/std",
"bp-rococo/std",
"bp-wococo/std",
"codec/std",
@@ -59,6 +59,7 @@ pub use sp_runtime::{MultiAddress, Perbill, Permill};
use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin};
use bp_polkadot_core::parachains::ParaId;
use bp_runtime::{HeaderId, HeaderIdProvider};
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
@@ -233,6 +234,14 @@ pub fn native_version() -> NativeVersion {
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
}
// TODO: check-parameter - move to bridges/primitives, once rebased and would compile with bp_bridge_hub_xyz dependencies
mod runtime_api {
use super::BlockNumber;
use super::Hash;
bp_runtime::decl_bridge_finality_runtime_apis!(rococo);
bp_runtime::decl_bridge_finality_runtime_apis!(wococo);
}
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
@@ -701,6 +710,18 @@ impl_runtime_apis! {
}
}
impl runtime_api::RococoFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<bp_rococo::Hash, bp_rococo::BlockNumber>> {
BridgeRococoGrandpa::best_finalized().map(|header| header.id())
}
}
impl runtime_api::WococoFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<bp_wococo::Hash, bp_wococo::BlockNumber>> {
BridgeWococoGrandpa::best_finalized().map(|header| header.id())
}
}
#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade() -> (Weight, Weight) {