Introduce OnSetCode type into system config trait. (#8496)

* Introduce OnSetCode type into system config trait.

* Docs.

* Fixes

* Fixes
This commit is contained in:
Gavin Wood
2021-04-01 14:20:24 +02:00
committed by GitHub
parent 34458e9b9c
commit 643d2b669f
65 changed files with 85 additions and 4 deletions
+18 -2
View File
@@ -140,6 +140,18 @@ pub type ConsumedWeight = PerDispatchClass<Weight>;
pub use pallet::*;
/// Do something when we should be setting the code.
pub trait SetCode {
/// Set the code to the given blob.
fn set_code(code: Vec<u8>);
}
impl SetCode for () {
fn set_code(code: Vec<u8>) {
storage::unhashed::put_raw(well_known_keys::CODE, &code);
}
}
#[frame_support::pallet]
pub mod pallet {
use crate::{*, pallet_prelude::*, self as frame_system};
@@ -253,6 +265,10 @@ pub mod pallet {
/// an identifier of the chain.
#[pallet::constant]
type SS58Prefix: Get<u8>;
/// What to do if the user wants the code set to something. Just use `()` unless you are in
/// cumulus.
type OnSetCode: SetCode;
}
#[pallet::pallet]
@@ -329,7 +345,7 @@ pub mod pallet {
ensure_root(origin)?;
Self::can_set_code(&code)?;
storage::unhashed::put_raw(well_known_keys::CODE, &code);
T::OnSetCode::set_code(code);
Self::deposit_event(Event::CodeUpdated);
Ok(().into())
}
@@ -348,7 +364,7 @@ pub mod pallet {
code: Vec<u8>,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
storage::unhashed::put_raw(well_known_keys::CODE, &code);
T::OnSetCode::set_code(code);
Self::deposit_event(Event::CodeUpdated);
Ok(().into())
}
+1
View File
@@ -107,6 +107,7 @@ impl Config for Test {
type OnKilledAccount = RecordKilled;
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}
pub type SysEvent = frame_system::Event<Test>;