revm_interpreter/interpreter_action/
eof_create_inputs.rs
1use crate::primitives::{Address, Bytes, Eof, TxEnv, U256};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14pub enum EOFCreateKind {
15 Tx {
16 initdata: Bytes,
17 },
18 Opcode {
19 initcode: Eof,
20 input: Bytes,
21 created_address: Address,
22 },
23}
24
25impl EOFCreateKind {
26 pub fn created_address(&self) -> Option<&Address> {
28 match self {
29 EOFCreateKind::Opcode {
30 created_address, ..
31 } => Some(created_address),
32 EOFCreateKind::Tx { .. } => None,
33 }
34 }
35}
36
37impl Default for EOFCreateKind {
38 fn default() -> Self {
39 EOFCreateKind::Opcode {
40 initcode: Eof::default(),
41 input: Bytes::default(),
42 created_address: Address::default(),
43 }
44 }
45}
46
47#[derive(Debug, Default, Clone, PartialEq, Eq)]
49#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
50pub struct EOFCreateInputs {
51 pub caller: Address,
53 pub value: U256,
55 pub gas_limit: u64,
57 pub kind: EOFCreateKind,
59}
60
61impl EOFCreateInputs {
62 pub fn new(caller: Address, value: U256, gas_limit: u64, kind: EOFCreateKind) -> Self {
66 EOFCreateInputs {
68 caller,
69 value,
70 gas_limit,
71 kind,
72 }
73 }
74
75 pub fn new_tx(tx: &TxEnv, gas_limit: u64) -> Self {
77 EOFCreateInputs::new(
78 tx.caller,
79 tx.value,
80 gas_limit,
81 EOFCreateKind::Tx {
82 initdata: tx.data.clone(),
83 },
84 )
85 }
86
87 pub fn new_opcode(
89 caller: Address,
90 created_address: Address,
91 value: U256,
92 eof_init_code: Eof,
93 gas_limit: u64,
94 input: Bytes,
95 ) -> EOFCreateInputs {
96 EOFCreateInputs::new(
97 caller,
98 value,
99 gas_limit,
100 EOFCreateKind::Opcode {
101 initcode: eof_init_code,
102 input,
103 created_address,
104 },
105 )
106 }
107}