git.delta.rocks / unique-network / refs/commits / 9322aa344eaa

difftreelog

Add properties extrinsics

Daniel Shiposha2022-04-29parent: #b699923.patch.diff
in: master

10 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
736 ) -> DispatchResult {736 ) -> DispatchResult {
737 collection.check_is_owner_or_admin(sender)?;737 collection.check_is_owner_or_admin(sender)?;
738738
739 CollectionProperties::<T>::get(collection.id).try_change_property(property)?;739 CollectionProperties::<T>::try_mutate(
740 collection.id,
741 |properties| properties.try_change_property(property.clone())
742 )?;
743
744 <Pallet<T>>::deposit_event(Event::CollectionPropertySet(collection.id, property));
740745
741 Ok(())746 Ok(())
742 }747 }
748
749 pub fn change_collection_properties(
750 collection: &CollectionHandle<T>,
751 sender: &T::CrossAccountId,
752 properties: Vec<Property>,
753 ) -> DispatchResult {
754 for property in properties {
755 Self::change_collection_property(collection, sender, property)?;
756 }
757
758 Ok(())
759 }
743760
744 pub fn change_property_permission(761 pub fn change_property_permission(
745 collection: &CollectionHandle<T>,762 collection: &CollectionHandle<T>,
909 fn create_multiple_items(amount: u32) -> Weight;926 fn create_multiple_items(amount: u32) -> Weight;
910 fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;927 fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;
911 fn burn_item() -> Weight;928 fn burn_item() -> Weight;
912 fn set_property() -> Weight;929 fn change_collection_properties(amount: u32) -> Weight;
930 fn change_token_properties(amount: u32) -> Weight;
913 fn transfer() -> Weight;931 fn transfer() -> Weight;
914 fn approve() -> Weight;932 fn approve() -> Weight;
915 fn transfer_from() -> Weight;933 fn transfer_from() -> Weight;
945 amount: u128,963 amount: u128,
946 ) -> DispatchResultWithPostInfo;964 ) -> DispatchResultWithPostInfo;
947965
948 fn change_collection_property(966 fn change_collection_properties(
949 &self,967 &self,
950 sender: T::CrossAccountId,968 sender: T::CrossAccountId,
951 property: Property,969 properties: Vec<Property>,
952 ) -> DispatchResultWithPostInfo;970 ) -> DispatchResultWithPostInfo;
953971
954 fn change_token_property(972 fn change_token_properties(
955 &self,973 &self,
956 sender: T::CrossAccountId,974 sender: T::CrossAccountId,
957 token_id: TokenId,975 token_id: TokenId,
958 property: Property,976 property: Vec<Property>,
959 ) -> DispatchResultWithPostInfo;977 ) -> DispatchResultWithPostInfo;
960978
961 fn transfer(979 fn transfer(
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
50 <SelfWeightOf<T>>::burn_item()50 <SelfWeightOf<T>>::burn_item()
51 }51 }
52
53 fn change_collection_properties(amount: u32) -> Weight {
54 <SelfWeightOf<T>>::change_collection_properties(amount)
55 }
5256
53 fn set_property() -> Weight {57 fn change_token_properties(amount: u32) -> Weight {
54 <SelfWeightOf<T>>::set_property()58 <SelfWeightOf<T>>::change_token_properties(amount)
55 }59 }
5660
57 fn transfer() -> Weight {61 fn transfer() -> Weight {
229 )233 )
230 }234 }
231235
232 fn change_collection_property(236 fn change_collection_properties(
233 &self,237 &self,
234 _sender: T::CrossAccountId,238 _sender: T::CrossAccountId,
235 _property: Property,239 _property: Vec<Property>,
236 ) -> DispatchResultWithPostInfo {240 ) -> DispatchResultWithPostInfo {
237 fail!(<Error<T>>::PropertiesNotAllowed)241 fail!(<Error<T>>::PropertiesNotAllowed)
238 }242 }
239243
240 fn change_token_property(244 fn change_token_properties(
241 &self,245 &self,
242 _sender: T::CrossAccountId,246 _sender: T::CrossAccountId,
243 _token_id: TokenId,247 _token_id: TokenId,
244 _property: Property,248 _property: Vec<Property>,
245 ) -> DispatchResultWithPostInfo {249 ) -> DispatchResultWithPostInfo {
246 fail!(<Error<T>>::PropertiesNotAllowed)250 fail!(<Error<T>>::PropertiesNotAllowed)
247 }251 }
modifiedpallets/fungible/src/weights.rsdiffbeforeafterboth
35 fn create_item() -> Weight;35 fn create_item() -> Weight;
36 fn create_multiple_items_ex(b: u32, ) -> Weight;36 fn create_multiple_items_ex(b: u32, ) -> Weight;
37 fn burn_item() -> Weight;37 fn burn_item() -> Weight;
38 fn set_property() -> Weight;38 fn change_collection_properties(amount: u32) -> Weight;
39 fn change_token_properties(amount: u32) -> Weight;
39 fn transfer() -> Weight;40 fn transfer() -> Weight;
40 fn approve() -> Weight;41 fn approve() -> Weight;
41 fn transfer_from() -> Weight;42 fn transfer_from() -> Weight;
71 .saturating_add(T::DbWeight::get().writes(2 as Weight))72 .saturating_add(T::DbWeight::get().writes(2 as Weight))
72 }73 }
7374
74 fn set_property() -> Weight {75 fn change_collection_properties(amount: u32) -> Weight {
75 // Error76 // Error
76 077 0
77 }78 }
79
80 fn change_token_properties(amount: u32) -> Weight {
81 // Error
82 0
83 }
7884
79 // Storage: Fungible Balance (r:2 w:2)85 // Storage: Fungible Balance (r:2 w:2)
80 fn transfer() -> Weight {86 fn transfer() -> Weight {
134 .saturating_add(RocksDbWeight::get().writes(2 as Weight))140 .saturating_add(RocksDbWeight::get().writes(2 as Weight))
135 }141 }
136142
137 fn set_property() -> Weight {143 fn change_collection_properties(amount: u32) -> Weight {
138 // Error144 // Error
139 0145 0
140 }146 }
147
148 fn change_token_properties(amount: u32) -> Weight {
149 // Error
150 0
151 }
141152
142 // Storage: Fungible Balance (r:2 w:2)153 // Storage: Fungible Balance (r:2 w:2)
143 fn transfer() -> Weight {154 fn transfer() -> Weight {
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
50 <SelfWeightOf<T>>::burn_item()50 <SelfWeightOf<T>>::burn_item()
51 }51 }
52
53 fn change_collection_properties(amount: u32) -> Weight {
54 <SelfWeightOf<T>>::change_collection_properties(amount)
55 }
5256
53 fn set_property() -> Weight {57 fn change_token_properties(amount: u32) -> Weight {
54 <SelfWeightOf<T>>::set_property()58 <SelfWeightOf<T>>::change_token_properties(amount)
55 }59 }
5660
57 fn transfer() -> Weight {61 fn transfer() -> Weight {
145 )149 )
146 }150 }
151
152 fn change_collection_properties(
153 &self,
154 sender: T::CrossAccountId,
155 properties: Vec<Property>,
156 ) -> DispatchResultWithPostInfo {
157 let weight = <CommonWeights<T>>::change_collection_properties(properties.len() as u32);
158
159 with_weight(
160 <Pallet<T>>::change_collection_properties(self, &sender, properties),
161 weight
162 )
163 }
164
165 fn change_token_properties(
166 &self,
167 sender: T::CrossAccountId,
168 token_id: TokenId,
169 properties: Vec<Property>,
170 ) -> DispatchResultWithPostInfo {
171 let weight = <CommonWeights<T>>::change_token_properties(properties.len() as u32);
172
173 with_weight(
174 <Pallet<T>>::change_token_properties(self, &sender, token_id, properties),
175 weight
176 )
177 }
147178
148 fn burn_item(179 fn burn_item(
149 &self,180 &self,
241 }272 }
242 }273 }
243
244 fn change_collection_property(
245 &self,
246 sender: T::CrossAccountId,
247 property: Property,
248 ) -> DispatchResultWithPostInfo {
249 // let token_id = None;
250 with_weight(
251 // <Pallet<T>>::change_property(self, &sender, token_id, property),
252 Ok(()),
253 <CommonWeights<T>>::set_property(),
254 )
255 }
256
257 fn change_token_property(
258 &self,
259 sender: T::CrossAccountId,
260 token_id: TokenId,
261 property: Property,
262 ) -> DispatchResultWithPostInfo {
263 with_weight(
264 // <Pallet<T>>::change_property(self, &sender, Some(token_id), property),
265 Ok(()),
266 <CommonWeights<T>>::set_property(),
267 )
268 }
269274
270 fn set_variable_metadata(275 fn set_variable_metadata(
271 &self,276 &self,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
265 .map(|p| p.clone())265 .map(|p| p.clone())
266 .unwrap_or(PropertyPermission::None);266 .unwrap_or(PropertyPermission::None);
267267
268 let check_token_owner = || -> DispatchResult {
269 let token_data = <TokenData<T>>::get((collection.id, token_id))268 let token_data = <TokenData<T>>::get((collection.id, token_id))
270 .ok_or(<CommonError<T>>::TokenNotFound)?;269 .ok_or(<CommonError<T>>::TokenNotFound)?;
271270
271 let check_token_owner = || -> DispatchResult {
272 ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);272 ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);
273
274 Ok(())273 Ok(())
275 };274 };
276275
277 let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))276 let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))
278 .get_property(&property.key)277 .get_property(&property.key)
304 Ok(())303 Ok(())
305 }304 }
305
306 pub fn change_token_properties(
307 collection: &NonfungibleHandle<T>,
308 sender: &T::CrossAccountId,
309 token_id: TokenId,
310 properties: Vec<Property>,
311 ) -> DispatchResult {
312 for property in properties {
313 Self::change_token_property(collection, sender, token_id, property)?;
314 }
315
316 Ok(())
317 }
318
319 pub fn change_collection_properties(
320 collection: &NonfungibleHandle<T>,
321 sender: &T::CrossAccountId,
322 properties: Vec<Property>,
323 ) -> DispatchResult {
324 <PalletCommon<T>>::change_collection_properties(collection, sender, properties)
325 }
306326
307 pub fn transfer(327 pub fn transfer(
308 collection: &NonfungibleHandle<T>,328 collection: &NonfungibleHandle<T>,
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
36 fn create_multiple_items(b: u32, ) -> Weight;36 fn create_multiple_items(b: u32, ) -> Weight;
37 fn create_multiple_items_ex(b: u32, ) -> Weight;37 fn create_multiple_items_ex(b: u32, ) -> Weight;
38 fn burn_item() -> Weight;38 fn burn_item() -> Weight;
39 fn set_property() -> Weight;39 fn change_collection_properties(amount: u32) -> Weight;
40 fn change_token_properties(amount: u32) -> Weight;
40 fn transfer() -> Weight;41 fn transfer() -> Weight;
41 fn approve() -> Weight;42 fn approve() -> Weight;
42 fn transfer_from() -> Weight;43 fn transfer_from() -> Weight;
92 .saturating_add(T::DbWeight::get().writes(4 as Weight))93 .saturating_add(T::DbWeight::get().writes(4 as Weight))
93 }94 }
95
96 fn change_collection_properties(amount: u32) -> Weight {
97 // TODO calculate appropriate weight
98 (50_000_000 as Weight).saturating_mul(amount as Weight)
99 }
94100
95 fn set_property() -> Weight {101 fn change_token_properties(amount: u32) -> Weight {
96 // TODO calculate appropriate weight102 // TODO calculate appropriate weight
97 50_000_000 as Weight103 (50_000_000 as Weight).saturating_mul(amount as Weight)
98 }104 }
99105
100 // Storage: Nonfungible TokenData (r:1 w:1)106 // Storage: Nonfungible TokenData (r:1 w:1)
187 .saturating_add(RocksDbWeight::get().writes(4 as Weight))193 .saturating_add(RocksDbWeight::get().writes(4 as Weight))
188 }194 }
195
196 fn change_collection_properties(amount: u32) -> Weight {
197 // TODO calculate appropriate weight
198 (50_000_000 as Weight).saturating_mul(amount as Weight)
199 }
189200
190 fn set_property() -> Weight {201 fn change_token_properties(amount: u32) -> Weight {
191 // TODO calculate appropriate weight202 // TODO calculate appropriate weight
192 50_000_000 as Weight203 (50_000_000 as Weight).saturating_mul(amount as Weight)
193 }204 }
194205
195 // Storage: Nonfungible TokenData (r:1 w:1)206 // Storage: Nonfungible TokenData (r:1 w:1)
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
66 max_weight_of!(burn_item_partial(), burn_item_fully())66 max_weight_of!(burn_item_partial(), burn_item_fully())
67 }67 }
68
69 fn change_collection_properties(amount: u32) -> Weight {
70 <SelfWeightOf<T>>::change_collection_properties(amount)
71 }
6872
69 fn set_property() -> Weight {73 fn change_token_properties(amount: u32) -> Weight {
70 <SelfWeightOf<T>>::set_property()74 <SelfWeightOf<T>>::change_token_properties(amount)
71 }75 }
7276
73 fn transfer() -> Weight {77 fn transfer() -> Weight {
248 )252 )
249 }253 }
250254
251 fn change_collection_property(255 fn change_collection_properties(
252 &self,256 &self,
253 _sender: T::CrossAccountId,257 _sender: T::CrossAccountId,
254 _property: Property,258 _property: Vec<Property>,
255 ) -> DispatchResultWithPostInfo {259 ) -> DispatchResultWithPostInfo {
256 fail!(<Error<T>>::PropertiesNotAllowed)260 fail!(<Error<T>>::PropertiesNotAllowed)
257 }261 }
258262
259 fn change_token_property(263 fn change_token_properties(
260 &self,264 &self,
261 _sender: T::CrossAccountId,265 _sender: T::CrossAccountId,
262 _token_id: TokenId,266 _token_id: TokenId,
263 _property: Property,267 _property: Vec<Property>,
264 ) -> DispatchResultWithPostInfo {268 ) -> DispatchResultWithPostInfo {
265 fail!(<Error<T>>::PropertiesNotAllowed)269 fail!(<Error<T>>::PropertiesNotAllowed)
266 }270 }
modifiedpallets/refungible/src/weights.rsdiffbeforeafterboth
38 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;38 fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;
39 fn burn_item_partial() -> Weight;39 fn burn_item_partial() -> Weight;
40 fn burn_item_fully() -> Weight;40 fn burn_item_fully() -> Weight;
41 fn set_property() -> Weight;41 fn change_collection_properties(amount: u32) -> Weight;
42 fn change_token_properties(amount: u32) -> Weight;
42 fn transfer_normal() -> Weight;43 fn transfer_normal() -> Weight;
43 fn transfer_creating() -> Weight;44 fn transfer_creating() -> Weight;
44 fn transfer_removing() -> Weight;45 fn transfer_removing() -> Weight;
131 .saturating_add(T::DbWeight::get().writes(6 as Weight))132 .saturating_add(T::DbWeight::get().writes(6 as Weight))
132 }133 }
133134
134 fn set_property() -> Weight {135 fn change_collection_properties(amount: u32) -> Weight {
135 // Error136 // Error
136 0137 0
137 }138 }
139
140 fn change_token_properties(amount: u32) -> Weight {
141 // Error
142 0
143 }
138144
139 // Storage: Refungible Balance (r:2 w:2)145 // Storage: Refungible Balance (r:2 w:2)
140 fn transfer_normal() -> Weight {146 fn transfer_normal() -> Weight {
305 .saturating_add(RocksDbWeight::get().writes(6 as Weight))311 .saturating_add(RocksDbWeight::get().writes(6 as Weight))
306 }312 }
307313
308 fn set_property() -> Weight {314 fn change_collection_properties(amount: u32) -> Weight {
309 // Error315 // Error
310 0316 0
311 }317 }
318
319 fn change_token_properties(amount: u32) -> Weight {
320 // Error
321 0
322 }
312323
313 // Storage: Refungible Balance (r:2 w:2)324 // Storage: Refungible Balance (r:2 w:2)
314 fn transfer_normal() -> Weight {325 fn transfer_normal() -> Weight {
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
694 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))694 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))
695 }695 }
696
697 #[weight = T::CommonWeightInfo::change_collection_properties(properties.len() as u32)]
698 #[transactional]
699 pub fn change_collection_properties(
700 origin,
701 collection_id: CollectionId,
702 properties: Vec<Property>
703 ) -> DispatchResultWithPostInfo {
704 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);
705
706 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
707
708 dispatch_call::<T, _>(collection_id, |d| d.change_collection_properties(sender, properties))
709 }
710
711 #[weight = T::CommonWeightInfo::change_token_properties(properties.len() as u32)]
712 #[transactional]
713 pub fn change_token_properties(
714 origin,
715 collection_id: CollectionId,
716 token_id: TokenId,
717 properties: Vec<Property>
718 ) -> DispatchResultWithPostInfo {
719 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);
720
721 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
722
723 dispatch_call::<T, _>(collection_id, |d| d.change_token_properties(sender, token_id, properties))
724 }
696725
697 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]726 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]
698 #[transactional]727 #[transactional]
modifiedruntime/common/src/weights.rsdiffbeforeafterboth
54 dispatch_weight::<T>() + max_weight_of!(burn_item())54 dispatch_weight::<T>() + max_weight_of!(burn_item())
55 }55 }
56
57 fn change_collection_properties(amount: u32) -> Weight {
58 dispatch_weight::<T>() + max_weight_of!(change_collection_properties(amount))
59 }
5660
57 fn set_property() -> Weight {61 fn change_token_properties(amount: u32) -> Weight {
58 dispatch_weight::<T>() + max_weight_of!(set_property())62 dispatch_weight::<T>() + max_weight_of!(change_token_properties(amount))
59 }63 }
6064
61 fn transfer() -> Weight {65 fn transfer() -> Weight {