git.delta.rocks / unique-network / refs/commits / 3b21e2ddf7e4

difftreelog

CORE-302 Fix compile after rebase

Trubnikov Sergey2022-05-20parent: #34309ac.patch.diff
in: master

6 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6818,11 +6818,15 @@
 name = "pallet-unique"
 version = "0.1.0"
 dependencies = [
+ "ethereum",
+ "evm-coder",
  "frame-benchmarking",
  "frame-support",
  "frame-system",
  "pallet-common",
  "pallet-evm",
+ "pallet-evm-coder-substrate",
+ "pallet-nonfungible",
  "parity-scale-codec 3.1.2",
  "scale-info",
  "serde",
modifiedpallets/unique/Cargo.tomldiffbeforeafterboth
--- a/pallets/unique/Cargo.toml
+++ b/pallets/unique/Cargo.toml
@@ -33,6 +33,22 @@
 limit-testing = ["up-data-structs/limit-testing"]
 
 ################################################################################
+# Standart Dependencies
+
+[dependencies.serde]
+default-features = false
+features = ['derive']
+version = '1.0.130'
+
+[dependencies.serde-json-core]
+default-features = false
+version = "0.4"
+
+[dependencies.ethereum]
+version = "0.12.0"
+default-features = false
+
+################################################################################
 # Substrate Dependencies
 
 [dependencies.codec]
@@ -66,15 +82,6 @@
 # default-features = false
 # git = "https://github.com/paritytech/substrate"
 # branch = "polkadot-v0.9.21"
-
-[dependencies.serde]
-default-features = false
-features = ['derive']
-version = '1.0.130'
-
-[dependencies.serde-json-core]
-default-features = false
-version = "0.4"
 
 [dependencies.sp-runtime]
 default-features = false
@@ -90,7 +97,6 @@
 default-features = false
 git = "https://github.com/paritytech/substrate"
 branch = "polkadot-v0.9.21"
-
 
 ################################################################################
 # Local Dependencies
@@ -101,3 +107,6 @@
 ] }
 pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.21-logs" }
 pallet-common = { default-features = false, path = "../common" }
