MCPcopy Create free account
hub / github.com/base/base / wrap_in_init_code

Function wrap_in_init_code

crates/execution/flashblocks-node/tests/flashblocks_rpc.rs:116–152  ·  view source on GitHub ↗

Wrap runtime code in init code that returns it Init code: CODECOPY runtime to memory[0:size], RETURN it

(runtime_hex: &str)

Source from the content-addressed store, hash-verified

114// Wrap runtime code in init code that returns it
115// Init code: CODECOPY runtime to memory[0:size], RETURN it
116fn wrap_in_init_code(runtime_hex: &str) -> Bytes {
117 // Parse hex string (handle both with and without 0x prefix)
118 let hex_str = runtime_hex.strip_prefix("0x").unwrap_or(runtime_hex);
119 let mut runtime_bytes = Vec::new();
120 for i in (0..hex_str.len()).step_by(2) {
121 let byte = u8::from_str_radix(&hex_str[i..i + 2], 16).expect("valid hex");
122 runtime_bytes.push(byte);
123 }
124 let runtime_size = runtime_bytes.len();
125
126 // Init code:
127 // PUSH1 runtime_size
128 // PUSH1 init_size (12 bytes)
129 // PUSH1 0
130 // CODECOPY
131 // PUSH1 runtime_size
132 // PUSH1 0
133 // RETURN
134 // Total init: 12 bytes
135 let init_size = 12u8;
136 let mut init_code = vec![
137 0x60,
138 runtime_size as u8, // PUSH1 runtime_size
139 0x60,
140 init_size, // PUSH1 init_size
141 0x60,
142 0x00, // PUSH1 0
143 0x39, // CODECOPY
144 0x60,
145 runtime_size as u8, // PUSH1 runtime_size
146 0x60,
147 0x00, // PUSH1 0
148 0xf3, // RETURN
149 ];
150 init_code.extend(runtime_bytes);
151 Bytes::from(init_code)
152}
153
154struct TestSetup {
155 harness: FlashblocksHarness,

Callers 1

newMethod · 0.85

Calls 3

extendMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected