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-assets-freezer to umbrella crate #6599

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 1 addition & 6 deletions Cargo.lock

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

13 changes: 13 additions & 0 deletions prdoc/pr_6599.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: migrate pallet-assets-freezer to umbrella crate

doc:
- audience: Runtime Dev
description: |
Imports frame umbrella crate systems into pallet-assets-freezer.

crates:
- name: pallet-assets-freezer
bump: minor
23 changes: 4 additions & 19 deletions substrate/frame/assets-freezer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,29 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { 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 }
frame = { workspace = true, features = ["experimental", "runtime"] }
pallet-assets = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]
sp-io = { workspace = true }
sp-core = { workspace = true }
pallet-balances = { workspace = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-assets/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-assets/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-assets/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
]
10 changes: 4 additions & 6 deletions substrate/frame/assets-freezer/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
// limitations under the License.

use super::*;

use frame_support::traits::{
use frame::traits::{
fungibles::{Inspect, InspectFreeze, MutateFreeze},
tokens::{DepositConsequence, Fortitude, Preservation, Provenance, WithdrawConsequence},
};
use pallet_assets::FrozenBalance;
use sp_runtime::traits::Zero;

// Implements [`FrozenBalance`] from [`pallet-assets`], so it can understand how much of an
// account balance is frozen, and is able to signal to this pallet when to clear the state of an
Expand Down Expand Up @@ -115,7 +113,7 @@ impl<T: Config<I>, I: 'static> MutateFreeze<T::AccountId> for Pallet<T, I> {
id: &Self::Id,
who: &T::AccountId,
amount: Self::Balance,
) -> sp_runtime::DispatchResult {
) -> DispatchResult {
if amount.is_zero() {
return Self::thaw(asset, id, who);
}
Expand All @@ -135,7 +133,7 @@ impl<T: Config<I>, I: 'static> MutateFreeze<T::AccountId> for Pallet<T, I> {
id: &Self::Id,
who: &T::AccountId,
amount: Self::Balance,
) -> sp_runtime::DispatchResult {
) -> DispatchResult {
if amount.is_zero() {
return Ok(());
}
Expand All @@ -150,7 +148,7 @@ impl<T: Config<I>, I: 'static> MutateFreeze<T::AccountId> for Pallet<T, I> {
Self::update_freezes(asset, who, freezes.as_bounded_slice())
}