+evm-coder = { default-features = false, path = '../../crates/evm-coder' }
+pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
+pallet-nonfungible = { default-features = false, path = '../../pallets/nonfungible' }
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
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/>.
16
17pub mod sponsoring;
18
19use fp_evm::PrecompileResult;
20use pallet_common::{
21 CollectionById,
22 erc::CommonEvmHandler,
23 eth::{map_eth_to_id, map_eth_to_token_id},
24};
25use pallet_fungible::FungibleHandle;
26use pallet_nonfungible::NonfungibleHandle;
27use pallet_refungible::{RefungibleHandle, erc::RefungibleTokenHandle};
28use sp_std::borrow::ToOwned;
29use sp_std::vec::Vec;
30use sp_core::{H160, U256};
31use crate::{CollectionMode, Config, dispatch::Dispatched};
32use pallet_common::CollectionHandle;
33
34pub struct UniqueErcSupport<T: Config>(core::marker::PhantomData<T>);
35
36impl<T: Config> pallet_evm::OnMethodCall<T> for UniqueErcSupport<T> {
37 fn is_reserved(target: &H160) -> bool {
38 map_eth_to_id(target).is_some()
39 }
40 fn is_used(target: &H160) -> bool {
41 map_eth_to_id(target)
42 .map(<CollectionById<T>>::contains_key)
43 .unwrap_or(false)
44 }
45 fn get_code(target: &H160) -> Option<Vec<u8>> {
46 if let Some(collection_id) = map_eth_to_id(target) {
47 let collection = <CollectionById<T>>::get(collection_id)?;
48 Some(
49 match collection.mode {
50 CollectionMode::NFT => <NonfungibleHandle<T>>::CODE,
51 CollectionMode::Fungible(_) => <FungibleHandle<T>>::CODE,
52 CollectionMode::ReFungible => <RefungibleHandle<T>>::CODE,
53 }
54 .to_owned(),
55 )
56 } else if let Some((collection_id, _token_id)) = map_eth_to_token_id(target) {
57 let collection = <CollectionById<T>>::get(collection_id)?;
58 if collection.mode != CollectionMode::ReFungible {
59 return None;
60 }
61 // TODO: check token existence
62 Some(<RefungibleTokenHandle<T>>::CODE.to_owned())
63 } else {
64 None
65 }
66 }
67 fn call(
68 source: &H160,
69 target: &H160,
70 gas_limit: u64,
71 input: &[u8],
72 value: U256,
73 ) -> Option<PrecompileResult> {
74 if let Some(collection_id) = map_eth_to_id(target) {
75 let collection = <CollectionHandle<T>>::new_with_gas_limit(collection_id, gas_limit)?;
76 let dispatched = Dispatched::dispatch(collection);
77
78 match dispatched {
79 Dispatched::Fungible(h) => h.call(source, input, value),
80 Dispatched::Nonfungible(h) => h.call(source, input, value),
81 Dispatched::Refungible(h) => h.call(source, input, value),
82 }
83 } else if let Some((collection_id, token_id)) = map_eth_to_token_id(target) {
84 let collection = <CollectionHandle<T>>::new_with_gas_limit(collection_id, gas_limit)?;
85 if collection.mode != CollectionMode::ReFungible {
86 return None;
87 }
88
89 let handle = RefungibleHandle::cast(collection);
90 // TODO: check token existence
91 RefungibleTokenHandle(handle, token_id).call(source, input, value)
92 } else {
93 None
94 }
95 }
96}
9716
98pub mod evm_collection {17pub mod evm_collection {
99 use core::marker::PhantomData;18 use core::marker::PhantomData;
100 use evm_coder::{execution::*, generate_stubgen, solidity_interface, types::*, ToLog};19 use evm_coder::{execution::*, generate_stubgen, solidity_interface, types::*, ToLog};
101 use ethereum as _;20 use ethereum as _;
102 use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};21 use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
103 use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId};22 use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId, Pallet as PalletEvm};
104 use up_data_structs::{23 use up_data_structs::{
105 CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,24 CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
106 MAX_COLLECTION_NAME_LENGTH,25 MAX_COLLECTION_NAME_LENGTH,
107 };26 };
108 use frame_support::traits::Get;27 use frame_support::traits::Get;
109 use sp_core::H160;28 use sp_core::H160;
110 use pallet_common::{CollectionHandle, save_eth, pallet::CollectionById};29 use pallet_common::{CollectionHandle, CollectionById};
111 30
112 use sp_std::{vec::Vec, rc::Rc};31 use sp_std::{vec::Vec, rc::Rc};
113 use alloc::format;32 use alloc::format;
121 type ContractAddress: Get<H160>;40 type ContractAddress: Get<H160>;
122 }41 }
12342
124 struct EvmCollectionHelper<T: Config>(Rc<SubstrateRecorder<T>>);43 struct EvmCollectionHelper<T: Config>(SubstrateRecorder<T>);
125 impl<T: Config> WithRecorder<T> for EvmCollectionHelper<T> {44 impl<T: Config> WithRecorder<T> for EvmCollectionHelper<T> {
126 fn recorder(&self) -> &SubstrateRecorder<T> {45 fn recorder(&self) -> &SubstrateRecorder<T> {
127 &self.046 &self.0
128 }47 }
129 48
130 fn into_recorder(self) -> Rc<SubstrateRecorder<T>> {49 fn into_recorder(self) -> SubstrateRecorder<T> {
131 self.050 self.0
132 }51 }
133 }52 }
171 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;90 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
172 91
173 let address = pallet_common::eth::collection_id_to_address(collection_id);92 let address = pallet_common::eth::collection_id_to_address(collection_id);
174 self.0.log_mirrored(EthCollectionEvent::CollectionCreated {93 <PalletEvm<T>>::deposit_log(
94 EthCollectionEvent::CollectionCreated {
175 owner: *caller.as_eth(),95 owner: *caller.as_eth(),
176 collection_id: address,96 collection_id: address,
177 });97 }
98 .to_log(address),
99 );
178 Ok(address)100 Ok(address)
179 }101 }
188 }110 }
189 }111 }
190 112
191 struct EvmCollection<T: Config>(Rc<SubstrateRecorder<T>>);113 struct EvmCollection<T: Config>(H160, SubstrateRecorder<T>);
192 impl<T: Config> WithRecorder<T> for EvmCollection<T> {114 impl<T: Config> WithRecorder<T> for EvmCollection<T> {
193 fn recorder(&self) -> &SubstrateRecorder<T> {115 fn recorder(&self) -> &SubstrateRecorder<T> {
194 &self.0116 &self.1
195 }117 }
196 118
197 fn into_recorder(self) -> Rc<SubstrateRecorder<T>> {119 fn into_recorder(self) -> SubstrateRecorder<T> {
198 self.0120 self.1
199 }121 }
200 }122 }
201 123
216 caller: caller,138 caller: caller,
217 sponsor: address,139 sponsor: address,
218 ) -> Result<void> {140 ) -> Result<void> {
219 let mut collection = collection_from_address(self.contract_address(caller).unwrap(), &self.0)?;141 let mut collection = collection_from_address::<T>(self.contract_address(caller).unwrap(), self.1.gas_left())?;
220 check_is_owner(caller, &collection)?;142 check_is_owner(caller, &collection)?;
221 143
222 let sponsor = T::CrossAccountId::from_eth(sponsor);144 let sponsor = T::CrossAccountId::from_eth(sponsor);
223 collection.set_sponsor(sponsor.as_sub().clone());145 collection.set_sponsor(sponsor.as_sub().clone());
224 save_eth(collection)146 collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
147 Ok(())
225 }148 }
226 149
227 fn confirm_sponsorship(&self, caller: caller) -> Result<void> {150 fn confirm_sponsorship(&self, caller: caller) -> Result<void> {
228 let mut collection = collection_from_address(self.contract_address(caller).unwrap(), &self.0)?;151 let mut collection = collection_from_address::<T>(self.contract_address(caller).unwrap(), self.1.gas_left())?;
229 let caller = T::CrossAccountId::from_eth(caller);152 let caller = T::CrossAccountId::from_eth(caller);
230 if !collection.confirm_sponsorship(caller.as_sub()) {153 if !collection.confirm_sponsorship(caller.as_sub()) {
231 return Err(Error::Revert("Caller is not set as sponsor".into()));154 return Err(Error::Revert("Caller is not set as sponsor".into()));
232 }155 }
233 save_eth(collection)156 collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
157 Ok(())
234 }158 }
235 159
236 fn set_limits(160 fn set_limits(
237 &self,161 &self,
238 caller: caller,162 caller: caller,
239 limits_json: string,163 limits_json: string,
240 ) -> Result<void> {164 ) -> Result<void> {
241 let mut collection = collection_from_address(self.contract_address(caller).unwrap(), &self.0)?;165 let mut collection = collection_from_address::<T>(self.contract_address(caller).unwrap(), self.1.gas_left())?;
242 check_is_owner(caller, &collection)?;166 check_is_owner(caller, &collection)?;
243 167
244 let limits = serde_json_core::from_str(limits_json.as_ref())168 let limits = serde_json_core::from_str(limits_json.as_ref())
245 .map_err(|e| Error::Revert(format!("Parse JSON error: {}", e)))?;169 .map_err(|e| Error::Revert(format!("Parse JSON error: {}", e)))?;
246 collection.limits = limits.0;170 collection.limits = limits.0;
247 save_eth(collection)171 collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
172 Ok(())
248 }173 }
249174
250 fn contract_address(&self, _caller: caller) -> Result<address> {175 fn contract_address(&self, _caller: caller) -> Result<address> {
251 Ok(self.0.contract())176 Ok(self.0)
252 }177 }
253 }178 }
254 179
258 183
259 fn collection_from_address<T: Config>(184 fn collection_from_address<T: Config>(
260 collection_address: address,185 collection_address: address,
261 recorder: &Rc<SubstrateRecorder<T>>,186 gas_limit: u64
262 ) -> Result<CollectionHandle<T>> {187 ) -> Result<CollectionHandle<T>> {
263 let collection_id = pallet_common::eth::map_eth_to_id(&collection_address)188 let collection_id = pallet_common::eth::map_eth_to_id(&collection_address)
264 .ok_or(Error::Revert("Contract is not an unique collection".into()))?;189 .ok_or(Error::Revert("Contract is not an unique collection".into()))?;
190 let recorder = <SubstrateRecorder<T>>::new(gas_limit);
265 let collection =191 let collection =
266 pallet_common::CollectionHandle::new_with_recorder(collection_id, recorder.clone())192 pallet_common::CollectionHandle::new_with_recorder(collection_id, recorder)
267 .ok_or(Error::Revert("Create collection handle error".into()))?;193 .ok_or(Error::Revert("Create collection handle error".into()))?;
268 Ok(collection)194 Ok(collection)
269 }195 }
297 return None;223 return None;
298 }224 }
299 225
300 let helpers = EvmCollectionHelper::<T>(Rc::new(SubstrateRecorder::<T>::new(*target, gas_left)));226 let helpers = EvmCollectionHelper::<T>(SubstrateRecorder::<T>::new(gas_left));
301 pallet_evm_coder_substrate::call(*source, helpers, value, input)227 pallet_evm_coder_substrate::call(*source, helpers, value, input)
302 }228 }
303 229
331 return None;257 return None;
332 }258 }
333259
334 let helpers = EvmCollection::<T>(Rc::new(SubstrateRecorder::<T>::new(*target, gas_left)));260 let helpers = EvmCollection::<T>(*target, SubstrateRecorder::<T>::new(gas_left));
335 pallet_evm_coder_substrate::call(*source, helpers, value, input)261 pallet_evm_coder_substrate::call(*source, helpers, value, input)
336 }262 }
337 263
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -22,6 +22,8 @@
 	clippy::unused_unit
 )]
 
