git.delta.rocks / unique-network / refs/commits / 3429f32311d9

difftreelog

fix PR comments

Trubnikov Sergey2023-05-17parent: #ab5c2b5.patch.diff
in: master

8 files changed

modifiedpallets/balances-adapter/src/common.rsdiffbeforeafterboth
88
9pub struct CommonWeights<T: Config>(PhantomData<T>);9pub struct CommonWeights<T: Config>(PhantomData<T>);
10
11// All implementations with `Weight::default` used in methods that return error `UnsupportedOperation`.
10impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {12impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
11 fn create_multiple_items(_amount: &[up_data_structs::CreateItemData]) -> Weight {13 fn create_multiple_items(_amount: &[up_data_structs::CreateItemData]) -> Weight {
12 Weight::default()14 Weight::default()
modifiedpallets/balances-adapter/src/erc.rsdiffbeforeafterboth
1use crate::{Config, NativeFungibleHandle, Pallet, SelfWeightOf};1use crate::{Config, NativeFungibleHandle, Pallet, SelfWeightOf};
2use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};2use evm_coder::{abi::AbiType, generate_stubgen, solidity_interface, types::*};
3use frame_support::traits::{Currency, ExistenceRequirement};3use frame_support::traits::{Currency};
4use pallet_balances::WeightInfo;4use pallet_balances::WeightInfo;
5use pallet_common::{5use pallet_common::{
6 consume_store_reads,
7 erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},6 erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},
8 eth::CrossAddress,7 eth::CrossAddress,
9};8};
14};13};
15use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};14use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
16use sp_core::{U256, Get};15use sp_core::{U256, Get};
17use sp_std::vec::Vec;
1816
19frontier_contract! {17frontier_contract! {
20 macro_rules! NativeFungibleHandle_result {...}18 macro_rules! NativeFungibleHandle_result {...}
21 impl<T: Config> Contract for NativeFungibleHandle<T> {...}19 impl<T: Config> Contract for NativeFungibleHandle<T> {...}
22}20}
23
24#[derive(ToLog)]
25pub enum ERC20Events {
26 Transfer {
27 #[indexed]
28 from: Address,
29 #[indexed]
30 to: Address,
31 value: U256,
32 },
33}
3421
35#[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)]22#[solidity_interface(name = ERC20, enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)]
36impl<T: Config> NativeFungibleHandle<T> {23impl<T: Config> NativeFungibleHandle<T> {
37 fn allowance(&self, _owner: Address, _spender: Address) -> Result<U256> {24 fn allowance(&self, _owner: Address, _spender: Address) -> Result<U256> {
38 Ok(U256::zero())25 Ok(U256::zero())
39 }26 }
4027
41 // #[weight(<SelfWeightOf<T>>::approve())]
42 fn approve(&mut self, _caller: Caller, _spender: Address, _amount: U256) -> Result<bool> {28 fn approve(&mut self, _caller: Caller, _spender: Address, _amount: U256) -> Result<bool> {
43 // self.consume_store_reads(1)?;
44 Err("Approve not supported".into())29 Err("Approve not supported".into())
45 }30 }
4631
47 fn balance_of(&self, owner: Address) -> Result<U256> {32 fn balance_of(&self, owner: Address) -> Result<U256> {
48 consume_store_reads(self, 1)?;33 self.consume_store_reads(1)?;
49 let owner = T::CrossAccountId::from_eth(owner);34 let owner = T::CrossAccountId::from_eth(owner);
50 let balance = <T as Config>::Currency::free_balance(owner.as_sub());35 let balance = <T as Config>::Currency::free_balance(owner.as_sub());
51 Ok(balance.into())36 Ok(balance.into())
64 }49 }
6550
66 fn total_supply(&self) -> Result<U256> {51 fn total_supply(&self) -> Result<U256> {
67 consume_store_reads(self, 1)?;52 self.consume_store_reads(1)?;
68 let total = <T as Config>::Currency::total_issuance();53 let total = <T as Config>::Currency::total_issuance();
69 Ok(total.into())54 Ok(total.into())
70 }55 }
111 T::AccountId: From<[u8; 32]>,96 T::AccountId: From<[u8; 32]>,
112{97{
113 fn balance_of_cross(&self, owner: CrossAddress) -> Result<U256> {98 fn balance_of_cross(&self, owner: CrossAddress) -> Result<U256> {
114 consume_store_reads(self, 1)?;99 self.consume_store_reads(1)?;
115 let owner = owner.into_sub_cross_account::<T>()?;100 let owner = owner.into_sub_cross_account::<T>()?;
116 let balance = <T as Config>::Currency::free_balance(owner.as_sub());101 let balance = <T as Config>::Currency::free_balance(owner.as_sub());
117 Ok(balance.into())102 Ok(balance.into())
122 let caller = T::CrossAccountId::from_eth(caller);107 let caller = T::CrossAccountId::from_eth(caller);
123 let to = to.into_sub_cross_account::<T>()?;108 let to = to.into_sub_cross_account::<T>()?;
124 let amount = amount.try_into().map_err(|_| "amount overflow")?;109 let amount = amount.try_into().map_err(|_| "amount overflow")?;
125 // let budget = self110 let budget = self
126 // .recorder111 .recorder()
127 // .weight_calls_budget(<StructureWeight<T>>::find_parent());112 .weight_calls_budget(<StructureWeight<T>>::find_parent());
128113
129 // <Pallet<T>>::transfer(self, &caller, &to, amount, &budget).map_err(|_| "transfer error")?;
130 <T as Config>::Currency::transfer(114 <Pallet<T>>::transfer(self, &caller, &to, amount, &budget)
131 caller.as_sub(),
132 to.as_sub(),
133 amount,
134 ExistenceRequirement::KeepAlive,
135 )
136 .map_err(dispatch_to_evm::<T>)?;115 .map_err(|e| dispatch_to_evm::<T>(e.error))?;
116
137 Ok(true)117 Ok(true)
138 }118 }
154 return Err("no permission".into());134 return Err("no permission".into());
155 }135 }
156136
157 // let budget = self137 let budget = self
158 // .recorder138 .recorder()
159 // .weight_calls_budget(<StructureWeight<T>>::find_parent());139 .weight_calls_budget(<StructureWeight<T>>::find_parent());
160140
161 // <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)
162 // .map_err(dispatch_to_evm::<T>)?;
163 <T as Config>::Currency::transfer(141 <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)
164 caller.as_sub(),
165 to.as_sub(),
166 amount,
167 ExistenceRequirement::KeepAlive,
168 )
169 .map_err(dispatch_to_evm::<T>)?;142 .map_err(|e| dispatch_to_evm::<T>(e.error))?;
143
170 Ok(true)144 Ok(true)
171 }145 }
modifiedpallets/balances-adapter/src/lib.rsdiffbeforeafterboth
1// #![doc = include_str!("../README.md")]
2#![cfg_attr(not(feature = "std"), no_std)]1#![cfg_attr(not(feature = "std"), no_std)]
32
4extern crate alloc;3extern crate alloc;
1312
14pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;13pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;
15
16const NATIVE_FUNGIBLE_COLLECTION_ID: up_data_structs::CollectionId =
17 up_data_structs::CollectionId(0);
1814
19/// Handle for native fungible collection15/// Handle for native fungible collection
20pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);16pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);
58 };54 };
59 use pallet_balances::WeightInfo;55 use pallet_balances::WeightInfo;
60 use pallet_common::{erc::CrossAccountId, Error as CommonError, Pallet as PalletCommon};56 use pallet_common::{
57 erc::CrossAccountId, Error as CommonError, Pallet as PalletCommon,
58 NATIVE_FUNGIBLE_COLLECTION_ID,
59 };
61 use pallet_structure::Pallet as PalletStructure;60 use pallet_structure::Pallet as PalletStructure;
62 use sp_core::U256;61 use sp_core::U256;
95 /// Checks if a non-owner has (enough) allowance from the owner to perform operations on the tokens.94 /// Checks if a non-owner has (enough) allowance from the owner to perform operations on the tokens.
96 /// Returns the expected remaining allowance - it should be set manually if the transaction proceeds.95 /// Returns the expected remaining allowance - it should be set manually if the transaction proceeds.
97 ///96 ///
98 /// - `collection`: Collection that contains the token.
99 /// - `spender`: CrossAccountId who has the allowance rights.97 /// - `spender`: CrossAccountId who has the allowance rights.
100 /// - `from`: The owner of the tokens who sets the allowance.98 /// - `from`: The owner of the tokens who sets the allowance.
101 /// - `amount`: Amount of tokens by which the allowance sholud be reduced.99 /// - `nesting_budget`: Limit for searching parents in-depth to check ownership.
102 fn check_allowed(100 fn check_allowed(
103 spender: &T::CrossAccountId,101 spender: &T::CrossAccountId,
104 from: &T::CrossAccountId,102 from: &T::CrossAccountId,
127 /// Transfers the specified amount of tokens. Will check that125 /// Transfers the specified amount of tokens. Will check that
128 /// the transfer is allowed for the token.126 /// the transfer is allowed for the token.
129 ///127 ///
128 /// - `collection`: Collection that contains the token.
130 /// - `from`: Owner of tokens to transfer.129 /// - `from`: Owner of tokens to transfer.
131 /// - `to`: Recepient of transfered tokens.130 /// - `to`: Recepient of transfered tokens.
132 /// - `amount`: Amount of tokens to transfer.131 /// - `amount`: Amount of tokens to transfer.
133 /// - `collection`: Collection that contains the token132 /// - `nesting_budget`: Limit for searching parents in-depth to check ownership.
134 pub fn transfer(133 pub fn transfer(
135 _collection: &NativeFungibleHandle<T>,134 _collection: &NativeFungibleHandle<T>,
136 from: &T::CrossAccountId,135 from: &T::CrossAccountId,
147 amount146 amount
148 .try_into()147 .try_into()
149 .map_err(|_| sp_runtime::ArithmeticError::Overflow)?,148 .map_err(|_| sp_runtime::ArithmeticError::Overflow)?,
150 ExistenceRequirement::KeepAlive,149 ExistenceRequirement::AllowDeath,
151 )?;150 )?;
152151
153 <PalletStructure<T>>::nest_if_sent_to_token(152 <PalletStructure<T>>::nest_if_sent_to_token(
175 })174 })
176 }175 }
177176
177 /// Transfer NFT token from one account to another.
178 ///
179 /// Same as the [`Self::transfer`] but spender doesn't needs to be the owner of the token.
180 /// The owner should set allowance for the spender to transfer token.
181 ///
182 /// - `collection`: Collection that contains the token.
183 /// - `spender`: Account that spend the money.
184 /// - `from`: Owner of tokens to transfer.
185 /// - `to`: Recepient of transfered tokens.
186 /// - `amount`: Amount of tokens to transfer.
187 /// - `nesting_budget`: Limit for searching parents in-depth to check ownership.
178 pub fn transfer_from(188 pub fn transfer_from(
179 collection: &NativeFungibleHandle<T>,189 collection: &NativeFungibleHandle<T>,
180 spender: &T::CrossAccountId,190 spender: &T::CrossAccountId,
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
77 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult>;77 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult>;
78}78}
79
80impl CommonEvmHandler for () {
81 const CODE: &'static [u8] = &[];
82
83 fn call(self, _handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {
84 None
85 }
86}
8779
88/// @title A contract that allows you to work with collections.80/// @title A contract that allows you to work with collections.
89#[solidity_interface(name = Collection, enum(derive(PreDispatch)), enum_attr(weight))]81#[solidity_interface(name = Collection, enum(derive(PreDispatch)), enum_attr(weight))]
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
68 dispatch::Pays,68 dispatch::Pays,
69 transactional, fail,69 transactional, fail,
70};70};
71use pallet_evm::GasWeightMapping;
72use up_data_structs::{71use up_data_structs::{
73 AccessMode, COLLECTION_NUMBER_LIMIT, Collection, RpcCollection, CollectionFlags,72 AccessMode, COLLECTION_NUMBER_LIMIT, Collection, RpcCollection, CollectionFlags,
74 RpcCollectionFlags, CollectionId, CreateItemData, MAX_TOKEN_PREFIX_LENGTH,73 RpcCollectionFlags, CollectionId, CreateItemData, MAX_TOKEN_PREFIX_LENGTH,
101/// Collection handle contains information about collection data and id.100/// Collection handle contains information about collection data and id.
102/// Also provides functionality to count consumed gas.101/// Also provides functionality to count consumed gas.
103///102///
104/// CollectionHandle is used as a generic wrapper for collections of all types.103/// CollectionHandle is used as a generic wrapper for collections of all types (except native fungible).
105/// It allows to perform common operations and queries on any collection type,104/// It allows to perform common operations and queries on any collection type,
106/// both completely general for all, as well as their respective implementations of [`CommonCollectionOperations`].105/// both completely general for all, as well as their respective implementations of [`CommonCollectionOperations`].
107#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]106#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]
153 &self,152 &self,
154 reads: u64,153 reads: u64,
155 ) -> pallet_evm_coder_substrate::execution::Result<()> {154 ) -> pallet_evm_coder_substrate::execution::Result<()> {
156 consume_store_reads(self.recorder(), reads)155 self.recorder().consume_store_reads(reads)
157 }156 }
158157
159 /// Consume gas for writing.158 /// Consume gas for writing.
160 pub fn consume_store_writes(159 pub fn consume_store_writes(
161 &self,160 &self,
162 writes: u64,161 writes: u64,
163 ) -> pallet_evm_coder_substrate::execution::Result<()> {162 ) -> pallet_evm_coder_substrate::execution::Result<()> {
164 consume_store_writes(self.recorder(), writes)163 self.recorder().consume_store_writes(writes)
165 }164 }
166165
167 /// Consume gas for reading and writing.166 /// Consume gas for reading and writing.
170 reads: u64,169 reads: u64,
171 writes: u64,170 writes: u64,
172 ) -> pallet_evm_coder_substrate::execution::Result<()> {171 ) -> pallet_evm_coder_substrate::execution::Result<()> {
173 consume_store_reads_and_writes(self.recorder(), reads, writes)172 self.recorder()
173 .consume_store_reads_and_writes(reads, writes)
174 }174 }
175175
176 /// Save collection to storage.176 /// Save collection to storage.
441441
442 const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);442 const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
443 /// Collection id for native fungible collction.443 /// Collection id for native fungible collction.
444 pub const NATIVE_FINGIBLE_COLLECTION_ID: CollectionId = CollectionId(0);444 pub const NATIVE_FUNGIBLE_COLLECTION_ID: CollectionId = CollectionId(0);
445445
446 #[pallet::pallet]446 #[pallet::pallet]
447 #[pallet::storage_version(STORAGE_VERSION)]447 #[pallet::storage_version(STORAGE_VERSION)]
2324 }2324 }
2325}2325}
2326
2327/// Consume gas for reading.
2328pub fn consume_store_reads<T: Config>(
2329 recorder: &SubstrateRecorder<T>,
2330 reads: u64,
2331) -> pallet_evm_coder_substrate::execution::Result<()> {
2332 recorder.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
2333 <T as frame_system::Config>::DbWeight::get()
2334 .read
2335 .saturating_mul(reads),
2336 // TODO: measure proof
2337 0,
2338 )))
2339}
2340
2341/// Consume gas for writing.
2342pub fn consume_store_writes<T: Config>(
2343 recorder: &SubstrateRecorder<T>,
2344 writes: u64,
2345) -> pallet_evm_coder_substrate::execution::Result<()> {
2346 recorder.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
2347 <T as frame_system::Config>::DbWeight::get()
2348 .write
2349 .saturating_mul(writes),
2350 // TODO: measure proof
2351 0,
2352 )))
2353}
2354
2355/// Consume gas for reading and writing.
2356pub fn consume_store_reads_and_writes<T: Config>(
2357 recorder: &SubstrateRecorder<T>,
2358 reads: u64,
2359 writes: u64,
2360) -> pallet_evm_coder_substrate::execution::Result<()> {
2361 let weight = <T as frame_system::Config>::DbWeight::get();
2362 let reads = weight.read.saturating_mul(reads);
2363 let writes = weight.read.saturating_mul(writes);
2364 recorder.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
2365 reads.saturating_add(writes),
2366 // TODO: measure proof
2367 0,
2368 )))
2369}
23702326
modifiedpallets/evm-coder-substrate/src/lib.rsdiffbeforeafterboth
37 ExitError, ExitRevert, ExitSucceed, GasWeightMapping, PrecompileFailure, PrecompileOutput,37 ExitError, ExitRevert, ExitSucceed, GasWeightMapping, PrecompileFailure, PrecompileOutput,
38 PrecompileResult, PrecompileHandle,38 PrecompileResult, PrecompileHandle,
39};39};
40use sp_core::H160;40use sp_core::{Get, H160};
41// #[cfg(feature = "runtime-benchmarks")]41// #[cfg(feature = "runtime-benchmarks")]
42// pub mod benchmarking;42// pub mod benchmarking;
43pub mod execution;43pub mod execution;
205 })205 })
206 }206 }
207
208 /// Consume gas for reading.
209 pub fn consume_store_reads(&self, reads: u64) -> execution::Result<()> {
210 self.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
211 <T as frame_system::Config>::DbWeight::get()
212 .read
213 .saturating_mul(reads),
214 // TODO: measure proof
215 0,
216 )))
217 }
218
219 /// Consume gas for writing.
220 pub fn consume_store_writes(&self, writes: u64) -> execution::Result<()> {
221 self.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
222 <T as frame_system::Config>::DbWeight::get()
223 .write
224 .saturating_mul(writes),
225 // TODO: measure proof
226 0,
227 )))
228 }
229
230 /// Consume gas for reading and writing.
231 pub fn consume_store_reads_and_writes(&self, reads: u64, writes: u64) -> execution::Result<()> {
232 let weight = <T as frame_system::Config>::DbWeight::get();
233 let reads = weight.read.saturating_mul(reads);
234 let writes = weight.read.saturating_mul(writes);
235 self.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
236 reads.saturating_add(writes),
237 // TODO: measure proof
238 0,
239 )))
240 }
207}241}
208242
209pub fn dispatch_to_evm<T: Config>(err: DispatchError) -> execution::Error {243pub fn dispatch_to_evm<T: Config>(err: DispatchError) -> execution::Error {
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
440 collection_id: CollectionId,440 collection_id: CollectionId,
441 address: T::CrossAccountId,441 address: T::CrossAccountId,
442 ) -> DispatchResult {442 ) -> DispatchResult {
443 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {443 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
444 fail!(<pallet_common::Error<T>>::UnsupportedOperation);444 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
445 }445 }
446446
471 collection_id: CollectionId,471 collection_id: CollectionId,
472 address: T::CrossAccountId,472 address: T::CrossAccountId,
473 ) -> DispatchResult {473 ) -> DispatchResult {
474 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {474 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
475 fail!(<pallet_common::Error<T>>::UnsupportedOperation);475 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
476 }476 }
477477
501 collection_id: CollectionId,501 collection_id: CollectionId,
502 new_owner: T::AccountId,502 new_owner: T::AccountId,
503 ) -> DispatchResult {503 ) -> DispatchResult {
504 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {504 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
505 fail!(<pallet_common::Error<T>>::UnsupportedOperation);505 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
506 }506 }
507 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);507 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
533 collection_id: CollectionId,533 collection_id: CollectionId,
534 new_admin_id: T::CrossAccountId,534 new_admin_id: T::CrossAccountId,
535 ) -> DispatchResult {535 ) -> DispatchResult {
536 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {536 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
537 fail!(<pallet_common::Error<T>>::UnsupportedOperation);537 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
538 }538 }
539 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);539 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
562 collection_id: CollectionId,562 collection_id: CollectionId,
563 account_id: T::CrossAccountId,563 account_id: T::CrossAccountId,
564 ) -> DispatchResult {564 ) -> DispatchResult {
565 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {565 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
566 fail!(<pallet_common::Error<T>>::UnsupportedOperation);566 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
567 }567 }
568 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);568 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
590 collection_id: CollectionId,590 collection_id: CollectionId,
591 new_sponsor: T::AccountId,591 new_sponsor: T::AccountId,
592 ) -> DispatchResult {592 ) -> DispatchResult {
593 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {593 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
594 fail!(<pallet_common::Error<T>>::UnsupportedOperation);594 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
595 }595 }
596 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);596 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
617 origin: OriginFor<T>,617 origin: OriginFor<T>,
618 collection_id: CollectionId,618 collection_id: CollectionId,
619 ) -> DispatchResult {619 ) -> DispatchResult {
620 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {620 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
621 fail!(<pallet_common::Error<T>>::UnsupportedOperation);621 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
622 }622 }
623 let sender = ensure_signed(origin)?;623 let sender = ensure_signed(origin)?;
640 origin: OriginFor<T>,640 origin: OriginFor<T>,
641 collection_id: CollectionId,641 collection_id: CollectionId,
642 ) -> DispatchResult {642 ) -> DispatchResult {
643 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {643 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
644 fail!(<pallet_common::Error<T>>::UnsupportedOperation);644 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
645 }645 }
646 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);646 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
920 collection_id: CollectionId,920 collection_id: CollectionId,
921 value: bool,921 value: bool,
922 ) -> DispatchResult {922 ) -> DispatchResult {
923 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {923 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
924 fail!(<pallet_common::Error<T>>::UnsupportedOperation);924 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
925 }925 }
926 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);926 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
1175 collection_id: CollectionId,1175 collection_id: CollectionId,
1176 new_limit: CollectionLimits,1176 new_limit: CollectionLimits,
1177 ) -> DispatchResult {1177 ) -> DispatchResult {
1178 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {1178 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
1179 fail!(<pallet_common::Error<T>>::UnsupportedOperation);1179 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
1180 }1180 }
1181 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1181 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
1202 collection_id: CollectionId,1202 collection_id: CollectionId,
1203 new_permission: CollectionPermissions,1203 new_permission: CollectionPermissions,
1204 ) -> DispatchResult {1204 ) -> DispatchResult {
1205 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {1205 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
1206 fail!(<pallet_common::Error<T>>::UnsupportedOperation);1206 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
1207 }1207 }
1208 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1208 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
1273 origin: OriginFor<T>,1273 origin: OriginFor<T>,
1274 collection_id: CollectionId,1274 collection_id: CollectionId,
1275 ) -> DispatchResult {1275 ) -> DispatchResult {
1276 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {1276 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
1277 fail!(<pallet_common::Error<T>>::UnsupportedOperation);1277 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
1278 }1278 }
1279 ensure_root(origin)?;1279 ensure_root(origin)?;
modifiedruntime/common/dispatch.rsdiffbeforeafterboth
100 }100 }
101101
102 fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult {102 fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult {
103 if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {103 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
104 fail!(<pallet_common::Error<T>>::UnsupportedOperation);104 fail!(<pallet_common::Error<T>>::UnsupportedOperation);
105 }105 }
106106
107 let collection = <CollectionHandle<T>>::try_get(collection_id)?;107 let collection = <CollectionHandle<T>>::try_get(collection_id)?;
108 collection.check_is_internal()?;
109108
110 match collection.mode {109 match collection.mode {
111 CollectionMode::ReFungible => {110 CollectionMode::ReFungible => {
122 }121 }
123122
124 fn dispatch(collection_id: CollectionId) -> Result<Self, DispatchError> {123 fn dispatch(collection_id: CollectionId) -> Result<Self, DispatchError> {
125 if collection_id == CollectionId(0) {124 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
126 return Ok(Self::NativeFungible(NativeFungibleHandle::new()));125 return Ok(Self::NativeFungible(NativeFungibleHandle::new()));
127 }126 }
128127
188 }187 }
189 fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {188 fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {
190 if let Some(collection_id) = map_eth_to_id(&handle.code_address()) {189 if let Some(collection_id) = map_eth_to_id(&handle.code_address()) {
191 if collection_id == CollectionId(0) {190 if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
192 <NativeFungibleHandle<T>>::new().call(handle)191 <NativeFungibleHandle<T>>::new().call(handle)
193 } else {192 } else {
194 let collection = <CollectionHandle<T>>::new_with_gas_limit(193 let collection = <CollectionHandle<T>>::new_with_gas_limit(