|
| 1 | +// Copyright 2019-2021 Parity Technologies (UK) Ltd. |
| 2 | +// This file is part of Parity Bridges Common. |
| 3 | + |
| 4 | +// Parity Bridges Common is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | + |
| 9 | +// Parity Bridges Common is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | + |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +#![cfg_attr(not(feature = "std"), no_std)] |
| 18 | +// RuntimeApi generated functions |
| 19 | +#![allow(clippy::too_many_arguments)] |
| 20 | +// Runtime-generated DecodeLimit::decode_all_with_depth_limit |
| 21 | +#![allow(clippy::unnecessary_mut_passed)] |
| 22 | + |
| 23 | +use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState, Weight}; |
| 24 | +use bp_runtime::Chain; |
| 25 | +use sp_std::prelude::*; |
| 26 | +use sp_version::RuntimeVersion; |
| 27 | + |
| 28 | +pub use bp_polkadot_core::*; |
| 29 | + |
| 30 | +/// Wococo Chain |
| 31 | +pub type Wococo = PolkadotLike; |
| 32 | + |
| 33 | +pub type UncheckedExtrinsic = bp_polkadot_core::UncheckedExtrinsic<Call>; |
| 34 | + |
| 35 | +// NOTE: This needs to be kept up to date with the Rococo runtime found in the Polkadot repo. |
| 36 | +pub const VERSION: RuntimeVersion = RuntimeVersion { |
| 37 | + spec_name: sp_version::create_runtime_str!("rococo"), |
| 38 | + impl_name: sp_version::create_runtime_str!("parity-rococo-v1.5"), |
| 39 | + authoring_version: 0, |
| 40 | + spec_version: 231, |
| 41 | + impl_version: 0, |
| 42 | + apis: sp_version::create_apis_vec![[]], |
| 43 | + transaction_version: 0, |
| 44 | +}; |
| 45 | + |
| 46 | +/// Wococo Runtime `Call` enum. |
| 47 | +/// |
| 48 | +/// The enum represents a subset of possible `Call`s we can send to Rococo chain. |
| 49 | +/// Ideally this code would be auto-generated from Metadata, because we want to |
| 50 | +/// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s. |
| 51 | +/// |
| 52 | +/// All entries here (like pretty much in the entire file) must be kept in sync with Rococo |
| 53 | +/// `construct_runtime`, so that we maintain SCALE-compatibility. |
| 54 | +/// |
| 55 | +/// See: https://github.com/paritytech/polkadot/blob/master/runtime/rococo/src/lib.rs |
| 56 | +#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, PartialEq, Eq, Clone)] |
| 57 | +pub enum Call { |
| 58 | + /// Westend bridge pallet. |
| 59 | + #[codec(index = 40)] |
| 60 | + BridgeGrandpaRococo(BridgeGrandpaRococoCall), |
| 61 | +} |
| 62 | + |
| 63 | +#[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, PartialEq, Eq, Clone)] |
| 64 | +#[allow(non_camel_case_types)] |
| 65 | +pub enum BridgeGrandpaRococoCall { |
| 66 | + #[codec(index = 0)] |
| 67 | + submit_finality_proof( |
| 68 | + <PolkadotLike as Chain>::Header, |
| 69 | + bp_header_chain::justification::GrandpaJustification<<PolkadotLike as Chain>::Header>, |
| 70 | + ), |
| 71 | + #[codec(index = 1)] |
| 72 | + initialize(bp_header_chain::InitializationData<<PolkadotLike as Chain>::Header>), |
| 73 | +} |
| 74 | + |
| 75 | +impl sp_runtime::traits::Dispatchable for Call { |
| 76 | + type Origin = (); |
| 77 | + type Config = (); |
| 78 | + type Info = (); |
| 79 | + type PostInfo = (); |
| 80 | + |
| 81 | + fn dispatch(self, _origin: Self::Origin) -> sp_runtime::DispatchResultWithInfo<Self::PostInfo> { |
| 82 | + unimplemented!("The Call is not expected to be dispatched.") |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +// We use this to get the account on Wococo (target) which is derived from Rococo's (source) |
| 87 | +// account. |
| 88 | +pub fn derive_account_from_rococo_id(id: bp_runtime::SourceAccount<AccountId>) -> AccountId { |
| 89 | + let encoded_id = bp_runtime::derive_account_id(bp_runtime::ROCOCO_BRIDGE_INSTANCE, id); |
| 90 | + AccountIdConverter::convert(encoded_id) |
| 91 | +} |
| 92 | + |
| 93 | +/// Name of the `WococoFinalityApi::best_finalized` runtime method. |
| 94 | +pub const BEST_FINALIZED_WOCOCO_HEADER_METHOD: &str = "WococoFinalityApi_best_finalized"; |
| 95 | +/// Name of the `WococoFinalityApi::is_known_header` runtime method. |
| 96 | +pub const IS_KNOWN_WOCOCO_HEADER_METHOD: &str = "WococoFinalityApi_is_known_header"; |
| 97 | + |
| 98 | +/// Name of the `ToWococoOutboundLaneApi::estimate_message_delivery_and_dispatch_fee` runtime method. |
| 99 | +pub const TO_WOCOCO_ESTIMATE_MESSAGE_FEE_METHOD: &str = |
| 100 | + "ToWococoOutboundLaneApi_estimate_message_delivery_and_dispatch_fee"; |
| 101 | +/// Name of the `ToWococoOutboundLaneApi::messages_dispatch_weight` runtime method. |
| 102 | +pub const TO_WOCOCO_MESSAGES_DISPATCH_WEIGHT_METHOD: &str = "ToWococoOutboundLaneApi_messages_dispatch_weight"; |
| 103 | +/// Name of the `ToWococoOutboundLaneApi::latest_generated_nonce` runtime method. |
| 104 | +pub const TO_WOCOCO_LATEST_GENERATED_NONCE_METHOD: &str = "ToWococoOutboundLaneApi_latest_generated_nonce"; |
| 105 | +/// Name of the `ToWococoOutboundLaneApi::latest_received_nonce` runtime method. |
| 106 | +pub const TO_WOCOCO_LATEST_RECEIVED_NONCE_METHOD: &str = "ToWococoOutboundLaneApi_latest_received_nonce"; |
| 107 | + |
| 108 | +/// Name of the `FromWococoInboundLaneApi::latest_received_nonce` runtime method. |
| 109 | +pub const FROM_WOCOCO_LATEST_RECEIVED_NONCE_METHOD: &str = "FromWococoInboundLaneApi_latest_received_nonce"; |
| 110 | +/// Name of the `FromWococoInboundLaneApi::latest_onfirmed_nonce` runtime method. |
| 111 | +pub const FROM_WOCOCO_LATEST_CONFIRMED_NONCE_METHOD: &str = "FromWococoInboundLaneApi_latest_confirmed_nonce"; |
| 112 | +/// Name of the `FromWococoInboundLaneApi::unrewarded_relayers_state` runtime method. |
| 113 | +pub const FROM_WOCOCO_UNREWARDED_RELAYERS_STATE: &str = "FromWococoInboundLaneApi_unrewarded_relayers_state"; |
| 114 | + |
| 115 | +sp_api::decl_runtime_apis! { |
| 116 | + /// API for querying information about the finalized Wococo headers. |
| 117 | + /// |
| 118 | + /// This API is implemented by runtimes that are bridging with the Wococo chain, not the |
| 119 | + /// Wococo runtime itself. |
| 120 | + pub trait WococoFinalityApi { |
| 121 | + /// Returns number and hash of the best finalized header known to the bridge module. |
| 122 | + fn best_finalized() -> (BlockNumber, Hash); |
| 123 | + /// Returns true if the header is known to the runtime. |
| 124 | + fn is_known_header(hash: Hash) -> bool; |
| 125 | + } |
| 126 | + |
| 127 | + /// Outbound message lane API for messages that are sent to Wococo chain. |
| 128 | + /// |
| 129 | + /// This API is implemented by runtimes that are sending messages to Wococo chain, not the |
| 130 | + /// Wococo runtime itself. |
| 131 | + pub trait ToWococoOutboundLaneApi<OutboundMessageFee: Parameter, OutboundPayload: Parameter> { |
| 132 | + /// Estimate message delivery and dispatch fee that needs to be paid by the sender on |
| 133 | + /// this chain. |
| 134 | + /// |
| 135 | + /// Returns `None` if message is too expensive to be sent to Wococo from this chain. |
| 136 | + /// |
| 137 | + /// Please keep in mind that this method returns lowest message fee required for message |
| 138 | + /// to be accepted to the lane. It may be good idea to pay a bit over this price to account |
| 139 | + /// future exchange rate changes and guarantee that relayer would deliver your message |
| 140 | + /// to the target chain. |
| 141 | + fn estimate_message_delivery_and_dispatch_fee( |
| 142 | + lane_id: LaneId, |
| 143 | + payload: OutboundPayload, |
| 144 | + ) -> Option<OutboundMessageFee>; |
| 145 | + /// Returns total dispatch weight and encoded payload size of all messages in given inclusive range. |
| 146 | + /// |
| 147 | + /// If some (or all) messages are missing from the storage, they'll also will |
| 148 | + /// be missing from the resulting vector. The vector is ordered by the nonce. |
| 149 | + fn messages_dispatch_weight( |
| 150 | + lane: LaneId, |
| 151 | + begin: MessageNonce, |
| 152 | + end: MessageNonce, |
| 153 | + ) -> Vec<(MessageNonce, Weight, u32)>; |
| 154 | + /// Returns nonce of the latest message, received by bridged chain. |
| 155 | + fn latest_received_nonce(lane: LaneId) -> MessageNonce; |
| 156 | + /// Returns nonce of the latest message, generated by given lane. |
| 157 | + fn latest_generated_nonce(lane: LaneId) -> MessageNonce; |
| 158 | + } |
| 159 | + |
| 160 | + /// Inbound message lane API for messages sent by Wococo chain. |
| 161 | + /// |
| 162 | + /// This API is implemented by runtimes that are receiving messages from Wococo chain, not the |
| 163 | + /// Wococo runtime itself. |
| 164 | + pub trait FromWococoInboundLaneApi { |
| 165 | + /// Returns nonce of the latest message, received by given lane. |
| 166 | + fn latest_received_nonce(lane: LaneId) -> MessageNonce; |
| 167 | + /// Nonce of latest message that has been confirmed to the bridged chain. |
| 168 | + fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce; |
| 169 | + /// State of the unrewarded relayers set at given lane. |
| 170 | + fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState; |
| 171 | + } |
| 172 | +} |
0 commit comments