Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "r
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" , default-features = false }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" , default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }

# pallets that we want to use
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" , default-features = false }
pallet-sudo = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }

# genesis builder that allows us to interacto with runtime genesis config
sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
Expand All @@ -59,12 +61,14 @@ std = [

"sp-core/std",
"sp-runtime/std",
"sp-io/std",

"pallet-balances/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"pallet-assets/std",

"pallet-minimal-template/std",

Expand Down
40 changes: 36 additions & 4 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ use frame::{
},
};

use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, IdentityFee, Weight};
use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_MILLIS, Weight};

// Substrate FRAME
#[cfg(feature = "with-paritydb-weights")]
use frame_support::weights::constants::ParityDbWeight as RuntimeDbWeight;
#[cfg(feature = "with-rocksdb-weights")]
use frame_support::weights::constants::RocksDbWeight as RuntimeDbWeight;

use sp_runtime::{generic, traits::BlakeTwo256, Perbill};
use sp_runtime::{generic, traits::BlakeTwo256, Perbill, AccountId32};

/// Type of block number.
pub type BlockNumber = u32;
Expand Down Expand Up @@ -100,6 +100,7 @@ construct_runtime!(
Balances: pallet_balances,
Sudo: pallet_sudo,
TransactionPayment: pallet_transaction_payment,
Assets: pallet_assets,

// our local pallet
Template: pallet_minimal_template,
Expand All @@ -122,6 +123,8 @@ parameter_types! {
pub const SS58Prefix: u8 = 42;
}

type AccountId = AccountId32;

impl frame_system::Config for Runtime {
/// The default type for storing how many extrinsics an account has signed.
type Nonce = u32;
Expand All @@ -135,7 +138,7 @@ impl frame_system::Config for Runtime {
type Hashing = sp_runtime::traits::BlakeTwo256;

/// The default identifier used to distinguish between accounts.
type AccountId = sp_runtime::AccountId32;
type AccountId = AccountId;

/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = sp_runtime::traits::AccountIdLookup<Self::AccountId, ()>;
Expand Down Expand Up @@ -201,6 +204,36 @@ impl frame_system::Config for Runtime {
type PostTransactions = ();
}

pub struct EnsureRootWithArg<T: frame_system::Config> {
_marker: PhantomData<T>,
}

impl<T: frame_system::Config> frame_support::traits::EnsureOriginWithArg<T::RuntimeOrigin, T::AccountId> for EnsureRootWithArg<T> {
type Success = T::AccountId;

fn try_origin(origin: T::RuntimeOrigin, _arg: &T::AccountId) -> Result<Self::Success, T::RuntimeOrigin> {
// First, check if the origin is root
if let Ok(_) = <EnsureRoot<<T as frame_system::Config>::AccountId> as frame::prelude::EnsureOrigin<T::RuntimeOrigin>>::try_origin(origin.clone()) {
// If it is, return some specific account ID as the success type
// You need to define what this account ID will be
return Ok(_arg.clone());
}

// If not root, you could check for other conditions or specific accounts
// For this example, we're just rejecting if not root
Err(origin)
}
}

#[derive_impl(pallet_assets::config_preludes::TestDefaultConfig)]
impl pallet_assets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type CreateOrigin = EnsureRootWithArg<Runtime>;
type ForceOrigin = frame_system::EnsureRoot<AccountId>;
type Freezer = ();
}

#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
impl pallet_balances::Config for Runtime {
type AccountStore = System;
Expand Down Expand Up @@ -349,7 +382,6 @@ impl_runtime_apis! {
// https://github.com/paritytech/substrate/issues/10579#issuecomment-1600537558
pub mod interface {
use super::Runtime;
use frame::deps::frame_system;

pub type Block = super::Block;
pub use frame::runtime::types_common::OpaqueBlock;
Expand Down