Skip to content

Commit

Permalink
WIP; Stop
Browse files Browse the repository at this point in the history
  • Loading branch information
mustermeiszer authored and cdamian committed Jul 11, 2023
1 parent 63d4bd9 commit 0cfe732
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ sp-session = { git = "https://github.com/paritytech/substrate", branch = "polkad
sp-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }

# Cli specific
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
Expand Down Expand Up @@ -173,7 +174,6 @@ substrate-build-script-utils = { optional = true, git = "https://github.com/pari
vergen = "3.0.4"

[dev-dependencies]
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
getrandom = { version = "0.2", features = ["js"] }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
sc-service-test = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }
Expand Down
80 changes: 78 additions & 2 deletions libs/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,67 @@ where
pallet_timestamp::Pallet::<T>::set_timestamp(timestamp);
}

pub mod evm {
use std::marker::PhantomData;
#[macro_export]
macro_rules! GenesisExt{
($id:ident, $( $name:ident : $gen:ty),* ) => {
#[cfg(feature = "std")]
#[derive(Serialize, Deserialize)]
#[allow(non_snake_case)]
pub struct $id {
$(
pub $name: $gen,
)*
}


impl $id {
fn new($($name: $gen),*) -> Self {
Self {
$(
$name,
)*
}
}
}

#[cfg(feature = "std")]
impl sp_runtime::BuildStorage for $id {
fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> {
$(
sp_runtime::BuildStorage::assimilate_storage(&self.$name, storage)?;
)*

Ok(())
}
}
};
}

pub mod evm {
#[cfg(feature = "std")]
use frame_support::traits::GenesisBuild;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_core::U256;
use sp_runtime::{app_crypto::sp_core::H160, traits::Get};
use sp_std::{default::Default, marker::PhantomData, vec::Vec};

#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
pub struct CodeDeployer<Origin> {
codes: Vec<(H160, Vec<u8>)>,
_phantom: PhantomData<Origin>,
}

impl<Origin> CodeDeployer<Origin> {
#[cfg(feature = "std")]
pub fn new(codes: Vec<(H160, Vec<u8>)>) -> Self {
Self {
codes,
_phantom: Default::default(),
}
}
}

impl<Origin> Default for CodeDeployer<Origin> {
fn default() -> Self {
CodeDeployer {
Expand All @@ -102,6 +148,7 @@ pub mod evm {
}
}

#[cfg(feature = "std")]
impl<T: frame_system::Config + pallet_evm::Config, Origin: Get<T::RuntimeOrigin>>
GenesisBuild<T> for CodeDeployer<Origin>
{
Expand Down Expand Up @@ -131,6 +178,35 @@ pub mod evm {
}
}
}

#[cfg(feature = "std")]
impl<Origin> BuildStorage for CodeDeployer<Origin> {
fn build(&self) {
for (who, code) in self.codes.clone() {
// origin: OriginFor<T>,
// source: H160,
// init: Vec<u8>,
// value: U256,
// gas_limit: u64,
// max_fee_per_gas: U256,
// max_priority_fee_per_gas: Option<U256>,
// nonce: Option<U256>,
// access_list: Vec<(H160, Vec<H256>)>,
pallet_evm::Pallet::<T>::create(
Origin::get(),
who,
code,
U256::MAX,
u64::MAX,
U256::MAX,
None,
None,
Vec::new(),
)
.expect("Deploying code in genesis failed.");
}
}
}
}

#[cfg(test)]
Expand Down
101 changes: 65 additions & 36 deletions src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#![allow(clippy::derive_partial_eq_without_eq)]

use altair_runtime::constants::currency::{AIR, MILLI_AIR};
use cfg_primitives::{currency_decimals, parachains, Balance, CFG, MILLI_CFG};
use cfg_primitives::{currency_decimals, parachains, AccountId, Balance, CFG, MILLI_CFG};
use cfg_types::{
fee_keys::FeeKey,
tokens::{AssetMetadata, CrossChainTransferability, CurrencyId, CustomMetadata},
Expand All @@ -35,7 +35,7 @@ use runtime_common::account_conversion::AccountConverter;
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::{ChainType, Properties};
use serde::{Deserialize, Serialize};
use sp_core::{crypto::UncheckedInto, sr25519, Encode, Pair, Public};
use sp_core::{crypto::UncheckedInto, sr25519, Encode, Get, Pair, Public, H160};
use sp_runtime::traits::{IdentifyAccount, Verify};
use xcm::{
latest::MultiLocation,
Expand All @@ -46,8 +46,21 @@ use xcm::{
pub type AltairChainSpec = sc_service::GenericChainSpec<altair_runtime::GenesisConfig, Extensions>;
pub type CentrifugeChainSpec =
sc_service::GenericChainSpec<centrifuge_runtime::GenesisConfig, Extensions>;
pub type DevelopmentChainSpec =
sc_service::GenericChainSpec<development_runtime::GenesisConfig, Extensions>;
pub type DevelopmentChainSpec = sc_service::GenericChainSpec<DevGenesisExt, Extensions>;

cfg_utils::GenesisExt!(
DevGenesisExt,
gen: development_runtime::GenesisConfig,
code: cfg_utils::evm::CodeDeployer<GetRoot>
);

#[derive(Debug)]
pub struct GetRoot;
impl Get<development_runtime::RuntimeOrigin> for GetRoot {
fn get() -> development_runtime::RuntimeOrigin {
frame_system::RawOrigin::Root.into()
}
}

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
Expand Down Expand Up @@ -397,20 +410,24 @@ pub fn demo(para_id: ParaId) -> DevelopmentChainSpec {
"demo_live",
ChainType::Live,
move || {
development_genesis(
// kANEUrMbi9xC16AfL5vSGwfvBVRoRdfWoQ8abPiXi5etFxpdP
hex!["e0c426785313bb7e712d66dce43ccb81a7eaef373784511fb508fff4b5df3305"].into(),
vec![(
// kAHJNhAragKRrAb9X8JxSNYoqPqv36TspSwdSuyMfxGKUmfdH
hex!["068f3bd4ed27bb83da8fdebbb4deba6b3b3b83ff47c8abad11e5c48c74c20b11"].into(),
// kAKXFWse8rghi8mbAFB4RaVyZu6XZXq5i9wv7uYakZ3vQcxMR
hex!["68d9baaa081802f8ec50d475b654810b158cdcb23e11c43815a6549f78f1b34f"]
.unchecked_into(),
)],
demo_endowed_accounts(),
vec![],
Some(100000000 * CFG),
para_id,
DevGenesisExt::new(
development_genesis(
// kANEUrMbi9xC16AfL5vSGwfvBVRoRdfWoQ8abPiXi5etFxpdP
hex!["e0c426785313bb7e712d66dce43ccb81a7eaef373784511fb508fff4b5df3305"].into(),
vec![(
// kAHJNhAragKRrAb9X8JxSNYoqPqv36TspSwdSuyMfxGKUmfdH
hex!["068f3bd4ed27bb83da8fdebbb4deba6b3b3b83ff47c8abad11e5c48c74c20b11"]
.into(),
// kAKXFWse8rghi8mbAFB4RaVyZu6XZXq5i9wv7uYakZ3vQcxMR
hex!["68d9baaa081802f8ec50d475b654810b158cdcb23e11c43815a6549f78f1b34f"]
.unchecked_into(),
)],
demo_endowed_accounts(),
vec![],
Some(100000000 * CFG),
para_id,
),
cfg_utils::evm::CodeDeployer::default(),
)
},
vec![],
Expand All @@ -432,16 +449,22 @@ pub fn development(para_id: ParaId) -> DevelopmentChainSpec {
"devel_live",
ChainType::Live,
move || {
development_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
vec![(
DevGenesisExt::new(
development_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<development_runtime::AuraId>("Alice"),
)],
endowed_accounts(),
endowed_evm_accounts(),
Some(10000000 * CFG),
para_id,
vec![(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<development_runtime::AuraId>("Alice"),
)],
endowed_accounts(),
endowed_evm_accounts(),
Some(10000000 * CFG),
para_id,
),
cfg_utils::evm::CodeDeployer::new(vec![
(H160::from([0u8; 20]), vec![0, 0]),
(H160::from([0u8; 20]), vec![0, 0]),
]),
)
},
vec![],
Expand All @@ -463,16 +486,22 @@ pub fn development_local(para_id: ParaId) -> DevelopmentChainSpec {
"devel_local",
ChainType::Local,
move || {
development_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
vec![(
DevGenesisExt::new(
development_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<development_runtime::AuraId>("Alice"),
)],
endowed_accounts(),
endowed_evm_accounts(),
Some(10000000 * CFG),
para_id,
vec![(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<development_runtime::AuraId>("Alice"),
)],
endowed_accounts(),
endowed_evm_accounts(),
Some(10000000 * CFG),
para_id,
),
cfg_utils::evm::CodeDeployer::new(vec![
(H160::from([0u8; 20]), vec![0, 0]),
(H160::from([0u8; 20]), vec![0, 0]),
]),
)
},
vec![],
Expand Down

0 comments on commit 0cfe732

Please sign in to comment.