difftreelog
CArgo fmt
in: master
6 files changed
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -14,7 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use evm_coder::{solidity_interface, types::*, execution::{Result, Error}};
+use evm_coder::{
+ solidity_interface,
+ types::*,
+ execution::{Result, Error},
+};
pub use pallet_evm::{PrecompileOutput, PrecompileResult, account::CrossAccountId};
use pallet_evm_coder_substrate::dispatch_to_evm;
use sp_core::{H160, U256};
@@ -66,11 +70,7 @@
Ok(prop.to_vec())
}
- fn eth_set_sponsor(
- &mut self,
- caller: caller,
- sponsor: address,
- ) -> Result<void> {
+ fn eth_set_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {
check_is_owner(caller, self)?;
let sponsor = T::CrossAccountId::from_eth(sponsor);
@@ -88,44 +88,40 @@
Ok(())
}
- fn set_limit(
- &mut self,
- caller: caller,
- limit: string,
- value: string,
- ) -> Result<void> {
+ fn set_limit(&mut self, caller: caller, limit: string, value: string) -> Result<void> {
check_is_owner(caller, self)?;
let mut limits = self.limits.clone();
match limit.as_str() {
"accountTokenOwnershipLimit" => {
limits.account_token_ownership_limit = parse_int(value)?;
- },
+ }
"sponsoredDataSize" => {
limits.sponsored_data_size = parse_int(value)?;
- },
+ }
"sponsoredDataRateLimit" => {
- limits.sponsored_data_rate_limit = Some(SponsoringRateLimit::Blocks(parse_int(value)?.unwrap()));
- },
+ limits.sponsored_data_rate_limit =
+ Some(SponsoringRateLimit::Blocks(parse_int(value)?.unwrap()));
+ }
"tokenLimit" => {
limits.token_limit = parse_int(value)?;
- },
+ }
"sponsorTransferTimeout" => {
limits.sponsor_transfer_timeout = parse_int(value)?;
- },
+ }
"sponsorApproveTimeout" => {
limits.sponsor_approve_timeout = parse_int(value)?;
- },
+ }
"ownerCanTransfer" => {
limits.owner_can_transfer = parse_bool(value)?;
- },
+ }
"ownerCanDestroy" => {
limits.owner_can_destroy = parse_bool(value)?;
- },
+ }
"transfersEnabled" => {
limits.transfers_enabled = parse_bool(value)?;
- },
- _ => return Err(Error::Revert(format!("Unknown limit \"{}\"", limit)))
+ }
+ _ => return Err(Error::Revert(format!("Unknown limit \"{}\"", limit))),
}
self.limits = limits;
save(self);
@@ -150,13 +146,15 @@
}
fn parse_int(value: string) -> Result<Option<u32>> {
- value.parse::<u32>()
+ value
+ .parse::<u32>()
.map_err(|e| Error::Revert(format!("Int value \"{}\" parse error: {}", value, e)))
.map(|value| Some(value))
}
fn parse_bool(value: string) -> Result<Option<bool>> {
- value.parse::<bool>()
+ value
+ .parse::<bool>()
.map_err(|e| Error::Revert(format!("Bool value \"{}\" parse error: {}", value, e)))
.map(|value| Some(value))
-}
\ No newline at end of file
+}
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use core::marker::PhantomData;18use evm_coder::{abi::AbiWriter, execution::*, generate_stubgen, solidity_interface, types::*, ToLog};19use ethereum as _;20use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};21use pallet_evm::{22 ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure,23 account::CrossAccountId24};25use sp_core::H160;26use crate::{27 AllowlistEnabled, Config, Owner, Pallet, SponsorBasket, SponsoringRateLimit, SponsoringModeT,28};29use frame_support::traits::Get;30use up_sponsorship::SponsorshipHandler;31use sp_std::vec::Vec;3233struct ContractHelpers<T: Config>(SubstrateRecorder<T>);34impl<T: Config> WithRecorder<T> for ContractHelpers<T> {35 fn recorder(&self) -> &SubstrateRecorder<T> {36 &self.037 }3839 fn into_recorder(self) -> SubstrateRecorder<T> {40 self.041 }42}4344#[derive(ToLog)]45pub enum ContractHelperEvent {46 CollectionCreated {47 #[indexed]48 owner: address,49 #[indexed]50 collection_id: address,51 },52}5354#[solidity_interface(name = "ContractHelpers")]55impl<T: Config> ContractHelpers<T> {56 fn contract_owner(&self, contract_address: address) -> Result<address> {57 Ok(<Owner<T>>::get(contract_address))58 }5960 fn sponsoring_enabled(&self, contract_address: address) -> Result<bool> {61 Ok(<Pallet<T>>::sponsoring_mode(contract_address) != SponsoringModeT::Disabled)62 }6364 /// Deprecated65 fn toggle_sponsoring(66 &mut self,67 caller: caller,68 contract_address: address,69 enabled: bool,70 ) -> Result<void> {71 <Pallet<T>>::ensure_owner(contract_address, caller)?;72 <Pallet<T>>::toggle_sponsoring(contract_address, enabled);73 Ok(())74 }7576 fn set_sponsoring_mode(77 &mut self,78 caller: caller,79 contract_address: address,80 mode: uint8,81 ) -> Result<void> {82 <Pallet<T>>::ensure_owner(contract_address, caller)?;83 let mode = SponsoringModeT::from_eth(mode).ok_or("unknown mode")?;84 <Pallet<T>>::set_sponsoring_mode(contract_address, mode);85 Ok(())86 }8788 fn sponsoring_mode(&self, contract_address: address) -> Result<uint8> {89 Ok(<Pallet<T>>::sponsoring_mode(contract_address).to_eth())90 }9192 fn set_sponsoring_rate_limit(93 &mut self,94 caller: caller,95 contract_address: address,96 rate_limit: uint32,97 ) -> Result<void> {98 <Pallet<T>>::ensure_owner(contract_address, caller)?;99 <Pallet<T>>::set_sponsoring_rate_limit(contract_address, rate_limit.into());100 Ok(())101 }102103 fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {104 Ok(<SponsoringRateLimit<T>>::get(contract_address)105 .try_into()106 .map_err(|_| "rate limit > u32::MAX")?)107 }108109 fn allowed(&self, contract_address: address, user: address) -> Result<bool> {110 self.0.consume_sload()?;111 Ok(<Pallet<T>>::allowed(contract_address, user))112 }113114 fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {115 Ok(<AllowlistEnabled<T>>::get(contract_address))116 }117118 fn toggle_allowlist(119 &mut self,120 caller: caller,121 contract_address: address,122 enabled: bool,123 ) -> Result<void> {124 <Pallet<T>>::ensure_owner(contract_address, caller)?;125 <Pallet<T>>::toggle_allowlist(contract_address, enabled);126 Ok(())127 }128129 fn toggle_allowed(130 &mut self,131 caller: caller,132 contract_address: address,133 user: address,134 allowed: bool,135 ) -> Result<void> {136 <Pallet<T>>::ensure_owner(contract_address, caller)?;137 <Pallet<T>>::toggle_allowed(contract_address, user, allowed);138 Ok(())139 }140}141142pub struct HelpersOnMethodCall<T: Config>(PhantomData<*const T>);143impl<T: Config> OnMethodCall<T> for HelpersOnMethodCall<T> {144 fn is_reserved(contract: &sp_core::H160) -> bool {145 contract == &T::ContractAddress::get()146 }147148 fn is_used(contract: &sp_core::H160) -> bool {149 contract == &T::ContractAddress::get()150 }151152 fn call(153 source: &sp_core::H160,154 target: &sp_core::H160,155 gas_left: u64,156 input: &[u8],157 value: sp_core::U256,158 ) -> Option<PrecompileResult> {159 // TODO: Extract to another OnMethodCall handler160 if <AllowlistEnabled<T>>::get(target) && !<Pallet<T>>::allowed(*target, *source) {161 return Some(Err(PrecompileFailure::Revert {162 exit_status: ExitRevert::Reverted,163 cost: 0,164 output: {165 let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));166 writer.string("Target contract is allowlisted");167 writer.finish()168 },169 }));170 }171172 if target != &T::ContractAddress::get() {173 return None;174 }175176 let helpers = ContractHelpers::<T>(SubstrateRecorder::<T>::new(gas_left));177 pallet_evm_coder_substrate::call(*source, helpers, value, input)178 }179180 fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {181 (contract == &T::ContractAddress::get())182 .then(|| include_bytes!("./stubs/ContractHelpers.raw").to_vec())183 }184}185186pub struct HelpersOnCreate<T: Config>(PhantomData<*const T>);187impl<T: Config> OnCreate<T> for HelpersOnCreate<T> {188 fn on_create(owner: H160, contract: H160) {189 <Owner<T>>::insert(contract, owner);190 }191}192193pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);194impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)>195 for HelpersContractSponsoring<T>196{197 fn get_sponsor(who: &T::CrossAccountId, call: &(H160, Vec<u8>)) -> Option<T::CrossAccountId> {198 let mode = <Pallet<T>>::sponsoring_mode(call.0);199 if mode == SponsoringModeT::Disabled {200 return None;201 }202203 if mode == SponsoringModeT::Allowlisted && !<Pallet<T>>::allowed(call.0, *who.as_eth()) {204 return None;205 }206 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;207208 if let Some(last_tx_block) = <SponsorBasket<T>>::get(&call.0, who.as_eth()) {209 let limit = <SponsoringRateLimit<T>>::get(&call.0);210211 let timeout = last_tx_block + limit;212 if block_number < timeout {213 return None;214 }215 }216217 <SponsorBasket<T>>::insert(&call.0, who.as_eth(), block_number);218219 let sponsor = T::CrossAccountId::from_eth(call.0);220 Some(sponsor)221 }222}223224generate_stubgen!(contract_helpers_impl, ContractHelpersCall<()>, true);225generate_stubgen!(contract_helpers_iface, ContractHelpersCall<()>, false);1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use core::marker::PhantomData;18use evm_coder::{abi::AbiWriter, execution::*, generate_stubgen, solidity_interface, types::*, ToLog};19use ethereum as _;20use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};21use pallet_evm::{22 ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure,23 account::CrossAccountId,24};25use sp_core::H160;26use crate::{27 AllowlistEnabled, Config, Owner, Pallet, SponsorBasket, SponsoringRateLimit, SponsoringModeT,28};29use frame_support::traits::Get;30use up_sponsorship::SponsorshipHandler;31use sp_std::vec::Vec;3233struct ContractHelpers<T: Config>(SubstrateRecorder<T>);34impl<T: Config> WithRecorder<T> for ContractHelpers<T> {35 fn recorder(&self) -> &SubstrateRecorder<T> {36 &self.037 }3839 fn into_recorder(self) -> SubstrateRecorder<T> {40 self.041 }42}4344#[derive(ToLog)]45pub enum ContractHelperEvent {46 CollectionCreated {47 #[indexed]48 owner: address,49 #[indexed]50 collection_id: address,51 },52}5354#[solidity_interface(name = "ContractHelpers")]55impl<T: Config> ContractHelpers<T> {56 fn contract_owner(&self, contract_address: address) -> Result<address> {57 Ok(<Owner<T>>::get(contract_address))58 }5960 fn sponsoring_enabled(&self, contract_address: address) -> Result<bool> {61 Ok(<Pallet<T>>::sponsoring_mode(contract_address) != SponsoringModeT::Disabled)62 }6364 /// Deprecated65 fn toggle_sponsoring(66 &mut self,67 caller: caller,68 contract_address: address,69 enabled: bool,70 ) -> Result<void> {71 <Pallet<T>>::ensure_owner(contract_address, caller)?;72 <Pallet<T>>::toggle_sponsoring(contract_address, enabled);73 Ok(())74 }7576 fn set_sponsoring_mode(77 &mut self,78 caller: caller,79 contract_address: address,80 mode: uint8,81 ) -> Result<void> {82 <Pallet<T>>::ensure_owner(contract_address, caller)?;83 let mode = SponsoringModeT::from_eth(mode).ok_or("unknown mode")?;84 <Pallet<T>>::set_sponsoring_mode(contract_address, mode);85 Ok(())86 }8788 fn sponsoring_mode(&self, contract_address: address) -> Result<uint8> {89 Ok(<Pallet<T>>::sponsoring_mode(contract_address).to_eth())90 }9192 fn set_sponsoring_rate_limit(93 &mut self,94 caller: caller,95 contract_address: address,96 rate_limit: uint32,97 ) -> Result<void> {98 <Pallet<T>>::ensure_owner(contract_address, caller)?;99 <Pallet<T>>::set_sponsoring_rate_limit(contract_address, rate_limit.into());100 Ok(())101 }102103 fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {104 Ok(<SponsoringRateLimit<T>>::get(contract_address)105 .try_into()106 .map_err(|_| "rate limit > u32::MAX")?)107 }108109 fn allowed(&self, contract_address: address, user: address) -> Result<bool> {110 self.0.consume_sload()?;111 Ok(<Pallet<T>>::allowed(contract_address, user))112 }113114 fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {115 Ok(<AllowlistEnabled<T>>::get(contract_address))116 }117118 fn toggle_allowlist(119 &mut self,120 caller: caller,121 contract_address: address,122 enabled: bool,123 ) -> Result<void> {124 <Pallet<T>>::ensure_owner(contract_address, caller)?;125 <Pallet<T>>::toggle_allowlist(contract_address, enabled);126 Ok(())127 }128129 fn toggle_allowed(130 &mut self,131 caller: caller,132 contract_address: address,133 user: address,134 allowed: bool,135 ) -> Result<void> {136 <Pallet<T>>::ensure_owner(contract_address, caller)?;137 <Pallet<T>>::toggle_allowed(contract_address, user, allowed);138 Ok(())139 }140}141142pub struct HelpersOnMethodCall<T: Config>(PhantomData<*const T>);143impl<T: Config> OnMethodCall<T> for HelpersOnMethodCall<T> {144 fn is_reserved(contract: &sp_core::H160) -> bool {145 contract == &T::ContractAddress::get()146 }147148 fn is_used(contract: &sp_core::H160) -> bool {149 contract == &T::ContractAddress::get()150 }151152 fn call(153 source: &sp_core::H160,154 target: &sp_core::H160,155 gas_left: u64,156 input: &[u8],157 value: sp_core::U256,158 ) -> Option<PrecompileResult> {159 // TODO: Extract to another OnMethodCall handler160 if <AllowlistEnabled<T>>::get(target) && !<Pallet<T>>::allowed(*target, *source) {161 return Some(Err(PrecompileFailure::Revert {162 exit_status: ExitRevert::Reverted,163 cost: 0,164 output: {165 let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));166 writer.string("Target contract is allowlisted");167 writer.finish()168 },169 }));170 }171172 if target != &T::ContractAddress::get() {173 return None;174 }175176 let helpers = ContractHelpers::<T>(SubstrateRecorder::<T>::new(gas_left));177 pallet_evm_coder_substrate::call(*source, helpers, value, input)178 }179180 fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {181 (contract == &T::ContractAddress::get())182 .then(|| include_bytes!("./stubs/ContractHelpers.raw").to_vec())183 }184}185186pub struct HelpersOnCreate<T: Config>(PhantomData<*const T>);187impl<T: Config> OnCreate<T> for HelpersOnCreate<T> {188 fn on_create(owner: H160, contract: H160) {189 <Owner<T>>::insert(contract, owner);190 }191}192193pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);194impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)>195 for HelpersContractSponsoring<T>196{197 fn get_sponsor(who: &T::CrossAccountId, call: &(H160, Vec<u8>)) -> Option<T::CrossAccountId> {198 let mode = <Pallet<T>>::sponsoring_mode(call.0);199 if mode == SponsoringModeT::Disabled {200 return None;201 }202203 if mode == SponsoringModeT::Allowlisted && !<Pallet<T>>::allowed(call.0, *who.as_eth()) {204 return None;205 }206 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;207208 if let Some(last_tx_block) = <SponsorBasket<T>>::get(&call.0, who.as_eth()) {209 let limit = <SponsoringRateLimit<T>>::get(&call.0);210211 let timeout = last_tx_block + limit;212 if block_number < timeout {213 return None;214 }215 }216217 <SponsorBasket<T>>::insert(&call.0, who.as_eth(), block_number);218219 let sponsor = T::CrossAccountId::from_eth(call.0);220 Some(sponsor)221 }222}223224generate_stubgen!(contract_helpers_impl, ContractHelpersCall<()>, true);225generate_stubgen!(contract_helpers_iface, ContractHelpersCall<()>, false);pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -23,6 +23,7 @@
};
use pallet_common::{
CommonCollectionOperations, CommonWeightInfo, with_weight, weights::WeightInfo as _,
+ PropertyKeyPermission,
};
use sp_runtime::DispatchError;
use sp_std::vec::Vec;
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -21,7 +21,10 @@
};
use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
use frame_support::BoundedVec;
-use up_data_structs::{TokenId, SchemaVersion, PropertyPermission, PropertyKeyPermission, Property, CollectionId, PropertyKey, CollectionPropertiesVec};
+use up_data_structs::{
+ TokenId, SchemaVersion, PropertyPermission, PropertyKeyPermission, Property, CollectionId,
+ PropertyKey, CollectionPropertiesVec,
+};
use pallet_evm_coder_substrate::dispatch_to_evm;
use sp_core::{H160, U256};
use sp_std::vec::Vec;
@@ -382,11 +385,15 @@
}
let mut properties = CollectionPropertiesVec::default();
- properties.try_push(Property{
- key,
- value: token_uri.into_bytes().try_into()
- .map_err(|_| "token uri is too long")?
- }).map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;
+ properties
+ .try_push(Property {
+ key,
+ value: token_uri
+ .into_bytes()
+ .try_into()
+ .map_err(|_| "token uri is too long")?,
+ })
+ .map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;
<Pallet<T>>::create_item(
self,
@@ -407,10 +414,14 @@
}
}
-fn get_token_permission<T: Config>(collection_id: CollectionId, key: &PropertyKey) -> Result<PropertyPermission> {
+fn get_token_permission<T: Config>(
+ collection_id: CollectionId,
+ key: &PropertyKey,
+) -> Result<PropertyPermission> {
let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)
.map_err(|_| Error::Revert("No permissions for collection".into()))?;
- let a = token_property_permissions.get(key)
+ let a = token_property_permissions
+ .get(key)
.map(|p| p.clone())
.ok_or_else(|| Error::Revert("No permission for tokenURI".into()))?;
Ok(a)
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -83,11 +83,11 @@
collection_admin: true,
token_owner: false,
};
- let mut token_property_permissions = up_data_structs::CollectionPropertiesPermissionsVec::default();
- token_property_permissions.try_push(up_data_structs::PropertyKeyPermission{
- key,
- permission,
- }).map_err(|e| Error::Revert(format!("{:?}", e)))?;
+ let mut token_property_permissions =
+ up_data_structs::CollectionPropertiesPermissionsVec::default();
+ token_property_permissions
+ .try_push(up_data_structs::PropertyKeyPermission { key, permission })
+ .map_err(|e| Error::Revert(format!("{:?}", e)))?;
let data = CreateCollectionData {
name,
runtime/opal/src/lib.rsdiffbeforeafterboth--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -49,8 +49,8 @@
// A few exports that help ease life for downstream crates.
pub use pallet_balances::Call as BalancesCall;
pub use pallet_evm::{
- EnsureAddressTruncated, HashedAddressMapping, Runner, account::CrossAccountId as _, OnMethodCall,
- Account as EVMAccount, FeeCalculator, GasWeightMapping,
+ EnsureAddressTruncated, HashedAddressMapping, Runner, account::CrossAccountId as _,
+ OnMethodCall, Account as EVMAccount, FeeCalculator, GasWeightMapping,
};
pub use frame_support::{
construct_runtime, match_types,