referrerpolicy=no-referrer-when-downgrade

pallet_revive/vm/evm/instructions/
tx_info.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18use crate::{address::AddressMapper, evm::runtime::GAS_PRICE, vm::RuntimeCosts};
19use revm::primitives::{Address, U256};
20
21use super::Context;
22use crate::{vm::Ext, Config};
23
24/// Implements the GASPRICE instruction.
25///
26/// Gets the gas price of the originating transaction.
27pub fn gasprice<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
28	gas!(context.interpreter, RuntimeCosts::GasPrice);
29	push!(context.interpreter, U256::from(GAS_PRICE));
30}
31
32/// Implements the ORIGIN instruction.
33///
34/// Gets the execution origination address.
35pub fn origin<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
36	gas!(context.interpreter, RuntimeCosts::Origin);
37	match context.interpreter.extend.origin().account_id() {
38		Ok(account_id) => {
39			let address: Address = <E::T as Config>::AddressMapper::to_address(account_id).0.into();
40			push!(context.interpreter, address.into_word().into());
41		},
42		Err(_) => {
43			context
44				.interpreter
45				.halt(revm::interpreter::InstructionResult::FatalExternalError);
46		},
47	}
48}
49
50/// Implements the BLOBHASH instruction.
51///
52/// EIP-4844: Shard Blob Transactions - gets the hash of a transaction blob.
53pub fn blob_hash<'ext, E: Ext>(context: Context<'_, 'ext, E>) {
54	context.interpreter.halt(revm::interpreter::InstructionResult::NotActivated);
55}