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-uniques to umbrella crate #6511

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
9 changes: 2 additions & 7 deletions Cargo.lock

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

28 changes: 8 additions & 20 deletions substrate/frame/uniques/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,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 }
sp-runtime = { workspace = true }
pallet-nfts = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }

[dev-dependencies]
pallet-balances = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }
sp-std = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-balances/std",
"pallet-nfts/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",
"pallet-nfts/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-balances/try-runtime",
"sp-runtime/try-runtime",
"pallet-nfts/try-runtime",
]
4 changes: 3 additions & 1 deletion substrate/frame/uniques/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

use super::*;
use alloc::{vec, vec::Vec};
use frame::benchmarking::prelude::*;
/*
use frame_benchmarking::v1::{
account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller, BenchmarkError,
};
Expand All @@ -30,7 +32,7 @@ use frame_support::{
};
use frame_system::RawOrigin as SystemOrigin;
use sp_runtime::traits::Bounded;

*/
use crate::Pallet as Uniques;

const SEED: u32 = 0;
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/uniques/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
//! Various pieces of common functionality.

use super::*;
/*
use frame_support::{
ensure,
traits::{ExistenceRequirement, Get},
};
use sp_runtime::{DispatchError, DispatchResult};
*/
use frame::{prelude::*, arithmetic::ArithmeticError, traits::{ExistenceRequirement, Currency}};

impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Perform a transfer of an item from one account to another within a collection.
Expand Down
12 changes: 9 additions & 3 deletions substrate/frame/uniques/src/impl_nonfungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@

use super::*;
use alloc::vec::Vec;
/*
use frame_support::{
storage::KeyPrefixIterator,
traits::{tokens::nonfungibles::*, Get},
BoundedSlice,
};
use sp_runtime::{DispatchError, DispatchResult};
*/
use pallet_nfts::{CollectionConfigFor, CollectionSettings, ItemConfig, MintSettings};
use frame::{prelude::*, traits::{tokens::nonfungibles_v2::*, Currency}, runtime::prelude::storage::{bounded_vec::BoundedSlice, KeyPrefixIterator}};

impl<T: Config<I>, I: 'static> Inspect<<T as SystemConfig>::AccountId> for Pallet<T, I> {
type ItemId = T::ItemId;
Expand Down Expand Up @@ -86,7 +90,7 @@ impl<T: Config<I>, I: 'static> Inspect<<T as SystemConfig>::AccountId> for Palle
}
}

impl<T: Config<I>, I: 'static> Create<<T as SystemConfig>::AccountId> for Pallet<T, I> {
impl<T: Config<I>, I: 'static> Create<<T as SystemConfig>::AccountId, CollectionConfigFor<T, I>> for Pallet<T, I> {
/// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin`.
fn create_collection(
collection: &Self::CollectionId,
Expand All @@ -97,7 +101,7 @@ impl<T: Config<I>, I: 'static> Create<<T as SystemConfig>::AccountId> for Pallet
collection.clone(),
who.clone(),
admin.clone(),
T::CollectionDeposit::get(),
<T as pallet::Config<I>>::CollectionDeposit::get(),
false,
Event::Created {
collection: collection.clone(),
Expand All @@ -124,11 +128,13 @@ impl<T: Config<I>, I: 'static> Destroy<<T as SystemConfig>::AccountId> for Palle
}
}

impl<T: Config<I>, I: 'static> Mutate<<T as SystemConfig>::AccountId> for Pallet<T, I> {
impl<T: Config<I>, I: 'static> Mutate<<T as SystemConfig>::AccountId, ItemConfig> for Pallet<T, I> {
fn mint_into(
collection: &Self::CollectionId,
item: &Self::ItemId,
who: &T::AccountId,
_item_config: &ItemConfig,
_deposit_collection_owner: bool,
) -> DispatchResult {
Self::do_mint(collection.clone(), *item, who.clone(), |_| Ok(()))
}
Expand Down
11 changes: 9 additions & 2 deletions substrate/frame/uniques/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,20 @@ pub mod weights;
extern crate alloc;

use alloc::vec::Vec;
/*
use codec::{Decode, Encode};
use frame_support::traits::{
tokens::Locker, BalanceStatus::Reserved, Currency, EnsureOriginWithArg, ReservableCurrency,
};
*/
use frame::{prelude::*, traits::{ReservableCurrency, EnsureOriginWithArg, Locker, BalanceStatus::Reserved}};
use frame_system::Config as SystemConfig;
/*
use sp_runtime::{
traits::{Saturating, StaticLookup, Zero},
ArithmeticError, RuntimeDebug,
};
*/

pub use pallet::*;
pub use types::*;
Expand All @@ -65,12 +70,14 @@ const LOG_TARGET: &str = "runtime::uniques";
/// A type alias for the account ID type used in the dispatchable functions of this pallet.
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;

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

*/
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

#[pallet::pallet]
Expand Down
7 changes: 4 additions & 3 deletions substrate/frame/uniques/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
//! Various pieces of common functionality.
use super::*;
use core::marker::PhantomData;
use frame_support::traits::{Get, UncheckedOnRuntimeUpgrade};

// use frame_support::traits::{Get, UncheckedOnRuntimeUpgrade};
use frame::{prelude::*, traits::UncheckedOnRuntimeUpgrade, weights_prelude::Weight, migration};
mod v1 {
use super::*;

/// Actual implementation of the storage migration.
pub struct UncheckedMigrateToV1Impl<T, I>(PhantomData<(T, I)>);

impl<T: Config<I>, I: 'static> UncheckedOnRuntimeUpgrade for UncheckedMigrateToV1Impl<T, I> {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
fn on_runtime_upgrade() -> Weight {
let mut count = 0;
for (collection, detail) in Collection::<T, I>::iter() {
CollectionAccount::<T, I>::insert(&detail.owner, &collection, ());
Expand All @@ -46,7 +47,7 @@ mod v1 {
}

/// Migrate the pallet storage from `0` to `1`.
pub type MigrateV0ToV1<T, I> = frame_support::migrations::VersionedMigration<
pub type MigrateV0ToV1<T, I> = migrations::VersionedMigration<
0,
1,
v1::UncheckedMigrateToV1Impl<T, I>,
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/uniques/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

use super::*;
use crate as pallet_uniques;

/*
use frame_support::{
construct_runtime, derive_impl,
traits::{AsEnsureOriginWithArg, ConstU32, ConstU64},
};
use sp_runtime::BuildStorage;
*/

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

Expand Down
4 changes: 4 additions & 0 deletions substrate/frame/uniques/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
//! Tests for Uniques pallet.

use crate::{mock::*, Event, *};
/*
use frame_support::{assert_noop, assert_ok, traits::Currency};
use pallet_balances::Error as BalancesError;
use sp_runtime::traits::Dispatchable;
*/

use frame::testing_prelude::*;

fn items() -> Vec<(u64, u32, u32)> {
let mut r: Vec<_> = Account::<Test>::iter().map(|x| x.0).collect();
Expand Down
4 changes: 4 additions & 0 deletions substrate/frame/uniques/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
//! Various basic types for use in the Uniques pallet.

use super::*;
/*
use frame_support::{
pallet_prelude::{BoundedVec, MaxEncodedLen},
traits::Get,
};
use scale_info::TypeInfo;
*/

use frame::{prelude::*, traits::Currency};

/// A type alias for handling balance deposits.
pub(super) type DepositBalanceOf<T, I = ()> =
Expand Down
4 changes: 3 additions & 1 deletion substrate/frame/uniques/src/weights.rs

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