difftreelog
fix evm nitpicks
in: master
11 files changed
Cargo.lockdiffbeforeafterboth4290version = "1.4.0"4290version = "1.4.0"4291source = "registry+https://github.com/rust-lang/crates.io-index"4291source = "registry+https://github.com/rust-lang/crates.io-index"4292checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"4292checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"4293dependencies = [4294 "spin",4295]429642934297[[package]]4294[[package]]4298name = "lazycell"4295name = "lazycell"5920 "frame-benchmarking",5917 "frame-benchmarking",5921 "frame-support",5918 "frame-support",5922 "frame-system",5919 "frame-system",5923 "lazy_static",5924 "pallet-evm",5920 "pallet-evm",5925 "pallet-evm-coder-substrate",5921 "pallet-evm-coder-substrate",5926 "parity-scale-codec 3.1.2",5922 "parity-scale-codec 3.1.2",pallets/common/Cargo.tomldiffbeforeafterboth27scale-info = { version = "2.0.1", default-features = false, features = [27scale-info = { version = "2.0.1", default-features = false, features = [28 "derive",28 "derive",29] }29] }30lazy_static = { version = "1.4.0", default-features = false, features = ["spin_no_std"] }313032[features]31[features]33default = ["std"]32default = ["std"]pallets/common/src/erc.rsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617use evm_coder::{17use evm_coder::{18 solidity_interface,18 solidity_interface, solidity,19 types::*,19 types::*,20 execution::{Result, Error},20 execution::{Result, Error},21};21};88 Ok(())88 Ok(())89 }89 }909091 #[solidity(rename_selector = "setLimit")]91 fn set_limit(&mut self, caller: caller, limit: string, value: string) -> Result<void> {92 fn set_int_limit(&mut self, caller: caller, limit: string, value: uint32) -> Result<void> {92 check_is_owner(caller, self)?;93 check_is_owner(caller, self)?;93 let mut limits = self.limits.clone();94 let mut limits = self.limits.clone();949595 match limit.as_str() {96 match limit.as_str() {96 "accountTokenOwnershipLimit" => {97 "accountTokenOwnershipLimit" => {97 limits.account_token_ownership_limit = parse_int(value)?;98 limits.account_token_ownership_limit = Some(value);98 }99 }99 "sponsoredDataSize" => {100 "sponsoredDataSize" => {100 limits.sponsored_data_size = parse_int(value)?;101 limits.sponsored_data_size = Some(value);101 }102 }102 "sponsoredDataRateLimit" => {103 "sponsoredDataRateLimit" => {103 limits.sponsored_data_rate_limit =104 limits.sponsored_data_rate_limit = Some(SponsoringRateLimit::Blocks(value));104 Some(SponsoringRateLimit::Blocks(parse_int(value)?.unwrap()));105 }105 }106 "tokenLimit" => {106 "tokenLimit" => {107 limits.token_limit = parse_int(value)?;107 limits.token_limit = Some(value);108 }108 }109 "sponsorTransferTimeout" => {109 "sponsorTransferTimeout" => {110 limits.sponsor_transfer_timeout = parse_int(value)?;110 limits.sponsor_transfer_timeout = Some(value);111 }111 }112 "sponsorApproveTimeout" => {112 "sponsorApproveTimeout" => {113 limits.sponsor_approve_timeout = parse_int(value)?;113 limits.sponsor_approve_timeout = Some(value);114 }114 }115 "ownerCanTransfer" => {116 limits.owner_can_transfer = parse_bool(value)?;117 }118 "ownerCanDestroy" => {119 limits.owner_can_destroy = parse_bool(value)?;120 }121 "transfersEnabled" => {122 limits.transfers_enabled = parse_bool(value)?;123 }124 _ => return Err(Error::Revert(format!("Unknown limit \"{}\"", limit))),115 _ => {116 return Err(Error::Revert(format!(117 "Unknown integer limit \"{}\"",118 limit119 )))120 }125 }121 }126 self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)122 self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)127 .map_err(dispatch_to_evm::<T>)?;123 .map_err(dispatch_to_evm::<T>)?;128 save(self);124 save(self);129 Ok(())125 Ok(())130 }126 }127128 #[solidity(rename_selector = "setLimit")]129 fn set_bool_limit(&mut self, caller: caller, limit: string, value: bool) -> Result<void> {130 check_is_owner(caller, self)?;131 let mut limits = self.limits.clone();132133 match limit.as_str() {134 "ownerCanTransfer" => {135 limits.owner_can_transfer = Some(value);136 }137 "ownerCanDestroy" => {138 limits.owner_can_destroy = Some(value);139 }140 "transfersEnabled" => {141 limits.transfers_enabled = Some(value);142 }143 _ => {144 return Err(Error::Revert(format!(145 "Unknown boolean limit \"{}\"",146 limit147 )))148 }149 }150 self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)151 .map_err(dispatch_to_evm::<T>)?;152 save(self);153 Ok(())154 }131155132 fn contract_address(&self, _caller: caller) -> Result<address> {156 fn contract_address(&self, _caller: caller) -> Result<address> {133 Ok(crate::eth::collection_id_to_address(self.id))157 Ok(crate::eth::collection_id_to_address(self.id))146 <crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());170 <crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());147}171}148172149fn parse_int(value: string) -> Result<Option<u32>> {173pub fn token_uri_key() -> up_data_structs::PropertyKey {150 value174 b"tokenURI"151 .parse::<u32>()152 .map_err(|e| Error::Revert(format!("Int value \"{}\" parse error: {}", value, e)))153 .map(|value| Some(value))154}155156fn parse_bool(value: string) -> Result<Option<bool>> {157 value158 .parse::<bool>()175 .to_vec()159 .map_err(|e| Error::Revert(format!("Bool value \"{}\" parse error: {}", value, e)))176 .try_into()160 .map(|value| Some(value))177 .expect("length < limit; qed")161}178}162179pallets/common/src/eth.rsdiffbeforeafterboth17use up_data_structs::CollectionId;17use up_data_structs::CollectionId;18use sp_core::H160;18use sp_core::H160;1920lazy_static::lazy_static! {21 pub static ref KEY_TOKEN_URI: up_data_structs::PropertyKey = {22 let key: evm_coder::types::string = "tokenURI".into(); //TODO: make static23 let key: up_data_structs::PropertyKey = key.into_bytes().try_into().expect("Can't create \"tokenURI\" key");24 key25 };26}271928// 0x17c4e6453Cc49AAAaEACA894e6D9683e00000001 - collection 120// 0x17c4e6453Cc49AAAaEACA894e6D9683e00000001 - collection 129// TODO: Unhardcode prefix21// TODO: Unhardcode prefixpallets/nonfungible/src/erc.rsdiffbeforeafterboth22use 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::{24use up_data_structs::{25 TokenId, SchemaVersion, PropertyPermission, PropertyKeyPermission, Property, CollectionId,25 TokenId, PropertyPermission, PropertyKeyPermission, Property, CollectionId, PropertyKey,26 PropertyKey, CollectionPropertiesVec,26 CollectionPropertiesVec,27};27};28use pallet_evm_coder_substrate::dispatch_to_evm;28use pallet_evm_coder_substrate::dispatch_to_evm;29use sp_core::{H160, U256};29use sp_core::{H160, U256};30use sp_std::vec::Vec;30use sp_std::vec::Vec;31use pallet_common::{31use pallet_common::{32 erc::{CommonEvmHandler, PrecompileResult, CollectionCall},32 erc::{CommonEvmHandler, PrecompileResult, CollectionCall, token_uri_key},33 CollectionHandle, CollectionPropertyPermissions,33 CollectionHandle, CollectionPropertyPermissions,34};34};35use pallet_evm::account::CrossAccountId;35use pallet_evm::account::CrossAccountId;161 /// Returns token's const_metadata161 /// Returns token's const_metadata162 #[solidity(rename_selector = "tokenURI")]162 #[solidity(rename_selector = "tokenURI")]163 fn token_uri(&self, token_id: uint256) -> Result<string> {163 fn token_uri(&self, token_id: uint256) -> Result<string> {164 let key = pallet_common::eth::KEY_TOKEN_URI.clone();164 let key = token_uri_key();165 if !has_token_permission::<T>(self.id, &key) {165 if !has_token_permission::<T>(self.id, &key) {166 return Err("No tokenURI permission".into());166 return Err("No tokenURI permission".into());167 }167 }362 token_id: uint256,362 token_id: uint256,363 token_uri: string,363 token_uri: string,364 ) -> Result<bool> {364 ) -> Result<bool> {365 let key = pallet_common::eth::KEY_TOKEN_URI.clone();365 let key = token_uri_key();366 let permission = get_token_permission::<T>(self.id, &key)?;366 let permission = get_token_permission::<T>(self.id, &key)?;367 if !permission.collection_admin {367 if !permission.collection_admin {368 return Err("Operation is not allowed".into());368 return Err("Operation is not allowed".into());524 to: address,524 to: address,525 tokens: Vec<(uint256, string)>,525 tokens: Vec<(uint256, string)>,526 ) -> Result<bool> {526 ) -> Result<bool> {527 let key = token_uri_key();527 let caller = T::CrossAccountId::from_eth(caller);528 let caller = T::CrossAccountId::from_eth(caller);528 let to = T::CrossAccountId::from_eth(to);529 let to = T::CrossAccountId::from_eth(to);529 let mut expected_index = <TokensMinted<T>>::get(self.id)530 let mut expected_index = <TokensMinted<T>>::get(self.id)541 }542 }542 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;543 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;544545 let mut properties = CollectionPropertiesVec::default();546 properties547 .try_push(Property {548 key: key.clone(),549 value: token_uri550 .into_bytes()551 .try_into()552 .map_err(|_| "token uri is too long")?,553 })554 .map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;543555544 data.push(CreateItemData::<T> {556 data.push(CreateItemData::<T> {545 properties: BoundedVec::default(),557 properties,546 owner: to.clone(),558 owner: to.clone(),547 });559 });548 }560 }pallets/unique/src/eth/mod.rsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617use core::marker::PhantomData;17use core::marker::PhantomData;18use evm_coder::{execution::*, generate_stubgen, solidity_interface, types::*, ToLog};18use evm_coder::{execution::*, generate_stubgen, solidity_interface, weight, types::*};19use ethereum as _;19use ethereum as _;20use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};20use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};21use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId, Pallet as PalletEvm};21use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId};22use up_data_structs::{22use up_data_structs::{23 CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,23 CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,24 MAX_COLLECTION_NAME_LENGTH,24 MAX_COLLECTION_NAME_LENGTH,25};25};26use frame_support::traits::Get;26use frame_support::traits::Get;27use sp_core::H160;27use pallet_common::{CollectionById, erc::token_uri_key};28use pallet_common::CollectionById;28use crate::{SelfWeightOf, Config, weights::WeightInfo};292930use sp_std::vec::Vec;30use sp_std::vec::Vec;31use alloc::format;31use alloc::format;3233pub trait Config:34 frame_system::Config35 + pallet_evm_coder_substrate::Config36 + pallet_evm::account::Config37 + pallet_nonfungible::Config38{39 type ContractAddress: Get<H160>;40}413242struct EvmCollectionHelper<T: Config>(SubstrateRecorder<T>);33struct EvmCollectionHelper<T: Config>(SubstrateRecorder<T>);43impl<T: Config> WithRecorder<T> for EvmCollectionHelper<T> {34impl<T: Config> WithRecorder<T> for EvmCollectionHelper<T> {51}42}524353#[solidity_interface(name = "CollectionHelper")]44#[solidity_interface(name = "CollectionHelper")]54impl<T: Config> EvmCollectionHelper<T> {45impl<T: Config + pallet_nonfungible::Config> EvmCollectionHelper<T> {46 #[weight(<SelfWeightOf<T>>::create_collection())]55 fn create_721_collection(47 fn create_nonfungible_collection(56 &self,48 &self,57 caller: caller,49 caller: caller,58 name: string,50 name: string,77 .try_into()69 .try_into()78 .map_err(|_| error_feild_too_long(stringify!(token_prefix), MAX_TOKEN_PREFIX_LENGTH))?;70 .map_err(|_| error_feild_too_long(stringify!(token_prefix), MAX_TOKEN_PREFIX_LENGTH))?;797180 let key = pallet_common::eth::KEY_TOKEN_URI.clone();72 let key = token_uri_key();81 let permission = up_data_structs::PropertyPermission {73 let permission = up_data_structs::PropertyPermission {82 mutable: true,74 mutable: true,83 collection_admin: true,75 collection_admin: true,102 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;94 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;10395104 let address = pallet_common::eth::collection_id_to_address(collection_id);96 let address = pallet_common::eth::collection_id_to_address(collection_id);105 <PalletEvm<T>>::deposit_log(106 EthCollectionEvent::CollectionCreated {107 owner: *caller.as_eth(),108 collection_id: address,109 }110 .to_log(address),111 );112 Ok(address)97 Ok(address)113 }98 }11499122 }107 }123}108}124125#[derive(ToLog)]126pub enum EthCollectionEvent {127 CollectionCreated {128 #[indexed]129 owner: address,130 #[indexed]131 collection_id: address,132 },133}134109135pub struct CollectionHelperOnMethodCall<T: Config>(PhantomData<*const T>);110pub struct CollectionHelperOnMethodCall<T: Config>(PhantomData<*const T>);136impl<T: Config> OnMethodCall<T> for CollectionHelperOnMethodCall<T> {111impl<T: Config + pallet_nonfungible::Config> OnMethodCall<T> for CollectionHelperOnMethodCall<T> {137 fn is_reserved(contract: &sp_core::H160) -> bool {112 fn is_reserved(contract: &sp_core::H160) -> bool {138 contract == &T::ContractAddress::get()113 contract == &T::ContractAddress::get()139 }114 }pallets/unique/src/lib.rsdiffbeforeafterboth30 ensure,30 ensure,31 weights::{Weight},31 weights::{Weight},32 transactional,32 transactional,33 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},33 pallet_prelude::{DispatchResultWithPostInfo, ConstU32, Get},34 BoundedVec,34 BoundedVec,35};35};36use sp_core::H160;36use scale_info::TypeInfo;37use scale_info::TypeInfo;37use frame_system::{self as system, ensure_signed};38use frame_system::{self as system, ensure_signed};38use sp_runtime::{sp_std::prelude::Vec};39use sp_runtime::{sp_std::prelude::Vec};39use up_data_structs::{40use up_data_structs::{40 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,41 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,41 AccessMode, CreateItemData, CollectionLimits, CollectionPermissions, CollectionId,42 CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,42 CollectionMode, TokenId, SponsorshipState, CreateCollectionData, CreateItemExData, budget,43 SponsorshipState, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,43 Property, PropertyKey, PropertyKeyPermission,44 PropertyKeyPermission,44};45};74 /// Weight information for extrinsics in this pallet.75 /// Weight information for extrinsics in this pallet.75 type WeightInfo: WeightInfo;76 type WeightInfo: WeightInfo;76 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;77 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;78 type ContractAddress: Get<H160>;77}79}788079decl_event! {81decl_event! {runtime/opal/src/lib.rsdiffbeforeafterboth917 type Event = Event;917 type Event = Event;918 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;918 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;919 type CommonWeightInfo = CommonWeights<Self>;919 type CommonWeightInfo = CommonWeights<Self>;920 type ContractAddress = EvmCollectionHelperAddress;920}921}921922922parameter_types! {923parameter_types! {989 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;990 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;990}991}991992impl pallet_unique::eth::Config for Runtime {993 type ContractAddress = EvmCollectionHelperAddress;994}995992996construct_runtime!(993construct_runtime!(997 pub enum Runtime where994 pub enum Runtime whereruntime/quartz/src/lib.rsdiffbeforeafterboth900 type Event = Event;900 type Event = Event;901 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;901 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;902 type CommonWeightInfo = CommonWeights<Self>;902 type CommonWeightInfo = CommonWeights<Self>;903 type ContractAddress = EvmCollectionHelperAddress;903}904}904905905parameter_types! {906parameter_types! {972 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;973 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;973}974}974975impl pallet_unique::eth::Config for Runtime {976 type ContractAddress = EvmCollectionHelperAddress;977}978975979construct_runtime!(976construct_runtime!(980 pub enum Runtime where977 pub enum Runtime whereruntime/tests/src/lib.rsdiffbeforeafterboth161617#![allow(clippy::from_over_into)]17#![allow(clippy::from_over_into)]181819use sp_core::{H256, U256};19use sp_core::{H160, H256, U256};20use frame_support::{20use frame_support::{21 parameter_types,21 parameter_types,22 traits::{Everything, ConstU32, ConstU64},22 traits::{Everything, ConstU32, ConstU64},245 type WeightInfo = ();245 type WeightInfo = ();246}246}247248parameter_types! {249 // 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f250 pub const EvmCollectionHelperAddress: H160 = H160([251 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,252 ]);253}247254248impl pallet_unique::Config for Test {255impl pallet_unique::Config for Test {249 type Event = ();256 type Event = ();250 type WeightInfo = ();257 type WeightInfo = ();251 type CommonWeightInfo = CommonWeights<Self>;258 type CommonWeightInfo = CommonWeights<Self>;259 type ContractAddress = EvmCollectionHelperAddress;252}260}253261254// Build genesis storage according to the mock runtime.262// Build genesis storage according to the mock runtime.runtime/unique/src/lib.rsdiffbeforeafterboth905 type Event = Event;905 type Event = Event;906 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;906 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;907 type CommonWeightInfo = CommonWeights<Self>;907 type CommonWeightInfo = CommonWeights<Self>;908 type ContractAddress = EvmCollectionHelperAddress;908}909}909910910parameter_types! {911parameter_types! {977 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;978 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;978}979}979980impl pallet_unique::eth::Config for Runtime {981 type ContractAddress = EvmCollectionHelperAddress;982}983980984construct_runtime!(981construct_runtime!(985 pub enum Runtime where982 pub enum Runtime where