Make SetCode::set_code return a result (#8515)

This commit is contained in:
Bastian Köcher
2021-04-02 01:09:41 +02:00
committed by GitHub
parent c90828ee34
commit dcf29a8523
+6 -5
View File
@@ -94,7 +94,7 @@ use frame_support::{
Weight, RuntimeDbWeight, DispatchInfo, DispatchClass, Weight, RuntimeDbWeight, DispatchInfo, DispatchClass,
extract_actual_weight, PerDispatchClass, extract_actual_weight, PerDispatchClass,
}, },
dispatch::DispatchResultWithPostInfo, dispatch::{DispatchResultWithPostInfo, DispatchResult},
}; };
use codec::{Encode, Decode, FullCodec, EncodeLike}; use codec::{Encode, Decode, FullCodec, EncodeLike};
@@ -143,12 +143,13 @@ pub use pallet::*;
/// Do something when we should be setting the code. /// Do something when we should be setting the code.
pub trait SetCode { pub trait SetCode {
/// Set the code to the given blob. /// Set the code to the given blob.
fn set_code(code: Vec<u8>); fn set_code(code: Vec<u8>) -> DispatchResult;
} }
impl SetCode for () { impl SetCode for () {
fn set_code(code: Vec<u8>) { fn set_code(code: Vec<u8>) -> DispatchResult {
storage::unhashed::put_raw(well_known_keys::CODE, &code); storage::unhashed::put_raw(well_known_keys::CODE, &code);
Ok(())
} }
} }
@@ -345,7 +346,7 @@ pub mod pallet {
ensure_root(origin)?; ensure_root(origin)?;
Self::can_set_code(&code)?; Self::can_set_code(&code)?;
T::OnSetCode::set_code(code); T::OnSetCode::set_code(code)?;
Self::deposit_event(Event::CodeUpdated); Self::deposit_event(Event::CodeUpdated);
Ok(().into()) Ok(().into())
} }
@@ -364,7 +365,7 @@ pub mod pallet {
code: Vec<u8>, code: Vec<u8>,
) -> DispatchResultWithPostInfo { ) -> DispatchResultWithPostInfo {
ensure_root(origin)?; ensure_root(origin)?;
T::OnSetCode::set_code(code); T::OnSetCode::set_code(code)?;
Self::deposit_event(Event::CodeUpdated); Self::deposit_event(Event::CodeUpdated);
Ok(().into()) Ok(().into())
} }