Skip to content
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

Migrate pallet-vesting to umbrella crate #6513

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ pub mod runtime {
};
pub use sp_inherents::{CheckInherentsResult, InherentData};
pub use sp_keyring::AccountKeyring;
pub use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode};
pub use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode, TransactionOutcome};
}

/// Types and traits for runtimes that implement runtime APIs.
Expand Down
21 changes: 4 additions & 17 deletions substrate/frame/vesting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ codec = { features = [
], workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-runtime = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }

[dev-dependencies]
pallet-balances = { workspace = true, default-features = true }
Expand All @@ -35,26 +32,16 @@ sp-io = { workspace = true }
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-balances/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
]
9 changes: 7 additions & 2 deletions substrate/frame/vesting/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
//! Vesting pallet benchmarking.

#![cfg(feature = "runtime-benchmarks")]

/*
use frame_benchmarking::{v2::*, BenchmarkError};
use frame_support::assert_ok;
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use sp_runtime::traits::{Bounded, CheckedDiv, CheckedMul};

*/
use frame::benchmarking::prelude::*;
use frame::testing_prelude::assert_ok;
use frame::traits::{Currency, Convert, WithdrawReasons, ExistenceRequirement, LockableCurrency, LockIdentifier, BlockNumberProvider, VestingSchedule, VestedTransfer};
use frame::arithmetic::{AtLeast32BitUnsigned, One};
use frame::runtime::{prelude::storage::with_transaction, prelude::TransactionOutcome};
use crate::*;

const SEED: u32 = 0;
Expand Down
23 changes: 18 additions & 5 deletions substrate/frame/vesting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ extern crate alloc;
use alloc::vec::Vec;
use codec::{Decode, Encode, MaxEncodedLen};
use core::{fmt::Debug, marker::PhantomData};
use frame::prelude::*;
/*
use frame_support::{
dispatch::DispatchResult,
ensure,
Expand All @@ -72,14 +74,22 @@ use frame_support::{
weights::Weight,
};
use frame_system::pallet_prelude::BlockNumberFor;
*/
use scale_info::TypeInfo;
use frame::traits::{Currency, Convert, WithdrawReasons, ExistenceRequirement, LockableCurrency, LockIdentifier, BlockNumberProvider, VestingSchedule, VestedTransfer};
use frame::runtime::{prelude::storage::with_transaction, prelude::TransactionOutcome};
use frame::arithmetic::One;


/*
use sp_runtime::{
traits::{
AtLeast32BitUnsigned, BlockNumberProvider, Bounded, Convert, MaybeSerializeDeserialize,
One, Saturating, StaticLookup, Zero,
},
DispatchError, RuntimeDebug,
};
*/

pub use pallet::*;
pub use vesting_info::*;
Expand Down Expand Up @@ -151,11 +161,14 @@ impl<T: Config> Get<u32> for MaxVestingSchedulesGet<T> {
}
}

#[frame_support::pallet]
// #[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;
/*
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
*/

#[pallet::config]
pub trait Config: frame_system::Config {
Expand Down Expand Up @@ -220,15 +233,15 @@ pub mod pallet {
pub struct Pallet<T>(_);

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
#[derive(frame::derive::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
pub vesting: Vec<(T::AccountId, BlockNumberFor<T>, BlockNumberFor<T>, BalanceOf<T>)>,
}

#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
use sp_runtime::traits::Saturating;
// use sp_runtime::traits::Saturating;

// Genesis uses the latest storage version.
StorageVersion::<T>::put(Releases::V1);
Expand All @@ -244,7 +257,7 @@ pub mod pallet {
// Total genesis `balance` minus `liquid` equals funds locked for vesting
let locked = balance.saturating_sub(liquid);
let length_as_balance = T::BlockNumberToBalance::convert(length);
let per_block = locked / length_as_balance.max(sp_runtime::traits::One::one());
let per_block = locked / length_as_balance.max(One::one());
let vesting_info = VestingInfo::new(locked, per_block, begin);
if !vesting_info.is_valid() {
panic!("Invalid VestingInfo params at genesis")
Expand Down Expand Up @@ -798,7 +811,7 @@ where
per_block: BalanceOf<T>,
starting_block: BlockNumberFor<T>,
) -> DispatchResult {
use frame_support::storage::{with_transaction, TransactionOutcome};
// use frame_support::storage::{with_transaction, TransactionOutcome};
let schedule = VestingInfo::new(locked, per_block, starting_block);
with_transaction(|| -> TransactionOutcome<DispatchResult> {
let result = Self::do_vested_transfer(source, target, schedule);
Expand Down
6 changes: 4 additions & 2 deletions substrate/frame/vesting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

/*
use frame_support::{derive_impl, parameter_types, traits::WithdrawReasons};
use sp_runtime::{traits::Identity, BuildStorage};

*/
use frame::testing_prelude::*;
use super::*;
use crate as pallet_vesting;

type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down
4 changes: 3 additions & 1 deletion substrate/frame/vesting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
// limitations under the License.

use codec::EncodeLike;
/*
use frame_support::{assert_noop, assert_ok, assert_storage_noop};
use frame_system::RawOrigin;
use sp_runtime::{
traits::{BadOrigin, Identity},
TokenError,
};

*/
use frame::testing_prelude::*;
use super::{Vesting as VestingStorage, *};
use crate::mock::{Balances, ExtBuilder, System, Test, Vesting};

Expand Down
4 changes: 4 additions & 0 deletions substrate/frame/vesting/src/vesting_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
//! Module to enforce private fields on `VestingInfo`.

use super::*;
use frame::arithmetic::{AtLeast32BitUnsigned, One};
use frame::traits::Convert;



/// Struct to encode the vesting schedule of an individual account.
#[derive(Encode, Decode, Copy, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/vesting/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.