Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Use Rococo/Wococo runtime APIs defined in bridge primitives (#2080)
Browse files Browse the repository at this point in the history
  • Loading branch information
serban300 authored Jan 12, 2023
1 parent 9bf5a7e commit 5835109
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,6 @@ 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
pub mod runtime_api {
use super::{BlockNumber, Hash};
bp_runtime::decl_bridge_finality_runtime_apis!(rococo);
bp_runtime::decl_bridge_finality_runtime_apis!(wococo);
bp_runtime::decl_bridge_finality_runtime_apis!(bridge_hub_rococo);
bp_runtime::decl_bridge_finality_runtime_apis!(bridge_hub_wococo);

use bp_messages::{
InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails,
};
use sp_std::prelude::Vec;
bp_runtime::decl_bridge_messages_runtime_apis!(bridge_hub_rococo);
bp_runtime::decl_bridge_messages_runtime_apis!(bridge_hub_wococo);
}

parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub RuntimeBlockLength: BlockLength =
Expand Down Expand Up @@ -754,28 +738,28 @@ impl_runtime_apis! {
}
}

impl runtime_api::RococoFinalityApi<Block> for Runtime {
impl bp_rococo::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 {
impl bp_wococo::WococoFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<bp_wococo::Hash, bp_wococo::BlockNumber>> {
BridgeWococoGrandpa::best_finalized().map(|header| header.id())
}
}


impl runtime_api::BridgeHubRococoFinalityApi<Block> for Runtime {
impl bp_bridge_hub_rococo::BridgeHubRococoFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<Hash, BlockNumber>> {
let encoded_head = BridgeRococoParachain::best_parachain_head(bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID.into())?;
let head = bp_bridge_hub_rococo::Header::decode(&mut &encoded_head.0[..]).ok()?;
Some(head.id())
}
}

impl runtime_api::BridgeHubWococoFinalityApi<Block> for Runtime {
impl bp_bridge_hub_wococo::BridgeHubWococoFinalityApi<Block> for Runtime {
fn best_finalized() -> Option<HeaderId<Hash, BlockNumber>> {
let encoded_head = BridgeWococoParachain::best_parachain_head(bp_bridge_hub_wococo::BRIDGE_HUB_WOCOCO_PARACHAIN_ID.into())?;
let head = bp_bridge_hub_wococo::Header::decode(&mut &encoded_head.0[..]).ok()?;
Expand All @@ -784,7 +768,7 @@ impl_runtime_apis! {
}

// This exposed by BridgeHubRococo
impl runtime_api::FromBridgeHubWococoInboundLaneApi<Block> for Runtime {
impl bp_bridge_hub_wococo::FromBridgeHubWococoInboundLaneApi<Block> for Runtime {
fn message_details(
lane: bp_messages::LaneId,
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails)>,
Expand All @@ -796,7 +780,7 @@ impl_runtime_apis! {
}
}

impl runtime_api::ToBridgeHubWococoOutboundLaneApi<Block> for Runtime {
impl bp_bridge_hub_wococo::ToBridgeHubWococoOutboundLaneApi<Block> for Runtime {
fn message_details(
lane: bp_messages::LaneId,
begin: bp_messages::MessageNonce,
Expand All @@ -810,7 +794,7 @@ impl_runtime_apis! {
}

// This is exposed by BridgeHubWococo
impl runtime_api::FromBridgeHubRococoInboundLaneApi<Block> for Runtime {
impl bp_bridge_hub_rococo::FromBridgeHubRococoInboundLaneApi<Block> for Runtime {
fn message_details(
lane: bp_messages::LaneId,
messages: Vec<(bp_messages::MessagePayload, bp_messages::OutboundMessageDetails)>,
Expand All @@ -822,7 +806,7 @@ impl_runtime_apis! {
}
}

impl runtime_api::ToBridgeHubRococoOutboundLaneApi<Block> for Runtime {
impl bp_bridge_hub_rococo::ToBridgeHubRococoOutboundLaneApi<Block> for Runtime {
fn message_details(
lane: bp_messages::LaneId,
begin: bp_messages::MessageNonce,
Expand Down

0 comments on commit 5835109

Please sign in to comment.