--- a/pallets/nft/src/lib.rs +++ b/pallets/nft/src/lib.rs @@ -145,7 +145,6 @@ #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct NftItemType { - pub collection: CollectionId, pub owner: AccountId, pub const_data: Vec, pub variable_data: Vec, @@ -154,7 +153,6 @@ #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct FungibleItemType { - pub collection: CollectionId, pub owner: AccountId, pub value: u128, } @@ -162,7 +160,6 @@ #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct ReFungibleItemType { - pub collection: CollectionId, pub owner: Vec>, pub const_data: Vec, pub variable_data: Vec, @@ -175,16 +172,16 @@ pub amount: u128, } -#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct VestingItem { - pub sender: AccountId, - pub recipient: AccountId, - pub collection_id: CollectionId, - pub item_id: TokenId, - pub amount: u64, - pub vesting_date: Moment, -} +// #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)] +// #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] +// pub struct VestingItem { +// pub sender: AccountId, +// pub recipient: AccountId, +// pub collection_id: CollectionId, +// pub item_id: TokenId, +// pub amount: u64, +// pub vesting_date: Moment, +// } #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] @@ -446,16 +443,16 @@ >::init_collection(_c); } - for (_num, _q, _i) in &config.nft_item_id { - >::init_nft_token(_i); + for (_num, _c, _i) in &config.nft_item_id { + >::init_nft_token(*_c, _i); } - for (_num, _q, _i) in &config.fungible_item_id { - >::init_fungible_token(_i); + for (_num, _c, _i) in &config.fungible_item_id { + >::init_fungible_token(*_c, _i); } - for (_num, _q, _i) in &config.refungible_item_id { - >::init_refungible_token(_i); + for (_num, _c, _i) in &config.refungible_item_id { + >::init_refungible_token(*_c, _i); } }) } @@ -1570,22 +1567,20 @@ { CreateItemData::NFT(data) => { let item = NftItemType { - collection: collection_id, owner, const_data: data.const_data, variable_data: data.variable_data }; - Self::add_nft_item(item)?; + Self::add_nft_item(collection_id, item)?; }, CreateItemData::Fungible(_) => { let item = FungibleItemType { - collection: collection_id, owner, value: (10 as u128).pow(collection.decimal_points as u32) }; - Self::add_fungible_item(item)?; + Self::add_fungible_item(collection_id, item)?; }, CreateItemData::ReFungible(data) => { let mut owner_list = Vec::new(); @@ -1593,13 +1588,12 @@ owner_list.push(Ownership {owner: owner.clone(), fraction: value}); let item = ReFungibleItemType { - collection: collection_id, owner: owner_list, const_data: data.const_data, variable_data: data.variable_data }; - Self::add_refungible_item(item)?; + Self::add_refungible_item(collection_id, item)?; } }; @@ -1609,33 +1603,33 @@ Ok(()) } - fn add_fungible_item(item: FungibleItemType) -> DispatchResult { - let current_index = ::get(item.collection) + fn add_fungible_item(collection_id: CollectionId, item: FungibleItemType) -> DispatchResult { + let current_index = ::get(collection_id) .checked_add(1) .ok_or(Error::::NumOverflow)?; let itemcopy = item.clone(); let owner = item.owner.clone(); - Self::add_token_index(item.collection, current_index, owner.clone())?; + Self::add_token_index(collection_id, current_index, owner.clone())?; - ::insert(item.collection, current_index); - >::insert(item.collection, current_index, itemcopy); + ::insert(collection_id, current_index); + >::insert(collection_id, current_index, itemcopy); // Add current block let v: Vec> = Vec::new(); - >::insert(item.collection, current_index, v); + >::insert(collection_id, current_index, v); // Update balance - let new_balance = >::get(item.collection, owner.clone()) + let new_balance = >::get(collection_id, owner.clone()) .checked_add(item.value) .ok_or(Error::::NumOverflow)?; - >::insert(item.collection, owner.clone(), new_balance); + >::insert(collection_id, owner.clone(), new_balance); Ok(()) } - fn add_refungible_item(item: ReFungibleItemType) -> DispatchResult { - let current_index = ::get(item.collection) + fn add_refungible_item(collection_id: CollectionId, item: ReFungibleItemType) -> DispatchResult { + let current_index = ::get(collection_id) .checked_add(1) .ok_or(Error::::NumOverflow)?; let itemcopy = item.clone(); @@ -1643,31 +1637,30 @@ let value = item.owner.first().unwrap().fraction; let owner = item.owner.first().unwrap().owner.clone(); - Self::add_token_index(item.collection, current_index, owner.clone())?; + Self::add_token_index(collection_id, current_index, owner.clone())?; - ::insert(item.collection, current_index); - >::insert(item.collection, current_index, itemcopy); + ::insert(collection_id, current_index); + >::insert(collection_id, current_index, itemcopy); // Add current block let block_number: T::BlockNumber = 0.into(); - >::insert(item.collection, current_index, block_number); + >::insert(collection_id, current_index, block_number); // Update balance - let new_balance = >::get(item.collection, owner.clone()) + let new_balance = >::get(collection_id, owner.clone()) .checked_add(value) .ok_or(Error::::NumOverflow)?; - >::insert(item.collection, owner.clone(), new_balance); + >::insert(collection_id, owner.clone(), new_balance); Ok(()) } - fn add_nft_item(item: NftItemType) -> DispatchResult { - let current_index = ::get(item.collection) + fn add_nft_item(collection_id: CollectionId, item: NftItemType) -> DispatchResult { + let current_index = ::get(collection_id) .checked_add(1) .ok_or(Error::::NumOverflow)?; let item_owner = item.owner.clone(); - let collection_id = item.collection.clone(); Self::add_token_index(collection_id, current_index, item.owner.clone())?; ::insert(collection_id, current_index); @@ -1903,12 +1896,11 @@ } else { // new owner do not have account let item = FungibleItemType { - collection: collection_id, owner: new_owner.clone(), value }; - Self::add_fungible_item(item)?; + Self::add_fungible_item(collection_id, item)?; } if amount == value { @@ -2122,13 +2114,12 @@ CreatedCollectionCount::put(next_id); } - fn init_nft_token(item: &NftItemType) { - let current_index = ::get(item.collection) + fn init_nft_token(collection_id: CollectionId, item: &NftItemType) { + let current_index = ::get(collection_id) .checked_add(1) .unwrap(); let item_owner = item.owner.clone(); - let collection_id = item.collection.clone(); Self::add_token_index(collection_id, current_index, item.owner.clone()).unwrap(); ::insert(collection_id, current_index); @@ -2140,40 +2131,40 @@ >::insert(collection_id, item_owner.clone(), new_balance); } - fn init_fungible_token(item: &FungibleItemType) { - let current_index = ::get(item.collection) + fn init_fungible_token(collection_id: CollectionId, item: &FungibleItemType) { + let current_index = ::get(collection_id) .checked_add(1) .unwrap(); let owner = item.owner.clone(); - Self::add_token_index(item.collection, current_index, owner.clone()).unwrap(); + Self::add_token_index(collection_id, current_index, owner.clone()).unwrap(); - ::insert(item.collection, current_index); + ::insert(collection_id, current_index); // Update balance - let new_balance = >::get(item.collection, owner.clone()) + let new_balance = >::get(collection_id, owner.clone()) .checked_add(item.value) .unwrap(); - >::insert(item.collection, owner.clone(), new_balance); + >::insert(collection_id, owner.clone(), new_balance); } - fn init_refungible_token(item: &ReFungibleItemType) { - let current_index = ::get(item.collection) + fn init_refungible_token(collection_id: CollectionId, item: &ReFungibleItemType) { + let current_index = ::get(collection_id) .checked_add(1) .unwrap(); let value = item.owner.first().unwrap().fraction; let owner = item.owner.first().unwrap().owner.clone(); - Self::add_token_index(item.collection, current_index, owner.clone()).unwrap(); + Self::add_token_index(collection_id, current_index, owner.clone()).unwrap(); - ::insert(item.collection, current_index); + ::insert(collection_id, current_index); // Update balance - let new_balance = >::get(item.collection, owner.clone()) + let new_balance = >::get(collection_id, owner.clone()) .checked_add(value) .unwrap(); - >::insert(item.collection, owner.clone(), new_balance); + >::insert(collection_id, owner.clone(), new_balance); } fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: T::AccountId) -> DispatchResult { --- a/runtime_types.json +++ b/runtime_types.json @@ -42,18 +42,15 @@ "Fraction": "u128" }, "FungibleItemType": { - "Collection": "CollectionId", "Owner": "AccountId", "Value": "u128" }, "NftItemType": { - "Collection": "CollectionId", "Owner": "AccountId", "ConstData": "Vec", "VariableData": "Vec" }, "ReFungibleItemType": { - "Collection": "CollectionId", "Owner": "Vec>", "ConstData": "Vec", "VariableData": "Vec"