+extern crate alloc;
+
 use frame_support::{
 	decl_module, decl_storage, decl_error, decl_event,
 	dispatch::DispatchResult,
@@ -46,7 +48,7 @@
 	CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_call,
 	dispatch::CollectionDispatch,
 };
-pub use eth::evm_collection;
+pub mod eth;
 
 #[cfg(feature = "runtime-benchmarks")]
 mod benchmarking;
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -66,7 +66,6 @@
 		WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, ConstantMultiplier,
 	},
 };
-use unique_runtime_common::dispatch::{CollectionDispatchT, CollectionDispatch};
 use up_data_structs::*;
 // use pallet_contracts::weights::WeightInfo;
 // #[cfg(any(feature = "std", test))]
@@ -79,8 +78,8 @@
 };
 use smallvec::smallvec;
 use codec::{Encode, Decode};
-use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};
-use pallet_unique::evm_collection;
+use pallet_unique::eth::evm_collection;
+use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping};
 use fp_rpc::TransactionStatus;
 use sp_runtime::{
 	traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},
@@ -117,7 +116,15 @@
 //use xcm_executor::traits::MatchesFungible;
 use sp_runtime::traits::CheckedConversion;
 
-use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};
+use unique_runtime_common::{
+	impl_common_runtime_apis,
+	types::*,
+	constants::*,
+	dispatch::{CollectionDispatchT, CollectionDispatch},
+	sponsoring::UniqueSponsorshipHandler,
+	eth_sponsoring::UniqueEthSponsorshipHandler,
+	weights::CommonWeights,
+};
 
 pub const RUNTIME_NAME: &str = "quartz";
 pub const TOKEN_SYMBOL: &str = "QTZ";
