difftreelog
Refcator token types - remove collection ID
in: master
2 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth--- 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<AccountId> {
- pub collection: CollectionId,
pub owner: AccountId,
pub const_data: Vec<u8>,
pub variable_data: Vec<u8>,
@@ -154,7 +153,6 @@
#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct FungibleItemType<AccountId> {
- 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<AccountId> {
- pub collection: CollectionId,
pub owner: Vec<Ownership<AccountId>>,
pub const_data: Vec<u8>,
pub variable_data: Vec<u8>,
@@ -175,16 +172,16 @@
pub amount: u128,
}
-#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-pub struct VestingItem<AccountId, Moment> {
- 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<AccountId, Moment> {
+// 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 @@
<Module<T>>::init_collection(_c);
}
- for (_num, _q, _i) in &config.nft_item_id {
- <Module<T>>::init_nft_token(_i);
+ for (_num, _c, _i) in &config.nft_item_id {
+ <Module<T>>::init_nft_token(*_c, _i);
}
- for (_num, _q, _i) in &config.fungible_item_id {
- <Module<T>>::init_fungible_token(_i);
+ for (_num, _c, _i) in &config.fungible_item_id {
+ <Module<T>>::init_fungible_token(*_c, _i);
}
- for (_num, _q, _i) in &config.refungible_item_id {
- <Module<T>>::init_refungible_token(_i);
+ for (_num, _c, _i) in &config.refungible_item_id {
+ <Module<T>>::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<T::AccountId>) -> DispatchResult {
- let current_index = <ItemListIndex>::get(item.collection)
+ fn add_fungible_item(collection_id: CollectionId, item: FungibleItemType<T::AccountId>) -> DispatchResult {
+ let current_index = <ItemListIndex>::get(collection_id)
.checked_add(1)
.ok_or(Error::<T>::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())?;
- <ItemListIndex>::insert(item.collection, current_index);
- <FungibleItemList<T>>::insert(item.collection, current_index, itemcopy);
+ <ItemListIndex>::insert(collection_id, current_index);
+ <FungibleItemList<T>>::insert(collection_id, current_index, itemcopy);
// Add current block
let v: Vec<BasketItem<T::AccountId, T::BlockNumber>> = Vec::new();
- <FungibleTransferBasket<T>>::insert(item.collection, current_index, v);
+ <FungibleTransferBasket<T>>::insert(collection_id, current_index, v);
// Update balance
- let new_balance = <Balance<T>>::get(item.collection, owner.clone())
+ let new_balance = <Balance<T>>::get(collection_id, owner.clone())
.checked_add(item.value)
.ok_or(Error::<T>::NumOverflow)?;
- <Balance<T>>::insert(item.collection, owner.clone(), new_balance);
+ <Balance<T>>::insert(collection_id, owner.clone(), new_balance);
Ok(())
}
- fn add_refungible_item(item: ReFungibleItemType<T::AccountId>) -> DispatchResult {
- let current_index = <ItemListIndex>::get(item.collection)
+ fn add_refungible_item(collection_id: CollectionId, item: ReFungibleItemType<T::AccountId>) -> DispatchResult {
+ let current_index = <ItemListIndex>::get(collection_id)
.checked_add(1)
.ok_or(Error::<T>::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())?;
- <ItemListIndex>::insert(item.collection, current_index);
- <ReFungibleItemList<T>>::insert(item.collection, current_index, itemcopy);
+ <ItemListIndex>::insert(collection_id, current_index);
+ <ReFungibleItemList<T>>::insert(collection_id, current_index, itemcopy);
// Add current block
let block_number: T::BlockNumber = 0.into();
- <ReFungibleTransferBasket<T>>::insert(item.collection, current_index, block_number);
+ <ReFungibleTransferBasket<T>>::insert(collection_id, current_index, block_number);
// Update balance
- let new_balance = <Balance<T>>::get(item.collection, owner.clone())
+ let new_balance = <Balance<T>>::get(collection_id, owner.clone())
.checked_add(value)
.ok_or(Error::<T>::NumOverflow)?;
- <Balance<T>>::insert(item.collection, owner.clone(), new_balance);
+ <Balance<T>>::insert(collection_id, owner.clone(), new_balance);
Ok(())
}
- fn add_nft_item(item: NftItemType<T::AccountId>) -> DispatchResult {
- let current_index = <ItemListIndex>::get(item.collection)
+ fn add_nft_item(collection_id: CollectionId, item: NftItemType<T::AccountId>) -> DispatchResult {
+ let current_index = <ItemListIndex>::get(collection_id)
.checked_add(1)
.ok_or(Error::<T>::NumOverflow)?;
let item_owner = item.owner.clone();
- let collection_id = item.collection.clone();
Self::add_token_index(collection_id, current_index, item.owner.clone())?;
<ItemListIndex>::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<T::AccountId>) {
- let current_index = <ItemListIndex>::get(item.collection)
+ fn init_nft_token(collection_id: CollectionId, item: &NftItemType<T::AccountId>) {
+ let current_index = <ItemListIndex>::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();
<ItemListIndex>::insert(collection_id, current_index);
@@ -2140,40 +2131,40 @@
<Balance<T>>::insert(collection_id, item_owner.clone(), new_balance);
}
- fn init_fungible_token(item: &FungibleItemType<T::AccountId>) {
- let current_index = <ItemListIndex>::get(item.collection)
+ fn init_fungible_token(collection_id: CollectionId, item: &FungibleItemType<T::AccountId>) {
+ let current_index = <ItemListIndex>::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();
- <ItemListIndex>::insert(item.collection, current_index);
+ <ItemListIndex>::insert(collection_id, current_index);
// Update balance
- let new_balance = <Balance<T>>::get(item.collection, owner.clone())
+ let new_balance = <Balance<T>>::get(collection_id, owner.clone())
.checked_add(item.value)
.unwrap();
- <Balance<T>>::insert(item.collection, owner.clone(), new_balance);
+ <Balance<T>>::insert(collection_id, owner.clone(), new_balance);
}
- fn init_refungible_token(item: &ReFungibleItemType<T::AccountId>) {
- let current_index = <ItemListIndex>::get(item.collection)
+ fn init_refungible_token(collection_id: CollectionId, item: &ReFungibleItemType<T::AccountId>) {
+ let current_index = <ItemListIndex>::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();
- <ItemListIndex>::insert(item.collection, current_index);
+ <ItemListIndex>::insert(collection_id, current_index);
// Update balance
- let new_balance = <Balance<T>>::get(item.collection, owner.clone())
+ let new_balance = <Balance<T>>::get(collection_id, owner.clone())
.checked_add(value)
.unwrap();
- <Balance<T>>::insert(item.collection, owner.clone(), new_balance);
+ <Balance<T>>::insert(collection_id, owner.clone(), new_balance);
}
fn add_token_index(collection_id: CollectionId, item_index: TokenId, owner: T::AccountId) -> DispatchResult {
runtime_types.jsondiffbeforeafterboth1{2 "Schedule": {3 "version": "u32",4 "put_code_per_byte_cost": "Gas",5 "grow_mem_cost": "Gas",6 "regular_op_cost": "Gas",7 "return_data_per_byte_cost": "Gas",8 "event_data_per_byte_cost": "Gas",9 "event_per_topic_cost": "Gas",10 "event_base_cost": "Gas",11 "call_base_cost": "Gas",12 "instantiate_base_cost": "Gas",13 "dispatch_base_cost": "Gas",14 "sandbox_data_read_cost": "Gas",15 "sandbox_data_write_cost": "Gas",16 "transfer_cost": "Gas",17 "instantiate_cost": "Gas",18 "max_event_topics": "u32",19 "max_stack_height": "u32",20 "max_memory_pages": "u32",21 "max_table_size": "u32",22 "enable_println": "bool",23 "max_subject_len": "u32"24 },25 "AccessMode": {26 "_enum": [27 "Normal",28 "WhiteList"29 ]30 },31 "DecimalPoints": "u8",32 "CollectionMode": {33 "_enum": {34 "Invalid": null,35 "NFT": null,36 "Fungible": "DecimalPoints",37 "ReFungible": "DecimalPoints"38 }39 },40 "Ownership": {41 "Owner": "AccountId",42 "Fraction": "u128"43 },44 "FungibleItemType": {45 "Collection": "CollectionId",46 "Owner": "AccountId",47 "Value": "u128"48 },49 "NftItemType": {50 "Collection": "CollectionId",51 "Owner": "AccountId",52 "ConstData": "Vec<u8>",53 "VariableData": "Vec<u8>"54 },55 "ReFungibleItemType": {56 "Collection": "CollectionId",57 "Owner": "Vec<Ownership<AccountId>>",58 "ConstData": "Vec<u8>",59 "VariableData": "Vec<u8>"60 },61 "CollectionType": {62 "Owner": "AccountId",63 "Mode": "CollectionMode",64 "Access": "AccessMode",65 "DecimalPoints": "DecimalPoints",66 "Name": "Vec<u16>",67 "Description": "Vec<u16>",68 "TokenPrefix": "Vec<u8>",69 "MintMode": "bool",70 "OffchainSchema": "Vec<u8>",71 "SchemaVersion": "SchemaVersion",72 "Sponsor": "AccountId",73 "SponsorConfirmed": "bool",74 "Limits": "CollectionLimits",75 "VariableOnChainSchema": "Vec<u8>",76 "ConstOnChainSchema": "Vec<u8>"77 },78 "ApprovePermissions": {79 "Approved": "AccountId",80 "Amount": "u128"81 },82 "RawData": "Vec<u8>",83 "Address": "AccountId",84 "LookupSource": "AccountId",85 "Weight": "u64",86 "CreateNftData": {87 "const_data": "Vec<u8>",88 "variable_data": "Vec<u8>" 89 },90 "CreateFungibleData": {},91 "CreateReFungibleData": {92 "const_data": "Vec<u8>",93 "variable_data": "Vec<u8>" 94 },95 "CreateItemData": {96 "_enum": {97 "NFT": "CreateNftData",98 "Fungible": "CreateFungibleData",99 "ReFungible": "CreateReFungibleData"100 }101 },102 "SchemaVersion": {103 "_enum": [104 "ImageURL",105 "Unique"106 ]107 },108 "CollectionId": "u32",109 "TokenId": "u32",110 "BasketItem": {111 "Address": "AccountId",112 "start_block": "BlockNumber"113 },114 "ChainLimits": {115 "collection_numbers_limit": "u32",116 "account_token_ownership_limit": "u32",117 "collections_admins_limit": "u64",118 "custom_data_limit": "u32",119 "nft_sponsor_timeout": "u32",120 "fungible_sponsor_timeout": "u32",121 "refungible_sponsor_timeout": "u32"122 },123 "CollectionLimits": {124 "AccountTokenOwnershipLimit": "u32",125 "SponsoredMintSize": "u32",126 "TokenLimit": "u32",127 "SponsorTimeout": "u32"128 }129 }130 1{2 "Schedule": {3 "version": "u32",4 "put_code_per_byte_cost": "Gas",5 "grow_mem_cost": "Gas",6 "regular_op_cost": "Gas",7 "return_data_per_byte_cost": "Gas",8 "event_data_per_byte_cost": "Gas",9 "event_per_topic_cost": "Gas",10 "event_base_cost": "Gas",11 "call_base_cost": "Gas",12 "instantiate_base_cost": "Gas",13 "dispatch_base_cost": "Gas",14 "sandbox_data_read_cost": "Gas",15 "sandbox_data_write_cost": "Gas",16 "transfer_cost": "Gas",17 "instantiate_cost": "Gas",18 "max_event_topics": "u32",19 "max_stack_height": "u32",20 "max_memory_pages": "u32",21 "max_table_size": "u32",22 "enable_println": "bool",23 "max_subject_len": "u32"24 },25 "AccessMode": {26 "_enum": [27 "Normal",28 "WhiteList"29 ]30 },31 "DecimalPoints": "u8",32 "CollectionMode": {33 "_enum": {34 "Invalid": null,35 "NFT": null,36 "Fungible": "DecimalPoints",37 "ReFungible": "DecimalPoints"38 }39 },40 "Ownership": {41 "Owner": "AccountId",42 "Fraction": "u128"43 },44 "FungibleItemType": {45 "Owner": "AccountId",46 "Value": "u128"47 },48 "NftItemType": {49 "Owner": "AccountId",50 "ConstData": "Vec<u8>",51 "VariableData": "Vec<u8>"52 },53 "ReFungibleItemType": {54 "Owner": "Vec<Ownership<AccountId>>",55 "ConstData": "Vec<u8>",56 "VariableData": "Vec<u8>"57 },58 "CollectionType": {59 "Owner": "AccountId",60 "Mode": "CollectionMode",61 "Access": "AccessMode",62 "DecimalPoints": "DecimalPoints",63 "Name": "Vec<u16>",64 "Description": "Vec<u16>",65 "TokenPrefix": "Vec<u8>",66 "MintMode": "bool",67 "OffchainSchema": "Vec<u8>",68 "SchemaVersion": "SchemaVersion",69 "Sponsor": "AccountId",70 "SponsorConfirmed": "bool",71 "Limits": "CollectionLimits",72 "VariableOnChainSchema": "Vec<u8>",73 "ConstOnChainSchema": "Vec<u8>"74 },75 "ApprovePermissions": {76 "Approved": "AccountId",77 "Amount": "u128"78 },79 "RawData": "Vec<u8>",80 "Address": "AccountId",81 "LookupSource": "AccountId",82 "Weight": "u64",83 "CreateNftData": {84 "const_data": "Vec<u8>",85 "variable_data": "Vec<u8>" 86 },87 "CreateFungibleData": {},88 "CreateReFungibleData": {89 "const_data": "Vec<u8>",90 "variable_data": "Vec<u8>" 91 },92 "CreateItemData": {93 "_enum": {94 "NFT": "CreateNftData",95 "Fungible": "CreateFungibleData",96 "ReFungible": "CreateReFungibleData"97 }98 },99 "SchemaVersion": {100 "_enum": [101 "ImageURL",102 "Unique"103 ]104 },105 "CollectionId": "u32",106 "TokenId": "u32",107 "BasketItem": {108 "Address": "AccountId",109 "start_block": "BlockNumber"110 },111 "ChainLimits": {112 "collection_numbers_limit": "u32",113 "account_token_ownership_limit": "u32",114 "collections_admins_limit": "u64",115 "custom_data_limit": "u32",116 "nft_sponsor_timeout": "u32",117 "fungible_sponsor_timeout": "u32",118 "refungible_sponsor_timeout": "u32"119 },120 "CollectionLimits": {121 "AccountTokenOwnershipLimit": "u32",122 "SponsoredMintSize": "u32",123 "TokenLimit": "u32",124 "SponsorTimeout": "u32"125 }126 }127