git.delta.rocks / unique-network / refs/commits / 6edd3f1acfd3

difftreelog

feat implement evm property manipulation

Yaroslav Bolyukin2022-05-17parent: #6020bb0.patch.diff
in: master

12 files changed

modified.maintain/scripts/generate_api.shdiffbeforeafterboth
7sed -n '/=== SNIP START ===/, /=== SNIP END ===/{ /=== SNIP START ===/! { /=== SNIP END ===/! p } }' $tmp > $raw7sed -n '/=== SNIP START ===/, /=== SNIP END ===/{ /=== SNIP START ===/! { /=== SNIP END ===/! p } }' $tmp > $raw
8formatted=$(mktemp)8formatted=$(mktemp)
9prettier --use-tabs $raw > $formatted9prettier --use-tabs $raw > $formatted
10solhint --fix $formatted
1110
12mv $formatted $OUTPUT11mv $formatted $OUTPUT
1312
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
21use sp_std::vec::Vec;21use sp_std::vec::Vec;
22use up_data_structs::Property;22use up_data_structs::Property;
2323
24use crate::{Pallet, CollectionHandle, Config};24use crate::{Pallet, CollectionHandle, Config, CollectionProperties};
2525
26/// Does not always represent a full collection, for RFT it is either26/// Does not always represent a full collection, for RFT it is either
27/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)27/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)
3333
34#[solidity_interface(name = "CollectionProperties")]34#[solidity_interface(name = "CollectionProperties")]
35impl<T: Config> CollectionHandle<T> {35impl<T: Config> CollectionHandle<T> {
36 fn set_property(&mut self, caller: caller, key: string, value: string) -> Result<()> {36 fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {
37 <Pallet<T>>::set_collection_property(
38 self,
39 &T::CrossAccountId::from_eth(caller),37 let caller = T::CrossAccountId::from_eth(caller);
40 Property {
41 key: <Vec<u8>>::from(key)38 let key = <Vec<u8>>::from(key)
42 .try_into()39 .try_into()
43 .map_err(|_| "key too large")?,40 .map_err(|_| "key too large")?;
44 value: <Vec<u8>>::from(value)41 let value = value.try_into().map_err(|_| "value too large")?;
45 .try_into()42
46 .map_err(|_| "value too large")?,43 <Pallet<T>>::set_collection_property(self, &caller, Property { key, value })
47 },
48 )
49 .map_err(dispatch_to_evm::<T>)?;44 .map_err(dispatch_to_evm::<T>)
50 Ok(())
51 }45 }
5246
53 fn delete_property(&mut self, caller: caller, key: string) -> Result<()> {47 fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {
48 let caller = T::CrossAccountId::from_eth(caller);
49 let key = <Vec<u8>>::from(key)
50 .try_into()
51 .map_err(|_| "key too large")?;
52
53 <Pallet<T>>::delete_collection_property(self, &caller, key).map_err(dispatch_to_evm::<T>)
54 }
55
56 /// Throws error if key not found
54 self.set_property(caller, key, string::new())57 fn collection_property(&self, key: string) -> Result<bytes> {
55 }58 let key = <Vec<u8>>::from(key)
59 .try_into()
60 .map_err(|_| "key too large")?;
61
62 let props = <CollectionProperties<T>>::get(self.id);
63 let prop = props.get(&key).ok_or("key not found")?;
64
65 Ok(prop.to_vec())
66 }
56}67}
5768
modifiedpallets/common/src/lib.rsdiffbeforeafterboth

no syntactic changes

modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
31 );
23}32}
24
25// Selector: 56fd500b
26contract CollectionProperties is Dummy, ERC165 {
27 // Selector: setProperty(string,string) 62d9491f
28 function setProperty(string memory key, string memory value) public {
29 require(false, stub_error);
30 key;
31 value;
32 dummy = 0;
33 }
34 // Selector: deleteProperty(string) 34241914
35 function deleteProperty(string memory key) public {
36 require(false, stub_error);
37 key;
38 dummy = 0;
39 }
40}
4133
42// Selector: 79cc679034// Selector: 79cc6790
43contract ERC20UniqueExtensions is Dummy, ERC165 {35contract ERC20UniqueExtensions is Dummy, ERC165 {
119 }127 }
120}128}
129
130// Selector: 9b5e29c5
131contract CollectionProperties is Dummy, ERC165 {
132 // Selector: setCollectionProperty(string,bytes) 2f073f66
133 function setCollectionProperty(string memory key, bytes memory value)
134 public
135 {
136 require(false, stub_error);
137 key;
138 value;
139 dummy = 0;
140 }
141
142 // Selector: deleteCollectionProperty(string) 7b7debce
143 function deleteCollectionProperty(string memory key) public {
144 require(false, stub_error);
145 key;
146 dummy = 0;
147 }
148
149 // Throws error if key not found
150 //
151 // Selector: collectionProperty(string) cf24fd6d
152 function collectionProperty(string memory key)
153 public
154 view
155 returns (bytes memory)
156 {
157 require(false, stub_error);
158 key;
159 dummy;
160 return hex"";
161 }
162}
121163
122contract UniqueFungible is Dummy, ERC165, ERC20, ERC20UniqueExtensions, CollectionProperties {164contract UniqueFungible is
165 Dummy,
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
21};21};
22use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};22use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
23use frame_support::BoundedVec;23use frame_support::BoundedVec;
24use up_data_structs::{TokenId, SchemaVersion};24use up_data_structs::{TokenId, SchemaVersion, PropertyPermission, PropertyKeyPermission, Property};
25use pallet_evm_coder_substrate::dispatch_to_evm;25use pallet_evm_coder_substrate::dispatch_to_evm;
26use sp_core::{H160, U256};26use sp_core::{H160, U256};
27use sp_std::vec::Vec;27use sp_std::vec::Vec;
3535
36use crate::{36use crate::{
37 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,37 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,
38 SelfWeightOf, weights::WeightInfo,38 SelfWeightOf, weights::WeightInfo, TokenProperties,
39};39};
40
41#[solidity_interface(name = "TokenProperties")]
42impl<T: Config> NonfungibleHandle<T> {
43 fn set_token_property_permission(
44 &mut self,
45 caller: caller,
46 key: string,
47 is_mutable: bool,
48 collection_admin: bool,
49 token_owner: bool,
50 ) -> Result<()> {
51 let caller = T::CrossAccountId::from_eth(caller);
52 <Pallet<T>>::set_property_permission(
53 self,
54 &caller,
55 PropertyKeyPermission {
56 key: <Vec<u8>>::from(key)
57 .try_into()
58 .map_err(|_| "too long key")?,
59 permission: PropertyPermission {
60 mutable: is_mutable,
61 collection_admin,
62 token_owner,
63 },
64 },
65 )
66 .map_err(dispatch_to_evm::<T>)
67 }
68
69 fn set_property(
70 &mut self,
71 caller: caller,
72 token_id: uint256,
73 key: string,
74 value: bytes,
75 ) -> Result<()> {
76 let caller = T::CrossAccountId::from_eth(caller);
77 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
78 let key = <Vec<u8>>::from(key)
79 .try_into()
80 .map_err(|_| "key too long")?;
81 let value = value.try_into().map_err(|_| "value too long")?;
82
83 <Pallet<T>>::set_token_property(self, &caller, TokenId(token_id), Property { key, value })
84 .map_err(dispatch_to_evm::<T>)
85 }
86
87 fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {
88 let caller = T::CrossAccountId::from_eth(caller);
89 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
90 let key = <Vec<u8>>::from(key)
91 .try_into()
92 .map_err(|_| "key too long")?;
93
94 <Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key)
95 .map_err(dispatch_to_evm::<T>)
96 }
97
98 /// Throws error if key not found
99 fn property(&self, token_id: uint256, key: string) -> Result<bytes> {
100 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
101 let key = <Vec<u8>>::from(key)
102 .try_into()
103 .map_err(|_| "key too long")?;
104
105 let props = <TokenProperties<T>>::get((self.id, token_id));
106 let prop = props.get(&key).ok_or("key not found")?;
107
108 Ok(prop.to_vec())
109 }
110}
40111
41fn error_unsupported_schema_version() -> Error {112fn error_unsupported_schema_version() -> Error {
42 alloc::format!(113 alloc::format!(
470 ERC721UniqueExtensions,541 ERC721UniqueExtensions,
471 ERC721Mintable,542 ERC721Mintable,
472 ERC721Burnable,543 ERC721Burnable,
473 via("CollectionHandle<T>", common_mut, CollectionProperties)544 via("CollectionHandle<T>", common_mut, CollectionProperties),
545 TokenProperties,
474 )546 )
475)]547)]
476impl<T: Config> NonfungibleHandle<T> {}548impl<T: Config> NonfungibleHandle<T> {}
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
64pub mod pallet {64pub mod pallet {
65 use super::*;65 use super::*;
66 use frame_support::{Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key, traits::StorageVersion};66 use frame_support::{
67 Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key, traits::StorageVersion,
68 };
67 use frame_system::pallet_prelude::*;69 use frame_system::pallet_prelude::*;
68 use up_data_structs::{CollectionId, TokenId};70 use up_data_structs::{CollectionId, TokenId};
429 <PalletCommon<T>>::set_property_permissions(collection, sender, property_permissions)431 <PalletCommon<T>>::set_property_permissions(collection, sender, property_permissions)
430 }432 }
433
434 pub fn set_property_permission(
435 collection: &CollectionHandle<T>,
436 sender: &T::CrossAccountId,
437 permission: PropertyKeyPermission,
438 ) -> DispatchResult {
439 <PalletCommon<T>>::set_property_permission(collection, sender, permission)
440 }
431441
432 pub fn transfer(442 pub fn transfer(
433 collection: &NonfungibleHandle<T>,443 collection: &NonfungibleHandle<T>,
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
51 event MintingFinished();51 event MintingFinished();
52}52}
53
54// Selector: 41369377
55contract TokenProperties is Dummy, ERC165 {
56 // Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
57 function setTokenPropertyPermission(
58 string memory key,
59 bool isMutable,
60 bool collectionAdmin,
61 bool tokenOwner
62 ) public {
63 require(false, stub_error);
64 key;
65 isMutable;
66 collectionAdmin;
67 tokenOwner;
68 dummy = 0;
69 }
70
71 // Selector: setProperty(uint256,string,bytes) 1752d67b
72 function setProperty(
73 uint256 tokenId,
74 string memory key,
75 bytes memory value
76 ) public {
77 require(false, stub_error);
78 tokenId;
79 key;
80 value;
81 dummy = 0;
82 }
83
84 // Selector: deleteProperty(uint256,string) 066111d1
85 function deleteProperty(uint256 tokenId, string memory key) public {
86 require(false, stub_error);
87 tokenId;
88 key;
89 dummy = 0;
90 }
91
92 // Throws error if key not found
93 //
94 // Selector: property(uint256,string) 7228c327
95 function property(uint256 tokenId, string memory key)
96 public
97 view
98 returns (bytes memory)
99 {
100 require(false, stub_error);
101 tokenId;
102 key;
103 dummy;
104 return hex"";
105 }
106}
53107
54// Selector: 42966c68108// Selector: 42966c68
55contract ERC721Burnable is Dummy, ERC165 {109contract ERC721Burnable is Dummy, ERC165 {
61 }115 }
62}116}
63
64// Selector: 56fd500b
65contract CollectionProperties is Dummy, ERC165 {
66 // Selector: setProperty(string,string) 62d9491f
67 function setProperty(string memory key, string memory value) public {
68 require(false, stub_error);
69 key;
70 value;
71 dummy = 0;
72 }
73
74 // Selector: deleteProperty(string) 34241914
75 function deleteProperty(string memory key) public {
76 require(false, stub_error);
77 key;
78 dummy = 0;
79 }
80}
81117
82// Selector: 58800161118// Selector: 58800161
83contract ERC721 is Dummy, ERC165, ERC721Events {119contract ERC721 is Dummy, ERC165, ERC721Events {
294 }330 }
295}331}
332
333// Selector: 9b5e29c5
334contract CollectionProperties is Dummy, ERC165 {
335 // Selector: setCollectionProperty(string,bytes) 2f073f66
336 function setCollectionProperty(string memory key, bytes memory value)
337 public
338 {
339 require(false, stub_error);
340 key;
341 value;
342 dummy = 0;
343 }
344
345 // Selector: deleteCollectionProperty(string) 7b7debce
346 function deleteCollectionProperty(string memory key) public {
347 require(false, stub_error);
348 key;
349 dummy = 0;
350 }
351
352 // Throws error if key not found
353 //
354 // Selector: collectionProperty(string) cf24fd6d
355 function collectionProperty(string memory key)
356 public
357 view
358 returns (bytes memory)
359 {
360 require(false, stub_error);
361 key;
362 dummy;
363 return hex"";
364 }
365}
296366
297// Selector: d74d154f367// Selector: d74d154f
298contract ERC721UniqueExtensions is Dummy, ERC165 {368contract ERC721UniqueExtensions is Dummy, ERC165 {
353 ERC721UniqueExtensions,423 ERC721UniqueExtensions,
354 ERC721Mintable,424 ERC721Mintable,
355 ERC721Burnable,425 ERC721Burnable,
356 CollectionProperties426 CollectionProperties,
427 TokenProperties
357{}428{}
358429
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
22 );22 );
23}23}
24
25// Selector: 56fd500b
26interface CollectionProperties is Dummy, ERC165 {
27 // Selector: setProperty(string,string) 62d9491f
28 function setProperty(string memory key, string memory value) external;
29
30 // Selector: deleteProperty(string) 34241914
31 function deleteProperty(string memory key) external;
32}
3324
34// Selector: 79cc679025// Selector: 79cc6790
35interface ERC20UniqueExtensions is Dummy, ERC165 {26interface ERC20UniqueExtensions is Dummy, ERC165 {
74 returns (uint256);65 returns (uint256);
75}66}
67
68// Selector: 9b5e29c5
69interface CollectionProperties is Dummy, ERC165 {
70 // Selector: setCollectionProperty(string,bytes) 2f073f66
71 function setCollectionProperty(string memory key, bytes memory value)
72 external;
73
74 // Selector: deleteCollectionProperty(string) 7b7debce
75 function deleteCollectionProperty(string memory key) external;
76
77 // Throws error if key not found
78 //
79 // Selector: collectionProperty(string) cf24fd6d
80 function collectionProperty(string memory key)
81 external
82 view
83 returns (bytes memory);
84}
7685
77interface UniqueFungible is86interface UniqueFungible is
78 Dummy,87 Dummy,
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
42 event MintingFinished();42 event MintingFinished();
43}43}
44
45// Selector: 41369377
46interface TokenProperties is Dummy, ERC165 {
47 // Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
48 function setTokenPropertyPermission(
49 string memory key,
50 bool isMutable,
51 bool collectionAdmin,
52 bool tokenOwner
53 ) external;
54
55 // Selector: setProperty(uint256,string,bytes) 1752d67b
56 function setProperty(
57 uint256 tokenId,
58 string memory key,
59 bytes memory value
60 ) external;
61
62 // Selector: deleteProperty(uint256,string) 066111d1
63 function deleteProperty(uint256 tokenId, string memory key) external;
64
65 // Throws error if key not found
66 //
67 // Selector: property(uint256,string) 7228c327
68 function property(uint256 tokenId, string memory key)
69 external
70 view
71 returns (bytes memory);
72}
4473
45// Selector: 42966c6874// Selector: 42966c68
46interface ERC721Burnable is Dummy, ERC165 {75interface ERC721Burnable is Dummy, ERC165 {
47 // Selector: burn(uint256) 42966c6876 // Selector: burn(uint256) 42966c68
48 function burn(uint256 tokenId) external;77 function burn(uint256 tokenId) external;
49}78}
50
51// Selector: 56fd500b
52interface CollectionProperties is Dummy, ERC165 {
53 // Selector: setProperty(string,string) 62d9491f
54 function setProperty(string memory key, string memory value) external;
55
56 // Selector: deleteProperty(string) 34241914
57 function deleteProperty(string memory key) external;
58}
5979
60// Selector: 5880016180// Selector: 58800161
61interface ERC721 is Dummy, ERC165, ERC721Events {81interface ERC721 is Dummy, ERC165, ERC721Events {
171 function totalSupply() external view returns (uint256);191 function totalSupply() external view returns (uint256);
172}192}
193
194// Selector: 9b5e29c5
195interface CollectionProperties is Dummy, ERC165 {
196 // Selector: setCollectionProperty(string,bytes) 2f073f66
197 function setCollectionProperty(string memory key, bytes memory value)
198 external;
199
200 // Selector: deleteCollectionProperty(string) 7b7debce
201 function deleteCollectionProperty(string memory key) external;
202
203 // Throws error if key not found
204 //
205 // Selector: collectionProperty(string) cf24fd6d
206 function collectionProperty(string memory key)
207 external
208 view
209 returns (bytes memory);
210}
173211
174// Selector: d74d154f212// Selector: d74d154f
175interface ERC721UniqueExtensions is Dummy, ERC165 {213interface ERC721UniqueExtensions is Dummy, ERC165 {
202 ERC721UniqueExtensions,240 ERC721UniqueExtensions,
203 ERC721Mintable,241 ERC721Mintable,
204 ERC721Burnable,242 ERC721Burnable,
205 CollectionProperties243 CollectionProperties,
244 TokenProperties
206{}245{}
207246