git.delta.rocks / unique-network / refs/commits / fe4e7633ea11

difftreelog

source

pallets/common/src/erc.rs2.0 KiBsourcehistory
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::{solidity_interface, types::*, execution::Result};18pub use pallet_evm::{PrecompileOutput, PrecompileResult, account::CrossAccountId};19use pallet_evm_coder_substrate::dispatch_to_evm;20use sp_core::{H160, U256};21use sp_std::vec::Vec;22use up_data_structs::Property;2324use crate::{Pallet, CollectionHandle, Config};2526/// Does not always represent a full collection, for RFT it is either27/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)28pub trait CommonEvmHandler {29	const CODE: &'static [u8];3031	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult>;32}3334#[solidity_interface(name = "CollectionProperties")]35impl<T: Config> CollectionHandle<T> {36	fn set_property(&mut self, caller: caller, key: string, value: string) -> Result<()> {37		<Pallet<T>>::set_collection_property(38			self,39			&T::CrossAccountId::from_eth(caller),40			Property {41				key: <Vec<u8>>::from(key)42					.try_into()43					.map_err(|_| "key too large")?,44				value: <Vec<u8>>::from(value)45					.try_into()46					.map_err(|_| "value too large")?,47			},48		)49		.map_err(dispatch_to_evm::<T>)?;50		Ok(())51	}5253	fn delete_property(&mut self, caller: caller, key: string) -> Result<()> {54		self.set_property(caller, key, string::new())55	}56}