difftreelog
style remove unused
in: master
6 files changed
pallets/common/src/erc.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 evm_coder::{18 solidity_interface, solidity, ToLog,19 types::*,20 execution::{Result, Error},21};22pub use pallet_evm::{PrecompileOutput, PrecompileResult, PrecompileHandle, account::CrossAccountId};23use pallet_evm_coder_substrate::dispatch_to_evm;24use sp_core::{H160, U256};25use sp_std::vec::Vec;26use up_data_structs::{Property, SponsoringRateLimit};27use alloc::format;2829use crate::{Pallet, CollectionHandle, Config, CollectionProperties};3031#[derive(ToLog)]32pub enum CollectionHelpersEvents {33 CollectionCreated {34 #[indexed]35 owner: address,36 #[indexed]37 collection_id: address,38 },39}4041/// Does not always represent a full collection, for RFT it is either42/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)43pub trait CommonEvmHandler {44 const CODE: &'static [u8];4546 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult>;47}4849#[solidity_interface(name = "Collection")]50impl<T: Config> CollectionHandle<T> {51 fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {52 let caller = T::CrossAccountId::from_eth(caller);53 let key = <Vec<u8>>::from(key)54 .try_into()55 .map_err(|_| "key too large")?;56 let value = value.try_into().map_err(|_| "value too large")?;5758 <Pallet<T>>::set_collection_property(self, &caller, Property { key, value })59 .map_err(dispatch_to_evm::<T>)60 }6162 fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {63 let caller = T::CrossAccountId::from_eth(caller);64 let key = <Vec<u8>>::from(key)65 .try_into()66 .map_err(|_| "key too large")?;6768 <Pallet<T>>::delete_collection_property(self, &caller, key).map_err(dispatch_to_evm::<T>)69 }7071 /// Throws error if key not found72 fn collection_property(&self, key: string) -> Result<bytes> {73 let key = <Vec<u8>>::from(key)74 .try_into()75 .map_err(|_| "key too large")?;7677 let props = <CollectionProperties<T>>::get(self.id);78 let prop = props.get(&key).ok_or("key not found")?;7980 Ok(prop.to_vec())81 }8283 fn eth_set_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {84 check_is_owner(caller, self)?;8586 let sponsor = T::CrossAccountId::from_eth(sponsor);87 self.set_sponsor(sponsor.as_sub().clone());88 save(self);89 Ok(())90 }9192 fn eth_confirm_sponsorship(&mut self, caller: caller) -> Result<void> {93 let caller = T::CrossAccountId::from_eth(caller);94 if !self.confirm_sponsorship(caller.as_sub()) {95 return Err(Error::Revert("Caller is not set as sponsor".into()));96 }97 save(self);98 Ok(())99 }100101 #[solidity(rename_selector = "setLimit")]102 fn set_int_limit(&mut self, caller: caller, limit: string, value: uint32) -> Result<void> {103 check_is_owner(caller, self)?;104 let mut limits = self.limits.clone();105106 match limit.as_str() {107 "accountTokenOwnershipLimit" => {108 limits.account_token_ownership_limit = Some(value);109 }110 "sponsoredDataSize" => {111 limits.sponsored_data_size = Some(value);112 }113 "sponsoredDataRateLimit" => {114 limits.sponsored_data_rate_limit = Some(SponsoringRateLimit::Blocks(value));115 }116 "tokenLimit" => {117 limits.token_limit = Some(value);118 }119 "sponsorTransferTimeout" => {120 limits.sponsor_transfer_timeout = Some(value);121 }122 "sponsorApproveTimeout" => {123 limits.sponsor_approve_timeout = Some(value);124 }125 _ => {126 return Err(Error::Revert(format!(127 "Unknown integer limit \"{}\"",128 limit129 )))130 }131 }132 self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)133 .map_err(dispatch_to_evm::<T>)?;134 save(self);135 Ok(())136 }137138 #[solidity(rename_selector = "setLimit")]139 fn set_bool_limit(&mut self, caller: caller, limit: string, value: bool) -> Result<void> {140 check_is_owner(caller, self)?;141 let mut limits = self.limits.clone();142143 match limit.as_str() {144 "ownerCanTransfer" => {145 limits.owner_can_transfer = Some(value);146 }147 "ownerCanDestroy" => {148 limits.owner_can_destroy = Some(value);149 }150 "transfersEnabled" => {151 limits.transfers_enabled = Some(value);152 }153 _ => {154 return Err(Error::Revert(format!(155 "Unknown boolean limit \"{}\"",156 limit157 )))158 }159 }160 self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)161 .map_err(dispatch_to_evm::<T>)?;162 save(self);163 Ok(())164 }165166 fn contract_address(&self, _caller: caller) -> Result<address> {167 Ok(crate::eth::collection_id_to_address(self.id))168 }169}170171fn check_is_owner<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<()> {172 let caller = T::CrossAccountId::from_eth(caller);173 collection174 .check_is_owner(&caller)175 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;176 Ok(())177}178179fn save<T: Config>(collection: &CollectionHandle<T>) {180 <crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());181}182183pub fn token_uri_key() -> up_data_structs::PropertyKey {184 b"tokenURI"185 .to_vec()186 .try_into()187 .expect("length < limit; qed")188}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 evm_coder::{18 solidity_interface, solidity, ToLog,19 types::*,20 execution::{Result, Error},21};22pub use pallet_evm::{PrecompileOutput, PrecompileResult, PrecompileHandle, account::CrossAccountId};23use pallet_evm_coder_substrate::dispatch_to_evm;24use sp_std::vec::Vec;25use up_data_structs::{Property, SponsoringRateLimit};26use alloc::format;2728use crate::{Pallet, CollectionHandle, Config, CollectionProperties};2930#[derive(ToLog)]31pub enum CollectionHelpersEvents {32 CollectionCreated {33 #[indexed]34 owner: address,35 #[indexed]36 collection_id: address,37 },38}3940/// Does not always represent a full collection, for RFT it is either41/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)42pub trait CommonEvmHandler {43 const CODE: &'static [u8];4445 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult>;46}4748#[solidity_interface(name = "Collection")]49impl<T: Config> CollectionHandle<T> {50 fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {51 let caller = T::CrossAccountId::from_eth(caller);52 let key = <Vec<u8>>::from(key)53 .try_into()54 .map_err(|_| "key too large")?;55 let value = value.try_into().map_err(|_| "value too large")?;5657 <Pallet<T>>::set_collection_property(self, &caller, Property { key, value })58 .map_err(dispatch_to_evm::<T>)59 }6061 fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {62 let caller = T::CrossAccountId::from_eth(caller);63 let key = <Vec<u8>>::from(key)64 .try_into()65 .map_err(|_| "key too large")?;6667 <Pallet<T>>::delete_collection_property(self, &caller, key).map_err(dispatch_to_evm::<T>)68 }6970 /// Throws error if key not found71 fn collection_property(&self, key: string) -> Result<bytes> {72 let key = <Vec<u8>>::from(key)73 .try_into()74 .map_err(|_| "key too large")?;7576 let props = <CollectionProperties<T>>::get(self.id);77 let prop = props.get(&key).ok_or("key not found")?;7879 Ok(prop.to_vec())80 }8182 fn eth_set_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {83 check_is_owner(caller, self)?;8485 let sponsor = T::CrossAccountId::from_eth(sponsor);86 self.set_sponsor(sponsor.as_sub().clone());87 save(self);88 Ok(())89 }9091 fn eth_confirm_sponsorship(&mut self, caller: caller) -> Result<void> {92 let caller = T::CrossAccountId::from_eth(caller);93 if !self.confirm_sponsorship(caller.as_sub()) {94 return Err(Error::Revert("Caller is not set as sponsor".into()));95 }96 save(self);97 Ok(())98 }99100 #[solidity(rename_selector = "setLimit")]101 fn set_int_limit(&mut self, caller: caller, limit: string, value: uint32) -> Result<void> {102 check_is_owner(caller, self)?;103 let mut limits = self.limits.clone();104105 match limit.as_str() {106 "accountTokenOwnershipLimit" => {107 limits.account_token_ownership_limit = Some(value);108 }109 "sponsoredDataSize" => {110 limits.sponsored_data_size = Some(value);111 }112 "sponsoredDataRateLimit" => {113 limits.sponsored_data_rate_limit = Some(SponsoringRateLimit::Blocks(value));114 }115 "tokenLimit" => {116 limits.token_limit = Some(value);117 }118 "sponsorTransferTimeout" => {119 limits.sponsor_transfer_timeout = Some(value);120 }121 "sponsorApproveTimeout" => {122 limits.sponsor_approve_timeout = Some(value);123 }124 _ => {125 return Err(Error::Revert(format!(126 "Unknown integer limit \"{}\"",127 limit128 )))129 }130 }131 self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)132 .map_err(dispatch_to_evm::<T>)?;133 save(self);134 Ok(())135 }136137 #[solidity(rename_selector = "setLimit")]138 fn set_bool_limit(&mut self, caller: caller, limit: string, value: bool) -> Result<void> {139 check_is_owner(caller, self)?;140 let mut limits = self.limits.clone();141142 match limit.as_str() {143 "ownerCanTransfer" => {144 limits.owner_can_transfer = Some(value);145 }146 "ownerCanDestroy" => {147 limits.owner_can_destroy = Some(value);148 }149 "transfersEnabled" => {150 limits.transfers_enabled = Some(value);151 }152 _ => {153 return Err(Error::Revert(format!(154 "Unknown boolean limit \"{}\"",155 limit156 )))157 }158 }159 self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)160 .map_err(dispatch_to_evm::<T>)?;161 save(self);162 Ok(())163 }164165 fn contract_address(&self, _caller: caller) -> Result<address> {166 Ok(crate::eth::collection_id_to_address(self.id))167 }168}169170fn check_is_owner<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<()> {171 let caller = T::CrossAccountId::from_eth(caller);172 collection173 .check_is_owner(&caller)174 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;175 Ok(())176}177178fn save<T: Config>(collection: &CollectionHandle<T>) {179 <crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());180}181182pub fn token_uri_key() -> up_data_structs::PropertyKey {183 b"tokenURI"184 .to_vec()185 .try_into()186 .expect("length < limit; qed")187}pallets/evm-migration/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-migration/src/lib.rs
+++ b/pallets/evm-migration/src/lib.rs
@@ -108,7 +108,7 @@
false
}
- fn call(handle: &mut impl PrecompileHandle) -> Option<pallet_evm::PrecompileResult> {
+ fn call(_handle: &mut impl PrecompileHandle) -> Option<pallet_evm::PrecompileResult> {
None
}
pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -19,7 +19,6 @@
use evm_coder::{ToLog, execution::*, generate_stubgen, solidity_interface, types::*, weight};
use up_data_structs::CollectionMode;
use pallet_common::erc::{CommonEvmHandler, PrecompileResult};
-use sp_core::{H160, U256};
use sp_std::vec::Vec;
use pallet_evm::{account::CrossAccountId, PrecompileHandle};
use pallet_evm_coder_substrate::{call, dispatch_to_evm};
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -26,7 +26,6 @@
CollectionPropertiesVec,
};
use pallet_evm_coder_substrate::dispatch_to_evm;
-use sp_core::{H160, U256};
use sp_std::vec::Vec;
use pallet_common::{
erc::{CommonEvmHandler, PrecompileResult, CollectionCall, token_uri_key},
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -25,7 +25,7 @@
fn call(
self,
- handle: &mut impl PrecompileHandle,
+ _handle: &mut impl PrecompileHandle,
) -> Option<pallet_common::erc::PrecompileResult> {
// TODO: Implement RFT variant of ERC721
None
@@ -39,7 +39,7 @@
fn call(
self,
- handle: &mut impl PrecompileHandle,
+ _handle: &mut impl PrecompileHandle,
) -> Option<pallet_common::erc::PrecompileResult> {
// TODO: Implement RFT variant of ERC20
None
runtime/common/src/dispatch.rsdiffbeforeafterboth--- a/runtime/common/src/dispatch.rs
+++ b/runtime/common/src/dispatch.rs
@@ -1,6 +1,6 @@
use frame_support::{dispatch::DispatchResult, ensure};
use pallet_evm::{PrecompileHandle, PrecompileResult};
-use sp_core::{H160, U256};
+use sp_core::H160;
use sp_std::{borrow::ToOwned, vec::Vec};
use pallet_common::{
CollectionById, CollectionHandle, CommonCollectionOperations, erc::CommonEvmHandler,