eva_asm/instruction/
block.rs

1//! Block information.
2
3use derive_more::Display;
4
5use crate::{
6    instruction::Instruction,
7    opcode::{Mnemonic, OpCode},
8};
9
10/// Get the hash of one of the 256 most recent complete blocks.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
12#[display("{}", self.opcode())]
13pub struct BlockHash;
14
15impl Instruction for BlockHash {
16    fn opcode(&self) -> OpCode {
17        OpCode::Known(Mnemonic::BLOCKHASH)
18    }
19}
20
21/// Get the block’s beneficiary address.
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
23#[display("{}", self.opcode())]
24pub struct CoinBase;
25
26impl Instruction for CoinBase {
27    fn opcode(&self) -> OpCode {
28        OpCode::Known(Mnemonic::COINBASE)
29    }
30}
31
32/// Get the block’s timestamp.
33#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
34#[display("{}", self.opcode())]
35pub struct Timestamp;
36
37impl Instruction for Timestamp {
38    fn opcode(&self) -> OpCode {
39        OpCode::Known(Mnemonic::TIMESTAMP)
40    }
41}
42
43/// Get the block’s number.
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
45#[display("{}", self.opcode())]
46pub struct Number;
47
48impl Instruction for Number {
49    fn opcode(&self) -> OpCode {
50        OpCode::Known(Mnemonic::NUMBER)
51    }
52}
53
54/// Get the block’s difficulty.
55#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
56#[display("{}", self.opcode())]
57pub struct PrevRandao;
58
59impl Instruction for PrevRandao {
60    fn opcode(&self) -> OpCode {
61        OpCode::Known(Mnemonic::PREVRANDAO)
62    }
63}
64
65/// Get the block’s gas limit.
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
67#[display("{}", self.opcode())]
68pub struct GasLimit;
69
70impl Instruction for GasLimit {
71    fn opcode(&self) -> OpCode {
72        OpCode::Known(Mnemonic::GASLIMIT)
73    }
74}
75
76/// Get the chain ID.
77#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
78#[display("{}", self.opcode())]
79pub struct ChainId;
80
81impl Instruction for ChainId {
82    fn opcode(&self) -> OpCode {
83        OpCode::Known(Mnemonic::CHAINID)
84    }
85}
86
87/// Get balance of currently executing account.
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
89#[display("{}", self.opcode())]
90pub struct SelfBalance;
91
92impl Instruction for SelfBalance {
93    fn opcode(&self) -> OpCode {
94        OpCode::Known(Mnemonic::SELFBALANCE)
95    }
96}
97
98/// Get the base fee.
99#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
100#[display("{}", self.opcode())]
101pub struct BaseFee;
102
103impl Instruction for BaseFee {
104    fn opcode(&self) -> OpCode {
105        OpCode::Known(Mnemonic::BASEFEE)
106    }
107}
108
109/// Get versioned hashes.
110#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
111#[display("{}", self.opcode())]
112pub struct BlobHash;
113
114impl Instruction for BlobHash {
115    fn opcode(&self) -> OpCode {
116        OpCode::Known(Mnemonic::BLOBHASH)
117    }
118}
119
120/// Returns the value of the blob base-fee of the current block.
121#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
122#[display("{}", self.opcode())]
123pub struct BlobBaseFee;
124
125impl Instruction for BlobBaseFee {
126    fn opcode(&self) -> OpCode {
127        OpCode::Known(Mnemonic::BLOBBASEFEE)
128    }
129}