Skip to content
This repository was archived by the owner on May 21, 2024. It is now read-only.
Merged
Prev Previous commit
Next Next commit
Adding specific call pallets
  • Loading branch information
hbulgarini committed May 2, 2023
commit 4ed3d836876f5b5e224715ce89afaa05ef6fceac
4 changes: 2 additions & 2 deletions pallets/maintenance-mode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ frame-system = { version = "4.0.0-dev", default-features = false, git = "https:/
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.37", default-features = false }
pallet-assets = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }

log = "0.4.17"
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.37" }

xcm-primitives = { path = "../../primitives/xcm", default-features = false }
Expand All @@ -30,7 +30,7 @@ sp-core = { version = "7.0.0", default-features = false, git = "https://github.c
sp-io = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-runtime = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
pallet-remark = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
log = "0.4.17"


xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.37" }
xcm-simulator = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.37" }
Expand Down
6 changes: 4 additions & 2 deletions pallets/maintenance-mode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ pub mod pallet {
traits::Contains,
};
use frame_system::pallet_prelude::*;
pub use log;
use sp_std::vec::Vec;
use xcm_primitives::PauseXcmExecution;

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);
Expand Down Expand Up @@ -128,10 +128,12 @@ pub mod pallet {

impl<T: Config> Contains<T::RuntimeCall> for Pallet<T> {
fn contains(call: &T::RuntimeCall) -> bool {
log::info!("Pallet Contains: {:?}", call);
if MaintenanceModeOnOff::<T>::get() {
T::FilteredCalls::contains(call)
} else {
return false
log::info!("Maintenance Mode is off, all calls are allowed");
return true
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions runtime/trappist/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use frame_support::{
traits::{Contains, Currency, Imbalance, OnUnbalanced},
weights::Weight,
};
pub use log;
use sp_runtime::DispatchResult;
use sp_std::marker::PhantomData;

Expand Down Expand Up @@ -76,8 +77,16 @@ pub struct RuntimeFilteredCalls;
impl Contains<RuntimeCall> for RuntimeFilteredCalls {
fn contains(call: &RuntimeCall) -> bool {
match call {
RuntimeCall::Balances(_) => true,
_ => false,
RuntimeCall::Balances(_) => false,
RuntimeCall::Assets(_) => false,
RuntimeCall::Dex(_) => false,
RuntimeCall::PolkadotXcm(_) => false,
RuntimeCall::Treasury(_) => false,
RuntimeCall::Chess(_) => false,
RuntimeCall::Contracts(_) => false,
RuntimeCall::Uniques(_) => false,
RuntimeCall::AssetRegistry(_) => false,
_ => true,
}
}
}
Expand Down Expand Up @@ -119,7 +128,6 @@ mod tests {
traits::{BlakeTwo256, ConstU32, ConstU64, IdentityLookup},
Perbill,
};
use xcm::prelude::*;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand Down
4 changes: 4 additions & 0 deletions runtime/trappist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod constants;
mod contracts;
pub mod impls;
pub mod xcm_config;
pub use log;

use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use sp_api::impl_runtime_apis;
Expand Down Expand Up @@ -785,6 +786,9 @@ impl_runtime_apis! {
tx: <Block as BlockT>::Extrinsic,
block_hash: <Block as BlockT>::Hash,
) -> TransactionValidity {
if !<Runtime as frame_system::Config>::BaseCallFilter::contains(&tx.function) {
return InvalidTransaction::Call.into();
};
Executive::validate_transaction(source, tx, block_hash)
}
}
Expand Down