difftreelog
Merge pull request #417 from UniqueNetwork/bugfix/remove_view
in: master
Remove 'view' from createNonfungibleCollection interface
5 files changed
pallets/unique/src/eth/mod.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use core::marker::PhantomData;18use evm_coder::{execution::*, generate_stubgen, solidity_interface, weight, types::*};19use ethereum as _;20use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};21use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId, PrecompileHandle};22use up_data_structs::{23 CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,24 MAX_COLLECTION_NAME_LENGTH,25};26use frame_support::traits::Get;27use pallet_common::{28 CollectionById,29 erc::{token_uri_key, CollectionHelpersEvents},30};31use crate::{SelfWeightOf, Config, weights::WeightInfo};3233use sp_std::vec::Vec;34use alloc::format;3536struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);37impl<T: Config> WithRecorder<T> for EvmCollectionHelpers<T> {38 fn recorder(&self) -> &SubstrateRecorder<T> {39 &self.040 }4142 fn into_recorder(self) -> SubstrateRecorder<T> {43 self.044 }45}4647#[solidity_interface(name = "CollectionHelpers", events(CollectionHelpersEvents))]48impl<T: Config + pallet_nonfungible::Config> EvmCollectionHelpers<T> {49 #[weight(<SelfWeightOf<T>>::create_collection())]50 fn create_nonfungible_collection(51 &self,52 caller: caller,53 name: string,54 description: string,55 token_prefix: string,56 ) -> Result<address> {57 let caller = T::CrossAccountId::from_eth(caller);58 let name = name59 .encode_utf16()60 .collect::<Vec<u16>>()61 .try_into()62 .map_err(|_| error_feild_too_long(stringify!(name), MAX_COLLECTION_NAME_LENGTH))?;63 let description = description64 .encode_utf16()65 .collect::<Vec<u16>>()66 .try_into()67 .map_err(|_| {68 error_feild_too_long(stringify!(description), MAX_COLLECTION_DESCRIPTION_LENGTH)69 })?;70 let token_prefix = token_prefix71 .into_bytes()72 .try_into()73 .map_err(|_| error_feild_too_long(stringify!(token_prefix), MAX_TOKEN_PREFIX_LENGTH))?;7475 let key = token_uri_key();76 let permission = up_data_structs::PropertyPermission {77 mutable: true,78 collection_admin: true,79 token_owner: false,80 };81 let mut token_property_permissions =82 up_data_structs::CollectionPropertiesPermissionsVec::default();83 token_property_permissions84 .try_push(up_data_structs::PropertyKeyPermission { key, permission })85 .map_err(|e| Error::Revert(format!("{:?}", e)))?;8687 let data = CreateCollectionData {88 name,89 description,90 token_prefix,91 token_property_permissions,92 ..Default::default()93 };9495 let collection_id =96 <pallet_nonfungible::Pallet<T>>::init_collection(caller.clone(), data, false)97 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;9899 let address = pallet_common::eth::collection_id_to_address(collection_id);100 Ok(address)101 }102103 fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {104 if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {105 let collection_id = id;106 return Ok(<CollectionById<T>>::contains_key(collection_id));107 }108109 Ok(false)110 }111}112113pub struct CollectionHelpersOnMethodCall<T: Config>(PhantomData<*const T>);114impl<T: Config + pallet_nonfungible::Config> OnMethodCall<T> for CollectionHelpersOnMethodCall<T> {115 fn is_reserved(contract: &sp_core::H160) -> bool {116 contract == &T::ContractAddress::get()117 }118119 fn is_used(contract: &sp_core::H160) -> bool {120 contract == &T::ContractAddress::get()121 }122123 fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {124 if handle.code_address() != T::ContractAddress::get() {125 return None;126 }127128 let helpers =129 EvmCollectionHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));130 pallet_evm_coder_substrate::call(handle, helpers)131 }132133 fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {134 (contract == &T::ContractAddress::get())135 .then(|| include_bytes!("./stubs/CollectionHelpers.raw").to_vec())136 }137}138139generate_stubgen!(collection_helper_impl, CollectionHelpersCall<()>, true);140generate_stubgen!(collection_helper_iface, CollectionHelpersCall<()>, false);141142fn error_feild_too_long(feild: &str, bound: u32) -> Error {143 Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))144}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use core::marker::PhantomData;18use evm_coder::{execution::*, generate_stubgen, solidity_interface, weight, types::*};19use ethereum as _;20use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};21use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId, PrecompileHandle};22use up_data_structs::{23 CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,24 MAX_COLLECTION_NAME_LENGTH,25};26use frame_support::traits::Get;27use pallet_common::{28 CollectionById,29 erc::{token_uri_key, CollectionHelpersEvents},30};31use crate::{SelfWeightOf, Config, weights::WeightInfo};3233use sp_std::vec::Vec;34use alloc::format;3536struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);37impl<T: Config> WithRecorder<T> for EvmCollectionHelpers<T> {38 fn recorder(&self) -> &SubstrateRecorder<T> {39 &self.040 }4142 fn into_recorder(self) -> SubstrateRecorder<T> {43 self.044 }45}4647#[solidity_interface(name = "CollectionHelpers", events(CollectionHelpersEvents))]48impl<T: Config + pallet_nonfungible::Config> EvmCollectionHelpers<T> {49 #[weight(<SelfWeightOf<T>>::create_collection())]50 fn create_nonfungible_collection(51 &mut self,52 caller: caller,53 name: string,54 description: string,55 token_prefix: string,56 ) -> Result<address> {57 let caller = T::CrossAccountId::from_eth(caller);58 let name = name59 .encode_utf16()60 .collect::<Vec<u16>>()61 .try_into()62 .map_err(|_| error_feild_too_long(stringify!(name), MAX_COLLECTION_NAME_LENGTH))?;63 let description = description64 .encode_utf16()65 .collect::<Vec<u16>>()66 .try_into()67 .map_err(|_| {68 error_feild_too_long(stringify!(description), MAX_COLLECTION_DESCRIPTION_LENGTH)69 })?;70 let token_prefix = token_prefix71 .into_bytes()72 .try_into()73 .map_err(|_| error_feild_too_long(stringify!(token_prefix), MAX_TOKEN_PREFIX_LENGTH))?;7475 let key = token_uri_key();76 let permission = up_data_structs::PropertyPermission {77 mutable: true,78 collection_admin: true,79 token_owner: false,80 };81 let mut token_property_permissions =82 up_data_structs::CollectionPropertiesPermissionsVec::default();83 token_property_permissions84 .try_push(up_data_structs::PropertyKeyPermission { key, permission })85 .map_err(|e| Error::Revert(format!("{:?}", e)))?;8687 let data = CreateCollectionData {88 name,89 description,90 token_prefix,91 token_property_permissions,92 ..Default::default()93 };9495 let collection_id =96 <pallet_nonfungible::Pallet<T>>::init_collection(caller.clone(), data, false)97 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;9899 let address = pallet_common::eth::collection_id_to_address(collection_id);100 Ok(address)101 }102103 fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {104 if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {105 let collection_id = id;106 return Ok(<CollectionById<T>>::contains_key(collection_id));107 }108109 Ok(false)110 }111}112113pub struct CollectionHelpersOnMethodCall<T: Config>(PhantomData<*const T>);114impl<T: Config + pallet_nonfungible::Config> OnMethodCall<T> for CollectionHelpersOnMethodCall<T> {115 fn is_reserved(contract: &sp_core::H160) -> bool {116 contract == &T::ContractAddress::get()117 }118119 fn is_used(contract: &sp_core::H160) -> bool {120 contract == &T::ContractAddress::get()121 }122123 fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {124 if handle.code_address() != T::ContractAddress::get() {125 return None;126 }127128 let helpers =129 EvmCollectionHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));130 pallet_evm_coder_substrate::call(handle, helpers)131 }132133 fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {134 (contract == &T::ContractAddress::get())135 .then(|| include_bytes!("./stubs/CollectionHelpers.raw").to_vec())136 }137}138139generate_stubgen!(collection_helper_impl, CollectionHelpersCall<()>, true);140generate_stubgen!(collection_helper_iface, CollectionHelpersCall<()>, false);141142fn error_feild_too_long(feild: &str, bound: u32) -> Error {143 Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))144}pallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth--- a/pallets/unique/src/eth/stubs/CollectionHelpers.sol
+++ b/pallets/unique/src/eth/stubs/CollectionHelpers.sol
@@ -36,12 +36,12 @@
string memory name,
string memory description,
string memory tokenPrefix
- ) public view returns (address) {
+ ) public returns (address) {
require(false, stub_error);
name;
description;
tokenPrefix;
- dummy;
+ dummy = 0;
return 0x0000000000000000000000000000000000000000;
}
tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -27,7 +27,7 @@
string memory name,
string memory description,
string memory tokenPrefix
- ) external view returns (address);
+ ) external returns (address);
// Selector: isCollectionExist(address) c3de1494
function isCollectionExist(address collectionAddress)
tests/src/eth/collectionHelpersAbi.jsondiffbeforeafterboth--- a/tests/src/eth/collectionHelpersAbi.json
+++ b/tests/src/eth/collectionHelpersAbi.json
@@ -26,7 +26,7 @@
],
"name": "createNonfungibleCollection",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
- "stateMutability": "view",
+ "stateMutability": "nonpayable",
"type": "function"
},
{