difftreelog
feat implement evm property manipulation
in: master
12 files changed
.maintain/scripts/generate_api.shdiffbeforeafterboth7sed -n '/=== SNIP START ===/, /=== SNIP END ===/{ /=== SNIP START ===/! { /=== SNIP END ===/! p } }' $tmp > $raw7sed -n '/=== SNIP START ===/, /=== SNIP END ===/{ /=== SNIP START ===/! { /=== SNIP END ===/! p } }' $tmp > $raw8formatted=$(mktemp)8formatted=$(mktemp)9prettier --use-tabs $raw > $formatted9prettier --use-tabs $raw > $formatted10solhint --fix $formatted111012mv $formatted $OUTPUT11mv $formatted $OUTPUT1312pallets/common/src/erc.rsdiffbeforeafterboth21use sp_std::vec::Vec;21use sp_std::vec::Vec;22use up_data_structs::Property;22use up_data_structs::Property;232324use crate::{Pallet, CollectionHandle, Config};24use crate::{Pallet, CollectionHandle, Config, CollectionProperties};252526/// Does not always represent a full collection, for RFT it is either26/// Does not always represent a full collection, for RFT it is either27/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)27/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)333334#[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()4246 .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 }524653 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")?;5253 <Pallet<T>>::delete_collection_property(self, &caller, key).map_err(dispatch_to_evm::<T>)54 }5556 /// Throws error if key not found54 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")?;6162 let props = <CollectionProperties<T>>::get(self.id);63 let prop = props.get(&key).ok_or("key not found")?;6465 Ok(prop.to_vec())66 }56}67}5768pallets/common/src/lib.rsdiffbeforeafterbothno syntactic changes
pallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth31 );23}32}2425// Selector: 56fd500b26contract CollectionProperties is Dummy, ERC165 {27 // Selector: setProperty(string,string) 62d9491f28 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) 3424191435 function deleteProperty(string memory key) public {36 require(false, stub_error);37 key;38 dummy = 0;39 }40}413342// Selector: 79cc679034// Selector: 79cc679043contract ERC20UniqueExtensions is Dummy, ERC165 {35contract ERC20UniqueExtensions is Dummy, ERC165 {119 }127 }120}128}129130// Selector: 9b5e29c5131contract CollectionProperties is Dummy, ERC165 {132 // Selector: setCollectionProperty(string,bytes) 2f073f66133 function setCollectionProperty(string memory key, bytes memory value)134 public135 {136 require(false, stub_error);137 key;138 value;139 dummy = 0;140 }141142 // Selector: deleteCollectionProperty(string) 7b7debce143 function deleteCollectionProperty(string memory key) public {144 require(false, stub_error);145 key;146 dummy = 0;147 }148149 // Throws error if key not found150 //151 // Selector: collectionProperty(string) cf24fd6d152 function collectionProperty(string memory key)153 public154 view155 returns (bytes memory)156 {157 require(false, stub_error);158 key;159 dummy;160 return hex"";161 }162}121163122contract UniqueFungible is Dummy, ERC165, ERC20, ERC20UniqueExtensions, CollectionProperties {164contract UniqueFungible is165 Dummy,pallets/nonfungible/src/erc.rsdiffbeforeafterboth21};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;353536use 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};4041#[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 }6869 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")?;8283 <Pallet<T>>::set_token_property(self, &caller, TokenId(token_id), Property { key, value })84 .map_err(dispatch_to_evm::<T>)85 }8687 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")?;9394 <Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key)95 .map_err(dispatch_to_evm::<T>)96 }9798 /// Throws error if key not found99 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")?;104105 let props = <TokenProperties<T>>::get((self.id, token_id));106 let prop = props.get(&key).ok_or("key not found")?;107108 Ok(prop.to_vec())109 }110}4011141fn 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> {}pallets/nonfungible/src/lib.rsdiffbeforeafterboth64pub 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 }433434 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 }431441432 pub fn transfer(442 pub fn transfer(433 collection: &NonfungibleHandle<T>,443 collection: &NonfungibleHandle<T>,pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth51 event MintingFinished();51 event MintingFinished();52}52}5354// Selector: 4136937755contract TokenProperties is Dummy, ERC165 {56 // Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa57 function setTokenPropertyPermission(58 string memory key,59 bool isMutable,60 bool collectionAdmin,61 bool tokenOwner62 ) public {63 require(false, stub_error);64 key;65 isMutable;66 collectionAdmin;67 tokenOwner;68 dummy = 0;69 }7071 // Selector: setProperty(uint256,string,bytes) 1752d67b72 function setProperty(73 uint256 tokenId,74 string memory key,75 bytes memory value76 ) public {77 require(false, stub_error);78 tokenId;79 key;80 value;81 dummy = 0;82 }8384 // Selector: deleteProperty(uint256,string) 066111d185 function deleteProperty(uint256 tokenId, string memory key) public {86 require(false, stub_error);87 tokenId;88 key;89 dummy = 0;90 }9192 // Throws error if key not found93 //94 // Selector: property(uint256,string) 7228c32795 function property(uint256 tokenId, string memory key)96 public97 view98 returns (bytes memory)99 {100 require(false, stub_error);101 tokenId;102 key;103 dummy;104 return hex"";105 }106}5310754// Selector: 42966c68108// Selector: 42966c6855contract ERC721Burnable is Dummy, ERC165 {109contract ERC721Burnable is Dummy, ERC165 {61 }115 }62}116}6364// Selector: 56fd500b65contract CollectionProperties is Dummy, ERC165 {66 // Selector: setProperty(string,string) 62d9491f67 function setProperty(string memory key, string memory value) public {68 require(false, stub_error);69 key;70 value;71 dummy = 0;72 }7374 // Selector: deleteProperty(string) 3424191475 function deleteProperty(string memory key) public {76 require(false, stub_error);77 key;78 dummy = 0;79 }80}8111782// Selector: 58800161118// Selector: 5880016183contract ERC721 is Dummy, ERC165, ERC721Events {119contract ERC721 is Dummy, ERC165, ERC721Events {294 }330 }295}331}332333// Selector: 9b5e29c5334contract CollectionProperties is Dummy, ERC165 {335 // Selector: setCollectionProperty(string,bytes) 2f073f66336 function setCollectionProperty(string memory key, bytes memory value)337 public338 {339 require(false, stub_error);340 key;341 value;342 dummy = 0;343 }344345 // Selector: deleteCollectionProperty(string) 7b7debce346 function deleteCollectionProperty(string memory key) public {347 require(false, stub_error);348 key;349 dummy = 0;350 }351352 // Throws error if key not found353 //354 // Selector: collectionProperty(string) cf24fd6d355 function collectionProperty(string memory key)356 public357 view358 returns (bytes memory)359 {360 require(false, stub_error);361 key;362 dummy;363 return hex"";364 }365}296366297// Selector: d74d154f367// Selector: d74d154f298contract 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 TokenProperties357{}428{}358429tests/src/eth/api/UniqueFungible.soldiffbeforeafterboth22 );22 );23}23}2425// Selector: 56fd500b26interface CollectionProperties is Dummy, ERC165 {27 // Selector: setProperty(string,string) 62d9491f28 function setProperty(string memory key, string memory value) external;2930 // Selector: deleteProperty(string) 3424191431 function deleteProperty(string memory key) external;32}332434// Selector: 79cc679025// Selector: 79cc679035interface ERC20UniqueExtensions is Dummy, ERC165 {26interface ERC20UniqueExtensions is Dummy, ERC165 {74 returns (uint256);65 returns (uint256);75}66}6768// Selector: 9b5e29c569interface CollectionProperties is Dummy, ERC165 {70 // Selector: setCollectionProperty(string,bytes) 2f073f6671 function setCollectionProperty(string memory key, bytes memory value)72 external;7374 // Selector: deleteCollectionProperty(string) 7b7debce75 function deleteCollectionProperty(string memory key) external;7677 // Throws error if key not found78 //79 // Selector: collectionProperty(string) cf24fd6d80 function collectionProperty(string memory key)81 external82 view83 returns (bytes memory);84}768577interface UniqueFungible is86interface UniqueFungible is78 Dummy,87 Dummy,tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth42 event MintingFinished();42 event MintingFinished();43}43}4445// Selector: 4136937746interface TokenProperties is Dummy, ERC165 {47 // Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa48 function setTokenPropertyPermission(49 string memory key,50 bool isMutable,51 bool collectionAdmin,52 bool tokenOwner53 ) external;5455 // Selector: setProperty(uint256,string,bytes) 1752d67b56 function setProperty(57 uint256 tokenId,58 string memory key,59 bytes memory value60 ) external;6162 // Selector: deleteProperty(uint256,string) 066111d163 function deleteProperty(uint256 tokenId, string memory key) external;6465 // Throws error if key not found66 //67 // Selector: property(uint256,string) 7228c32768 function property(uint256 tokenId, string memory key)69 external70 view71 returns (bytes memory);72}447345// Selector: 42966c6874// Selector: 42966c6846interface ERC721Burnable is Dummy, ERC165 {75interface ERC721Burnable is Dummy, ERC165 {47 // Selector: burn(uint256) 42966c6876 // Selector: burn(uint256) 42966c6848 function burn(uint256 tokenId) external;77 function burn(uint256 tokenId) external;49}78}5051// Selector: 56fd500b52interface CollectionProperties is Dummy, ERC165 {53 // Selector: setProperty(string,string) 62d9491f54 function setProperty(string memory key, string memory value) external;5556 // Selector: deleteProperty(string) 3424191457 function deleteProperty(string memory key) external;58}597960// Selector: 5880016180// Selector: 5880016161interface 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}193194// Selector: 9b5e29c5195interface CollectionProperties is Dummy, ERC165 {196 // Selector: setCollectionProperty(string,bytes) 2f073f66197 function setCollectionProperty(string memory key, bytes memory value)198 external;199200 // Selector: deleteCollectionProperty(string) 7b7debce201 function deleteCollectionProperty(string memory key) external;202203 // Throws error if key not found204 //205 // Selector: collectionProperty(string) cf24fd6d206 function collectionProperty(string memory key)207 external208 view209 returns (bytes memory);210}173211174// Selector: d74d154f212// Selector: d74d154f175interface 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 TokenProperties206{}245{}207246