difftreelog
Safe transfer added
in: master
2 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -59,18 +59,20 @@
/// Next available collection ID
pub NextCollectionID get(fn next_collection_id): u64;
- /// Collection map
pub Collection get(collection): map hasher(identity) u64 => CollectionType<T::AccountId>;
+ //pub Collection get(collection): map hasher(identity) u64 => CollectionType<T::AccountId>;
- /// Admins map (collection)
pub AdminList get(admin_list_collection): map hasher(identity) u64 => Vec<T::AccountId>;
/// Balance owner per collection map
pub Balance get(balance_count): map hasher(blake2_128_concat) (u64, T::AccountId) => u64;
+ pub ApprovedList get(approved): map hasher(blake2_128_concat) (u64, u64) => Vec<T::AccountId>;
- pub ApprovedList get(approved): map hasher(blake2_128_concat) (u64, u64) => Vec<T::AccountId>;
pub ItemList get(item_id): map hasher(blake2_128_concat) (u64, u64) => NftItemType<T::AccountId>;
+ // pub ItemList get(item_id): map hasher(blake2_128_concat) (u64, u64) => NftItemType<T::AccountId>;
+
pub ItemListIndex get(item_index): map hasher(blake2_128_concat) u64 => u64;
+ // pub ItemListIndex get(item_index): map hasher(blake2_128_concat) u64 => u64;
}
}
@@ -114,7 +116,7 @@
// Generate next collection ID
let next_id = NextCollectionID::get()
.checked_add(1)
- .expect("collection id error");
+ .expect("collection id error") - 1;
NextCollectionID::put(next_id);
@@ -384,5 +386,18 @@
Ok(())
}
+
+ #[weight = frame_support::weights::SimpleDispatchInfo::default()]
+ pub fn safe_transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {
+
+ let no_perm_mes = "You do not have permissions to modify this collection";
+ ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);
+ let list_itm = <ApprovedList<T>>::get((collection_id, item_id));
+ ensure!(list_itm.contains(&new_owner.clone()), no_perm_mes);
+
+ Self::transfer(origin, collection_id, item_id, new_owner)?;
+
+ Ok(())
+ }
}
}
runtime/src/lib.rsdiffbeforeafterboth8#[cfg(feature = "std")]8#[cfg(feature = "std")]9include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));9include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));101011use sp_std::prelude::*;11use grandpa::fg_primitives;12use sp_core::OpaqueMetadata;13use sp_runtime::{14 ApplyExtrinsicResult, generic, create_runtime_str, impl_opaque_keys, MultiSignature,15 transaction_validity::{TransactionValidity, TransactionSource},16};17use sp_runtime::traits::{12use grandpa::AuthorityList as GrandpaAuthorityList;18 BlakeTwo256, Block as BlockT, IdentityLookup, Verify, ConvertInto, IdentifyAccount19};20use sp_api::impl_runtime_apis;13use sp_api::impl_runtime_apis;21use sp_consensus_aura::sr25519::AuthorityId as AuraId;14use sp_consensus_aura::sr25519::AuthorityId as AuraId;15use sp_core::OpaqueMetadata;22use grandpa::AuthorityList as GrandpaAuthorityList;16use sp_runtime::traits::{17 BlakeTwo256, Block as BlockT, ConvertInto, IdentifyAccount, IdentityLookup, Verify,18};23use grandpa::fg_primitives;19use sp_runtime::{20 create_runtime_str, generic, impl_opaque_keys,21 transaction_validity::{TransactionSource, TransactionValidity},22 ApplyExtrinsicResult, MultiSignature,23};24use sp_version::RuntimeVersion;24use sp_std::prelude::*;25#[cfg(feature = "std")]25#[cfg(feature = "std")]26use sp_version::NativeVersion;26use sp_version::NativeVersion;27use sp_version::RuntimeVersion;272828// A few exports that help ease life for downstream crates.29// A few exports that help ease life for downstream crates.30pub use balances::Call as BalancesCall;31pub use frame_support::{32 construct_runtime, parameter_types, traits::Randomness, weights::Weight, StorageValue,33};29#[cfg(any(feature = "std", test))]34#[cfg(any(feature = "std", test))]30pub use sp_runtime::BuildStorage;35pub use sp_runtime::BuildStorage;36pub use sp_runtime::{Perbill, Permill};31pub use timestamp::Call as TimestampCall;37pub use timestamp::Call as TimestampCall;32pub use balances::Call as BalancesCall;33pub use sp_runtime::{Permill, Perbill};34pub use frame_support::{35 StorageValue, construct_runtime, parameter_types,36 traits::Randomness,37 weights::Weight,38};393840/// Importing a template pallet39/// Importing a template pallet41pub use nft;40pub use nft;262 system::CheckEra<Runtime>,261 system::CheckEra<Runtime>,263 system::CheckNonce<Runtime>,262 system::CheckNonce<Runtime>,264 system::CheckWeight<Runtime>,263 system::CheckWeight<Runtime>,265 transaction_payment::ChargeTransactionPayment<Runtime>264 transaction_payment::ChargeTransactionPayment<Runtime>,266);265);267/// Unchecked extrinsic type as expected by this runtime.266/// Unchecked extrinsic type as expected by this runtime.268pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;267pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;