feat: Rebrand Polkadot/Substrate references to PezkuwiChain
This commit systematically rebrands various references from Parity Technologies' Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk. Key changes include: - Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks. - Modified internal documentation and code comments to reflect PezkuwiChain naming and structure. - Replaced direct references to with or specific paths within the for XCM, Pezkuwi, and other modules. - Cleaned up deprecated issue and PR references in various and files, particularly in and modules. - Adjusted image and logo URLs in documentation to point to PezkuwiChain assets. - Removed or rephrased comments related to external Polkadot/Substrate PRs and issues. This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
@@ -0,0 +1,252 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! # bizinikiwi-test pallet
|
||||
//!
|
||||
//! Provides functionality used in unit-tests of numerous modules across bizinikiwi that require
|
||||
//! functioning runtime. Some calls are allowed to be submitted as unsigned extrinsics, however most
|
||||
//! of them requires signing. Refer to `pallet::Call` for further details.
|
||||
|
||||
use alloc::{vec, vec::Vec};
|
||||
use pezframe_support::{pezpallet_prelude::*, storage};
|
||||
use pezsp_core::sr25519::Public;
|
||||
use pezsp_runtime::{
|
||||
traits::Hash,
|
||||
transaction_validity::{
|
||||
InvalidTransaction, TransactionSource, TransactionValidity, ValidTransaction,
|
||||
},
|
||||
};
|
||||
|
||||
pub use self::pallet::*;
|
||||
|
||||
const LOG_TARGET: &str = "bizinikiwi_test_pallet";
|
||||
|
||||
#[pezframe_support::pallet(dev_mode)]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use crate::TransferData;
|
||||
use pezframe_system::pezpallet_prelude::*;
|
||||
use pezsp_core::storage::well_known_keys;
|
||||
use pezsp_runtime::{traits::BlakeTwo256, transaction_validity::TransactionPriority, Perbill};
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: pezframe_system::Config {}
|
||||
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn authorities)]
|
||||
pub type Authorities<T> = StorageValue<_, Vec<Public>, ValueQuery>;
|
||||
|
||||
#[pallet::genesis_config]
|
||||
#[derive(pezframe_support::DefaultNoBound)]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
pub authorities: Vec<Public>,
|
||||
#[serde(skip)]
|
||||
pub _config: core::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
fn build(&self) {
|
||||
<Authorities<T>>::put(self.authorities.clone());
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Legacy call used in transaction pool benchmarks.
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(100)]
|
||||
pub fn bench_call(_origin: OriginFor<T>, _transfer: TransferData) -> DispatchResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Implicitly fill a block body with some data.
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight(100)]
|
||||
pub fn include_data(origin: OriginFor<T>, _data: Vec<u8>) -> DispatchResult {
|
||||
pezframe_system::ensure_signed(origin)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Put/delete some data from storage. Intended to use as an unsigned extrinsic.
|
||||
#[pallet::call_index(2)]
|
||||
#[pallet::weight(100)]
|
||||
pub fn storage_change(
|
||||
_origin: OriginFor<T>,
|
||||
key: Vec<u8>,
|
||||
value: Option<Vec<u8>>,
|
||||
) -> DispatchResult {
|
||||
match value {
|
||||
Some(value) => storage::unhashed::put_raw(&key, &value),
|
||||
None => storage::unhashed::kill(&key),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Write a key value pair to the offchain database.
|
||||
#[pallet::call_index(3)]
|
||||
#[pallet::weight(100)]
|
||||
pub fn offchain_index_set(
|
||||
origin: OriginFor<T>,
|
||||
key: Vec<u8>,
|
||||
value: Vec<u8>,
|
||||
) -> DispatchResult {
|
||||
pezframe_system::ensure_signed(origin)?;
|
||||
pezsp_io::offchain_index::set(&key, &value);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove a key and an associated value from the offchain database.
|
||||
#[pallet::call_index(4)]
|
||||
#[pallet::weight(100)]
|
||||
pub fn offchain_index_clear(origin: OriginFor<T>, key: Vec<u8>) -> DispatchResult {
|
||||
pezframe_system::ensure_signed(origin)?;
|
||||
pezsp_io::offchain_index::clear(&key);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Create an index for this call.
|
||||
#[pallet::call_index(5)]
|
||||
#[pallet::weight(100)]
|
||||
pub fn indexed_call(origin: OriginFor<T>, data: Vec<u8>) -> DispatchResult {
|
||||
pezframe_system::ensure_signed(origin)?;
|
||||
let content_hash = pezsp_io::hashing::blake2_256(&data);
|
||||
let extrinsic_index: u32 =
|
||||
storage::unhashed::get(well_known_keys::EXTRINSIC_INDEX).unwrap();
|
||||
pezsp_io::transaction_index::index(extrinsic_index, data.len() as u32, content_hash);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Deposit given digest items into the system storage. They will be included in a header
|
||||
/// during finalization.
|
||||
#[pallet::call_index(6)]
|
||||
#[pallet::weight(100)]
|
||||
pub fn deposit_log_digest_item(
|
||||
_origin: OriginFor<T>,
|
||||
log: pezsp_runtime::generic::DigestItem,
|
||||
) -> DispatchResult {
|
||||
<pezframe_system::Pallet<T>>::deposit_log(log);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// This call is validated as `ValidTransaction` with given priority.
|
||||
#[pallet::call_index(7)]
|
||||
#[pallet::weight(100)]
|
||||
pub fn call_with_priority(
|
||||
_origin: OriginFor<T>,
|
||||
_priority: TransactionPriority,
|
||||
) -> DispatchResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// This call is validated as non-propagable `ValidTransaction`.
|
||||
#[pallet::call_index(8)]
|
||||
#[pallet::weight(100)]
|
||||
pub fn call_do_not_propagate(_origin: OriginFor<T>) -> DispatchResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Fill the block weight up to the given ratio.
|
||||
#[pallet::call_index(9)]
|
||||
#[pallet::weight(*_ratio * T::BlockWeights::get().max_block)]
|
||||
pub fn fill_block(origin: OriginFor<T>, _ratio: Perbill) -> DispatchResult {
|
||||
ensure_signed(origin)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Read X times from the state some data.
|
||||
///
|
||||
/// Panics if it can not read `X` times.
|
||||
#[pallet::call_index(10)]
|
||||
#[pallet::weight(100)]
|
||||
pub fn read(_origin: OriginFor<T>, count: u32) -> DispatchResult {
|
||||
Self::execute_read(count, false)
|
||||
}
|
||||
|
||||
/// Read X times from the state some data and then panic!
|
||||
///
|
||||
/// Returns `Ok` if it didn't read anything.
|
||||
#[pallet::call_index(11)]
|
||||
#[pallet::weight(100)]
|
||||
pub fn read_and_panic(_origin: OriginFor<T>, count: u32) -> DispatchResult {
|
||||
Self::execute_read(count, true)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
fn execute_read(read: u32, panic_at_end: bool) -> DispatchResult {
|
||||
let mut next_key = vec![];
|
||||
for _ in 0..(read as usize) {
|
||||
if let Some(next) = pezsp_io::storage::next_key(&next_key) {
|
||||
// Read the value
|
||||
pezsp_io::storage::get(&next);
|
||||
|
||||
next_key = next;
|
||||
} else {
|
||||
if panic_at_end {
|
||||
return Ok(());
|
||||
} else {
|
||||
panic!("Could not read {read} times from the state");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if panic_at_end {
|
||||
panic!("BYE")
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::validate_unsigned]
|
||||
impl<T: Config> ValidateUnsigned for Pallet<T> {
|
||||
type Call = Call<T>;
|
||||
|
||||
fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
|
||||
log::trace!(target: LOG_TARGET, "validate_unsigned {call:?}");
|
||||
match call {
|
||||
// Some tests do not need to be complicated with signer and nonce, some need
|
||||
// reproducible block hash (call signature can't be there).
|
||||
// Offchain testing requires storage_change.
|
||||
Call::deposit_log_digest_item { .. } |
|
||||
Call::storage_change { .. } |
|
||||
Call::read { .. } |
|
||||
Call::read_and_panic { .. } => Ok(ValidTransaction {
|
||||
provides: vec![BlakeTwo256::hash_of(&call).encode()],
|
||||
..Default::default()
|
||||
}),
|
||||
_ => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate_runtime_call<T: pallet::Config>(call: &pallet::Call<T>) -> TransactionValidity {
|
||||
log::trace!(target: LOG_TARGET, "validate_runtime_call {call:?}");
|
||||
match call {
|
||||
Call::call_do_not_propagate {} =>
|
||||
Ok(ValidTransaction { propagate: false, ..Default::default() }),
|
||||
Call::call_with_priority { priority } =>
|
||||
Ok(ValidTransaction { priority: *priority, ..Default::default() }),
|
||||
_ => Ok(Default::default()),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Provides utils for building the `Extrinsic` instances used with `bizinikiwi-test-runtime`.
|
||||
|
||||
use crate::{
|
||||
bizinikiwi_test_pallet::pallet::Call as PalletCall, AccountId, Balance, BalancesCall,
|
||||
CheckBizinikiwiCall, Extrinsic, Nonce, Pair, RuntimeCall, SignedPayload, TransferData,
|
||||
};
|
||||
use codec::Encode;
|
||||
use pezframe_metadata_hash_extension::CheckMetadataHash;
|
||||
use pezframe_system::{CheckNonce, CheckWeight};
|
||||
use pezsp_core::crypto::Pair as TraitPair;
|
||||
use pezsp_keyring::Sr25519Keyring;
|
||||
use pezsp_runtime::{
|
||||
generic::Preamble, traits::TransactionExtension, transaction_validity::TransactionPriority,
|
||||
Perbill,
|
||||
};
|
||||
|
||||
/// Transfer used in test bizinikiwi pallet. Extrinsic is created and signed using this data.
|
||||
#[derive(Clone)]
|
||||
pub struct Transfer {
|
||||
/// Transfer sender and signer of created extrinsic
|
||||
pub from: Pair,
|
||||
/// The recipient of the transfer
|
||||
pub to: AccountId,
|
||||
/// Amount of transfer
|
||||
pub amount: Balance,
|
||||
/// Sender's account nonce at which transfer is valid
|
||||
pub nonce: u64,
|
||||
}
|
||||
|
||||
impl Transfer {
|
||||
/// Convert into a signed unchecked extrinsic.
|
||||
pub fn into_unchecked_extrinsic(self) -> Extrinsic {
|
||||
ExtrinsicBuilder::new_transfer(self).build()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for TransferData {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
from: Sr25519Keyring::Alice.into(),
|
||||
to: Sr25519Keyring::Bob.into(),
|
||||
amount: 0,
|
||||
nonce: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// If feasible converts given `Extrinsic` to `TransferData`
|
||||
impl TryFrom<&Extrinsic> for TransferData {
|
||||
type Error = ();
|
||||
fn try_from(uxt: &Extrinsic) -> Result<Self, Self::Error> {
|
||||
match uxt {
|
||||
Extrinsic {
|
||||
function: RuntimeCall::Balances(BalancesCall::transfer_allow_death { dest, value }),
|
||||
preamble: Preamble::Signed(from, _, ((CheckNonce(nonce), ..), ..)),
|
||||
} => Ok(TransferData { from: *from, to: *dest, amount: *value, nonce: *nonce }),
|
||||
Extrinsic {
|
||||
function: RuntimeCall::BizinikiwiTest(PalletCall::bench_call { transfer }),
|
||||
preamble: Preamble::Bare(_),
|
||||
} => Ok(transfer.clone()),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Generates `Extrinsic`
|
||||
pub struct ExtrinsicBuilder {
|
||||
function: RuntimeCall,
|
||||
signer: Option<Pair>,
|
||||
nonce: Option<Nonce>,
|
||||
metadata_hash: Option<[u8; 32]>,
|
||||
}
|
||||
|
||||
impl ExtrinsicBuilder {
|
||||
/// Create builder for given `RuntimeCall`. By default `Extrinsic` will be signed by `Alice`.
|
||||
pub fn new(function: impl Into<RuntimeCall>) -> Self {
|
||||
Self {
|
||||
function: function.into(),
|
||||
signer: Some(Sr25519Keyring::Alice.pair()),
|
||||
nonce: None,
|
||||
metadata_hash: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create builder for given `RuntimeCall`. `Extrinsic` will be unsigned.
|
||||
pub fn new_unsigned(function: impl Into<RuntimeCall>) -> Self {
|
||||
Self { function: function.into(), signer: None, nonce: None, metadata_hash: None }
|
||||
}
|
||||
|
||||
/// Create builder for `pezpallet_call::bench_transfer` from given `TransferData`.
|
||||
pub fn new_bench_call(transfer: TransferData) -> Self {
|
||||
Self::new_unsigned(PalletCall::bench_call { transfer })
|
||||
}
|
||||
|
||||
/// Create builder for given `Transfer`. Transfer `nonce` will be used as `Extrinsic` nonce.
|
||||
/// Transfer `from` will be used as Extrinsic signer.
|
||||
pub fn new_transfer(transfer: Transfer) -> Self {
|
||||
Self {
|
||||
nonce: Some(transfer.nonce),
|
||||
signer: Some(transfer.from.clone()),
|
||||
metadata_hash: None,
|
||||
..Self::new(BalancesCall::transfer_allow_death {
|
||||
dest: transfer.to,
|
||||
value: transfer.amount,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Create builder for `PalletCall::include_data` call using given parameters
|
||||
pub fn new_include_data(data: Vec<u8>) -> Self {
|
||||
Self::new(PalletCall::include_data { data })
|
||||
}
|
||||
|
||||
/// Create builder for `PalletCall::storage_change` call using given parameters. Will
|
||||
/// create unsigned Extrinsic.
|
||||
pub fn new_storage_change(key: Vec<u8>, value: Option<Vec<u8>>) -> Self {
|
||||
Self::new_unsigned(PalletCall::storage_change { key, value })
|
||||
}
|
||||
|
||||
/// Create builder for `PalletCall::offchain_index_set` call using given parameters
|
||||
pub fn new_offchain_index_set(key: Vec<u8>, value: Vec<u8>) -> Self {
|
||||
Self::new(PalletCall::offchain_index_set { key, value })
|
||||
}
|
||||
|
||||
/// Create builder for `PalletCall::offchain_index_clear` call using given parameters
|
||||
pub fn new_offchain_index_clear(key: Vec<u8>) -> Self {
|
||||
Self::new(PalletCall::offchain_index_clear { key })
|
||||
}
|
||||
|
||||
/// Create builder for `PalletCall::indexed_call` call using given parameters
|
||||
pub fn new_indexed_call(data: Vec<u8>) -> Self {
|
||||
Self::new(PalletCall::indexed_call { data })
|
||||
}
|
||||
|
||||
/// Create builder for `PalletCall::new_deposit_log_digest_item` call using given `log`
|
||||
pub fn new_deposit_log_digest_item(log: pezsp_runtime::generic::DigestItem) -> Self {
|
||||
Self::new_unsigned(PalletCall::deposit_log_digest_item { log })
|
||||
}
|
||||
|
||||
/// Create builder for `PalletCall::Call::new_deposit_log_digest_item`
|
||||
pub fn new_fill_block(ratio: Perbill) -> Self {
|
||||
Self::new(PalletCall::fill_block { ratio })
|
||||
}
|
||||
|
||||
/// Create builder for `PalletCall::call_do_not_propagate` call using given parameters
|
||||
pub fn new_call_do_not_propagate() -> Self {
|
||||
Self::new(PalletCall::call_do_not_propagate {})
|
||||
}
|
||||
|
||||
/// Create builder for `PalletCall::call_with_priority` call using given parameters
|
||||
pub fn new_call_with_priority(priority: TransactionPriority) -> Self {
|
||||
Self::new(PalletCall::call_with_priority { priority })
|
||||
}
|
||||
|
||||
/// Create builder for `PalletCall::read` call using given parameters
|
||||
pub fn new_read(count: u32) -> Self {
|
||||
Self::new_unsigned(PalletCall::read { count })
|
||||
}
|
||||
|
||||
/// Create builder for `PalletCall::read` call using given parameters
|
||||
pub fn new_read_and_panic(count: u32) -> Self {
|
||||
Self::new_unsigned(PalletCall::read_and_panic { count })
|
||||
}
|
||||
|
||||
/// Unsigned `Extrinsic` will be created
|
||||
pub fn unsigned(mut self) -> Self {
|
||||
self.signer = None;
|
||||
self
|
||||
}
|
||||
|
||||
/// Given `nonce` will be set in `Extrinsic`
|
||||
pub fn nonce(mut self, nonce: Nonce) -> Self {
|
||||
self.nonce = Some(nonce);
|
||||
self
|
||||
}
|
||||
|
||||
/// Extrinsic will be signed by `signer`
|
||||
pub fn signer(mut self, signer: Pair) -> Self {
|
||||
self.signer = Some(signer);
|
||||
self
|
||||
}
|
||||
|
||||
/// Metadata hash to put into the signed data of the extrinsic.
|
||||
pub fn metadata_hash(mut self, metadata_hash: [u8; 32]) -> Self {
|
||||
self.metadata_hash = Some(metadata_hash);
|
||||
self
|
||||
}
|
||||
|
||||
/// Build `Extrinsic` using embedded parameters
|
||||
pub fn build(self) -> Extrinsic {
|
||||
if let Some(signer) = self.signer {
|
||||
let tx_ext = (
|
||||
(CheckNonce::from(self.nonce.unwrap_or(0)), CheckWeight::new()),
|
||||
CheckBizinikiwiCall {},
|
||||
self.metadata_hash
|
||||
.map(CheckMetadataHash::new_with_custom_hash)
|
||||
.unwrap_or_else(|| CheckMetadataHash::new(false)),
|
||||
pezframe_system::WeightReclaim::new(),
|
||||
);
|
||||
let raw_payload = SignedPayload::from_raw(
|
||||
self.function.clone(),
|
||||
tx_ext.clone(),
|
||||
tx_ext.implicit().unwrap(),
|
||||
);
|
||||
let signature = raw_payload.using_encoded(|e| signer.sign(e));
|
||||
|
||||
Extrinsic::new_signed(self.function, signer.public(), signature, tx_ext)
|
||||
} else {
|
||||
Extrinsic::new_bare(self.function)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Tool for creating the genesis block.
|
||||
|
||||
use super::{
|
||||
currency, bizinikiwi_test_pallet, wasm_binary_unwrap, AccountId, Balance, RuntimeGenesisConfig,
|
||||
};
|
||||
use codec::Encode;
|
||||
use pezsc_service::construct_genesis_block;
|
||||
use pezsp_core::{
|
||||
sr25519,
|
||||
storage::{well_known_keys, StateVersion, Storage},
|
||||
Pair,
|
||||
};
|
||||
use pezsp_keyring::Sr25519Keyring;
|
||||
use pezsp_runtime::{
|
||||
traits::{Block as BlockT, Hash as HashT, Header as HeaderT},
|
||||
BuildStorage,
|
||||
};
|
||||
|
||||
/// Builder for generating storage from bizinikiwi-test-runtime genesis config.
|
||||
///
|
||||
/// Default storage can be extended with additional key-value pairs.
|
||||
pub struct GenesisStorageBuilder {
|
||||
/// Authorities accounts used by any component requiring an authority set (e.g. babe).
|
||||
authorities: Vec<AccountId>,
|
||||
/// Accounts to be endowed with some funds.
|
||||
balances: Vec<(AccountId, u64)>,
|
||||
/// Override default number of heap pages.
|
||||
heap_pages_override: Option<u64>,
|
||||
/// Additional storage key pairs that will be added to the genesis map.
|
||||
extra_storage: Storage,
|
||||
/// Optional wasm code override.
|
||||
wasm_code: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl Default for GenesisStorageBuilder {
|
||||
/// Creates a builder with default settings for `bizinikiwi_test_runtime`.
|
||||
fn default() -> Self {
|
||||
Self::new(
|
||||
vec![
|
||||
Sr25519Keyring::Alice.into(),
|
||||
Sr25519Keyring::Bob.into(),
|
||||
Sr25519Keyring::Charlie.into(),
|
||||
],
|
||||
(0..16_usize)
|
||||
.into_iter()
|
||||
.map(|i| Sr25519Keyring::numeric(i).public())
|
||||
.chain(vec![
|
||||
Sr25519Keyring::Alice.into(),
|
||||
Sr25519Keyring::Bob.into(),
|
||||
Sr25519Keyring::Charlie.into(),
|
||||
])
|
||||
.collect(),
|
||||
1000 * currency::DOLLARS,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl GenesisStorageBuilder {
|
||||
/// Creates a storage builder for genesis config. `substrage test runtime`
|
||||
/// [`RuntimeGenesisConfig`] is initialized with provided `authorities`, `endowed_accounts` with
|
||||
/// given balance. Key-value pairs from `extra_storage` will be injected into built storage.
|
||||
/// `HEAP_PAGES` key and value will also be placed into storage.
|
||||
pub fn new(
|
||||
authorities: Vec<AccountId>,
|
||||
endowed_accounts: Vec<AccountId>,
|
||||
balance: Balance,
|
||||
) -> Self {
|
||||
GenesisStorageBuilder {
|
||||
authorities,
|
||||
balances: endowed_accounts.into_iter().map(|a| (a, balance)).collect(),
|
||||
heap_pages_override: None,
|
||||
extra_storage: Default::default(),
|
||||
wasm_code: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Override default wasm code to be placed into RuntimeGenesisConfig.
|
||||
pub fn with_wasm_code(mut self, wasm_code: &Option<Vec<u8>>) -> Self {
|
||||
self.wasm_code = wasm_code.clone();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_heap_pages(mut self, heap_pages_override: Option<u64>) -> Self {
|
||||
self.heap_pages_override = heap_pages_override;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_extra_storage(mut self, storage: Storage) -> Self {
|
||||
self.extra_storage = storage;
|
||||
self
|
||||
}
|
||||
|
||||
/// A `RuntimeGenesisConfig` from internal configuration
|
||||
pub fn genesis_config(&self) -> RuntimeGenesisConfig {
|
||||
let authorities_sr25519: Vec<_> = self
|
||||
.authorities
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|id| sr25519::Public::from(id))
|
||||
.collect();
|
||||
|
||||
RuntimeGenesisConfig {
|
||||
system: Default::default(),
|
||||
babe: pezpallet_babe::GenesisConfig {
|
||||
authorities: authorities_sr25519
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|x| (x.into(), 1))
|
||||
.collect(),
|
||||
..Default::default()
|
||||
},
|
||||
bizinikiwi_test: bizinikiwi_test_pallet::GenesisConfig {
|
||||
authorities: authorities_sr25519.clone(),
|
||||
..Default::default()
|
||||
},
|
||||
balances: pezpallet_balances::GenesisConfig {
|
||||
balances: self.balances.clone(),
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds the `RuntimeGenesisConfig` and returns its storage.
|
||||
pub fn build(self) -> Storage {
|
||||
let mut storage = self
|
||||
.genesis_config()
|
||||
.build_storage()
|
||||
.expect("Build storage from bizinikiwi-test-runtime RuntimeGenesisConfig");
|
||||
|
||||
if let Some(heap_pages) = self.heap_pages_override {
|
||||
storage.top.insert(well_known_keys::HEAP_PAGES.into(), heap_pages.encode());
|
||||
}
|
||||
|
||||
storage.top.insert(
|
||||
well_known_keys::CODE.into(),
|
||||
self.wasm_code.clone().unwrap_or(wasm_binary_unwrap().to_vec()),
|
||||
);
|
||||
|
||||
storage.top.extend(self.extra_storage.top.clone());
|
||||
storage.children_default.extend(self.extra_storage.children_default.clone());
|
||||
|
||||
storage
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert_genesis_block(storage: &mut Storage) -> pezsp_core::hash::H256 {
|
||||
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
||||
let state_root =
|
||||
<<<crate::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
child_content.data.clone().into_iter().collect(),
|
||||
pezsp_runtime::StateVersion::V1,
|
||||
);
|
||||
(sk.clone(), state_root.encode())
|
||||
});
|
||||
// add child roots to storage
|
||||
storage.top.extend(child_roots);
|
||||
let state_root = <<<crate::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
storage.top.clone().into_iter().collect(),
|
||||
pezsp_runtime::StateVersion::V1,
|
||||
);
|
||||
let block: crate::Block = construct_genesis_block(state_root, StateVersion::V1);
|
||||
let genesis_hash = block.header.hash();
|
||||
|
||||
genesis_hash
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user