multiplexer_evm/
opcodes.rs1use alloy_primitives::{Address, U256};
2
3pub const OP_EOF: u8 = 0x00;
5pub const OP_CLEARDATA: u8 = 0x01;
6pub const OP_SETDATA: u8 = 0x02;
7pub const OP_SETADDR: u8 = 0x03;
8pub const OP_SETVALUE: u8 = 0x04;
9pub const OP_EXTCODECOPY: u8 = 0x05;
10pub const OP_CALL: u8 = 0x06;
11pub const OP_CREATE: u8 = 0x07;
12pub const OP_DELEGATECALL: u8 = 0x08;
13pub const OP_SETCALLBACK: u8 = 0x09;
14pub const OP_SETFAIL: u8 = 0x0a;
15pub const OP_CLEARFAIL: u8 = 0x0b;
16
17
18pub struct ClearData {
20 pub size: u16,
21}
22
23impl ClearData {
24 pub fn new(size: u16) -> Self {
25 ClearData { size }
26 }
27
28 pub fn encode(&self) -> Vec<u8> {
29 let mut encoded = Vec::new();
30 encoded.push(OP_CLEARDATA); encoded.extend(&self.size.to_be_bytes()); encoded
33 }
34}
35
36pub struct SetData {
38 pub offset: u16,
39 pub data: Vec<u8>,
40}
41
42impl SetData {
43 pub fn new(offset: u16, data: Vec<u8>) -> Self {
44 SetData { offset, data }
45 }
46
47 pub fn encode(&self) -> Vec<u8> {
48 let data_size = self.data.len() as u16;
49 let mut encoded = Vec::new();
50 encoded.push(OP_SETDATA); encoded.extend(&self.offset.to_be_bytes()); encoded.extend(&data_size.to_be_bytes()); encoded.extend(&self.data); encoded
56 }
57}
58
59pub struct SetAddr {
61 pub addr: Address, }
63
64impl SetAddr {
65 pub fn new(addr: Address) -> Self {
66 SetAddr { addr }
67 }
68
69 pub fn encode(&self) -> Vec<u8> {
70 let mut encoded = Vec::new();
71 encoded.push(OP_SETADDR); encoded.extend(&self.addr); encoded
74 }
75}
76
77#[derive(Clone, Debug)]
79pub struct SetValue {
80 pub value: U256,
81}
82
83impl SetValue {
84 pub fn new(value: U256) -> Self {
85 SetValue { value }
86 }
87
88 pub fn encode(&self) -> Vec<u8> {
89 let mut encoded = Vec::new();
90 encoded.push(OP_SETVALUE); encoded.extend(&self.value.to_be_bytes::<32>()); encoded
93 }
94}
95
96pub struct ExtCodeCopy {
98 pub source: Address, pub data_offset: u16, pub code_offset: u16, pub size: u16, }
103
104impl ExtCodeCopy {
105 pub fn new(source: Address, data_offset: u16, code_offset: u16, size: u16) -> Self {
106 ExtCodeCopy {
107 source,
108 data_offset,
109 code_offset,
110 size,
111 }
112 }
113
114 pub fn encode(&self) -> Vec<u8> {
115 let mut encoded = Vec::new();
116 encoded.push(OP_EXTCODECOPY); encoded.extend(&self.source); encoded.extend(&self.data_offset.to_be_bytes()); encoded.extend(&self.code_offset.to_be_bytes()); encoded.extend(&self.size.to_be_bytes()); encoded
122 }
123}
124
125#[derive(Default)]
127pub struct Call {}
128
129impl Call {
130 pub fn new() -> Self {
131 Call {}
132 }
133
134 pub fn encode(&self) -> Vec<u8> {
135 vec![OP_CALL] }
137}
138
139#[derive(Default)]
141pub struct Create {
142 pub created_address: Address,
143}
144
145impl Create {
146 pub fn new(created_address: Address) -> Self {
147 Self { created_address }
148 }
149
150 pub fn encode(&self) -> Vec<u8> {
151 vec![OP_CREATE] }
153}
154
155#[derive(Default)]
157pub struct DelegateCall {}
158
159impl DelegateCall {
160 pub fn new() -> Self {
161 DelegateCall {}
162 }
163
164 pub fn encode(&self) -> Vec<u8> {
165 vec![OP_DELEGATECALL] }
167}
168
169#[derive(Default)]
171pub struct SetCallback {
172 pub callback_address: Address
173}
174
175impl SetCallback {
176 pub fn new(callback_address: Address) -> Self {
177 SetCallback {callback_address}
178 }
179
180 pub fn encode(&self) -> Vec<u8> {
181 let mut encoded = vec![OP_SETCALLBACK]; encoded.extend(&self.callback_address); encoded
184 }
185}
186
187#[derive(Default)]
189pub struct SetFail {}
190
191impl SetFail {
192 pub fn new() -> Self {
193 SetFail {}
194 }
195
196 pub fn encode(&self) -> Vec<u8> {
197 vec![OP_SETFAIL] }
199}
200
201#[derive(Default)]
203pub struct ClearFail {}
204
205impl ClearFail {
206 pub fn new() -> Self {
207 ClearFail {}
208 }
209
210 pub fn encode(&self) -> Vec<u8> {
211 vec![OP_CLEARFAIL] }
213}
214