revm_rwasm_bytecode/
rwasm.rs

1use crate::BytecodeDecodeError;
2use primitives::Bytes;
3use rwasm::RwasmModule;
4
5/// Rwasm magic number in array form.
6pub static RWASM_MAGIC_BYTES: Bytes = primitives::bytes!("ef52");
7/// Wasm magic number in array form.
8pub static WASM_MAGIC_BYTES: Bytes = primitives::bytes!("0061736d");
9
10/// rWasm bytecode wrapper.
11#[derive(Clone, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct RwasmBytecode {
14    /// A parsed rWasm bytecode (with code & data sections).
15    pub module: RwasmModule,
16    /// Raw rWasm bytes.
17    pub raw: Bytes,
18}
19
20impl RwasmBytecode {
21    /// Create new rWasm module from bytes.
22    pub fn new(raw: Bytes) -> Result<Self, BytecodeDecodeError> {
23        let (module, _) = RwasmModule::new(raw.as_ref());
24        Ok(Self { module, raw })
25    }
26
27    /// Return raw rWasm bytes
28    #[inline]
29    pub fn raw(&self) -> &Bytes {
30        &self.raw
31    }
32}