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:
Serban Iorga
2023-02-03 12:12:49 +02:00
committed by Bastian Köcher
parent 2657973bb8
commit b2832575f6
11 changed files with 9866 additions and 79 deletions
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),
}