mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-24 20:35:41 +00:00
Moves Block to frame_system instead of construct_runtime and removes Header and BlockNumber (#14437)
* Initial setup * Adds node block * Uses UncheckedExtrinsic and removes Where section * Updates frame_system to use Block * Adds deprecation warning * Fixes pallet-timestamp * Removes Header and BlockNumber * Addresses review comments * Addresses review comments * Adds comment about compiler bug * Removes where clause * Refactors code * Fixes errors in cargo check * Fixes errors in cargo check * Fixes warnings in cargo check * Formatting * Fixes construct_runtime tests * Uses import instead of full path for BlockNumber * Uses import instead of full path for Header * Formatting * Fixes construct_runtime tests * Fixes imports in benchmarks * Formatting * Fixes construct_runtime tests * Formatting * Minor updates * Fixes construct_runtime ui tests * Fixes construct_runtime ui tests with 1.70 * Fixes docs * Fixes docs * Adds u128 mock block type * Fixes split example * fixes for cumulus * ".git/.scripts/commands/fmt/fmt.sh" * Updates new tests * Fixes fully-qualified path in few places * Formatting * Update frame/examples/default-config/src/lib.rs Co-authored-by: Juan <juangirini@gmail.com> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Juan <juangirini@gmail.com> * ".git/.scripts/commands/fmt/fmt.sh" * Addresses some review comments * Fixes build * ".git/.scripts/commands/fmt/fmt.sh" * Update frame/democracy/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/democracy/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Addresses review comments * Updates trait bounds * Minor fix * ".git/.scripts/commands/fmt/fmt.sh" * Removes unnecessary bound * ".git/.scripts/commands/fmt/fmt.sh" * Updates test * Fixes build * Adds a bound for header * ".git/.scripts/commands/fmt/fmt.sh" * Removes where block * Minor fix * Minor fix * Fixes tests * ".git/.scripts/commands/update-ui/update-ui.sh" 1.70 * Updates test * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Updates doc * Updates doc --------- Co-authored-by: command-bot <> Co-authored-by: Juan <juangirini@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -67,6 +67,7 @@ use frame_support::{
|
||||
},
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
traits::{
|
||||
@@ -127,8 +128,8 @@ impl VestingAction {
|
||||
/// Pick the schedules that this action dictates should continue vesting undisturbed.
|
||||
fn pick_schedules<T: Config>(
|
||||
&self,
|
||||
schedules: Vec<VestingInfo<BalanceOf<T>, T::BlockNumber>>,
|
||||
) -> impl Iterator<Item = VestingInfo<BalanceOf<T>, T::BlockNumber>> + '_ {
|
||||
schedules: Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>,
|
||||
) -> impl Iterator<Item = VestingInfo<BalanceOf<T>, BlockNumberFor<T>>> + '_ {
|
||||
schedules.into_iter().enumerate().filter_map(move |(index, schedule)| {
|
||||
if self.should_remove(index) {
|
||||
None
|
||||
@@ -162,7 +163,7 @@ pub mod pallet {
|
||||
type Currency: LockableCurrency<Self::AccountId>;
|
||||
|
||||
/// Convert the block number into a balance.
|
||||
type BlockNumberToBalance: Convert<Self::BlockNumber, BalanceOf<Self>>;
|
||||
type BlockNumberToBalance: Convert<BlockNumberFor<Self>, BalanceOf<Self>>;
|
||||
|
||||
/// The minimum amount transferred to call `vested_transfer`.
|
||||
#[pallet::constant]
|
||||
@@ -201,7 +202,7 @@ pub mod pallet {
|
||||
_,
|
||||
Blake2_128Concat,
|
||||
T::AccountId,
|
||||
BoundedVec<VestingInfo<BalanceOf<T>, T::BlockNumber>, MaxVestingSchedulesGet<T>>,
|
||||
BoundedVec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>, MaxVestingSchedulesGet<T>>,
|
||||
>;
|
||||
|
||||
/// Storage version of the pallet.
|
||||
@@ -216,7 +217,7 @@ pub mod pallet {
|
||||
#[pallet::genesis_config]
|
||||
#[derive(frame_support::DefaultNoBound)]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
pub vesting: Vec<(T::AccountId, T::BlockNumber, T::BlockNumber, BalanceOf<T>)>,
|
||||
pub vesting: Vec<(T::AccountId, BlockNumberFor<T>, BlockNumberFor<T>, BalanceOf<T>)>,
|
||||
}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
@@ -342,7 +343,7 @@ pub mod pallet {
|
||||
pub fn vested_transfer(
|
||||
origin: OriginFor<T>,
|
||||
target: AccountIdLookupOf<T>,
|
||||
schedule: VestingInfo<BalanceOf<T>, T::BlockNumber>,
|
||||
schedule: VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
|
||||
) -> DispatchResult {
|
||||
let transactor = ensure_signed(origin)?;
|
||||
let transactor = <T::Lookup as StaticLookup>::unlookup(transactor);
|
||||
@@ -371,7 +372,7 @@ pub mod pallet {
|
||||
origin: OriginFor<T>,
|
||||
source: AccountIdLookupOf<T>,
|
||||
target: AccountIdLookupOf<T>,
|
||||
schedule: VestingInfo<BalanceOf<T>, T::BlockNumber>,
|
||||
schedule: VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
Self::do_vested_transfer(source, target, schedule)
|
||||
@@ -433,10 +434,10 @@ impl<T: Config> Pallet<T> {
|
||||
// Create a new `VestingInfo`, based off of two other `VestingInfo`s.
|
||||
// NOTE: We assume both schedules have had funds unlocked up through the current block.
|
||||
fn merge_vesting_info(
|
||||
now: T::BlockNumber,
|
||||
schedule1: VestingInfo<BalanceOf<T>, T::BlockNumber>,
|
||||
schedule2: VestingInfo<BalanceOf<T>, T::BlockNumber>,
|
||||
) -> Option<VestingInfo<BalanceOf<T>, T::BlockNumber>> {
|
||||
now: BlockNumberFor<T>,
|
||||
schedule1: VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
|
||||
schedule2: VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
|
||||
) -> Option<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>> {
|
||||
let schedule1_ending_block = schedule1.ending_block_as_balance::<T::BlockNumberToBalance>();
|
||||
let schedule2_ending_block = schedule2.ending_block_as_balance::<T::BlockNumberToBalance>();
|
||||
let now_as_balance = T::BlockNumberToBalance::convert(now);
|
||||
@@ -483,7 +484,7 @@ impl<T: Config> Pallet<T> {
|
||||
fn do_vested_transfer(
|
||||
source: AccountIdLookupOf<T>,
|
||||
target: AccountIdLookupOf<T>,
|
||||
schedule: VestingInfo<BalanceOf<T>, T::BlockNumber>,
|
||||
schedule: VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
|
||||
) -> DispatchResult {
|
||||
// Validate user inputs.
|
||||
ensure!(schedule.locked() >= T::MinVestedTransfer::get(), Error::<T>::AmountLow);
|
||||
@@ -531,9 +532,9 @@ impl<T: Config> Pallet<T> {
|
||||
///
|
||||
/// NOTE: the amount locked does not include any schedules that are filtered out via `action`.
|
||||
fn report_schedule_updates(
|
||||
schedules: Vec<VestingInfo<BalanceOf<T>, T::BlockNumber>>,
|
||||
schedules: Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>,
|
||||
action: VestingAction,
|
||||
) -> (Vec<VestingInfo<BalanceOf<T>, T::BlockNumber>>, BalanceOf<T>) {
|
||||
) -> (Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>, BalanceOf<T>) {
|
||||
let now = <frame_system::Pallet<T>>::block_number();
|
||||
|
||||
let mut total_locked_now: BalanceOf<T> = Zero::zero();
|
||||
@@ -570,10 +571,10 @@ impl<T: Config> Pallet<T> {
|
||||
/// Write an accounts updated vesting schedules to storage.
|
||||
fn write_vesting(
|
||||
who: &T::AccountId,
|
||||
schedules: Vec<VestingInfo<BalanceOf<T>, T::BlockNumber>>,
|
||||
schedules: Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>,
|
||||
) -> Result<(), DispatchError> {
|
||||
let schedules: BoundedVec<
|
||||
VestingInfo<BalanceOf<T>, T::BlockNumber>,
|
||||
VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
|
||||
MaxVestingSchedulesGet<T>,
|
||||
> = schedules.try_into().map_err(|_| Error::<T>::AtMaxVestingSchedules)?;
|
||||
|
||||
@@ -602,9 +603,9 @@ impl<T: Config> Pallet<T> {
|
||||
/// Execute a `VestingAction` against the given `schedules`. Returns the updated schedules
|
||||
/// and locked amount.
|
||||
fn exec_action(
|
||||
schedules: Vec<VestingInfo<BalanceOf<T>, T::BlockNumber>>,
|
||||
schedules: Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>,
|
||||
action: VestingAction,
|
||||
) -> Result<(Vec<VestingInfo<BalanceOf<T>, T::BlockNumber>>, BalanceOf<T>), DispatchError> {
|
||||
) -> Result<(Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>, BalanceOf<T>), DispatchError> {
|
||||
let (schedules, locked_now) = match action {
|
||||
VestingAction::Merge { index1: idx1, index2: idx2 } => {
|
||||
// The schedule index is based off of the schedule ordering prior to filtering out
|
||||
@@ -649,7 +650,7 @@ where
|
||||
BalanceOf<T>: MaybeSerializeDeserialize + Debug,
|
||||
{
|
||||
type Currency = T::Currency;
|
||||
type Moment = T::BlockNumber;
|
||||
type Moment = BlockNumberFor<T>;
|
||||
|
||||
/// Get the amount that is currently being vested and cannot be transferred out of this account.
|
||||
fn vesting_balance(who: &T::AccountId) -> Option<BalanceOf<T>> {
|
||||
@@ -680,7 +681,7 @@ where
|
||||
who: &T::AccountId,
|
||||
locked: BalanceOf<T>,
|
||||
per_block: BalanceOf<T>,
|
||||
starting_block: T::BlockNumber,
|
||||
starting_block: BlockNumberFor<T>,
|
||||
) -> DispatchResult {
|
||||
if locked.is_zero() {
|
||||
return Ok(())
|
||||
@@ -713,7 +714,7 @@ where
|
||||
who: &T::AccountId,
|
||||
locked: BalanceOf<T>,
|
||||
per_block: BalanceOf<T>,
|
||||
starting_block: T::BlockNumber,
|
||||
starting_block: BlockNumberFor<T>,
|
||||
) -> DispatchResult {
|
||||
// Check for `per_block` or `locked` of 0.
|
||||
if !VestingInfo::new(locked, per_block, starting_block).is_valid() {
|
||||
|
||||
Reference in New Issue
Block a user