difftreelog
warning removed
in: master
3 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth1#![cfg_attr(not(feature = "std"), no_std)]1#![cfg_attr(not(feature = "std"), no_std)]223use codec::{Decode, Encode};3/// A FRAME pallet template with necessary imports4/// A FRAME pallet template with necessary imports455/// Feel free to remove or edit this file as needed.6/// Feel free to remove or edit this file as needed.9/// For more guidance on Substrate FRAME, see the example pallet10/// For more guidance on Substrate FRAME, see the example pallet10/// https://github.com/paritytech/substrate/blob/master/frame/example/src/lib.rs11/// https://github.com/paritytech/substrate/blob/master/frame/example/src/lib.rs1112use frame_support::{12use frame_support::{decl_event, decl_module, decl_storage, dispatch::DispatchResult, ensure};13 dispatch::DispatchResult, decl_module, decl_storage, decl_event,14 ensure,15};16use frame_system::{self as system, ensure_signed };13use frame_system::{self as system, ensure_signed};17use codec::{Encode, Decode};18use sp_runtime::sp_std::prelude::Vec;14use sp_runtime::sp_std::prelude::Vec;191520#[cfg(test)]16#[cfg(test)]82decl_event!(78decl_event!(83 pub enum Event<T> where AccountId = <T as system::Trait>::AccountId {79 pub enum Event<T>80 where81 AccountId = <T as system::Trait>::AccountId,82 {84 Created(u32, AccountId),83 Created(u32, AccountId),85 }84 }376 #[weight = frame_support::weights::SimpleDispatchInfo::default()]375 #[weight = frame_support::weights::SimpleDispatchInfo::default()]377 pub fn transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {376 pub fn transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {378379 // let sender = ensure_signed(origin)?;380 // ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");381382 // let target_collection = <Collection<T>>::get(collection_id);383 // let is_owner = sender == target_collection.owner;384385 // ensure!(<ItemList<T>>::contains_key((collection_id, item_id)), "Item does not exists");386 // let mut item = <ItemList<T>>::get((collection_id, item_id));387388 // if !is_owner 389 // {390 // let no_perm_mes = "You do not have permissions to modify this collection";391392 // // check if item owner393 // if item.owner != sender 394 // {395 // ensure!(<AdminList<T>>::contains_key(collection_id), no_perm_mes);396 // ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);397 // }398399 // ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);400 // let list_itm = <ApprovedList<T>>::get((collection_id, item_id));401 // ensure!(list_itm.contains(&new_owner.clone()), no_perm_mes);402403 // }404405377406 let no_perm_mes = "You do not have permissions to modify this collection";378 let no_perm_mes = "You do not have permissions to modify this collection";407 ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);379 ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);408 let list_itm = <ApprovedList<T>>::get((collection_id, item_id));380 let list_itm = <ApprovedList<T>>::get((collection_id, item_id));409 ensure!(list_itm.contains(&new_owner.clone()), no_perm_mes);381 ensure!(list_itm.contains(&new_owner.clone()), no_perm_mes);410382411 Self::transfer(origin, collection_id, item_id, new_owner);383 Self::transfer(origin, collection_id, item_id, new_owner)?;412384413 Ok(())385 Ok(())414 }386 }pallets/nft/src/mock.rsdiffbeforeafterboth1// Creating mock runtime here1// Creating mock runtime here223use crate::{Module, Trait};3use crate::{Module, Trait};4use sp_core::H256;5use frame_support::{impl_outer_origin, parameter_types, weights::Weight};4use frame_support::{impl_outer_origin, parameter_types, weights::Weight};5use frame_system as system;6use sp_core::H256;6use sp_runtime::{7use sp_runtime::{8 testing::Header,7 traits::{BlakeTwo256, IdentityLookup}, testing::Header, Perbill,9 traits::{BlakeTwo256, IdentityLookup},10 Perbill,8};11};9use frame_system as system;101211impl_outer_origin! {13impl_outer_origin! {12 pub enum Origin for Test {}14 pub enum Origin for Test {}pallets/nft/src/tests.rsdiffbeforeafterboth1// Tests to be written here1// Tests to be written here2use crate::{ mock::*};2use crate::mock::*;3use frame_support::{assert_ok, assert_noop};3use frame_support::{assert_noop, assert_ok};445#[test]5#[test]6fn create_collection_test() {6fn create_collection_test() {