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

difftreelog

Refcator token types - remove collection ID

Greg Zaitsev2020-12-24parent: #427c943.patch.diff
in: master

2 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
145#[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}
161159
162#[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}
177174
178#[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// }
188185
189#[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 }
448445
449 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 }
452449
453 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 }
456453
457 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_data
1577 };1573 };
15781574
1579 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 };
15871582
1588 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});
15941589
1595 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_data
1600 };1594 };
16011595
1602 Self::add_refungible_item(item)?;1596 Self::add_refungible_item(collection_id, item)?;
1603 }1597 }
1604 };1598 };
16051599
1609 Ok(())1603 Ok(())
1610 }1604 }
16111605
1612 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();
16181612
1619 Self::add_token_index(item.collection, current_index, owner.clone())?;1613 Self::add_token_index(collection_id, current_index, owner.clone())?;
16201614
1621 <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);
16231617
1624 // Add current block1618 // Add current block
1625 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 balance
1629 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);
16331627
1634 Ok(())1628 Ok(())
1635 }1629 }
16361630
1637 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();
16421636
1643 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();
16451639
1646 Self::add_token_index(item.collection, current_index, owner.clone())?;1640 Self::add_token_index(collection_id, current_index, owner.clone())?;
16471641
1648 <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);
16501644
1651 // Add current block1645 // Add current block
1652 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);
16541648
1655 // Update balance1649 // Update balance
1656 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);
16601654
1661 Ok(())1655 Ok(())
1662 }1656 }
16631657
1664 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)?;
16681662
1669 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())?;
16721665
1673 <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 account
1905 let item = FungibleItemType {1898 let item = FungibleItemType {
1906 collection: collection_id,
1907 owner: new_owner.clone(),1899 owner: new_owner.clone(),
1908 value1900 value
1909 };1901 };
19101902
1911 Self::add_fungible_item(item)?;1903 Self::add_fungible_item(collection_id, item)?;
1912 }1904 }
19131905
1914 if amount == value {1906 if amount == value {
2122 CreatedCollectionCount::put(next_id);2114 CreatedCollectionCount::put(next_id);
2123 }2115 }
21242116
2125 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();
21292121
2130 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();
21332124
2134 <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 }
21422133
2143 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();
21482139
2149 Self::add_token_index(item.collection, current_index, owner.clone()).unwrap();2140 Self::add_token_index(collection_id, current_index, owner.clone()).unwrap();
21502141
2151 <ItemListIndex>::insert(item.collection, current_index);2142 <ItemListIndex>::insert(collection_id, current_index);
21522143
2153 // Update balance2144 // Update balance
2154 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 }
21592150
2160 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();
21642155
2165 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();
21672158
2168 Self::add_token_index(item.collection, current_index, owner.clone()).unwrap();2159 Self::add_token_index(collection_id, current_index, owner.clone()).unwrap();
21692160
2170 <ItemListIndex>::insert(item.collection, current_index);2161 <ItemListIndex>::insert(collection_id, current_index);
21712162
2172 // Update balance2163 // Update balance
2173 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 }
21782169
2179 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 {
modifiedruntime_types.jsondiffbeforeafterboth
--- 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<u8>",
       "VariableData": "Vec<u8>"
     },
     "ReFungibleItemType": {
-      "Collection": "CollectionId",
       "Owner": "Vec<Ownership<AccountId>>",
       "ConstData": "Vec<u8>",
       "VariableData": "Vec<u8>"