-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pallet-base-fee
storage utility functions
#585
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,15 @@ | |
|
||
pub use pallet::*; | ||
|
||
use frame_support::{traits::Get, weights::Weight}; | ||
use sp_core::U256; | ||
use sp_runtime::Permill; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use super::*; | ||
use frame_support::{dispatch::DispatchResult, pallet_prelude::*}; | ||
use frame_system::pallet_prelude::*; | ||
use sp_core::U256; | ||
use sp_runtime::Permill; | ||
|
||
pub trait BaseFeeThreshold { | ||
fn lower() -> Permill; | ||
|
@@ -210,23 +213,23 @@ pub mod pallet { | |
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))] | ||
pub fn set_base_fee_per_gas(origin: OriginFor<T>, fee: U256) -> DispatchResult { | ||
ensure_root(origin)?; | ||
<BaseFeePerGas<T>>::put(fee); | ||
let _ = Self::set_base_fee_per_gas_inner(fee); | ||
Self::deposit_event(Event::NewBaseFeePerGas(fee)); | ||
Ok(()) | ||
} | ||
|
||
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))] | ||
pub fn set_is_active(origin: OriginFor<T>, is_active: bool) -> DispatchResult { | ||
ensure_root(origin)?; | ||
<IsActive<T>>::put(is_active); | ||
let _ = Self::set_is_active_inner(is_active); | ||
Self::deposit_event(Event::IsActive(is_active)); | ||
Ok(()) | ||
} | ||
|
||
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))] | ||
pub fn set_elasticity(origin: OriginFor<T>, elasticity: Permill) -> DispatchResult { | ||
ensure_root(origin)?; | ||
<Elasticity<T>>::put(elasticity); | ||
let _ = Self::set_elasticity_inner(elasticity); | ||
Self::deposit_event(Event::NewElasticity(elasticity)); | ||
Ok(()) | ||
} | ||
|
@@ -239,6 +242,21 @@ pub mod pallet { | |
} | ||
} | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub fn set_base_fee_per_gas_inner(value: U256) -> Weight { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you rename the name to without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I also believed that was the case and previously tried, but the compiler throws |
||
<BaseFeePerGas<T>>::put(value); | ||
T::DbWeight::get().write | ||
} | ||
pub fn set_elasticity_inner(value: Permill) -> Weight { | ||
<Elasticity<T>>::put(value); | ||
T::DbWeight::get().write | ||
} | ||
pub fn set_is_active_inner(value: bool) -> Weight { | ||
<IsActive<T>>::put(value); | ||
T::DbWeight::get().write | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain the reason for doing this, it doesn't seem necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are just some convenience functions to set the storage i.e. to update the storage values on runtime upgrade from outside the pallet or write integration tests.