git.delta.rocks / unique-network / refs/commits / 5ef1c1c9c81a

difftreelog

source

runtime/common/ethereum/precompiles/mod.rs1.9 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::{18	IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet,19};20use pallet_evm_precompile_simple::ECRecover;21use sp_core::H160;22use sp_std::marker::PhantomData;23use sr25519::Sr25519Precompile;2425mod sr25519;26mod utils;2728pub struct UniquePrecompiles<R>(PhantomData<R>);2930impl<R> UniquePrecompiles<R>31where32	R: pallet_evm::Config,33{34	pub fn new() -> Self {35		Self(Default::default())36	}37	pub fn used_addresses() -> [H160; 2] {38		[hash(1), hash(20482)]39	}40}4142impl<R> Default for UniquePrecompiles<R>43where44	R: pallet_evm::Config,45{46	fn default() -> Self {47		Self::new()48	}49}5051impl<R> PrecompileSet for UniquePrecompiles<R>52where53	R: pallet_evm::Config,54{55	fn execute(&self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {56		match handle.code_address() {57			a if a == hash(1) => Some(ECRecover::execute(handle)),58			// Sr25519     0x500259			a if a == hash(20482) => Some(Sr25519Precompile::<R>::execute(handle)),60			_ => None,61		}62	}6364	fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult {65		IsPrecompileResult::Answer {66			is_precompile: Self::used_addresses().contains(&address),67			extra_cost: 0,68		}69	}70}7172fn hash(a: u64) -> H160 {73	H160::from_low_u64_be(a)74}