mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 21:41:02 +00:00
The great refactor (#325)
* Move pallets to pallets folder and rename them * Move genesis file to service * Rename primitives to primitives-core * Delete cumulus-runtime * Move stuff to client folder and rename
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "cumulus-primitives"
|
||||
name = "cumulus-primitives-core"
|
||||
version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
@@ -9,7 +9,6 @@ edition = "2018"
|
||||
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sc-chain-spec = { git = "https://github.com/paritytech/substrate", optional = true, branch = "master" }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
sp-trie = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
|
||||
|
||||
@@ -19,7 +18,7 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", default-
|
||||
|
||||
# Other dependencies
|
||||
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [ "derive" ] }
|
||||
impl-trait-for-tuples = "0.1.3"
|
||||
impl-trait-for-tuples = "0.2.1"
|
||||
|
||||
# Polkadot dependencies
|
||||
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
|
||||
@@ -27,7 +26,6 @@ polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", def
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
std = [
|
||||
"sc-chain-spec",
|
||||
"sp-std/std",
|
||||
"codec/std",
|
||||
"polkadot-primitives/std",
|
||||
@@ -14,19 +14,18 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Cumulus related primitive types and traits.
|
||||
//! Cumulus related core primitive types and traits.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
|
||||
pub use polkadot_core_primitives::InboundDownwardMessage;
|
||||
pub use polkadot_parachain::primitives::{Id as ParaId, UpwardMessage, ValidationParams};
|
||||
pub use polkadot_primitives::v1::{
|
||||
PersistedValidationData, AbridgedHostConfiguration, AbridgedHrmpChannel,
|
||||
};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub mod genesis;
|
||||
|
||||
/// A module that re-exports relevant relay chain definitions.
|
||||
pub mod relay_chain {
|
||||
pub use polkadot_core_primitives::*;
|
||||
@@ -133,3 +132,57 @@ pub trait HrmpMessageSender {
|
||||
pub trait OnValidationData {
|
||||
fn on_validation_data(data: &PersistedValidationData);
|
||||
}
|
||||
|
||||
/// The parachain block that is created by a collator.
|
||||
///
|
||||
/// This is send as PoV (proof of validity block) to the relay-chain validators. There it will be
|
||||
/// passed to the parachain validation Wasm blob to be validated.
|
||||
#[derive(codec::Encode, codec::Decode)]
|
||||
pub struct ParachainBlockData<B: BlockT> {
|
||||
/// The header of the parachain block.
|
||||
header: B::Header,
|
||||
/// The extrinsics of the parachain block.
|
||||
extrinsics: sp_std::vec::Vec<B::Extrinsic>,
|
||||
/// The data that is required to emulate the storage accesses executed by all extrinsics.
|
||||
storage_proof: sp_trie::StorageProof,
|
||||
}
|
||||
|
||||
impl<B: BlockT> ParachainBlockData<B> {
|
||||
/// Creates a new instance of `Self`.
|
||||
pub fn new(
|
||||
header: <B as BlockT>::Header,
|
||||
extrinsics: sp_std::vec::Vec<<B as BlockT>::Extrinsic>,
|
||||
storage_proof: sp_trie::StorageProof,
|
||||
) -> Self {
|
||||
Self {
|
||||
header,
|
||||
extrinsics,
|
||||
storage_proof,
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert `self` into the stored header.
|
||||
pub fn into_header(self) -> B::Header {
|
||||
self.header
|
||||
}
|
||||
|
||||
/// Returns the header.
|
||||
pub fn header(&self) -> &B::Header {
|
||||
&self.header
|
||||
}
|
||||
|
||||
/// Returns the extrinsics.
|
||||
pub fn extrinsics(&self) -> &[B::Extrinsic] {
|
||||
&self.extrinsics
|
||||
}
|
||||
|
||||
/// Returns the [`StorageProof`](sp_trie::StorageProof).
|
||||
pub fn storage_proof(&self) -> &sp_trie::StorageProof {
|
||||
&self.storage_proof
|
||||
}
|
||||
|
||||
/// Deconstruct into the inner parts.
|
||||
pub fn deconstruct(self) -> (B::Header, sp_std::vec::Vec<B::Extrinsic>, sp_trie::StorageProof) {
|
||||
(self.header, self.extrinsics, self.storage_proof)
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Cumulus 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.
|
||||
|
||||
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use codec::Encode;
|
||||
use sc_chain_spec::ChainSpec;
|
||||
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero};
|
||||
|
||||
/// Generate the genesis state for a given ChainSpec.
|
||||
pub fn generate_genesis_block<Block: BlockT>(
|
||||
chain_spec: &Box<dyn ChainSpec>,
|
||||
) -> Result<Block, String> {
|
||||
let storage = chain_spec.build_storage()?;
|
||||
|
||||
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
||||
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
child_content.data.clone().into_iter().collect(),
|
||||
);
|
||||
(sk.clone(), state_root.encode())
|
||||
});
|
||||
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
storage.top.clone().into_iter().chain(child_roots).collect(),
|
||||
);
|
||||
|
||||
let extrinsics_root =
|
||||
<<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(Vec::new());
|
||||
|
||||
Ok(Block::new(
|
||||
<<Block as BlockT>::Header as HeaderT>::new(
|
||||
Zero::zero(),
|
||||
extrinsics_root,
|
||||
state_root,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
),
|
||||
Default::default(),
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user