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
6818name = "pallet-unique"6818name = "pallet-unique"
6819version = "0.1.0"6819version = "0.1.0"
6820dependencies = [6820dependencies = [
6821 "ethereum",
6822 "evm-coder",
6821 "frame-benchmarking",6823 "frame-benchmarking",
6822 "frame-support",6824 "frame-support",
6823 "frame-system",6825 "frame-system",
6824 "pallet-common",6826 "pallet-common",
6825 "pallet-evm",6827 "pallet-evm",
6828 "pallet-evm-coder-substrate",
6829 "pallet-nonfungible",
6826 "parity-scale-codec 3.1.2",6830 "parity-scale-codec 3.1.2",
6827 "scale-info",6831 "scale-info",
6828 "serde",6832 "serde",
modifiedpallets/unique/Cargo.tomldiffbeforeafterboth
33limit-testing = ["up-data-structs/limit-testing"]33limit-testing = ["up-data-structs/limit-testing"]
3434
35################################################################################35################################################################################
36# Substrate Dependencies36# Standart Dependencies
37
38[dependencies.serde]
39default-features = false
40features = ['derive']
41version = '1.0.130'
42
43[dependencies.serde-json-core]
44default-features = false
45version = "0.4"
46
47[dependencies.ethereum]
48version = "0.12.0"
49default-features = false
50
51################################################################################
52# Substrate Dependencies
3753
38[dependencies.codec]54[dependencies.codec]
39default-features = false55default-features = false
67# git = "https://github.com/paritytech/substrate"83# git = "https://github.com/paritytech/substrate"
68# branch = "polkadot-v0.9.21"84# branch = "polkadot-v0.9.21"
69
70[dependencies.serde]
71default-features = false
72features = ['derive']
73version = '1.0.130'
74
75[dependencies.serde-json-core]
76default-features = false
77version = "0.4"
7885
79[dependencies.sp-runtime]86[dependencies.sp-runtime]
80default-features = false87default-features = false
101] }107] }
102pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.21-logs" }108pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.21-logs" }
103pallet-common = { default-features = false, path = "../common" }109pallet-common = { default-features = false, path = "../common" }
110evm-coder = { default-features = false, path = '../../crates/evm-coder' }
111pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
112pallet-nonfungible = { default-features = false, path = '../../pallets/nonfungible' }
104113
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
22 clippy::unused_unit22 clippy::unused_unit
23)]23)]
24
25extern crate alloc;
2426
25use frame_support::{27use frame_support::{
26 decl_module, decl_storage, decl_error, decl_event,28 decl_module, decl_storage, decl_error, decl_event,
46 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_call,48 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_call,
47 dispatch::CollectionDispatch,49 dispatch::CollectionDispatch,
48};50};
49pub use eth::evm_collection;51pub mod eth;
5052
51#[cfg(feature = "runtime-benchmarks")]53#[cfg(feature = "runtime-benchmarks")]
52mod benchmarking;54mod benchmarking;
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
66 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, ConstantMultiplier,66 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, ConstantMultiplier,
67 },67 },
68};68};
69use unique_runtime_common::dispatch::{CollectionDispatchT, CollectionDispatch};
70use up_data_structs::*;69use up_data_structs::*;
71// use pallet_contracts::weights::WeightInfo;70// use pallet_contracts::weights::WeightInfo;
72// #[cfg(any(feature = "std", test))]71// #[cfg(any(feature = "std", test))]
79};78};
80use smallvec::smallvec;79use smallvec::smallvec;
81use codec::{Encode, Decode};80use codec::{Encode, Decode};
81use pallet_unique::eth::evm_collection;
82use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};82use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping};
83use pallet_unique::evm_collection;
84use fp_rpc::TransactionStatus;83use fp_rpc::TransactionStatus;
85use sp_runtime::{84use sp_runtime::{
86 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},85 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},
120use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};119use unique_runtime_common::{
120 impl_common_runtime_apis,
121 types::*,
122 constants::*,
123 dispatch::{CollectionDispatchT, CollectionDispatch},
124 sponsoring::UniqueSponsorshipHandler,
125 eth_sponsoring::UniqueEthSponsorshipHandler,
126 weights::CommonWeights,
127};
121128
122pub const RUNTIME_NAME: &str = "quartz";129pub const RUNTIME_NAME: &str = "quartz";
894impl pallet_unique::Config for Runtime {901impl pallet_unique::Config for Runtime {
895 type Event = Event;902 type Event = Event;
896 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;903 type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;
904 type CommonWeightInfo = CommonWeights<Self>;
897}905}
898906
899parameter_types! {907parameter_types! {
915// }923// }
916924
917type EvmSponsorshipHandler = (925type EvmSponsorshipHandler = (
918 pallet_unique::UniqueEthSponsorshipHandler<Runtime>,926 UniqueEthSponsorshipHandler<Runtime>,
919 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,927 pallet_evm_contract_helpers::HelpersContractSponsoring<Runtime>,
920);928);
921type SponsorshipHandler = (929type SponsorshipHandler = (
922 pallet_unique::UniqueSponsorshipHandler<Runtime>,930 UniqueSponsorshipHandler<Runtime>,
923 //pallet_contract_helpers::ContractSponsorshipHandler<Runtime>,931 //pallet_contract_helpers::ContractSponsorshipHandler<Runtime>,
924 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,932 pallet_evm_transaction_payment::BridgeSponsorshipHandler<Runtime>,
925);933);
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
50pub use pallet_balances::Call as BalancesCall;50pub use pallet_balances::Call as BalancesCall;
51pub use pallet_evm::{51pub use pallet_evm::{
52 EnsureAddressTruncated, HashedAddressMapping, Runner, account::CrossAccountId as _, OnMethodCall,52 EnsureAddressTruncated, HashedAddressMapping, Runner, account::CrossAccountId as _, OnMethodCall,
53 Account as EVMAccount, FeeCalculator, GasWeightMapping,
53};54};
54pub use frame_support::{55pub use frame_support::{
55 construct_runtime, match_types,56 construct_runtime, match_types,
84};85};
85use smallvec::smallvec;86use smallvec::smallvec;
86use codec::{Encode, Decode};87use codec::{Encode, Decode};
87use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};
88use pallet_unique::evm_collection;88use pallet_unique::eth::evm_collection;
89use fp_rpc::TransactionStatus;89use fp_rpc::TransactionStatus;
90use sp_runtime::{90use sp_runtime::{
91 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},91 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},
124use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};124use unique_runtime_common::{
125 impl_common_runtime_apis,
126 types::*,
127 constants::*,
128 dispatch::{CollectionDispatchT, CollectionDispatch},
129 sponsoring::UniqueSponsorshipHandler,
130 eth_sponsoring::UniqueEthSponsorshipHandler,
131 weights::CommonWeights,
132};
125133
126pub const RUNTIME_NAME: &str = "unique";134pub const RUNTIME_NAME: &str = "unique";