From 779bff2f23240dd1aadf9ca736d151f75ce580b0 Mon Sep 17 00:00:00 2001 From: Pavel Iakushin Date: Wed, 13 Jul 2022 13:13:28 +0400 Subject: [PATCH 1/3] clean deprecated storages on next runtime upgrade/delete deprecated code --- runtime/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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, From ba7e760ea7fefba61ad12b8fd1be2e23784c5bf6 Mon Sep 17 00:00:00 2001 From: Pavel Iakushin Date: Wed, 13 Jul 2022 17:07:44 +0400 Subject: [PATCH 2/3] add blank on_runtime_upgrade --- pallets/deip_f_nft/src/impl_asset_system.rs | 2 +- pallets/deip_f_nft/src/lib.rs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) 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..cd626d72 100644 --- a/pallets/deip_f_nft/src/lib.rs +++ b/pallets/deip_f_nft/src/lib.rs @@ -19,14 +19,28 @@ pub mod pallet { dispatch::DispatchResult, pallet_prelude::{ Member, NMapKey, StorageDoubleMap, StorageMap, StorageNMap, StorageValue, ValueQuery, + Weight, }, - traits::IsType, + traits::{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; + T::DbWeight::get().reads_writes(reads, writes) + } + } + #[pallet::config] pub trait Config: frame_system::Config From 76b225fa9705b28d049ff0bde5461276e317cbd4 Mon Sep 17 00:00:00 2001 From: Pavel Iakushin Date: Thu, 14 Jul 2022 11:48:41 +0400 Subject: [PATCH 3/3] fill NextFTokenId storage --- Cargo.lock | 1 - pallets/deip_f_nft/Cargo.toml | 2 -- pallets/deip_f_nft/src/lib.rs | 40 ++++++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 6 deletions(-) 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/lib.rs b/pallets/deip_f_nft/src/lib.rs index cd626d72..a4bae92b 100644 --- a/pallets/deip_f_nft/src/lib.rs +++ b/pallets/deip_f_nft/src/lib.rs @@ -17,11 +17,13 @@ pub mod pallet { }; use frame_support::{ dispatch::DispatchResult, + migration::storage_key_iter, pallet_prelude::{ Member, NMapKey, StorageDoubleMap, StorageMap, StorageNMap, StorageValue, ValueQuery, Weight, }, - traits::{Hooks, IsType}, + sp_runtime::traits::{AtLeast32BitUnsigned, Bounded, CheckedAdd, One, StaticLookup, Zero}, + traits::{tokens::currency::Currency, Get, Hooks, IsType}, transactional, Blake2_128Concat, Parameter, }; use frame_system::{ @@ -29,7 +31,6 @@ pub mod pallet { pallet_prelude::{BlockNumberFor, OriginFor}, }; use sp_core::H160; - use sp_runtime::traits::{AtLeast32BitUnsigned, Bounded, StaticLookup}; #[doc(hidden)] #[pallet::hooks] @@ -37,6 +38,39 @@ pub mod 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) } } @@ -60,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<