difftreelog
Refcator token types - remove collection ID
in: master
2 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth145#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]145#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]146#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]146#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]147pub struct NftItemType<AccountId> {147pub struct NftItemType<AccountId> {148 pub collection: CollectionId,149 pub owner: AccountId,148 pub owner: AccountId,150 pub const_data: Vec<u8>,149 pub const_data: Vec<u8>,151 pub variable_data: Vec<u8>,150 pub variable_data: Vec<u8>,154#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]153#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]155#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]154#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]156pub struct FungibleItemType<AccountId> {155pub struct FungibleItemType<AccountId> {157 pub collection: CollectionId,158 pub owner: AccountId,156 pub owner: AccountId,159 pub value: u128,157 pub value: u128,160}158}161159162#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]160#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]163#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]161#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]164pub struct ReFungibleItemType<AccountId> {162pub struct ReFungibleItemType<AccountId> {165 pub collection: CollectionId,166 pub owner: Vec<Ownership<AccountId>>,163 pub owner: Vec<Ownership<AccountId>>,167 pub const_data: Vec<u8>,164 pub const_data: Vec<u8>,168 pub variable_data: Vec<u8>,165 pub variable_data: Vec<u8>,175 pub amount: u128,172 pub amount: u128,176}173}177174178#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]175// #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]179#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]176// #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]180pub struct VestingItem<AccountId, Moment> {177// pub struct VestingItem<AccountId, Moment> {181 pub sender: AccountId,178// pub sender: AccountId,182 pub recipient: AccountId,179// pub recipient: AccountId,183 pub collection_id: CollectionId,180// pub collection_id: CollectionId,184 pub item_id: TokenId,181// pub item_id: TokenId,185 pub amount: u64,182// pub amount: u64,186 pub vesting_date: Moment,183// pub vesting_date: Moment,187}184// }188185189#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]186#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]190#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]187#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]446 <Module<T>>::init_collection(_c);443 <Module<T>>::init_collection(_c);447 }444 }448445449 for (_num, _q, _i) in &config.nft_item_id {446 for (_num, _c, _i) in &config.nft_item_id {450 <Module<T>>::init_nft_token(_i);447 <Module<T>>::init_nft_token(*_c, _i);451 }448 }452449453 for (_num, _q, _i) in &config.fungible_item_id {450 for (_num, _c, _i) in &config.fungible_item_id {454 <Module<T>>::init_fungible_token(_i);451 <Module<T>>::init_fungible_token(*_c, _i);455 }452 }456453457 for (_num, _q, _i) in &config.refungible_item_id {454 for (_num, _c, _i) in &config.refungible_item_id {458 <Module<T>>::init_refungible_token(_i);455 <Module<T>>::init_refungible_token(*_c, _i);459 }456 }460 })457 })461 }458 }1570 {1567 {1571 CreateItemData::NFT(data) => {1568 CreateItemData::NFT(data) => {1572 let item = NftItemType {1569 let item = NftItemType {1573 collection: collection_id,1574 owner,1570 owner,1575 const_data: data.const_data,1571 const_data: data.const_data,1576 variable_data: data.variable_data1572 variable_data: data.variable_data1577 };1573 };157815741579 Self::add_nft_item(item)?;1575 Self::add_nft_item(collection_id, item)?;1580 },1576 },1581 CreateItemData::Fungible(_) => {1577 CreateItemData::Fungible(_) => {1582 let item = FungibleItemType {1578 let item = FungibleItemType {1583 collection: collection_id,1584 owner,1579 owner,1585 value: (10 as u128).pow(collection.decimal_points as u32)1580 value: (10 as u128).pow(collection.decimal_points as u32)1586 };1581 };158715821588 Self::add_fungible_item(item)?;1583 Self::add_fungible_item(collection_id, item)?;1589 },1584 },1590 CreateItemData::ReFungible(data) => {1585 CreateItemData::ReFungible(data) => {1591 let mut owner_list = Vec::new();1586 let mut owner_list = Vec::new();1592 let value = (10 as u128).pow(collection.decimal_points as u32);1587 let value = (10 as u128).pow(collection.decimal_points as u32);1593 owner_list.push(Ownership {owner: owner.clone(), fraction: value});1588 owner_list.push(Ownership {owner: owner.clone(), fraction: value});159415891595 let item = ReFungibleItemType {1590 let item = ReFungibleItemType {1596 collection: collection_id,1597 owner: owner_list,1591 owner: owner_list,1598 const_data: data.const_data,1592 const_data: data.const_data,1599 variable_data: data.variable_data1593 variable_data: data.variable_data1600 };1594 };160115951602 Self::add_refungible_item(item)?;1596 Self::add_refungible_item(collection_id, item)?;1603 }1597 }1604 };1598 };160515991609 Ok(())1603 Ok(())1610 }1604 }161116051612 fn add_fungible_item(item: FungibleItemType<T::AccountId>) -> DispatchResult {1606 fn add_fungible_item(collection_id: CollectionId, item: FungibleItemType<T::AccountId>) -> DispatchResult {1613 let current_index = <ItemListIndex>::get(item.collection)1607 let current_index = <ItemListIndex>::get(collection_id)1614 .checked_add(1)1608 .checked_add(1)1615 .ok_or(Error::<T>::NumOverflow)?;1609 .ok_or(Error::<T>::NumOverflow)?;1616 let itemcopy = item.clone();1610 let itemcopy = item.clone();1617 let owner = item.owner.clone();1611 let owner = item.owner.clone();161816121619 Self::add_token_index(item.collection, current_index, owner.clone())?;1613 Self::add_token_index(collection_id, current_index, owner.clone())?;162016141621 <ItemListIndex>::insert(item.collection, current_index);1615 <ItemListIndex>::insert(collection_id, current_index);1622 <FungibleItemList<T>>::insert(item.collection, current_index, itemcopy);1616 <FungibleItemList<T>>::insert(collection_id, current_index, itemcopy);162316171624 // Add current block1618 // Add current block1625 let v: Vec<BasketItem<T::AccountId, T::BlockNumber>> = Vec::new();1619 let v: Vec<BasketItem<T::AccountId, T::BlockNumber>> = Vec::new();1626 <FungibleTransferBasket<T>>::insert(item.collection, current_index, v);1620 <FungibleTransferBasket<T>>::insert(collection_id, current_index, v);1627 1621 1628 // Update balance1622 // Update balance1629 let new_balance = <Balance<T>>::get(item.collection, owner.clone())1623 let new_balance = <Balance<T>>::get(collection_id, owner.clone())1630 .checked_add(item.value)1624 .checked_add(item.value)1631 .ok_or(Error::<T>::NumOverflow)?;1625 .ok_or(Error::<T>::NumOverflow)?;1632 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);1626 <Balance<T>>::insert(collection_id, owner.clone(), new_balance);163316271634 Ok(())1628 Ok(())1635 }1629 }163616301637 fn add_refungible_item(item: ReFungibleItemType<T::AccountId>) -> DispatchResult {1631 fn add_refungible_item(collection_id: CollectionId, item: ReFungibleItemType<T::AccountId>) -> DispatchResult {1638 let current_index = <ItemListIndex>::get(item.collection)1632 let current_index = <ItemListIndex>::get(collection_id)1639 .checked_add(1)1633 .checked_add(1)1640 .ok_or(Error::<T>::NumOverflow)?;1634 .ok_or(Error::<T>::NumOverflow)?;1641 let itemcopy = item.clone();1635 let itemcopy = item.clone();164216361643 let value = item.owner.first().unwrap().fraction;1637 let value = item.owner.first().unwrap().fraction;1644 let owner = item.owner.first().unwrap().owner.clone();1638 let owner = item.owner.first().unwrap().owner.clone();164516391646 Self::add_token_index(item.collection, current_index, owner.clone())?;1640 Self::add_token_index(collection_id, current_index, owner.clone())?;164716411648 <ItemListIndex>::insert(item.collection, current_index);1642 <ItemListIndex>::insert(collection_id, current_index);1649 <ReFungibleItemList<T>>::insert(item.collection, current_index, itemcopy);1643 <ReFungibleItemList<T>>::insert(collection_id, current_index, itemcopy);165016441651 // Add current block1645 // Add current block1652 let block_number: T::BlockNumber = 0.into();1646 let block_number: T::BlockNumber = 0.into();1653 <ReFungibleTransferBasket<T>>::insert(item.collection, current_index, block_number);1647 <ReFungibleTransferBasket<T>>::insert(collection_id, current_index, block_number);165416481655 // Update balance1649 // Update balance1656 let new_balance = <Balance<T>>::get(item.collection, owner.clone())1650 let new_balance = <Balance<T>>::get(collection_id, owner.clone())1657 .checked_add(value)1651 .checked_add(value)1658 .ok_or(Error::<T>::NumOverflow)?;1652 .ok_or(Error::<T>::NumOverflow)?;1659 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);1653 <Balance<T>>::insert(collection_id, owner.clone(), new_balance);166016541661 Ok(())1655 Ok(())1662 }1656 }166316571664 fn add_nft_item(item: NftItemType<T::AccountId>) -> DispatchResult {1658 fn add_nft_item(collection_id: CollectionId, item: NftItemType<T::AccountId>) -> DispatchResult {1665 let current_index = <ItemListIndex>::get(item.collection)1659 let current_index = <ItemListIndex>::get(collection_id)1666 .checked_add(1)1660 .checked_add(1)1667 .ok_or(Error::<T>::NumOverflow)?;1661 .ok_or(Error::<T>::NumOverflow)?;166816621669 let item_owner = item.owner.clone();1663 let item_owner = item.owner.clone();1670 let collection_id = item.collection.clone();1671 Self::add_token_index(collection_id, current_index, item.owner.clone())?;1664 Self::add_token_index(collection_id, current_index, item.owner.clone())?;167216651673 <ItemListIndex>::insert(collection_id, current_index);1666 <ItemListIndex>::insert(collection_id, current_index);1903 } else {1896 } else {1904 // new owner do not have account1897 // new owner do not have account1905 let item = FungibleItemType {1898 let item = FungibleItemType {1906 collection: collection_id,1907 owner: new_owner.clone(),1899 owner: new_owner.clone(),1908 value1900 value1909 };1901 };191019021911 Self::add_fungible_item(item)?;1903 Self::add_fungible_item(collection_id, item)?;1912 }1904 }191319051914 if amount == value {1906 if amount == value {2122 CreatedCollectionCount::put(next_id);2114 CreatedCollectionCount::put(next_id);2123 }2115 }212421162125 fn init_nft_token(item: &NftItemType<T::AccountId>) {2117 fn init_nft_token(collection_id: CollectionId, item: &NftItemType<T::AccountId>) {2126 let current_index = <ItemListIndex>::get(item.collection)2118 let current_index = <ItemListIndex>::get(collection_id)2127 .checked_add(1)2119 .checked_add(1)2128 .unwrap();2120 .unwrap();212921212130 let item_owner = item.owner.clone();2122 let item_owner = item.owner.clone();2131 let collection_id = item.collection.clone();2132 Self::add_token_index(collection_id, current_index, item.owner.clone()).unwrap();2123 Self::add_token_index(collection_id, current_index, item.owner.clone()).unwrap();213321242134 <ItemListIndex>::insert(collection_id, current_index);2125 <ItemListIndex>::insert(collection_id, current_index);2140 <Balance<T>>::insert(collection_id, item_owner.clone(), new_balance);2131 <Balance<T>>::insert(collection_id, item_owner.clone(), new_balance);2141 }2132 }214221332143 fn init_fungible_token(item: &FungibleItemType<T::AccountId>) {2134 fn init_fungible_token(collection_id: CollectionId, item: &FungibleItemType<T::AccountId>) {2144 let current_index = <ItemListIndex>::get(item.collection)2135 let current_index = <ItemListIndex>::get(collection_id)2145 .checked_add(1)2136 .checked_add(1)2146 .unwrap();2137 .unwrap();2147 let owner = item.owner.clone();2138 let owner = item.owner.clone();214821392149 Self::add_token_index(item.collection, current_index, owner.clone()).unwrap();2140 Self::add_token_index(collection_id, current_index, owner.clone()).unwrap();215021412151 <ItemListIndex>::insert(item.collection, current_index);2142 <ItemListIndex>::insert(collection_id, current_index);215221432153 // Update balance2144 // Update balance2154 let new_balance = <Balance<T>>::get(item.collection, owner.clone())2145 let new_balance = <Balance<T>>::get(collection_id, owner.clone())2155 .checked_add(item.value)2146 .checked_add(item.value)2156 .unwrap();2147 .unwrap();2157 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);2148 <Balance<T>>::insert(collection_id, owner.clone(), new_balance);2158 }2149 }215921502160 fn init_refungible_token(item: &ReFungibleItemType<T::AccountId>) {2151 fn init_refungible_token(collection_id: CollectionId, item: &ReFungibleItemType<T::AccountId>) {2161 let current_index = <ItemListIndex>::get(item.collection)2152 let current_index = <ItemListIndex>::get(collection_id)2162 .checked_add(1)2153 .checked_add(1)2163 .unwrap();2154 .unwrap();216421552165 let value = item.owner.first().unwrap().fraction;2156 let value = item.owner.first().unwrap().fraction;2166 let owner = item.owner.first().unwrap().owner.clone();2157 let owner = item.owner.first().unwrap().owner.clone();216721582168 Self::add_token_index(item.collection, current_index, owner.clone()).unwrap();2159 Self::add_token_index(collection_id, current_index, owner.clone()).unwrap();216921602170 <ItemListIndex>::insert(item.collection, current_index);2161 <ItemListIndex>::insert(collection_id, current_index);217121622172 // Update balance2163 // Update balance2173 let new_balance = <Balance<T>>::get(item.collection, owner.clone())2164 let new_balance = <Balance<T>>::get(collection_id, owner.clone())2174 .checked_add(value)2165 .checked_add(value)2175 .unwrap();2166 .unwrap();2176 <Balance<T>>::insert(item.collection, owner.clone(), new_balance);2167 <Balance<T>>::insert(collection_id, owner.clone(), new_balance);2177 }2168 }217821692179 fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: T::AccountId) -> DispatchResult {2170 fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: T::AccountId) -> DispatchResult {runtime_types.jsondiffbeforeafterboth42 "Fraction": "u128"42 "Fraction": "u128"43 },43 },44 "FungibleItemType": {44 "FungibleItemType": {45 "Collection": "CollectionId",46 "Owner": "AccountId",45 "Owner": "AccountId",47 "Value": "u128"46 "Value": "u128"48 },47 },49 "NftItemType": {48 "NftItemType": {50 "Collection": "CollectionId",51 "Owner": "AccountId",49 "Owner": "AccountId",52 "ConstData": "Vec<u8>",50 "ConstData": "Vec<u8>",53 "VariableData": "Vec<u8>"51 "VariableData": "Vec<u8>"54 },52 },55 "ReFungibleItemType": {53 "ReFungibleItemType": {56 "Collection": "CollectionId",57 "Owner": "Vec<Ownership<AccountId>>",54 "Owner": "Vec<Ownership<AccountId>>",58 "ConstData": "Vec<u8>",55 "ConstData": "Vec<u8>",59 "VariableData": "Vec<u8>"56 "VariableData": "Vec<u8>"