git.delta.rocks / unique-network / refs/commits / fde4f4fb030f

difftreelog

Safe transfer added

str-mv2020-06-26parent: #6ffe6c8.patch.diff
in: master

2 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
59 /// Next available collection ID59 /// Next available collection ID
60 pub NextCollectionID get(fn next_collection_id): u64;60 pub NextCollectionID get(fn next_collection_id): u64;
6161
62 /// Collection map
63 pub Collection get(collection): map hasher(identity) u64 => CollectionType<T::AccountId>;62 pub Collection get(collection): map hasher(identity) u64 => CollectionType<T::AccountId>;
6463 //pub Collection get(collection): map hasher(identity) u64 => CollectionType<T::AccountId>;
65 /// Admins map (collection)64
66 pub AdminList get(admin_list_collection): map hasher(identity) u64 => Vec<T::AccountId>;65 pub AdminList get(admin_list_collection): map hasher(identity) u64 => Vec<T::AccountId>;
6766
68 /// Balance owner per collection map67 /// Balance owner per collection map
69 pub Balance get(balance_count): map hasher(blake2_128_concat) (u64, T::AccountId) => u64;68 pub Balance get(balance_count): map hasher(blake2_128_concat) (u64, T::AccountId) => u64;
70
71 pub ApprovedList get(approved): map hasher(blake2_128_concat) (u64, u64) => Vec<T::AccountId>;69 pub ApprovedList get(approved): map hasher(blake2_128_concat) (u64, u64) => Vec<T::AccountId>;
70
72 pub ItemList get(item_id): map hasher(blake2_128_concat) (u64, u64) => NftItemType<T::AccountId>;71 pub ItemList get(item_id): map hasher(blake2_128_concat) (u64, u64) => NftItemType<T::AccountId>;
72 // pub ItemList get(item_id): map hasher(blake2_128_concat) (u64, u64) => NftItemType<T::AccountId>;
73
73 pub ItemListIndex get(item_index): map hasher(blake2_128_concat) u64 => u64;74 pub ItemListIndex get(item_index): map hasher(blake2_128_concat) u64 => u64;
75 // pub ItemListIndex get(item_index): map hasher(blake2_128_concat) u64 => u64;
74 }76 }
75}77}
7678
114 // Generate next collection ID116 // Generate next collection ID
115 let next_id = NextCollectionID::get()117 let next_id = NextCollectionID::get()
116 .checked_add(1)118 .checked_add(1)
117 .expect("collection id error");119 .expect("collection id error") - 1;
118120
119 NextCollectionID::put(next_id);121 NextCollectionID::put(next_id);
120122
373 }375 }
374376
375 #[weight = frame_support::weights::SimpleDispatchInfo::default()]377 #[weight = frame_support::weights::SimpleDispatchInfo::default()]
376 pub fn transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {378 pub fn transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {
379
380 let no_perm_mes = "You do not have permissions to modify this collection";
381 ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);
382 let list_itm = <ApprovedList<T>>::get((collection_id, item_id));
383 ensure!(list_itm.contains(&new_owner.clone()), no_perm_mes);
384
385 Self::transfer(origin, collection_id, item_id, new_owner)?;
386
387 Ok(())
388 }
389
390 #[weight = frame_support::weights::SimpleDispatchInfo::default()]
391 pub fn safe_transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {
377392
378 let no_perm_mes = "You do not have permissions to modify this collection";393 let no_perm_mes = "You do not have permissions to modify this collection";
379 ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);394 ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);
modifiedruntime/src/lib.rsdiffbeforeafterboth
8#[cfg(feature = "std")]8#[cfg(feature = "std")]
9include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));9include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
1010
11use 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, IdentifyAccount
19};
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;
2728
28// 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};
3938
40/// Importing a template pallet39/// Importing a template pallet
41pub 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>;