fn thaw(asset: Self::AssetId, id: &Self::Id, who: &T::AccountId) -> sp_runtime::DispatchResult {
fn thaw(asset: Self::AssetId, id: &Self::Id, who: &T::AccountId) -> DispatchResult {
let mut freezes = Freezes::<T, I>::get(asset.clone(), who);
freezes.retain(|f| &f.id != id);
Self::update_freezes(asset, who, freezes.as_bounded_slice())
Expand Down
21 changes: 9 additions & 12 deletions substrate/frame/assets-freezer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,14 @@

#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::{
pallet_prelude::*,
use frame::{
prelude::*,
traits::{tokens::IdAmount, VariantCount, VariantCountOf},
BoundedVec,
};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_runtime::{
traits::{Saturating, Zero},
BoundedSlice,
};

#[cfg(feature = "try-runtime")]
use frame::try_runtime::TryRuntimeError;

pub use pallet::*;

#[cfg(test)]
Expand All @@ -62,7 +59,7 @@ mod tests;

mod impls;

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

Expand Down Expand Up @@ -125,7 +122,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
#[cfg(feature = "try-runtime")]
fn try_state(_: BlockNumberFor<T>) -> Result<(), sp_runtime::TryRuntimeError> {
fn try_state(_: BlockNumberFor<T>) -> Result<(), TryRuntimeError> {
Self::do_try_state()
}
}
Expand Down Expand Up @@ -160,12 +157,12 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}

#[cfg(any(test, feature = "try-runtime"))]
fn do_try_state() -> Result<(), sp_runtime::TryRuntimeError> {
fn do_try_state() -> Result<(), TryRuntimeError> {
for (asset, who, _) in FrozenBalances::<T, I>::iter() {
let max_frozen_amount =
Freezes::<T, I>::get(asset.clone(), who.clone()).iter().map(|l| l.amount).max();

frame_support::ensure!(
ensure!(
FrozenBalances::<T, I>::get(asset, who) == max_frozen_amount,
"The `FrozenAmount` is not equal to the maximum amount in `Freezes` for (`asset`, `who`)"
);
Expand Down
23 changes: 9 additions & 14 deletions substrate/frame/assets-freezer/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@
use crate as pallet_assets_freezer;
pub use crate::*;
use codec::{Compact, Decode, Encode, MaxEncodedLen};
use frame_support::{
derive_impl,
traits::{AsEnsureOriginWithArg, ConstU64},
use frame::{
testing_prelude::*,
traits::{AsEnsureOriginWithArg, Everything, IdentityLookup},
};
use scale_info::TypeInfo;
use sp_core::{ConstU32, H256};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

pub type AccountId = u64;
pub type Balance = u64;
pub type AssetId = u32;
type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand All @@ -48,7 +43,7 @@ frame_support::construct_runtime!(

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
Expand All @@ -70,7 +65,7 @@ impl frame_system::Config for Test {
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
type MaxConsumers = ConstU32<16>;
}

impl pallet_balances::Config for Test {
Expand Down Expand Up @@ -132,7 +127,7 @@ impl Config for Test {
type RuntimeEvent = RuntimeEvent;
}

pub fn new_test_ext(execute: impl FnOnce()) -> sp_io::TestExternalities {
pub fn new_test_ext(execute: impl FnOnce()) -> TestExternalities {
let t = RuntimeGenesisConfig {
assets: pallet_assets::GenesisConfig {
assets: vec![(1, 0, true, 1)],
Expand All @@ -145,11 +140,11 @@ pub fn new_test_ext(execute: impl FnOnce()) -> sp_io::TestExternalities {
}
.build_storage()
.unwrap();
let mut ext: sp_io::TestExternalities = t.into();
let mut ext: TestExternalities = t.into();
ext.execute_with(|| {
System::set_block_number(1);
execute();
frame_support::assert_ok!(AssetsFreezer::do_try_state());
assert_ok!(AssetsFreezer::do_try_state());
});

ext
Expand Down
6 changes: 2 additions & 4 deletions substrate/frame/assets-freezer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
use crate::mock::*;

use codec::Compact;
use frame_support::{
assert_ok, assert_storage_noop,
use frame::{
testing_prelude::*,
traits::{
fungibles::{Inspect, InspectFreeze, MutateFreeze},
tokens::{Fortitude, Preservation},
Expand Down Expand Up @@ -281,8 +281,6 @@ mod impl_mutate_freeze {
}

mod with_pallet_assets {
use frame_support::assert_noop;

use super::*;

#[test]
Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ pub mod prelude {

/// Runtime traits
#[doc(no_inline)]
pub use sp_runtime::traits::{
BlockNumberProvider, Bounded, DispatchInfoOf, Dispatchable, SaturatedConversion,
Saturating, StaticLookup, TrailingZeroInput,
};
pub use sp_runtime::{traits::{
Bounded, DispatchInfoOf, Dispatchable, SaturatedConversion, Saturating, StaticLookup,
TrailingZeroInput,
}, BoundedSlice};

/// Other error/result types for runtime
#[doc(no_inline)]
Expand Down Expand Up @@ -307,7 +307,7 @@ pub mod testing_prelude {

/// Other helper macros from `frame_support` that help with asserting in tests.
pub use frame_support::{
assert_err, assert_err_ignore_postinfo, assert_error_encoded_size, assert_noop, assert_ok,
assert_err, assert_err_ignore_postinfo, assert_error_encoded_size, assert_noop, assert_ok, ensure,
assert_storage_noop, storage_alias,
};

Expand Down
Loading