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

difftreelog

source

runtime/common/ethereum/precompiles/mod.rs1.7 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 pallet_evm::{Precompile, PrecompileHandle, PrecompileResult, PrecompileSet};18use sp_core::H160;19use sp_std::marker::PhantomData;2021use pallet_evm_precompile_simple::{ECRecover};22use sr25519::Sr25519Precompile;2324mod sr25519;25mod utils;2627pub struct UniquePrecompiles<R>(PhantomData<R>);2829impl<R> UniquePrecompiles<R>30where31	R: pallet_evm::Config,32{33	pub fn new() -> Self {34		Self(Default::default())35	}36	pub fn used_addresses() -> [H160; 2] {37		[hash(1), hash(20482)]38	}39}40impl<R> PrecompileSet for UniquePrecompiles<R>41where42	R: pallet_evm::Config,43{44	fn execute(&self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {45		match handle.code_address() {46			a if a == hash(1) => Some(ECRecover::execute(handle)),47			// Sr25519     0x500248			a if a == hash(20482) => Some(Sr25519Precompile::<R>::execute(handle)),49			_ => None,50		}51	}5253	fn is_precompile(&self, address: H160) -> bool {54		Self::used_addresses().contains(&address)55	}56}5758fn hash(a: u64) -> H160 {59	H160::from_low_u64_be(a)60}