difftreelog
fix PR comments
in: master
8 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth1use alloc::{vec, vec::Vec};2use core::marker::PhantomData;3use crate::{Config, NativeFungibleHandle, Pallet};4use frame_support::{fail, traits::Currency, weights::Weight};5use pallet_balances::{weights::SubstrateWeight as BalancesWeight, WeightInfo};6use pallet_common::{erc::CrossAccountId, CommonCollectionOperations, CommonWeightInfo};7use up_data_structs::TokenId;89pub struct CommonWeights<T: Config>(PhantomData<T>);10impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {11 fn create_multiple_items(_amount: &[up_data_structs::CreateItemData]) -> Weight {12 Weight::default()13 }1415 fn create_multiple_items_ex(16 _cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,17 ) -> Weight {18 Weight::default()19 }2021 fn burn_item() -> Weight {22 Weight::default()23 }2425 fn set_collection_properties(_amount: u32) -> Weight {26 Weight::default()27 }2829 fn delete_collection_properties(_amount: u32) -> Weight {30 Weight::default()31 }3233 fn set_token_properties(_amount: u32) -> Weight {34 Weight::default()35 }3637 fn delete_token_properties(_amount: u32) -> Weight {38 Weight::default()39 }4041 fn set_token_property_permissions(_amount: u32) -> Weight {42 Weight::default()43 }4445 fn transfer() -> Weight {46 <BalancesWeight<T> as WeightInfo>::transfer()47 }4849 fn approve() -> Weight {50 Weight::default()51 }5253 fn approve_from() -> Weight {54 Weight::default()55 }5657 fn transfer_from() -> Weight {58 <BalancesWeight<T> as WeightInfo>::transfer()59 }6061 fn burn_from() -> Weight {62 Weight::default()63 }6465 fn burn_recursively_self_raw() -> Weight {66 Weight::default()67 }6869 fn burn_recursively_breadth_raw(_amount: u32) -> Weight {70 Weight::default()71 }7273 fn token_owner() -> Weight {74 Weight::default()75 }7677 fn set_allowance_for_all() -> Weight {78 Weight::default()79 }8081 fn force_repair_item() -> Weight {82 Weight::default()83 }84}8586/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallete87/// methods and adds weight info.88impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {89 fn create_item(90 &self,91 _sender: <T>::CrossAccountId,92 _to: <T>::CrossAccountId,93 _data: up_data_structs::CreateItemData,94 _nesting_budget: &dyn up_data_structs::budget::Budget,95 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {96 fail!(<pallet_common::Error<T>>::UnsupportedOperation);97 }9899 fn create_multiple_items(100 &self,101 _sender: <T>::CrossAccountId,102 _to: <T>::CrossAccountId,103 _data: Vec<up_data_structs::CreateItemData>,104 _nesting_budget: &dyn up_data_structs::budget::Budget,105 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {106 fail!(<pallet_common::Error<T>>::UnsupportedOperation);107 }108109 fn create_multiple_items_ex(110 &self,111 _sender: <T>::CrossAccountId,112 _data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,113 _nesting_budget: &dyn up_data_structs::budget::Budget,114 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {115 fail!(<pallet_common::Error<T>>::UnsupportedOperation);116 }117118 fn burn_item(119 &self,120 _sender: <T>::CrossAccountId,121 _token: TokenId,122 _amount: u128,123 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {124 fail!(<pallet_common::Error<T>>::UnsupportedOperation);125 }126127 fn burn_item_recursively(128 &self,129 _sender: <T>::CrossAccountId,130 _token: TokenId,131 _self_budget: &dyn up_data_structs::budget::Budget,132 _breadth_budget: &dyn up_data_structs::budget::Budget,133 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {134 fail!(<pallet_common::Error<T>>::UnsupportedOperation);135 }136137 fn set_collection_properties(138 &self,139 _sender: <T>::CrossAccountId,140 _properties: Vec<up_data_structs::Property>,141 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {142 fail!(<pallet_common::Error<T>>::UnsupportedOperation);143 }144145 fn delete_collection_properties(146 &self,147 _sender: &<T>::CrossAccountId,148 _property_keys: Vec<up_data_structs::PropertyKey>,149 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {150 fail!(<pallet_common::Error<T>>::UnsupportedOperation);151 }152153 fn set_token_properties(154 &self,155 _sender: <T>::CrossAccountId,156 _token_id: TokenId,157 _properties: Vec<up_data_structs::Property>,158 _budget: &dyn up_data_structs::budget::Budget,159 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {160 fail!(<pallet_common::Error<T>>::UnsupportedOperation);161 }162163 fn delete_token_properties(164 &self,165 _sender: <T>::CrossAccountId,166 _token_id: TokenId,167 _property_keys: Vec<up_data_structs::PropertyKey>,168 _budget: &dyn up_data_structs::budget::Budget,169 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {170 fail!(<pallet_common::Error<T>>::UnsupportedOperation);171 }172173 fn set_token_property_permissions(174 &self,175 _sender: &<T>::CrossAccountId,176 _property_permissions: Vec<up_data_structs::PropertyKeyPermission>,177 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {178 fail!(<pallet_common::Error<T>>::UnsupportedOperation);179 }180181 fn transfer(182 &self,183 sender: <T>::CrossAccountId,184 to: <T>::CrossAccountId,185 _token: TokenId,186 amount: u128,187 budget: &dyn up_data_structs::budget::Budget,188 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {189 <Pallet<T>>::transfer(self, &sender, &to, amount, budget)190 }191192 fn approve(193 &self,194 _sender: <T>::CrossAccountId,195 _spender: <T>::CrossAccountId,196 _token: TokenId,197 _amount: u128,198 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {199 fail!(<pallet_common::Error<T>>::UnsupportedOperation);200 }201202 fn approve_from(203 &self,204 _sender: <T>::CrossAccountId,205 _from: <T>::CrossAccountId,206 _to: <T>::CrossAccountId,207 _token: TokenId,208 _amount: u128,209 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {210 fail!(<pallet_common::Error<T>>::UnsupportedOperation);211 }212213 fn transfer_from(214 &self,215 sender: <T>::CrossAccountId,216 from: <T>::CrossAccountId,217 to: <T>::CrossAccountId,218 _token: TokenId,219 amount: u128,220 budget: &dyn up_data_structs::budget::Budget,221 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {222 <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, budget)223 }224225 fn burn_from(226 &self,227 _sender: <T>::CrossAccountId,228 _from: <T>::CrossAccountId,229 _token: TokenId,230 _amount: u128,231 _budget: &dyn up_data_structs::budget::Budget,232 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {233 fail!(<pallet_common::Error<T>>::UnsupportedOperation);234 }235236 fn check_nesting(237 &self,238 _sender: <T>::CrossAccountId,239 _from: (up_data_structs::CollectionId, TokenId),240 _under: TokenId,241 _budget: &dyn up_data_structs::budget::Budget,242 ) -> frame_support::sp_runtime::DispatchResult {243 fail!(<pallet_common::Error<T>>::UnsupportedOperation);244 }245246 fn nest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}247248 fn unnest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}249250 fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<TokenId> {251 let balance = <T as Config>::Currency::total_balance(account.as_sub());252 let balance: u128 = balance.into();253 if balance != 0 {254 vec![TokenId::default()]255 } else {256 vec![]257 }258 }259260 fn collection_tokens(&self) -> Vec<TokenId> {261 vec![TokenId::default()]262 }263264 fn token_exists(&self, token: TokenId) -> bool {265 token == TokenId::default()266 }267268 fn last_token_id(&self) -> TokenId {269 TokenId::default()270 }271272 fn token_owner(273 &self,274 _token: TokenId,275 ) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {276 Err(up_data_structs::TokenOwnerError::MultipleOwners)277 }278279 fn token_owners(&self, _token: TokenId) -> Vec<<T>::CrossAccountId> {280 vec![]281 }282283 fn token_property(284 &self,285 _token_id: TokenId,286 _key: &up_data_structs::PropertyKey,287 ) -> Option<up_data_structs::PropertyValue> {288 None289 }290291 fn token_properties(292 &self,293 _token: TokenId,294 _keys: Option<Vec<up_data_structs::PropertyKey>>,295 ) -> Vec<up_data_structs::Property> {296 vec![]297 }298299 fn total_supply(&self) -> u32 {300 1301 }302303 fn account_balance(&self, account: <T>::CrossAccountId) -> u32 {304 let balance: u128 = <T as Config>::Currency::free_balance(account.as_sub()).into();305 (balance != 0).into()306 }307308 fn balance(&self, account: <T>::CrossAccountId, token: TokenId) -> u128 {309 if token != TokenId::default() {310 return 0;311 }312 <T as Config>::Currency::free_balance(account.as_sub()).into()313 }314315 fn total_pieces(&self, token: TokenId) -> Option<u128> {316 if token != TokenId::default() {317 return None;318 }319 let total = <T as Config>::Currency::total_issuance();320 Some(total.into())321 }322323 fn allowance(324 &self,325 _sender: <T>::CrossAccountId,326 _spender: <T>::CrossAccountId,327 _token: TokenId,328 ) -> u128 {329 0330 }331332 fn refungible_extensions(&self) -> Option<&dyn pallet_common::RefungibleExtensions<T>> {333 None334 }335336 fn set_allowance_for_all(337 &self,338 _owner: <T>::CrossAccountId,339 _operator: <T>::CrossAccountId,340 _approve: bool,341 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {342 fail!(<pallet_common::Error<T>>::UnsupportedOperation);343 }344345 fn allowance_for_all(346 &self,347 _owner: <T>::CrossAccountId,348 _operator: <T>::CrossAccountId,349 ) -> bool {350 false351 }352353 fn repair_item(354 &self,355 _token: TokenId,356 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {357 fail!(<pallet_common::Error<T>>::UnsupportedOperation);358 }359}1use alloc::{vec, vec::Vec};2use core::marker::PhantomData;3use crate::{Config, NativeFungibleHandle, Pallet};4use frame_support::{fail, traits::Currency, weights::Weight};5use pallet_balances::{weights::SubstrateWeight as BalancesWeight, WeightInfo};6use pallet_common::{erc::CrossAccountId, CommonCollectionOperations, CommonWeightInfo};7use up_data_structs::TokenId;89pub struct CommonWeights<T: Config>(PhantomData<T>);1011// All implementations with `Weight::default` used in methods that return error `UnsupportedOperation`.12impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {13 fn create_multiple_items(_amount: &[up_data_structs::CreateItemData]) -> Weight {14 Weight::default()15 }1617 fn create_multiple_items_ex(18 _cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,19 ) -> Weight {20 Weight::default()21 }2223 fn burn_item() -> Weight {24 Weight::default()25 }2627 fn set_collection_properties(_amount: u32) -> Weight {28 Weight::default()29 }3031 fn delete_collection_properties(_amount: u32) -> Weight {32 Weight::default()33 }3435 fn set_token_properties(_amount: u32) -> Weight {36 Weight::default()37 }3839 fn delete_token_properties(_amount: u32) -> Weight {40 Weight::default()41 }4243 fn set_token_property_permissions(_amount: u32) -> Weight {44 Weight::default()45 }4647 fn transfer() -> Weight {48 <BalancesWeight<T> as WeightInfo>::transfer()49 }5051 fn approve() -> Weight {52 Weight::default()53 }5455 fn approve_from() -> Weight {56 Weight::default()57 }5859 fn transfer_from() -> Weight {60 <BalancesWeight<T> as WeightInfo>::transfer()61 }6263 fn burn_from() -> Weight {64 Weight::default()65 }6667 fn burn_recursively_self_raw() -> Weight {68 Weight::default()69 }7071 fn burn_recursively_breadth_raw(_amount: u32) -> Weight {72 Weight::default()73 }7475 fn token_owner() -> Weight {76 Weight::default()77 }7879 fn set_allowance_for_all() -> Weight {80 Weight::default()81 }8283 fn force_repair_item() -> Weight {84 Weight::default()85 }86}8788/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallete89/// methods and adds weight info.90impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {91 fn create_item(92 &self,93 _sender: <T>::CrossAccountId,94 _to: <T>::CrossAccountId,95 _data: up_data_structs::CreateItemData,96 _nesting_budget: &dyn up_data_structs::budget::Budget,97 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {98 fail!(<pallet_common::Error<T>>::UnsupportedOperation);99 }100101 fn create_multiple_items(102 &self,103 _sender: <T>::CrossAccountId,104 _to: <T>::CrossAccountId,105 _data: Vec<up_data_structs::CreateItemData>,106 _nesting_budget: &dyn up_data_structs::budget::Budget,107 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {108 fail!(<pallet_common::Error<T>>::UnsupportedOperation);109 }110111 fn create_multiple_items_ex(112 &self,113 _sender: <T>::CrossAccountId,114 _data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,115 _nesting_budget: &dyn up_data_structs::budget::Budget,116 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {117 fail!(<pallet_common::Error<T>>::UnsupportedOperation);118 }119120 fn burn_item(121 &self,122 _sender: <T>::CrossAccountId,123 _token: TokenId,124 _amount: u128,125 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {126 fail!(<pallet_common::Error<T>>::UnsupportedOperation);127 }128129 fn burn_item_recursively(130 &self,131 _sender: <T>::CrossAccountId,132 _token: TokenId,133 _self_budget: &dyn up_data_structs::budget::Budget,134 _breadth_budget: &dyn up_data_structs::budget::Budget,135 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {136 fail!(<pallet_common::Error<T>>::UnsupportedOperation);137 }138139 fn set_collection_properties(140 &self,141 _sender: <T>::CrossAccountId,142 _properties: Vec<up_data_structs::Property>,143 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {144 fail!(<pallet_common::Error<T>>::UnsupportedOperation);145 }146147 fn delete_collection_properties(148 &self,149 _sender: &<T>::CrossAccountId,150 _property_keys: Vec<up_data_structs::PropertyKey>,151 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {152 fail!(<pallet_common::Error<T>>::UnsupportedOperation);153 }154155 fn set_token_properties(156 &self,157 _sender: <T>::CrossAccountId,158 _token_id: TokenId,159 _properties: Vec<up_data_structs::Property>,160 _budget: &dyn up_data_structs::budget::Budget,161 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {162 fail!(<pallet_common::Error<T>>::UnsupportedOperation);163 }164165 fn delete_token_properties(166 &self,167 _sender: <T>::CrossAccountId,168 _token_id: TokenId,169 _property_keys: Vec<up_data_structs::PropertyKey>,170 _budget: &dyn up_data_structs::budget::Budget,171 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {172 fail!(<pallet_common::Error<T>>::UnsupportedOperation);173 }174175 fn set_token_property_permissions(176 &self,177 _sender: &<T>::CrossAccountId,178 _property_permissions: Vec<up_data_structs::PropertyKeyPermission>,179 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {180 fail!(<pallet_common::Error<T>>::UnsupportedOperation);181 }182183 fn transfer(184 &self,185 sender: <T>::CrossAccountId,186 to: <T>::CrossAccountId,187 _token: TokenId,188 amount: u128,189 budget: &dyn up_data_structs::budget::Budget,190 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {191 <Pallet<T>>::transfer(self, &sender, &to, amount, budget)192 }193194 fn approve(195 &self,196 _sender: <T>::CrossAccountId,197 _spender: <T>::CrossAccountId,198 _token: TokenId,199 _amount: u128,200 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {201 fail!(<pallet_common::Error<T>>::UnsupportedOperation);202 }203204 fn approve_from(205 &self,206 _sender: <T>::CrossAccountId,207 _from: <T>::CrossAccountId,208 _to: <T>::CrossAccountId,209 _token: TokenId,210 _amount: u128,211 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {212 fail!(<pallet_common::Error<T>>::UnsupportedOperation);213 }214215 fn transfer_from(216 &self,217 sender: <T>::CrossAccountId,218 from: <T>::CrossAccountId,219 to: <T>::CrossAccountId,220 _token: TokenId,221 amount: u128,222 budget: &dyn up_data_structs::budget::Budget,223 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {224 <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, budget)225 }226227 fn burn_from(228 &self,229 _sender: <T>::CrossAccountId,230 _from: <T>::CrossAccountId,231 _token: TokenId,232 _amount: u128,233 _budget: &dyn up_data_structs::budget::Budget,234 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {235 fail!(<pallet_common::Error<T>>::UnsupportedOperation);236 }237238 fn check_nesting(239 &self,240 _sender: <T>::CrossAccountId,241 _from: (up_data_structs::CollectionId, TokenId),242 _under: TokenId,243 _budget: &dyn up_data_structs::budget::Budget,244 ) -> frame_support::sp_runtime::DispatchResult {245 fail!(<pallet_common::Error<T>>::UnsupportedOperation);246 }247248 fn nest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}249250 fn unnest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}251252 fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<TokenId> {253 let balance = <T as Config>::Currency::total_balance(account.as_sub());254 let balance: u128 = balance.into();255 if balance != 0 {256 vec![TokenId::default()]257 } else {258 vec![]259 }260 }261262 fn collection_tokens(&self) -> Vec<TokenId> {263 vec![TokenId::default()]264 }265266 fn token_exists(&self, token: TokenId) -> bool {267 token == TokenId::default()268 }269270 fn last_token_id(&self) -> TokenId {271 TokenId::default()272 }273274 fn token_owner(275 &self,276 _token: TokenId,277 ) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {278 Err(up_data_structs::TokenOwnerError::MultipleOwners)279 }280281 fn token_owners(&self, _token: TokenId) -> Vec<<T>::CrossAccountId> {282 vec![]283 }284285 fn token_property(286 &self,287 _token_id: TokenId,288 _key: &up_data_structs::PropertyKey,289 ) -> Option<up_data_structs::PropertyValue> {290 None291 }292293 fn token_properties(294 &self,295 _token: TokenId,296 _keys: Option<Vec<up_data_structs::PropertyKey>>,297 ) -> Vec<up_data_structs::Property> {298 vec![]299 }300301 fn total_supply(&self) -> u32 {302 1303 }304305 fn account_balance(&self, account: <T>::CrossAccountId) -> u32 {306 let balance: u128 = <T as Config>::Currency::free_balance(account.as_sub()).into();307 (balance != 0).into()308 }309310 fn balance(&self, account: <T>::CrossAccountId, token: TokenId) -> u128 {311 if token != TokenId::default() {312 return 0;313 }314 <T as Config>::Currency::free_balance(account.as_sub()).into()315 }316317 fn total_pieces(&self, token: TokenId) -> Option<u128> {318 if token != TokenId::default() {319 return None;320 }321 let total = <T as Config>::Currency::total_issuance();322 Some(total.into())323 }324325 fn allowance(326 &self,327 _sender: <T>::CrossAccountId,328 _spender: <T>::CrossAccountId,329 _token: TokenId,330 ) -> u128 {331 0332 }333334 fn refungible_extensions(&self) -> Option<&dyn pallet_common::RefungibleExtensions<T>> {335 None336 }337338 fn set_allowance_for_all(339 &self,340 _owner: <T>::CrossAccountId,341 _operator: <T>::CrossAccountId,342 _approve: bool,343 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {344 fail!(<pallet_common::Error<T>>::UnsupportedOperation);345 }346347 fn allowance_for_all(348 &self,349 _owner: <T>::CrossAccountId,350 _operator: <T>::CrossAccountId,351 ) -> bool {352 false353 }354355 fn repair_item(356 &self,357 _token: TokenId,358 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {359 fail!(<pallet_common::Error<T>>::UnsupportedOperation);360 }361}pallets/balances-adapter/src/erc.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/erc.rs
+++ b/pallets/balances-adapter/src/erc.rs
@@ -1,9 +1,8 @@
use crate::{Config, NativeFungibleHandle, Pallet, SelfWeightOf};
-use evm_coder::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};
-use frame_support::traits::{Currency, ExistenceRequirement};
+use evm_coder::{abi::AbiType, generate_stubgen, solidity_interface, types::*};
+use frame_support::traits::{Currency};
use pallet_balances::WeightInfo;
use pallet_common::{
- consume_store_reads,
erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},
eth::CrossAddress,
};
@@ -14,38 +13,24 @@
};
use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
use sp_core::{U256, Get};
-use sp_std::vec::Vec;
frontier_contract! {
macro_rules! NativeFungibleHandle_result {...}
impl<T: Config> Contract for NativeFungibleHandle<T> {...}
}
-#[derive(ToLog)]
-pub enum ERC20Events {
- Transfer {
- #[indexed]
- from: Address,
- #[indexed]
- to: Address,
- value: U256,
- },
-}
-
-#[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)]
+#[solidity_interface(name = ERC20, enum(derive(PreDispatch)), enum_attr(weight), expect_selector = 0x942e8b22)]
impl<T: Config> NativeFungibleHandle<T> {
fn allowance(&self, _owner: Address, _spender: Address) -> Result<U256> {
Ok(U256::zero())
}
- // #[weight(<SelfWeightOf<T>>::approve())]
fn approve(&mut self, _caller: Caller, _spender: Address, _amount: U256) -> Result<bool> {
- // self.consume_store_reads(1)?;
Err("Approve not supported".into())
}
fn balance_of(&self, owner: Address) -> Result<U256> {
- consume_store_reads(self, 1)?;
+ self.consume_store_reads(1)?;
let owner = T::CrossAccountId::from_eth(owner);
let balance = <T as Config>::Currency::free_balance(owner.as_sub());
Ok(balance.into())
@@ -64,7 +49,7 @@
}
fn total_supply(&self) -> Result<U256> {
- consume_store_reads(self, 1)?;
+ self.consume_store_reads(1)?;
let total = <T as Config>::Currency::total_issuance();
Ok(total.into())
}
@@ -111,7 +96,7 @@
T::AccountId: From<[u8; 32]>,
{
fn balance_of_cross(&self, owner: CrossAddress) -> Result<U256> {
- consume_store_reads(self, 1)?;
+ self.consume_store_reads(1)?;
let owner = owner.into_sub_cross_account::<T>()?;
let balance = <T as Config>::Currency::free_balance(owner.as_sub());
Ok(balance.into())
@@ -122,18 +107,13 @@
let caller = T::CrossAccountId::from_eth(caller);
let to = to.into_sub_cross_account::<T>()?;
let amount = amount.try_into().map_err(|_| "amount overflow")?;
- // let budget = self
- // .recorder
- // .weight_calls_budget(<StructureWeight<T>>::find_parent());
+ let budget = self
+ .recorder()
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
+
+ <Pallet<T>>::transfer(self, &caller, &to, amount, &budget)
+ .map_err(|e| dispatch_to_evm::<T>(e.error))?;
- // <Pallet<T>>::transfer(self, &caller, &to, amount, &budget).map_err(|_| "transfer error")?;
- <T as Config>::Currency::transfer(
- caller.as_sub(),
- to.as_sub(),
- amount,
- ExistenceRequirement::KeepAlive,
- )
- .map_err(dispatch_to_evm::<T>)?;
Ok(true)
}
@@ -154,19 +134,13 @@
return Err("no permission".into());
}
- // let budget = self
- // .recorder
- // .weight_calls_budget(<StructureWeight<T>>::find_parent());
+ let budget = self
+ .recorder()
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
+
+ <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)
+ .map_err(|e| dispatch_to_evm::<T>(e.error))?;
- // <Pallet<T>>::transfer_from(self, &caller, &from, &to, amount, &budget)
- // .map_err(dispatch_to_evm::<T>)?;
- <T as Config>::Currency::transfer(
- caller.as_sub(),
- to.as_sub(),
- amount,
- ExistenceRequirement::KeepAlive,
- )
- .map_err(dispatch_to_evm::<T>)?;
Ok(true)
}
}
pallets/balances-adapter/src/lib.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/lib.rs
+++ b/pallets/balances-adapter/src/lib.rs
@@ -1,4 +1,3 @@
-// #![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
@@ -12,9 +11,6 @@
pub mod erc;
pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;
-
-const NATIVE_FUNGIBLE_COLLECTION_ID: up_data_structs::CollectionId =
- up_data_structs::CollectionId(0);
/// Handle for native fungible collection
pub struct NativeFungibleHandle<T: Config>(SubstrateRecorder<T>);
@@ -57,7 +53,10 @@
traits::{Currency, ExistenceRequirement, Get},
};
use pallet_balances::WeightInfo;
- use pallet_common::{erc::CrossAccountId, Error as CommonError, Pallet as PalletCommon};
+ use pallet_common::{
+ erc::CrossAccountId, Error as CommonError, Pallet as PalletCommon,
+ NATIVE_FUNGIBLE_COLLECTION_ID,
+ };
use pallet_structure::Pallet as PalletStructure;
use sp_core::U256;
use sp_runtime::DispatchError;
@@ -95,10 +94,9 @@
/// Checks if a non-owner has (enough) allowance from the owner to perform operations on the tokens.
/// Returns the expected remaining allowance - it should be set manually if the transaction proceeds.
///
- /// - `collection`: Collection that contains the token.
/// - `spender`: CrossAccountId who has the allowance rights.
/// - `from`: The owner of the tokens who sets the allowance.
- /// - `amount`: Amount of tokens by which the allowance sholud be reduced.
+ /// - `nesting_budget`: Limit for searching parents in-depth to check ownership.
fn check_allowed(
spender: &T::CrossAccountId,
from: &T::CrossAccountId,
@@ -127,10 +125,11 @@
/// Transfers the specified amount of tokens. Will check that
/// the transfer is allowed for the token.
///
+ /// - `collection`: Collection that contains the token.
/// - `from`: Owner of tokens to transfer.
/// - `to`: Recepient of transfered tokens.
/// - `amount`: Amount of tokens to transfer.
- /// - `collection`: Collection that contains the token
+ /// - `nesting_budget`: Limit for searching parents in-depth to check ownership.
pub fn transfer(
_collection: &NativeFungibleHandle<T>,
from: &T::CrossAccountId,
@@ -147,7 +146,7 @@
amount
.try_into()
.map_err(|_| sp_runtime::ArithmeticError::Overflow)?,
- ExistenceRequirement::KeepAlive,
+ ExistenceRequirement::AllowDeath,
)?;
<PalletStructure<T>>::nest_if_sent_to_token(
@@ -175,6 +174,17 @@
})
}
+ /// Transfer NFT token from one account to another.
+ ///
+ /// Same as the [`Self::transfer`] but spender doesn't needs to be the owner of the token.
+ /// The owner should set allowance for the spender to transfer token.
+ ///
+ /// - `collection`: Collection that contains the token.
+ /// - `spender`: Account that spend the money.
+ /// - `from`: Owner of tokens to transfer.
+ /// - `to`: Recepient of transfered tokens.
+ /// - `amount`: Amount of tokens to transfer.
+ /// - `nesting_budget`: Limit for searching parents in-depth to check ownership.
pub fn transfer_from(
collection: &NativeFungibleHandle<T>,
spender: &T::CrossAccountId,
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -77,14 +77,6 @@
fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult>;
}
-impl CommonEvmHandler for () {
- const CODE: &'static [u8] = &[];
-
- fn call(self, _handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {
- None
- }
-}
-
/// @title A contract that allows you to work with collections.
#[solidity_interface(name = Collection, enum(derive(PreDispatch)), enum_attr(weight))]
impl<T: Config> CollectionHandle<T>
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -68,7 +68,6 @@
dispatch::Pays,
transactional, fail,
};
-use pallet_evm::GasWeightMapping;
use up_data_structs::{
AccessMode, COLLECTION_NUMBER_LIMIT, Collection, RpcCollection, CollectionFlags,
RpcCollectionFlags, CollectionId, CreateItemData, MAX_TOKEN_PREFIX_LENGTH,
@@ -101,7 +100,7 @@
/// Collection handle contains information about collection data and id.
/// Also provides functionality to count consumed gas.
///
-/// CollectionHandle is used as a generic wrapper for collections of all types.
+/// CollectionHandle is used as a generic wrapper for collections of all types (except native fungible).
/// It allows to perform common operations and queries on any collection type,
/// both completely general for all, as well as their respective implementations of [`CommonCollectionOperations`].
#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]
@@ -153,7 +152,7 @@
&self,
reads: u64,
) -> pallet_evm_coder_substrate::execution::Result<()> {
- consume_store_reads(self.recorder(), reads)
+ self.recorder().consume_store_reads(reads)
}
/// Consume gas for writing.
@@ -161,7 +160,7 @@
&self,
writes: u64,
) -> pallet_evm_coder_substrate::execution::Result<()> {
- consume_store_writes(self.recorder(), writes)
+ self.recorder().consume_store_writes(writes)
}
/// Consume gas for reading and writing.
@@ -170,7 +169,8 @@
reads: u64,
writes: u64,
) -> pallet_evm_coder_substrate::execution::Result<()> {
- consume_store_reads_and_writes(self.recorder(), reads, writes)
+ self.recorder()
+ .consume_store_reads_and_writes(reads, writes)
}
/// Save collection to storage.
@@ -441,7 +441,7 @@
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
/// Collection id for native fungible collction.
- pub const NATIVE_FINGIBLE_COLLECTION_ID: CollectionId = CollectionId(0);
+ pub const NATIVE_FUNGIBLE_COLLECTION_ID: CollectionId = CollectionId(0);
#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
@@ -2322,48 +2322,4 @@
PropertiesError::EmptyPropertyKey => Self::EmptyPropertyKey,
}
}
-}
-
-/// Consume gas for reading.
-pub fn consume_store_reads<T: Config>(
- recorder: &SubstrateRecorder<T>,
- reads: u64,
-) -> pallet_evm_coder_substrate::execution::Result<()> {
- recorder.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
- <T as frame_system::Config>::DbWeight::get()
- .read
- .saturating_mul(reads),
- // TODO: measure proof
- 0,
- )))
-}
-
-/// Consume gas for writing.
-pub fn consume_store_writes<T: Config>(
- recorder: &SubstrateRecorder<T>,
- writes: u64,
-) -> pallet_evm_coder_substrate::execution::Result<()> {
- recorder.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
- <T as frame_system::Config>::DbWeight::get()
- .write
- .saturating_mul(writes),
- // TODO: measure proof
- 0,
- )))
-}
-
-/// Consume gas for reading and writing.
-pub fn consume_store_reads_and_writes<T: Config>(
- recorder: &SubstrateRecorder<T>,
- reads: u64,
- writes: u64,
-) -> pallet_evm_coder_substrate::execution::Result<()> {
- let weight = <T as frame_system::Config>::DbWeight::get();
- let reads = weight.read.saturating_mul(reads);
- let writes = weight.read.saturating_mul(writes);
- recorder.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
- reads.saturating_add(writes),
- // TODO: measure proof
- 0,
- )))
}
pallets/evm-coder-substrate/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-coder-substrate/src/lib.rs
+++ b/pallets/evm-coder-substrate/src/lib.rs
@@ -37,7 +37,7 @@
ExitError, ExitRevert, ExitSucceed, GasWeightMapping, PrecompileFailure, PrecompileOutput,
PrecompileResult, PrecompileHandle,
};
-use sp_core::H160;
+use sp_core::{Get, H160};
// #[cfg(feature = "runtime-benchmarks")]
// pub mod benchmarking;
pub mod execution;
@@ -204,6 +204,40 @@
Err(Error::Error(e)) => Err(e.into()),
})
}
+
+ /// Consume gas for reading.
+ pub fn consume_store_reads(&self, reads: u64) -> execution::Result<()> {
+ self.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
+ <T as frame_system::Config>::DbWeight::get()
+ .read
+ .saturating_mul(reads),
+ // TODO: measure proof
+ 0,
+ )))
+ }
+
+ /// Consume gas for writing.
+ pub fn consume_store_writes(&self, writes: u64) -> execution::Result<()> {
+ self.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
+ <T as frame_system::Config>::DbWeight::get()
+ .write
+ .saturating_mul(writes),
+ // TODO: measure proof
+ 0,
+ )))
+ }
+
+ /// Consume gas for reading and writing.
+ pub fn consume_store_reads_and_writes(&self, reads: u64, writes: u64) -> execution::Result<()> {
+ let weight = <T as frame_system::Config>::DbWeight::get();
+ let reads = weight.read.saturating_mul(reads);
+ let writes = weight.read.saturating_mul(writes);
+ self.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
+ reads.saturating_add(writes),
+ // TODO: measure proof
+ 0,
+ )))
+ }
}
pub fn dispatch_to_evm<T: Config>(err: DispatchError) -> execution::Error {
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -440,7 +440,7 @@
collection_id: CollectionId,
address: T::CrossAccountId,
) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
@@ -471,7 +471,7 @@
collection_id: CollectionId,
address: T::CrossAccountId,
) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
@@ -501,7 +501,7 @@
collection_id: CollectionId,
new_owner: T::AccountId,
) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
@@ -533,7 +533,7 @@
collection_id: CollectionId,
new_admin_id: T::CrossAccountId,
) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
@@ -562,7 +562,7 @@
collection_id: CollectionId,
account_id: T::CrossAccountId,
) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
@@ -590,7 +590,7 @@
collection_id: CollectionId,
new_sponsor: T::AccountId,
) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
@@ -617,7 +617,7 @@
origin: OriginFor<T>,
collection_id: CollectionId,
) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
let sender = ensure_signed(origin)?;
@@ -640,7 +640,7 @@
origin: OriginFor<T>,
collection_id: CollectionId,
) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
@@ -920,7 +920,7 @@
collection_id: CollectionId,
value: bool,
) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
@@ -1175,7 +1175,7 @@
collection_id: CollectionId,
new_limit: CollectionLimits,
) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
@@ -1202,7 +1202,7 @@
collection_id: CollectionId,
new_permission: CollectionPermissions,
) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
@@ -1273,7 +1273,7 @@
origin: OriginFor<T>,
collection_id: CollectionId,
) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
ensure_root(origin)?;
runtime/common/dispatch.rsdiffbeforeafterboth--- a/runtime/common/dispatch.rs
+++ b/runtime/common/dispatch.rs
@@ -100,12 +100,11 @@
}
fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult {
- if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
let collection = <CollectionHandle<T>>::try_get(collection_id)?;
- collection.check_is_internal()?;
match collection.mode {
CollectionMode::ReFungible => {
@@ -122,7 +121,7 @@
}
fn dispatch(collection_id: CollectionId) -> Result<Self, DispatchError> {
- if collection_id == CollectionId(0) {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
return Ok(Self::NativeFungible(NativeFungibleHandle::new()));
}
@@ -188,7 +187,7 @@
}
fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {
if let Some(collection_id) = map_eth_to_id(&handle.code_address()) {
- if collection_id == CollectionId(0) {
+ if collection_id == pallet_common::NATIVE_FUNGIBLE_COLLECTION_ID {
<NativeFungibleHandle<T>>::new().call(handle)
} else {
let collection = <CollectionHandle<T>>::new_with_gas_limit(