@@ -894,6 +901,7 @@
 impl pallet_unique::Config for Runtime {
 	type Event = Event;
 	type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;
+	type CommonWeightInfo = CommonWeights<Self>;
 }
 
 parameter_types! {
@@ -915,11 +923,11 @@
 // }
 
 type EvmSponsorshipHandler = (
-	pallet_unique::UniqueEthSponsorshipHandler<Runtime>,
+	UniqueEthSponsorshipHandler<Runtime>,
 	pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,
 );
 type SponsorshipHandler = (
-	pallet_unique::UniqueSponsorshipHandler<Runtime>,
+	UniqueSponsorshipHandler<Runtime>,
 	//pallet_contract_helpers::ContractSponsorshipHandler<Runtime>,
 	pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,
 );
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -50,6 +50,7 @@
 pub use pallet_balances::Call as BalancesCall;
 pub use pallet_evm::{
 	EnsureAddressTruncated, HashedAddressMapping, Runner, account::CrossAccountId as _, OnMethodCall,
+	Account as EVMAccount, FeeCalculator, GasWeightMapping,
 };
 pub use frame_support::{
 	construct_runtime, match_types,
@@ -84,8 +85,7 @@
 };
 use smallvec::smallvec;
 use codec::{Encode, Decode};
-use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};
-use pallet_unique::evm_collection;
+use pallet_unique::eth::evm_collection;
 use fp_rpc::TransactionStatus;
 use sp_runtime::{
 	traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},
@@ -121,7 +121,15 @@
 //use xcm_executor::traits::MatchesFungible;
 use sp_runtime::traits::CheckedConversion;
 
-use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};
+use unique_runtime_common::{
+	impl_common_runtime_apis,
+	types::*,
+	constants::*,
+	dispatch::{CollectionDispatchT, CollectionDispatch},
+	sponsoring::UniqueSponsorshipHandler,
+	eth_sponsoring::UniqueEthSponsorshipHandler,
+	weights::CommonWeights,
+};
 
 pub const RUNTIME_NAME: &str = "unique";
 pub const TOKEN_SYMBOL: &str = "UNQ";