git.delta.rocks / unique-network / refs/commits / 4eba81a8c797

difftreelog

fix evm nitpicks

Yaroslav Bolyukin2022-05-30parent: #1a755a0.patch.diff
in: master

11 files changed

modifiedCargo.lockdiffbeforeafterboth
4290version = "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]
42964293
4297[[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",
modifiedpallets/common/Cargo.tomldiffbeforeafterboth
27scale-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"] }
3130
32[features]31[features]
33default = ["std"]32default = ["std"]
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
15// 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/>.
1616
17use 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 }
9090
91 #[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();
9495
95 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 limit
119 )))
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 }
127
128 #[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();
132
133 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 limit
147 )))
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 }
131155
132 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}
148172
149fn 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}
155
156fn parse_bool(value: string) -> Result<Option<bool>> {
157 value
158 .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}
162179
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
17use up_data_structs::CollectionId;17use up_data_structs::CollectionId;
18use sp_core::H160;18use sp_core::H160;
19
20lazy_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 static
23 let key: up_data_structs::PropertyKey = key.into_bytes().try_into().expect("Can't create \"tokenURI\" key");
24 key
25 };
26}
2719
28// 0x17c4e6453Cc49AAAaEACA894e6D9683e00000001 - collection 120// 0x17c4e6453Cc49AAAaEACA894e6D9683e00000001 - collection 1
29// TODO: Unhardcode prefix21// TODO: Unhardcode prefix
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
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::{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_metadata
162 #[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")?;
544
545 let mut properties = CollectionPropertiesVec::default();
546 properties
547 .try_push(Property {
548 key: key.clone(),
549 value: token_uri
550 .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)))?;
543555
544 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 }
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
15// 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/>.
1616
17use 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};
2929
30use sp_std::vec::Vec;30use sp_std::vec::Vec;
31use alloc::format;31use alloc::format;
32
33pub trait Config:
34 frame_system::Config
35 + pallet_evm_coder_substrate::Config
36 + pallet_evm::account::Config
37 + pallet_nonfungible::Config
38{
39 type ContractAddress: Get<H160>;
40}
4132
42struct 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}
5243
53#[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))?;
7971
80 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>)?;
10395
104 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 }
11499
122 }107 }
123}108}
124
125#[derive(ToLog)]
126pub enum EthCollectionEvent {
127 CollectionCreated {
128 #[indexed]
129 owner: address,
130 #[indexed]
131 collection_id: address,
132 },
133}
134109
135pub 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 }
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
30 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}
7880
79decl_event! {81decl_event! {
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
917 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}
921922
922parameter_types! {923parameter_types! {
989 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;990 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
990}991}
991
992impl pallet_unique::eth::Config for Runtime {
993 type ContractAddress = EvmCollectionHelperAddress;
994}
995992
996construct_runtime!(993construct_runtime!(
997 pub enum Runtime where994 pub enum Runtime where
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
900 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}
904905
905parameter_types! {906parameter_types! {
972 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;973 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
973}974}
974
975impl pallet_unique::eth::Config for Runtime {
976 type ContractAddress = EvmCollectionHelperAddress;
977}
978975
979construct_runtime!(976construct_runtime!(
980 pub enum Runtime where977 pub enum Runtime where
modifiedruntime/tests/src/lib.rsdiffbeforeafterboth
1616
17#![allow(clippy::from_over_into)]17#![allow(clippy::from_over_into)]
1818
19use 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}
247
248parameter_types! {
249 // 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f
250 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}
247254
248impl 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}
253261
254// Build genesis storage according to the mock runtime.262// Build genesis storage according to the mock runtime.
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
905 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}
909910
910parameter_types! {911parameter_types! {
977 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;978 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
978}979}
979
980impl pallet_unique::eth::Config for Runtime {
981 type ContractAddress = EvmCollectionHelperAddress;
982}
983980
984construct_runtime!(981construct_runtime!(
985 pub enum Runtime where982 pub enum Runtime where