mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 02:51:01 +00:00
Add tool for auto generating runtime code from metadata (#1812)
* Create CLI tool for generating indirect runtimes code * Use the generated runtime for rialto parachain * Avoid autogenerated files when executing cargo spellcheck * Fix clippy warning
This commit is contained in:
committed by
Bastian Köcher
parent
2657973bb8
commit
b2832575f6
@@ -17,7 +17,7 @@ fixed-hash = { version = "0.8.0", default-features = false }
|
||||
hash256-std-hasher = { version = "0.15.2", default-features = false }
|
||||
impl-codec = { version = "0.6", default-features = false }
|
||||
impl-serde = { version = "0.4.0", optional = true }
|
||||
parity-util-mem = { version = "0.12", default-features = false, features = ["primitive-types"] }
|
||||
parity-util-mem = { version = "0.11.0", default-features = false, features = ["primitive-types"] }
|
||||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0", optional = true, features = ["derive"] }
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
|
||||
parity-util-mem = { version = "0.12.0", optional = true }
|
||||
parity-util-mem = { version = "0.11.0", optional = true }
|
||||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
|
||||
serde = { version = "1.0", optional = true, features = ["derive"] }
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ use substrate_relay_helper::finality::{
|
||||
substrate_relay_helper::generate_submit_finality_proof_call_builder!(
|
||||
MillauFinalityToRialtoParachain,
|
||||
MillauFinalityToRialtoParachainCallBuilder,
|
||||
relay_rialto_parachain_client::runtime::Call::BridgeMillauGrandpa,
|
||||
relay_rialto_parachain_client::runtime::BridgeMillauGrandpaCall::submit_finality_proof
|
||||
relay_rialto_parachain_client::RuntimeCall::BridgeMillauGrandpa,
|
||||
relay_rialto_parachain_client::BridgeGrandpaCall::submit_finality_proof
|
||||
);
|
||||
|
||||
/// Description of Millau -> Rialto finalized headers bridge.
|
||||
|
||||
@@ -25,8 +25,8 @@ use substrate_relay_helper::messages_lane::{
|
||||
substrate_relay_helper::generate_receive_message_proof_call_builder!(
|
||||
MillauMessagesToRialtoParachain,
|
||||
MillauMessagesToRialtoParachainReceiveMessagesProofCallBuilder,
|
||||
relay_rialto_parachain_client::runtime::Call::BridgeMillauMessages,
|
||||
relay_rialto_parachain_client::runtime::BridgeMillauMessagesCall::receive_messages_proof
|
||||
relay_rialto_parachain_client::RuntimeCall::BridgeMillauMessages,
|
||||
relay_rialto_parachain_client::BridgeMessagesCall::receive_messages_proof
|
||||
);
|
||||
|
||||
/// Description of Millau -> RialtoParachain messages bridge.
|
||||
|
||||
@@ -20,7 +20,7 @@ use crate::cli::{bridge, encode_message::CliEncodeMessage, CliChain};
|
||||
use bp_runtime::EncodedOrDecodedCall;
|
||||
use bridge_runtime_common::CustomNetworkId;
|
||||
use relay_rialto_parachain_client::RialtoParachain;
|
||||
use relay_substrate_client::{calls::XcmCall, SimpleRuntimeVersion};
|
||||
use relay_substrate_client::SimpleRuntimeVersion;
|
||||
use xcm::latest::prelude::*;
|
||||
|
||||
impl CliEncodeMessage for RialtoParachain {
|
||||
@@ -28,6 +28,9 @@ impl CliEncodeMessage for RialtoParachain {
|
||||
message: xcm::VersionedXcm<()>,
|
||||
bridge_instance_index: u8,
|
||||
) -> anyhow::Result<EncodedOrDecodedCall<Self::Call>> {
|
||||
type RuntimeCall = relay_rialto_parachain_client::RuntimeCall;
|
||||
type XcmCall = relay_rialto_parachain_client::runtime_types::pallet_xcm::pallet::Call;
|
||||
|
||||
let dest = match bridge_instance_index {
|
||||
bridge::RIALTO_PARACHAIN_TO_MILLAU_INDEX =>
|
||||
(Parent, X1(GlobalConsensus(CustomNetworkId::Millau.as_network_id()))),
|
||||
@@ -37,9 +40,12 @@ impl CliEncodeMessage for RialtoParachain {
|
||||
),
|
||||
};
|
||||
|
||||
let xcm_call = XcmCall::send(Box::new(dest.into()), Box::new(message));
|
||||
let xcm_call = XcmCall::send {
|
||||
dest: Box::new(unsafe { std::mem::transmute(xcm::VersionedMultiLocation::from(dest)) }),
|
||||
message: Box::new(unsafe { std::mem::transmute(message) }),
|
||||
};
|
||||
|
||||
Ok(relay_rialto_parachain_client::runtime::Call::PolkadotXcm(xcm_call).into())
|
||||
Ok(RuntimeCall::PolkadotXcm(xcm_call).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ use substrate_relay_helper::{
|
||||
substrate_relay_helper::generate_receive_message_delivery_proof_call_builder!(
|
||||
RialtoParachainMessagesToMillau,
|
||||
RialtoParachainMessagesToMillauReceiveMessagesDeliveryProofCallBuilder,
|
||||
relay_rialto_parachain_client::runtime::Call::BridgeMillauMessages,
|
||||
relay_rialto_parachain_client::runtime::BridgeMillauMessagesCall::receive_messages_delivery_proof
|
||||
relay_rialto_parachain_client::RuntimeCall::BridgeMillauMessages,
|
||||
relay_rialto_parachain_client::BridgeMessagesCall::receive_messages_delivery_proof
|
||||
);
|
||||
|
||||
/// Description of RialtoParachain -> Millau messages bridge.
|
||||
|
||||
@@ -29,7 +29,7 @@ use crate::{
|
||||
cli::{bridge::CliBridgeBase, chain_schema::*},
|
||||
};
|
||||
use bp_runtime::Chain as ChainBase;
|
||||
use relay_substrate_client::{calls::SudoCall, AccountKeyPairOf, Chain, UnsignedTransaction};
|
||||
use relay_substrate_client::{AccountKeyPairOf, Chain, UnsignedTransaction};
|
||||
use sp_core::Pair;
|
||||
use structopt::StructOpt;
|
||||
use strum::{EnumString, EnumVariantNames, VariantNames};
|
||||
@@ -123,14 +123,14 @@ impl BridgeInitializer for MillauToRialtoParachainCliBridge {
|
||||
fn encode_init_bridge(
|
||||
init_data: <Self::Engine as Engine<Self::Source>>::InitializationData,
|
||||
) -> <Self::Target as Chain>::Call {
|
||||
use relay_rialto_parachain_client::runtime;
|
||||
type RuntimeCall = relay_rialto_parachain_client::RuntimeCall;
|
||||
type BridgeGrandpaCall = relay_rialto_parachain_client::BridgeGrandpaCall;
|
||||
type SudoCall = relay_rialto_parachain_client::SudoCall;
|
||||
|
||||
let initialize_call =
|
||||
runtime::Call::BridgeMillauGrandpa(runtime::BridgeMillauGrandpaCall::initialize {
|
||||
init_data,
|
||||
});
|
||||
let sudo_call = SudoCall::sudo(Box::new(initialize_call));
|
||||
runtime::Call::Sudo(sudo_call)
|
||||
RuntimeCall::BridgeMillauGrandpa(BridgeGrandpaCall::initialize { init_data });
|
||||
|
||||
RuntimeCall::Sudo(SudoCall::sudo { call: Box::new(initialize_call) })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "3.1.5" }
|
||||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
|
||||
subxt = { git = "https://github.com/paritytech/subxt", branch = "master" }
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
@@ -24,3 +25,4 @@ relay-substrate-client = { path = "../client-substrate" }
|
||||
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-weights = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Types used to connect to the Rialto-Substrate chain.
|
||||
|
||||
pub mod runtime_wrapper;
|
||||
pub mod codegen_runtime;
|
||||
|
||||
use bp_messages::MessageNonce;
|
||||
use bp_polkadot_core::PolkadotSignedExtension;
|
||||
@@ -29,7 +29,12 @@ use sp_core::{storage::StorageKey, Pair};
|
||||
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount, MultiAddress};
|
||||
use std::time::Duration;
|
||||
|
||||
pub use runtime_wrapper as runtime;
|
||||
pub use codegen_runtime::api::runtime_types;
|
||||
|
||||
pub type RuntimeCall = runtime_types::rialto_parachain_runtime::RuntimeCall;
|
||||
pub type SudoCall = runtime_types::pallet_sudo::pallet::Call;
|
||||
pub type BridgeGrandpaCall = runtime_types::pallet_bridge_grandpa::pallet::Call;
|
||||
pub type BridgeMessagesCall = runtime_types::pallet_bridge_messages::pallet::Call;
|
||||
|
||||
/// The address format for describing accounts.
|
||||
pub type Address = MultiAddress<bp_rialto_parachain::AccountId, ()>;
|
||||
@@ -51,12 +56,13 @@ impl Chain for RialtoParachain {
|
||||
const AVERAGE_BLOCK_INTERVAL: Duration = Duration::from_secs(5);
|
||||
|
||||
type SignedBlock = bp_polkadot_core::SignedBlock;
|
||||
type Call = runtime::Call;
|
||||
type Call = runtime_types::rialto_parachain_runtime::RuntimeCall;
|
||||
}
|
||||
|
||||
impl ChainWithBalances for RialtoParachain {
|
||||
fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey {
|
||||
bp_polkadot_core::AccountInfoStorageMapKeyProvider::final_key(account_id)
|
||||
let key = codegen_runtime::api::storage().system().account(account_id);
|
||||
StorageKey(key.to_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Types that are specific to the `RialtoParachain` runtime. Normally we could use the full
|
||||
//! `RialtoParachain` runtime here, since it is constructed in this repo and we have access to it.
|
||||
//! However we use a wrapped runtime instead in order to test the indirect runtime calls
|
||||
//! functionality.
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use scale_info::TypeInfo;
|
||||
|
||||
use bp_header_chain::BridgeGrandpaCallOf;
|
||||
use bridge_runtime_common::messages::BridgeMessagesCallOf;
|
||||
use relay_substrate_client::calls::{SudoCall, XcmCall};
|
||||
|
||||
// The indirect pallet call used to sync `Millau` GRANDPA finality to `RialtoParachain`.
|
||||
pub type BridgeMillauGrandpaCall = BridgeGrandpaCallOf<bp_millau::Millau>;
|
||||
// The indirect pallet call used to sync `Millau` messages to `RialtoParachain`.
|
||||
pub type BridgeMillauMessagesCall = BridgeMessagesCallOf<bp_millau::Millau>;
|
||||
|
||||
/// `RialtoParachain` Runtime `Call` enum.
|
||||
///
|
||||
/// The enum represents a subset of possible `Call`s we can send to `RialtoParachain` chain.
|
||||
///
|
||||
/// All entries here (like pretty much in the entire file) must be kept in sync with
|
||||
/// `RialtoParachain` `construct_runtime`, so that we maintain SCALE-compatibility.
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
|
||||
pub enum Call {
|
||||
/// `Sudo` pallet.
|
||||
#[codec(index = 2)]
|
||||
Sudo(SudoCall<Call>),
|
||||
|
||||
/// `Xcm` pallet.
|
||||
#[codec(index = 51)]
|
||||
PolkadotXcm(XcmCall),
|
||||
|
||||
/// Millau GRANDPA bridge pallet.
|
||||
#[codec(index = 55)]
|
||||
BridgeMillauGrandpa(BridgeMillauGrandpaCall),
|
||||
/// Millau messages bridge pallet.
|
||||
#[codec(index = 56)]
|
||||
BridgeMillauMessages(BridgeMillauMessagesCall),
|
||||
}
|
||||
Reference in New Issue
Block a user