diff --git a/Cargo.lock b/Cargo.lock index 27964196..d97ca887 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4400,7 +4400,6 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-core", - "sp-runtime", ] [[package]] diff --git a/pallets/deip_f_nft/Cargo.toml b/pallets/deip_f_nft/Cargo.toml index 2b8f239a..c0a06f4b 100644 --- a/pallets/deip_f_nft/Cargo.toml +++ b/pallets/deip_f_nft/Cargo.toml @@ -17,7 +17,6 @@ pallet-assets = { git = "https://github.com/paritytech/substrate.git", branch = pallet-uniques = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13", default-features = false } scale-info = { version = "1.0", default-features = false, features = ["derive"] } sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13", default-features = false } [features] default = ["std"] @@ -30,5 +29,4 @@ std = [ "pallet-uniques/std", "scale-info/std", "sp-core/std", - "sp-runtime/std", ] diff --git a/pallets/deip_f_nft/src/impl_asset_system.rs b/pallets/deip_f_nft/src/impl_asset_system.rs index 8e280a7f..0ec439fd 100644 --- a/pallets/deip_f_nft/src/impl_asset_system.rs +++ b/pallets/deip_f_nft/src/impl_asset_system.rs @@ -6,7 +6,7 @@ use sp_core::H160; use crate::{ CollectionRepo, Config, Error, FingerprintByFractionTokenId, FractionHolds, FractionRepo, - FractionalRepo, ItemRepo, NextCollectionId, Pallet, NextFTokenId + FractionalRepo, ItemRepo, NextCollectionId, NextFTokenId, Pallet, }; impl FTImplT for Pallet { diff --git a/pallets/deip_f_nft/src/lib.rs b/pallets/deip_f_nft/src/lib.rs index 06f55f13..a4bae92b 100644 --- a/pallets/deip_f_nft/src/lib.rs +++ b/pallets/deip_f_nft/src/lib.rs @@ -17,15 +17,63 @@ pub mod pallet { }; use frame_support::{ dispatch::DispatchResult, + migration::storage_key_iter, pallet_prelude::{ Member, NMapKey, StorageDoubleMap, StorageMap, StorageNMap, StorageValue, ValueQuery, + Weight, }, - traits::IsType, + sp_runtime::traits::{AtLeast32BitUnsigned, Bounded, CheckedAdd, One, StaticLookup, Zero}, + traits::{tokens::currency::Currency, Get, Hooks, IsType}, transactional, Blake2_128Concat, Parameter, }; - use frame_system::{ensure_signed, pallet_prelude::OriginFor}; + use frame_system::{ + ensure_signed, + pallet_prelude::{BlockNumberFor, OriginFor}, + }; use sp_core::H160; - use sp_runtime::traits::{AtLeast32BitUnsigned, Bounded, StaticLookup}; + + #[doc(hidden)] + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_runtime_upgrade() -> Weight { + let reads = 0; + let writes = 0; + + // NextFTokenId + let pallet = b"Assets"; + let storage = b"Asset"; + type DepositBalanceOf = <::Currency as Currency< + ::AccountId, + >>::Balance; + let iterator = storage_key_iter::< + T::AssetId, + pallet_assets::AssetDetails>, + Blake2_128Concat, + >(pallet, storage); + let next_id = iterator + .map(|(id, _)| id) + .max() + .and_then(|id| id.checked_add(&One::one())) + .unwrap_or_else(Zero::zero); + NextFTokenId::::put(next_id); + + // CollectionRepo + + // ItemRepo + + // FingerprintByFractionTokenId + + // FractionRepo + + // FractionalRepo + + // FractionHolds + + // NextCollectionId + + T::DbWeight::get().reads_writes(reads, writes) + } + } #[pallet::config] pub trait Config: @@ -46,7 +94,7 @@ pub mod pallet { type NFTFractionAmount: Member + Parameter + AtLeast32BitUnsigned + Copy + Default; type InternalCollectionId: Member + Parameter + AtLeast32BitUnsigned + Copy + Default; - type InternalFTokenId: Member + Parameter + AtLeast32BitUnsigned + Copy + Default; + type InternalFTokenId: Member + Parameter + AtLeast32BitUnsigned + Copy + Default + One; /// Pallet with low level control over fungible tokens. type Fungibles: FTImplT< diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 7a6dc1d6..878ba3eb 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -14,8 +14,7 @@ pub use frame_support::{ TransactionValidity, Weight, }, parameter_types, - traits::fungibles::Inspect, - traits::{Everything, KeyOwnerProofSystem, StorageInfo}, + traits::{fungibles::Inspect, Everything, KeyOwnerProofSystem, StorageInfo}, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, IdentityFee,