difftreelog
Smart contract update
in: master
7 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth1#![cfg_attr(not(feature = "std"), no_std)]23use codec::{Decode, Encode};4/// A FRAME pallet template with necessary imports56/// Feel free to remove or edit this file as needed.7/// If you change the name of this file, make sure to update its references in runtime/src/lib.rs8/// If you remove this file, you can remove those references910/// For more guidance on Substrate FRAME, see the example pallet11/// https://github.com/paritytech/substrate/blob/master/frame/example/src/lib.rs12use frame_support::{decl_event, decl_module, decl_storage, dispatch::DispatchResult, ensure};13use frame_system::{self as system, ensure_signed};14use sp_runtime::sp_std::prelude::Vec;1516#[cfg(test)]17mod mock;1819#[cfg(test)]20mod tests;2122#[derive(Encode, Decode, Default, Clone, PartialEq)]23#[cfg_attr(feature = "std", derive(Debug))]24pub struct CollectionType<AccountId> {25 pub owner: AccountId,26 pub next_item_id: u64,27 pub name: Vec<u16>, // 64 include null escape char28 pub description: Vec<u16>, // 256 include null escape char29 pub token_prefix: Vec<u8>, // 16 include null escape char30 pub custom_data_size: u32,31}3233#[derive(Encode, Decode, Default, Clone, PartialEq)]34#[cfg_attr(feature = "std", derive(Debug))]35pub struct CollectionAdminsType<AccountId> {36 pub admin: AccountId,37 pub collection_id: u64,38}3940#[derive(Encode, Decode, Default, Clone, PartialEq)]41#[cfg_attr(feature = "std", derive(Debug))]42pub struct NftItemType<AccountId> {43 pub collection: u64,44 pub owner: AccountId,45 pub data: Vec<u8>,46}4748/// The pallet's configuration trait.49pub trait Trait: system::Trait {50 // Add other types and constants required to configure this pallet.5152 /// The overarching event type.53 type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;54}5556// This pallet's storage items.57decl_storage! {58 // It is important to update your storage name so that your pallet's59 // storage items are isolated from other pallets.60 trait Store for Module<T: Trait> as Nft {6162 /// Next available collection ID63 pub NextCollectionID get(fn next_collection_id): u64;64 pub Collection get(fn collection): map hasher(identity) u64 => CollectionType<T::AccountId>;65 pub AdminList get(fn admin_list_collection): map hasher(identity) u64 => Vec<T::AccountId>;6667 /// Balance owner per collection map68 pub Balance get(fn balance_count): map hasher(blake2_128_concat) (u64, T::AccountId) => u64;69 pub ApprovedList get(fn approved): map hasher(blake2_128_concat) (u64, u64) => Vec<T::AccountId>;7071 pub ItemList get(fn item_id): map hasher(blake2_128_concat) (u64, u64) => NftItemType<T::AccountId>;72 pub ItemListIndex get(fn item_index): map hasher(blake2_128_concat) u64 => u64;7374 pub AddressTokens get(fn address_tokens): map hasher(blake2_128_concat) (u64, T::AccountId) => Vec<u64>;75 }76}7778// The pallet's events79decl_event!(80 pub enum Event<T>81 where82 AccountId = <T as system::Trait>::AccountId,83 {84 Created(u64, AccountId),85 ItemCreated(u64),86 ItemDestroyed(u64, u64),87 }88);8990// The pallet's dispatchable functions.91decl_module! {92 /// The module declaration.93 pub struct Module<T: Trait> for enum Call where origin: T::Origin {9495 // Initializing events96 // this is needed only if you are using events in your pallet97 fn deposit_event() = default;9899 // Initializing events100 // this is needed only if you are using events in your module101 // fn deposit_event<T>() = default;102103 // Create collection of NFT with given parameters104 //105 // @param customDataSz size of custom data in each collection item106 // returns collection ID107108 // Create collection of NFT with given parameters109 //110 // @param customDataSz size of custom data in each collection item111 // returns collection ID112 #[weight = 0]113 pub fn create_collection( origin,114 collection_name: Vec<u16>,115 collection_description: Vec<u16>,116 token_prefix: Vec<u8>,117 custom_data_sz: u32) -> DispatchResult {118119 // Anyone can create a collection120 let who = ensure_signed(origin)?;121122 // check params123 let mut name = collection_name.to_vec();124 name.push(0);125 ensure!(name.len() <= 64, "Collection name can not be longer than 63 char");126127 let mut description = collection_description.to_vec();128 description.push(0);129 ensure!(name.len() <= 256, "Collection description can not be longer than 255 char");130131 let mut prefix = token_prefix.to_vec();132 prefix.push(0);133 ensure!(prefix.len() <= 16, "Token prefix can not be longer than 15 char");134135 // Generate next collection ID136 let next_id = NextCollectionID::get()137 .checked_add(1)138 .expect("collection id error");139140 NextCollectionID::put(next_id);141142 // Create new collection143 let new_collection = CollectionType {144 owner: who.clone(),145 name: name,146 description: description,147 token_prefix: prefix,148 next_item_id: next_id,149 custom_data_size: custom_data_sz,150 };151152 // Add new collection to map153 <Collection<T>>::insert(next_id, new_collection);154155 // call event156 Self::deposit_event(RawEvent::Created(next_id, who.clone()));157158 Ok(())159 }160161 #[weight = 0]162 pub fn destroy_collection(origin, collection_id: u64) -> DispatchResult {163164 let sender = ensure_signed(origin)?;165 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");166167 let owner = <Collection<T>>::get(collection_id).owner;168 ensure!(sender == owner, "You do not own this collection");169 <Collection<T>>::remove(collection_id);170171 Ok(())172 }173174 #[weight = 0]175 pub fn change_collection_owner(origin, collection_id: u64, new_owner: T::AccountId) -> DispatchResult {176177 let sender = ensure_signed(origin)?;178 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");179180 let mut target_collection = <Collection<T>>::get(collection_id);181 ensure!(sender == target_collection.owner, "You do not own this collection");182183 target_collection.owner = new_owner;184 <Collection<T>>::insert(collection_id, target_collection);185186 Ok(())187 }188189 #[weight = 0]190 pub fn add_collection_admin(origin, collection_id: u64, new_admin_id: T::AccountId) -> DispatchResult {191192 let sender = ensure_signed(origin)?;193 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");194195 let target_collection = <Collection<T>>::get(collection_id);196 let is_owner = sender == target_collection.owner;197198 let no_perm_mes = "You do not have permissions to modify this collection";199 let exists = <AdminList<T>>::contains_key(collection_id);200201 if !is_owner202 {203 ensure!(exists, no_perm_mes);204 ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);205 }206207 let mut admin_arr: Vec<T::AccountId> = Vec::new();208 if exists209 {210 admin_arr = <AdminList<T>>::get(collection_id);211 ensure!(!admin_arr.contains(&new_admin_id), "Account already has admin role");212 }213214 admin_arr.push(new_admin_id);215 <AdminList<T>>::insert(collection_id, admin_arr);216217 Ok(())218 }219220 #[weight = 0]221 pub fn remove_collection_admin(origin, collection_id: u64, account_id: T::AccountId) -> DispatchResult {222223 let sender = ensure_signed(origin)?;224 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");225226 let target_collection = <Collection<T>>::get(collection_id);227 let is_owner = sender == target_collection.owner;228229 let no_perm_mes = "You do not have permissions to modify this collection";230 let exists = <AdminList<T>>::contains_key(collection_id);231232 if !is_owner233 {234 ensure!(exists, no_perm_mes);235 ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);236 }237238 if exists239 {240 let mut admin_arr = <AdminList<T>>::get(collection_id);241 admin_arr.retain(|i| *i != account_id);242 <AdminList<T>>::insert(collection_id, admin_arr);243 }244245 Ok(())246 }247248 #[weight = 0]249 pub fn create_item(origin, collection_id: u64, properties: Vec<u8>) -> DispatchResult {250251 let sender = ensure_signed(origin)?;252 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");253254 let target_collection = <Collection<T>>::get(collection_id);255 ensure!(target_collection.custom_data_size >= properties.len() as u32, "Size of item is too large");256 let is_owner = sender == target_collection.owner;257258 let no_perm_mes = "You do not have permissions to modify this collection";259 let exists = <AdminList<T>>::contains_key(collection_id);260261 if !is_owner262 {263 ensure!(exists, no_perm_mes);264 ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);265 }266267 let new_balance = <Balance<T>>::get((collection_id, sender.clone())) + 1;268 <Balance<T>>::insert((collection_id, sender.clone()), new_balance);269270 // Create new item271 let new_item = NftItemType {272 collection: collection_id,273 owner: sender,274 data: properties,275 };276277278 let current_index = <ItemListIndex>::get(collection_id)279 .checked_add(1)280 .expect("Item list index id error");281282 Self::add_token_index(collection_id, current_index, new_item.owner.clone())?;283284 <ItemListIndex>::insert(collection_id, current_index);285 <ItemList<T>>::insert((collection_id, current_index), new_item);286287 // call event288 Self::deposit_event(RawEvent::ItemCreated(collection_id));289290 Ok(())291 }292293 #[weight = 0]294 pub fn burn_item(origin, collection_id: u64, item_id: u64) -> DispatchResult {295296 let sender = ensure_signed(origin)?;297 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");298299 let target_collection = <Collection<T>>::get(collection_id);300 let is_owner = sender == target_collection.owner;301302 ensure!(<ItemList<T>>::contains_key((collection_id, item_id)), "Item does not exists");303 let item = <ItemList<T>>::get((collection_id, item_id));304305 if !is_owner306 {307 // check if item owner308 if item.owner != sender309 {310 let no_perm_mes = "You do not have permissions to modify this collection";311312 ensure!(<AdminList<T>>::contains_key(collection_id), no_perm_mes);313 ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);314 }315 }316 <ItemList<T>>::remove((collection_id, item_id));317318 Self::remove_token_index(collection_id, item_id, item.owner.clone())?;319320 // update balance321 let new_balance = <Balance<T>>::get((collection_id, item.owner.clone())) - 1;322 <Balance<T>>::insert((collection_id, item.owner.clone()), new_balance);323324 // call event325 Self::deposit_event(RawEvent::ItemDestroyed(collection_id, item_id));326327 Ok(())328 }329330 #[weight = 0]331 pub fn transfer(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {332333 let sender = ensure_signed(origin)?;334 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");335336 let target_collection = <Collection<T>>::get(collection_id);337 let is_owner = sender == target_collection.owner;338339 ensure!(<ItemList<T>>::contains_key((collection_id, item_id)), "Item does not exists");340 let mut item = <ItemList<T>>::get((collection_id, item_id));341342 if !is_owner343 {344 // check if item owner345 if item.owner != sender346 {347 let no_perm_mes = "You do not have permissions to modify this collection";348349 ensure!(<AdminList<T>>::contains_key(collection_id), no_perm_mes);350 ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);351 }352 }353 <ItemList<T>>::remove((collection_id, item_id));354355 // update balance356 let balance_old_owner = <Balance<T>>::get((collection_id, item.owner.clone())) - 1;357 <Balance<T>>::insert((collection_id, item.owner.clone()), balance_old_owner);358359 let balance_new_owner = <Balance<T>>::get((collection_id, new_owner.clone())) + 1;360 <Balance<T>>::insert((collection_id, new_owner.clone()), balance_new_owner);361362 // change owner363 let old_owner = item.owner.clone();364 item.owner = new_owner.clone();365 <ItemList<T>>::insert((collection_id, item_id), item);366367 // update index collection368 Self::move_token_index(collection_id, item_id, old_owner, new_owner.clone())?;369370 // reset approved list371 let itm: Vec<T::AccountId> = Vec::new();372 <ApprovedList<T>>::insert((collection_id, item_id), itm);373374 Ok(())375 }376377 #[weight = 0]378 pub fn approve(origin, approved: T::AccountId, collection_id: u64, item_id: u64) -> DispatchResult {379380 let sender = ensure_signed(origin)?;381 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");382383 let target_collection = <Collection<T>>::get(collection_id);384 let is_owner = sender == target_collection.owner;385386 ensure!(<ItemList<T>>::contains_key((collection_id, item_id)), "Item does not exists");387 let item = <ItemList<T>>::get((collection_id, item_id));388389 if !is_owner390 {391 // check if item owner392 if item.owner != sender393 {394 let no_perm_mes = "You do not have permissions to modify this collection";395396 ensure!(<AdminList<T>>::contains_key(collection_id), no_perm_mes);397 ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);398 }399 }400401 let list_exists = <ApprovedList<T>>::contains_key((collection_id, item_id));402 if list_exists {403404 let mut list = <ApprovedList<T>>::get((collection_id, item_id));405 let item_contains = list.contains(&approved.clone());406407 if !item_contains {408 list.push(approved.clone());409 }410 } else {411412 let mut itm = Vec::new();413 itm.push(approved.clone());414 <ApprovedList<T>>::insert((collection_id, item_id), itm);415 }416417 Ok(())418 }419420 #[weight = 0]421 pub fn transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {422423 let no_perm_mes = "You do not have permissions to modify this collection";424 ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);425 let list_itm = <ApprovedList<T>>::get((collection_id, item_id));426 ensure!(list_itm.contains(&new_owner.clone()), no_perm_mes);427428 Self::transfer(origin, collection_id, item_id, new_owner)?;429430 Ok(())431 }432433 #[weight = 0]434 pub fn safe_transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {435436 let no_perm_mes = "You do not have permissions to modify this collection";437 ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);438 let list_itm = <ApprovedList<T>>::get((collection_id, item_id));439 ensure!(list_itm.contains(&new_owner.clone()), no_perm_mes);440441 // on_nft_received call442443 Self::transfer(origin, collection_id, item_id, new_owner)?;444445 Ok(())446 }447 }448}449450impl<T: Trait> Module<T> {451 fn add_token_index(collection_id: u64, item_index: u64, owner: T::AccountId) -> DispatchResult {452 let list_exists = <AddressTokens<T>>::contains_key((collection_id, owner.clone()));453 if list_exists {454 let mut list = <AddressTokens<T>>::get((collection_id, owner.clone()));455 let item_contains = list.contains(&item_index.clone());456457 if !item_contains {458 list.push(item_index.clone());459 }460461 <AddressTokens<T>>::insert((collection_id, owner.clone()), list);462 } else {463 let mut itm = Vec::new();464 itm.push(item_index.clone());465 <AddressTokens<T>>::insert((collection_id, owner), itm);466 }467468 Ok(())469 }470471 fn remove_token_index(472 collection_id: u64,473 item_index: u64,474 owner: T::AccountId,475 ) -> DispatchResult {476 let list_exists = <AddressTokens<T>>::contains_key((collection_id, owner.clone()));477 if list_exists {478 let mut list = <AddressTokens<T>>::get((collection_id, owner.clone()));479 let item_contains = list.contains(&item_index.clone());480481 if item_contains {482 list.retain(|&item| item != item_index);483 <AddressTokens<T>>::insert((collection_id, owner), list);484 }485 }486487 Ok(())488 }489490 fn move_token_index(491 collection_id: u64,492 item_index: u64,493 old_owner: T::AccountId,494 new_owner: T::AccountId,495 ) -> DispatchResult {496 Self::remove_token_index(collection_id, item_index, old_owner)?;497 Self::add_token_index(collection_id, item_index, new_owner)?;498499 Ok(())500 }501}1#![cfg_attr(not(feature = "std"), no_std)]23use codec::{Decode, Encode};4/// A FRAME pallet template with necessary imports56/// Feel free to remove or edit this file as needed.7/// If you change the name of this file, make sure to update its references in runtime/src/lib.rs8/// If you remove this file, you can remove those references910/// For more guidance on Substrate FRAME, see the example pallet11/// https://github.com/paritytech/substrate/blob/master/frame/example/src/lib.rs12use frame_support::{decl_event, decl_module, decl_storage, dispatch::DispatchResult, ensure};13use frame_system::{self as system, ensure_signed};14use sp_runtime::sp_std::prelude::Vec;1516#[cfg(test)]17mod mock;1819#[cfg(test)]20mod tests;2122#[derive(Encode, Decode, Default, Clone, PartialEq)]23#[cfg_attr(feature = "std", derive(Debug))]24pub struct CollectionType<AccountId> {25 pub owner: AccountId,26 pub next_item_id: u64,27 pub name: Vec<u16>, // 64 include null escape char28 pub description: Vec<u16>, // 256 include null escape char29 pub token_prefix: Vec<u8>, // 16 include null escape char30 pub custom_data_size: u32,31}3233#[derive(Encode, Decode, Default, Clone, PartialEq)]34#[cfg_attr(feature = "std", derive(Debug))]35pub struct CollectionAdminsType<AccountId> {36 pub admin: AccountId,37 pub collection_id: u64,38}3940#[derive(Encode, Decode, Default, Clone, PartialEq)]41#[cfg_attr(feature = "std", derive(Debug))]42pub struct NftItemType<AccountId> {43 pub collection: u64,44 pub owner: AccountId,45 pub data: Vec<u8>,46}4748/// The pallet's configuration trait.49pub trait Trait: system::Trait {50 // Add other types and constants required to configure this pallet.5152 /// The overarching event type.53 type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;54}5556// This pallet's storage items.57decl_storage! {58 // It is important to update your storage name so that your pallet's59 // storage items are isolated from other pallets.60 trait Store for Module<T: Trait> as Nft {6162 /// Next available collection ID63 pub NextCollectionID get(fn next_collection_id): u64;64 pub Collection get(fn collection): map hasher(identity) u64 => CollectionType<T::AccountId>;65 pub AdminList get(fn admin_list_collection): map hasher(identity) u64 => Vec<T::AccountId>;6667 /// Balance owner per collection map68 pub Balance get(fn balance_count): map hasher(blake2_128_concat) (u64, T::AccountId) => u64;69 pub ApprovedList get(fn approved): map hasher(blake2_128_concat) (u64, u64) => Vec<T::AccountId>;7071 pub ItemList get(fn item_id): map hasher(blake2_128_concat) (u64, u64) => NftItemType<T::AccountId>;72 pub ItemListIndex get(fn item_index): map hasher(blake2_128_concat) u64 => u64;7374 pub AddressTokens get(fn address_tokens): map hasher(blake2_128_concat) (u64, T::AccountId) => Vec<u64>;75 }76}7778// The pallet's events79decl_event!(80 pub enum Event<T>81 where82 AccountId = <T as system::Trait>::AccountId,83 {84 Created(u64, AccountId),85 ItemCreated(u64),86 ItemDestroyed(u64, u64),87 }88);8990// The pallet's dispatchable functions.91decl_module! {92 /// The module declaration.93 pub struct Module<T: Trait> for enum Call where origin: T::Origin {9495 // Initializing events96 // this is needed only if you are using events in your pallet97 fn deposit_event() = default;9899 // Create collection of NFT with given parameters100 //101 // @param customDataSz size of custom data in each collection item102 // returns collection ID103 #[weight = 0]104 pub fn create_collection( origin,105 collection_name: Vec<u16>,106 collection_description: Vec<u16>,107 token_prefix: Vec<u8>,108 custom_data_sz: u32) -> DispatchResult {109110 // Anyone can create a collection111 let who = ensure_signed(origin)?;112113 // check params114 let mut name = collection_name.to_vec();115 name.push(0);116 ensure!(name.len() <= 64, "Collection name can not be longer than 63 char");117118 let mut description = collection_description.to_vec();119 description.push(0);120 ensure!(name.len() <= 256, "Collection description can not be longer than 255 char");121122 let mut prefix = token_prefix.to_vec();123 prefix.push(0);124 ensure!(prefix.len() <= 16, "Token prefix can not be longer than 15 char");125126 // Generate next collection ID127 let next_id = NextCollectionID::get()128 .checked_add(1)129 .expect("collection id error");130131 NextCollectionID::put(next_id);132133 // Create new collection134 let new_collection = CollectionType {135 owner: who.clone(),136 name: name,137 description: description,138 token_prefix: prefix,139 next_item_id: next_id,140 custom_data_size: custom_data_sz,141 };142143 // Add new collection to map144 <Collection<T>>::insert(next_id, new_collection);145146 // call event147 Self::deposit_event(RawEvent::Created(next_id, who.clone()));148149 Ok(())150 }151152 #[weight = 0]153 pub fn destroy_collection(origin, collection_id: u64) -> DispatchResult {154155 let sender = ensure_signed(origin)?;156 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");157158 let owner = <Collection<T>>::get(collection_id).owner;159 ensure!(sender == owner, "You do not own this collection");160 <Collection<T>>::remove(collection_id);161162 Ok(())163 }164165 #[weight = 0]166 pub fn change_collection_owner(origin, collection_id: u64, new_owner: T::AccountId) -> DispatchResult {167168 let sender = ensure_signed(origin)?;169 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");170171 let mut target_collection = <Collection<T>>::get(collection_id);172 ensure!(sender == target_collection.owner, "You do not own this collection");173174 target_collection.owner = new_owner;175 <Collection<T>>::insert(collection_id, target_collection);176177 Ok(())178 }179180 #[weight = 0]181 pub fn add_collection_admin(origin, collection_id: u64, new_admin_id: T::AccountId) -> DispatchResult {182183 let sender = ensure_signed(origin)?;184 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");185186 let target_collection = <Collection<T>>::get(collection_id);187 let is_owner = sender == target_collection.owner;188189 let no_perm_mes = "You do not have permissions to modify this collection";190 let exists = <AdminList<T>>::contains_key(collection_id);191192 if !is_owner193 {194 ensure!(exists, no_perm_mes);195 ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);196 }197198 let mut admin_arr: Vec<T::AccountId> = Vec::new();199 if exists200 {201 admin_arr = <AdminList<T>>::get(collection_id);202 ensure!(!admin_arr.contains(&new_admin_id), "Account already has admin role");203 }204205 admin_arr.push(new_admin_id);206 <AdminList<T>>::insert(collection_id, admin_arr);207208 Ok(())209 }210211 #[weight = 0]212 pub fn remove_collection_admin(origin, collection_id: u64, account_id: T::AccountId) -> DispatchResult {213214 let sender = ensure_signed(origin)?;215 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");216217 let target_collection = <Collection<T>>::get(collection_id);218 let is_owner = sender == target_collection.owner;219220 let no_perm_mes = "You do not have permissions to modify this collection";221 let exists = <AdminList<T>>::contains_key(collection_id);222223 if !is_owner224 {225 ensure!(exists, no_perm_mes);226 ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);227 }228229 if exists230 {231 let mut admin_arr = <AdminList<T>>::get(collection_id);232 admin_arr.retain(|i| *i != account_id);233 <AdminList<T>>::insert(collection_id, admin_arr);234 }235236 Ok(())237 }238239 #[weight = 0]240 pub fn create_item(origin, collection_id: u64, properties: Vec<u8>) -> DispatchResult {241242 let sender = ensure_signed(origin)?;243 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");244245 let target_collection = <Collection<T>>::get(collection_id);246 ensure!(target_collection.custom_data_size >= properties.len() as u32, "Size of item is too large");247 let is_owner = sender == target_collection.owner;248249 let no_perm_mes = "You do not have permissions to modify this collection";250 let exists = <AdminList<T>>::contains_key(collection_id);251252 if !is_owner253 {254 ensure!(exists, no_perm_mes);255 ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);256 }257258 let new_balance = <Balance<T>>::get((collection_id, sender.clone())) + 1;259 <Balance<T>>::insert((collection_id, sender.clone()), new_balance);260261 // Create new item262 let new_item = NftItemType {263 collection: collection_id,264 owner: sender,265 data: properties,266 };267268269 let current_index = <ItemListIndex>::get(collection_id)270 .checked_add(1)271 .expect("Item list index id error");272273 Self::add_token_index(collection_id, current_index, new_item.owner.clone())?;274275 <ItemListIndex>::insert(collection_id, current_index);276 <ItemList<T>>::insert((collection_id, current_index), new_item);277278 // call event279 Self::deposit_event(RawEvent::ItemCreated(collection_id));280281 Ok(())282 }283284 #[weight = 0]285 pub fn burn_item(origin, collection_id: u64, item_id: u64) -> DispatchResult {286287 let sender = ensure_signed(origin)?;288 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");289290 let target_collection = <Collection<T>>::get(collection_id);291 let is_owner = sender == target_collection.owner;292293 ensure!(<ItemList<T>>::contains_key((collection_id, item_id)), "Item does not exists");294 let item = <ItemList<T>>::get((collection_id, item_id));295296 if !is_owner297 {298 // check if item owner299 if item.owner != sender300 {301 let no_perm_mes = "You do not have permissions to modify this collection";302303 ensure!(<AdminList<T>>::contains_key(collection_id), no_perm_mes);304 ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);305 }306 }307 <ItemList<T>>::remove((collection_id, item_id));308309 Self::remove_token_index(collection_id, item_id, item.owner.clone())?;310311 // update balance312 let new_balance = <Balance<T>>::get((collection_id, item.owner.clone())) - 1;313 <Balance<T>>::insert((collection_id, item.owner.clone()), new_balance);314315 // call event316 Self::deposit_event(RawEvent::ItemDestroyed(collection_id, item_id));317318 Ok(())319 }320321 #[weight = 0]322 pub fn transfer(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {323324 let sender = ensure_signed(origin)?;325 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");326327 let target_collection = <Collection<T>>::get(collection_id);328 let is_owner = sender == target_collection.owner;329330 ensure!(<ItemList<T>>::contains_key((collection_id, item_id)), "Item does not exists");331 let mut item = <ItemList<T>>::get((collection_id, item_id));332333 if !is_owner334 {335 // check if item owner336 if item.owner != sender337 {338 let no_perm_mes = "You do not have permissions to modify this collection";339340 ensure!(<AdminList<T>>::contains_key(collection_id), no_perm_mes);341 ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);342 }343 }344 <ItemList<T>>::remove((collection_id, item_id));345346 // update balance347 let balance_old_owner = <Balance<T>>::get((collection_id, item.owner.clone())) - 1;348 <Balance<T>>::insert((collection_id, item.owner.clone()), balance_old_owner);349350 let balance_new_owner = <Balance<T>>::get((collection_id, new_owner.clone())) + 1;351 <Balance<T>>::insert((collection_id, new_owner.clone()), balance_new_owner);352353 // change owner354 let old_owner = item.owner.clone();355 item.owner = new_owner.clone();356 <ItemList<T>>::insert((collection_id, item_id), item);357358 // update index collection359 Self::move_token_index(collection_id, item_id, old_owner, new_owner.clone())?;360361 // reset approved list362 let itm: Vec<T::AccountId> = Vec::new();363 <ApprovedList<T>>::insert((collection_id, item_id), itm);364365 Ok(())366 }367368 #[weight = 0]369 pub fn approve(origin, approved: T::AccountId, collection_id: u64, item_id: u64) -> DispatchResult {370371 let sender = ensure_signed(origin)?;372 ensure!(<Collection<T>>::contains_key(collection_id), "This collection does not exist");373374 let target_collection = <Collection<T>>::get(collection_id);375 let is_owner = sender == target_collection.owner;376377 ensure!(<ItemList<T>>::contains_key((collection_id, item_id)), "Item does not exists");378 let item = <ItemList<T>>::get((collection_id, item_id));379380 if !is_owner381 {382 // check if item owner383 if item.owner != sender384 {385 let no_perm_mes = "You do not have permissions to modify this collection";386387 ensure!(<AdminList<T>>::contains_key(collection_id), no_perm_mes);388 ensure!(<AdminList<T>>::get(collection_id).contains(&sender), no_perm_mes);389 }390 }391392 let list_exists = <ApprovedList<T>>::contains_key((collection_id, item_id));393 if list_exists {394395 let mut list = <ApprovedList<T>>::get((collection_id, item_id));396 let item_contains = list.contains(&approved.clone());397398 if !item_contains {399 list.push(approved.clone());400 }401 } else {402403 let mut itm = Vec::new();404 itm.push(approved.clone());405 <ApprovedList<T>>::insert((collection_id, item_id), itm);406 }407408 Ok(())409 }410411 #[weight = 0]412 pub fn transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {413414 let no_perm_mes = "You do not have permissions to modify this collection";415 ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);416 let list_itm = <ApprovedList<T>>::get((collection_id, item_id));417 ensure!(list_itm.contains(&new_owner.clone()), no_perm_mes);418419 Self::transfer(origin, collection_id, item_id, new_owner)?;420421 Ok(())422 }423424 #[weight = 0]425 pub fn safe_transfer_from(origin, collection_id: u64, item_id: u64, new_owner: T::AccountId) -> DispatchResult {426427 let no_perm_mes = "You do not have permissions to modify this collection";428 ensure!(<ApprovedList<T>>::contains_key((collection_id, item_id)), no_perm_mes);429 let list_itm = <ApprovedList<T>>::get((collection_id, item_id));430 ensure!(list_itm.contains(&new_owner.clone()), no_perm_mes);431432 // on_nft_received call433434 Self::transfer(origin, collection_id, item_id, new_owner)?;435436 Ok(())437 }438 }439}440441impl<T: Trait> Module<T> {442 fn add_token_index(collection_id: u64, item_index: u64, owner: T::AccountId) -> DispatchResult {443 let list_exists = <AddressTokens<T>>::contains_key((collection_id, owner.clone()));444 if list_exists {445 let mut list = <AddressTokens<T>>::get((collection_id, owner.clone()));446 let item_contains = list.contains(&item_index.clone());447448 if !item_contains {449 list.push(item_index.clone());450 }451452 <AddressTokens<T>>::insert((collection_id, owner.clone()), list);453 } else {454 let mut itm = Vec::new();455 itm.push(item_index.clone());456 <AddressTokens<T>>::insert((collection_id, owner), itm);457 }458459 Ok(())460 }461462 fn remove_token_index(463 collection_id: u64,464 item_index: u64,465 owner: T::AccountId,466 ) -> DispatchResult {467 let list_exists = <AddressTokens<T>>::contains_key((collection_id, owner.clone()));468 if list_exists {469 let mut list = <AddressTokens<T>>::get((collection_id, owner.clone()));470 let item_contains = list.contains(&item_index.clone());471472 if item_contains {473 list.retain(|&item| item != item_index);474 <AddressTokens<T>>::insert((collection_id, owner), list);475 }476 }477478 Ok(())479 }480481 fn move_token_index(482 collection_id: u64,483 item_index: u64,484 old_owner: T::AccountId,485 new_owner: T::AccountId,486 ) -> DispatchResult {487 Self::remove_token_index(collection_id, item_index, old_owner)?;488 Self::add_token_index(collection_id, item_index, new_owner)?;489490 Ok(())491 }492}runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -8,6 +8,7 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
+use contracts_rpc_runtime_api::ContractExecResult;
use grandpa::fg_primitives;
use grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
use sp_api::impl_runtime_apis;
@@ -21,7 +22,6 @@
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
};
-use contracts_rpc_runtime_api::ContractExecResult;
use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
smart_contract/ink-types-node-runtime/Cargo.tomldiffbeforeafterboth--- a/smart_contract/ink-types-node-runtime/Cargo.toml
+++ b/smart_contract/ink-types-node-runtime/Cargo.toml
@@ -19,6 +19,7 @@
[dependencies]
ink_core = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_core", default-features = false }
+ink_prelude = { version = "2", git = "https://github.com/paritytech/ink", tag = "latest-v2", package = "ink_prelude", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate/", tag = "v2.0.0-rc3", package = "frame-system", default-features = false }
pallet-indices = { git = "https://github.com/paritytech/substrate/", tag = "v2.0.0-rc3", package = "pallet-indices", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate/", tag = "v2.0.0-rc3", package = "sp-core", default-features = false }
smart_contract/ink-types-node-runtime/examples/calls/Cargo.lockdiffbeforeafterboth--- a/smart_contract/ink-types-node-runtime/examples/calls/Cargo.lock
+++ b/smart_contract/ink-types-node-runtime/examples/calls/Cargo.lock
@@ -803,6 +803,7 @@
dependencies = [
"frame-system",
"ink_core",
+ "ink_prelude",
"pallet-indices",
"parity-scale-codec",
"sp-core",
smart_contract/ink-types-node-runtime/examples/calls/lib.rsdiffbeforeafterboth--- a/smart_contract/ink-types-node-runtime/examples/calls/lib.rs
+++ b/smart_contract/ink-types-node-runtime/examples/calls/lib.rs
@@ -7,7 +7,7 @@
use ink_core::env;
use ink_prelude::*;
use ink_types_node_runtime::{calls as runtime_calls, NodeRuntimeTypes};
- use ink_core::{memory::vec::Vec, storage};
+ use ink_prelude::vec::Vec;
/// This simple dummy contract dispatches substrate runtime calls
#[ink(storage)]
@@ -17,43 +17,167 @@
#[ink(constructor)]
fn new(&mut self) {}
- /// Dispatches a `transfer` call to the Balances srml module
#[ink(message)]
- fn create_collection(&self, collection_name: Vec<u16>, collection_description: Vec<u16>,
- token_prefix: Vec<u8>,
- custom_data_sz: u32) {
- // create the Balances::transfer Call
+ fn transfer(&self, collection_id: u64, item_id: u64, new_owner: AccountId) {
- // collection_name: Vec<u16>,
- // collection_description: Vec<u16>,
- // token_prefix: Vec<u8>,
- // custom_data_sz: u32
+ env::println(&format!(
+ "transfer invoke_runtime params {:?}, {:?}, {:?} ",
+ collection_id,
+ item_id,
+ new_owner
+ ));
- let transfer_call = runtime_calls::create_collection(collection_name, collection_description, token_prefix, custom_data_sz);
+ let transfer_call = runtime_calls::transfer(collection_id, item_id, new_owner);
// dispatch the call to the runtime
let result = self.env().invoke_runtime(&transfer_call);
// report result to console
// NOTE: println should only be used on a development chain)
env::println(&format!(
- "Balance transfer invoke_runtime result {:?}",
+ "transfer invoke_runtime result {:?}",
+ result
+ ));
+ }
+
+ // SafeTransfer
+
+ #[ink(message)]
+ fn approve(&self, approved: AccountId, collection_id: u64, item_id: u64) {
+
+ env::println(&format!(
+ "approve invoke_runtime params {:?}, {:?}, {:?} ",
+ approved,
+ collection_id,
+ item_id
+ ));
+
+ let approve_call = runtime_calls::approve(approved, collection_id, item_id);
+ // dispatch the call to the runtime
+ let result = self.env().invoke_runtime(&approve_call);
+
+ // report result to console
+ // NOTE: println should only be used on a development chain)
+ env::println(&format!(
+ "approve invoke_runtime result {:?}",
+ result
+ ));
+ }
+
+ ////////////////////////////////////////// GetApproved
+ ///
+ /// Returns an account's free balance, read directly from runtime storage
+ ///
+ /// # Key Scheme
+ ///
+ /// A key for the [substrate storage map]
+ /// (https://github.com/paritytech/substrate/blob/dd97b1478b31a4715df7e88a5ebc6664425fb6c6/frame/support/src/storage/generator/map.rs#L28)
+ /// is constructed with:
+ ///
+ /// ```nocompile
+ /// Twox128(module_prefix) ++ Twox128(storage_prefix) ++ Hasher(encode(key))
+ /// ```
+ ///
+ /// For the `System` module's `Account` map, the [hasher implementation]
+ /// (https://github.com/paritytech/substrate/blob/2c87fe171bc341755a43a3b32d67560469f8daac/frame/system/src/lib.rs#L349)
+ /// is `blake2_128_concat`.
+ // #[ink(message)]
+ // fn get_balance(&self, account: AccountId) -> Balance {
+ // let mut key = vec![
+ // // Precomputed: Twox128("System")
+ // 38, 170, 57, 78, 234, 86, 48, 224, 124, 72, 174, 12, 149, 88, 206, 247,
+ // // Precomputed: Twox128("Account")
+ // 185, 157, 136, 14, 198, 129, 121, 156, 12, 243, 14, 136, 134, 55, 29, 169,
+ // ];
+
+ // let encoded_account = account.encode();
+ // let hashed_account = <Blake2x128>::hash_bytes(&encoded_account);
+
+ // // The hasher is `Blake2_128Concat` which appends the unhashed account to the hashed account
+ // key.extend_from_slice(&hashed_account);
+ // key.extend_from_slice(&encoded_account);
+
+ // // fetch from runtime storage
+ // let result = self.env().get_runtime_storage::<AccountInfo>(&key[..]);
+ // match result {
+ // Some(Ok(account_info)) => account_info.data.free,
+ // Some(Err(err)) => {
+ // env::println(&format!("Error reading AccountInfo {:?}", err));
+ // 0
+ // }
+ // None => {
+ // env::println(&format!("No data at key {:?}", key));
+ // 0
+ // }
+ // }
+ // }
+
+ #[ink(message)]
+ fn transfer_from(&self, collection_id: u64, item_id: u64, new_owner: AccountId) {
+
+ env::println(&format!(
+ "transfer_from invoke_runtime params {:?}, {:?}, {:?} ",
+ collection_id,
+ item_id,
+ new_owner
+ ));
+
+ let transfer_from_call = runtime_calls::transfer_from(collection_id, item_id, new_owner);
+ // dispatch the call to the runtime
+ let result = self.env().invoke_runtime(&transfer_from_call);
+
+ // report result to console
+ // NOTE: println should only be used on a development chain)
+ env::println(&format!(
+ "transfer_from invoke_runtime result {:?}",
+ result
+ ));
+ }
+
+ // SafeTransferFrom
+
+ #[ink(message)]
+ fn create_item(&self, collection_id: u64, properties: Vec<u8>) {
+
+ env::println(&format!(
+ "create_item invoke_runtime params {:?}, {:?} ",
+ collection_id,
+ properties
+ ));
+
+ let create_item_call = runtime_calls::create_item(collection_id, properties);
+ // dispatch the call to the runtime
+ let result = self.env().invoke_runtime(&create_item_call);
+
+ // report result to console
+ // NOTE: println should only be used on a development chain)
+ env::println(&format!(
+ "create_item invoke_runtime result {:?}",
result
));
}
- }
- #[cfg(test)]
- mod tests {
- use super::*;
- use sp_keyring::AccountKeyring;
+ #[ink(message)]
+ fn burn_item(&self, collection_id: u64, item_id: u64) {
- #[test]
- fn dispatches_balances_call() {
- let calls = Calls::new();
- let alice = AccountId::from(AccountKeyring::Alice.to_account_id());
- // assert_eq!(calls.env().dispatched_calls().into_iter().count(), 0);
- calls.balance_transfer(alice, 10000);
- // assert_eq!(calls.env().dispatched_calls().into_iter().count(), 1);
+ env::println(&format!(
+ "burn_item invoke_runtime params {:?}, {:?}",
+ collection_id,
+ item_id
+ ));
+
+ let burn_item_call = runtime_calls::burn_item(collection_id, item_id);
+ // dispatch the call to the runtime
+ let result = self.env().invoke_runtime(&burn_item_call);
+
+ // report result to console
+ // NOTE: println should only be used on a development chain)
+ env::println(&format!(
+ "burn_item invoke_runtime result {:?}",
+ result
+ ));
}
+
+ // GetOwner
+ // BalanceOf
}
}
smart_contract/ink-types-node-runtime/src/calls.rsdiffbeforeafterboth--- a/smart_contract/ink-types-node-runtime/src/calls.rs
+++ b/smart_contract/ink-types-node-runtime/src/calls.rs
@@ -50,46 +50,6 @@
// Balances::<NodeRuntimeTypes>::transfer(account.into(), balance).into()
// }
-// #[cfg(test)]
-// mod tests {
-// use crate::{calls, NodeRuntimeTypes};
-// use super::Call;
-
-// use node_runtime::{self, Runtime};
-// use pallet_indices::address;
-// use scale::{Decode, Encode};
-
-
-// #[test]
-// fn call_balance_transfer() {
-// let balance = 10_000;
-// let account_index = 0;
-
-// let contract_address = calls::Address::Index(account_index);
-// let contract_transfer =
-// calls::Balances::<NodeRuntimeTypes>::transfer(contract_address, balance);
-// let contract_call = Call::Balances(contract_transfer);
-
-// let srml_address = address::Address::Index(account_index);
-// let srml_transfer = node_runtime::BalancesCall::<Runtime>::transfer(srml_address, balance);
-// let srml_call = node_runtime::Call::Balances(srml_transfer);
-
-// let contract_call_encoded = contract_call.encode();
-// let srml_call_encoded = srml_call.encode();
-
-// assert_eq!(srml_call_encoded, contract_call_encoded);
-
-// let srml_call_decoded: node_runtime::Call =
-// Decode::decode(&mut contract_call_encoded.as_slice())
-// .expect("Balances transfer call decodes to srml type");
-// let srml_call_encoded = srml_call_decoded.encode();
-// let contract_call_decoded: Call = Decode::decode(&mut srml_call_encoded.as_slice())
-// .expect("Balances transfer call decodes back to contract type");
-// assert!(contract_call == contract_call_decoded);
-// }
-// }
-
-
@@ -114,18 +74,18 @@
use ink_core::env::EnvTypes;
use scale::{Codec, Decode, Encode};
-use pallet_indices::address::Address;
use sp_runtime::traits::Member;
+use ink_prelude::vec::Vec;
use crate::{AccountId, Balance, NodeRuntimeTypes};
-use sp_runtime::sp_std::prelude::Vec;
+
/// Default runtime Call type, a subset of the runtime Call module variants
///
/// The codec indices of the modules *MUST* match those in the concrete runtime.
#[derive(Encode, Decode)]
#[cfg_attr(feature = "std", derive(Clone, PartialEq, Eq))]
pub enum Call {
- #[codec(index = "8")]
+ #[codec(index = "7")]
Nft(Nft<NodeRuntimeTypes>),
}
@@ -140,61 +100,74 @@
where
T: EnvTypes,
T::AccountId: Member + Codec,
-{
- #[allow(non_camel_case_types)]
- create_nft_collection(Vec<u16>, Vec<u16>, Vec<u8>, u32),
+ {
+ #[allow(non_camel_case_types)]
+ create_collection(Vec<u16>, Vec<u16>, Vec<u8>, u32),
- #[allow(non_camel_case_types)]
- add_collection_admin(u64, T::AccountId),
+ #[allow(non_camel_case_types)]
+ destroy_collection(u64),
- // collection_name: Vec<u16>,
- // collection_description: Vec<u16>,
- // token_prefix: Vec<u8>,
- // custom_data_sz: u32
+ #[allow(non_camel_case_types)]
+ change_collection_owner(u64, T::AccountId),
-}
+ #[allow(non_camel_case_types)]
+ add_collection_admin(u64, T::AccountId),
-// Construct a `Balances::transfer` call
-pub fn create_collection(collection_name: Vec<u16>, collection_description: Vec<u16>,
- token_prefix: Vec<u8>, custom_data_sz: u32) -> Call {
- Nft::<NodeRuntimeTypes>::create_nft_collection(collection_name, collection_description, token_prefix, custom_data_sz).into()
-}
+ #[allow(non_camel_case_types)]
+ remove_collection_admin(u64, T::AccountId),
-#[cfg(test)]
-mod tests {
- use crate::{calls, NodeRuntimeTypes};
- use super::Call;
+ #[allow(non_camel_case_types)]
+ create_item(u64, Vec<u8>),
- use node_runtime::{self, Runtime};
- use pallet_indices::address;
- use scale::{Decode, Encode};
+ #[allow(non_camel_case_types)]
+ burn_item(u64, u64),
+ #[allow(non_camel_case_types)]
+ transfer(u64, u64, T::AccountId),
- #[test]
- fn call_balance_transfer() {
- let balance = 10_000;
- let account_index = 0;
+ #[allow(non_camel_case_types)]
+ nft_approve(T::AccountId, u64, u64),
- let contract_address = calls::Address::Index(account_index);
- let contract_transfer =
- calls::Balances::<NodeRuntimeTypes>::transfer(contract_address, balance);
- let contract_call = Call::Balances(contract_transfer);
+ #[allow(non_camel_case_types)]
+ nft_transfer_from(u64, u64, T::AccountId),
- let srml_address = address::Address::Index(account_index);
- let srml_transfer = node_runtime::BalancesCall::<Runtime>::transfer(srml_address, balance);
- let srml_call = node_runtime::Call::Balances(srml_transfer);
+ #[allow(non_camel_case_types)]
+ nft_safe_transfer(u64, u64, T::AccountId),
+ }
- let contract_call_encoded = contract_call.encode();
- let srml_call_encoded = srml_call.encode();
- assert_eq!(srml_call_encoded, contract_call_encoded);
- let srml_call_decoded: node_runtime::Call =
- Decode::decode(&mut contract_call_encoded.as_slice())
- .expect("Balances transfer call decodes to srml type");
- let srml_call_encoded = srml_call_decoded.encode();
- let contract_call_decoded: Call = Decode::decode(&mut srml_call_encoded.as_slice())
- .expect("Balances transfer call decodes back to contract type");
- assert!(contract_call == contract_call_decoded);
- }
+
+pub fn transfer(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {
+ Nft::<NodeRuntimeTypes>::transfer(collection_id, item_id, new_owner.into()).into()
+}
+
+pub fn create_collection(collection_name: Vec<u16>, collection_description: Vec<u16>,
+ token_prefix: Vec<u8>, custom_data_sz: u32) -> Call {
+ Nft::<NodeRuntimeTypes>::create_collection(collection_name, collection_description, token_prefix, custom_data_sz).into()
+}
+
+// pub fn safe_transfer(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {
+// Nft::<NodeRuntimeTypes>::nft_safe_transfer(collection_id, item_id, new_owner.into()).into()
+// }
+
+pub fn approve(approved: AccountId, collection_id: u64, item_id: u64) -> Call {
+ Nft::<NodeRuntimeTypes>::nft_approve(approved.into(), collection_id, item_id).into()
+}
+
+//GetApproved
+
+pub fn transfer_from(collection_id: u64, item_id: u64, new_owner: AccountId) -> Call {
+ Nft::<NodeRuntimeTypes>::nft_transfer_from(collection_id, item_id, new_owner.into()).into()
+}
+
+pub fn create_item(collection_id: u64, properties: Vec<u8>) -> Call {
+ Nft::<NodeRuntimeTypes>::create_item(collection_id, properties).into()
+}
+
+pub fn burn_item(collection_id: u64, item_id: u64) -> Call {
+ Nft::<NodeRuntimeTypes>::burn_item(collection_id, item_id).into()
}
+
+//GetOwner
+//BalanceOf
\ No newline at end of file
smart_contract/ink-types-node-runtime/src/lib.rsdiffbeforeafterboth--- a/smart_contract/ink-types-node-runtime/src/lib.rs
+++ b/smart_contract/ink-types-node-runtime/src/lib.rs
@@ -36,6 +36,7 @@
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)]
pub struct AccountId (AccountId32);
+
impl From<AccountId32> for AccountId {
fn from(account: AccountId32) -> Self {
AccountId(account)