git.delta.rocks / unique-network / refs/commits / 6edd3f1acfd3

difftreelog

source

pallets/common/src/erc.rs2.5 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, CollectionProperties};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_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {37		let caller = T::CrossAccountId::from_eth(caller);38		let key = <Vec<u8>>::from(key)39			.try_into()40			.map_err(|_| "key too large")?;41		let value = value.try_into().map_err(|_| "value too large")?;4243		<Pallet<T>>::set_collection_property(self, &caller, Property { key, value })44			.map_err(dispatch_to_evm::<T>)45	}4647	fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {48		let caller = T::CrossAccountId::from_eth(caller);49		let key = <Vec<u8>>::from(key)50			.try_into()51			.map_err(|_| "key too large")?;5253		<Pallet<T>>::delete_collection_property(self, &caller, key).map_err(dispatch_to_evm::<T>)54	}5556	/// Throws error if key not found57	fn collection_property(&self, key: string) -> Result<bytes> {58		let key = <Vec<u8>>::from(key)59			.try_into()60			.map_err(|_| "key too large")?;6162		let props = <CollectionProperties<T>>::get(self.id);63		let prop = props.get(&key).ok_or("key not found")?;6465		Ok(prop.to_vec())66	}67}