dharitri_vm_executor/
missing_wasm.rs

1use std::{error::Error, fmt};
2
3use crate::ExecutorError;
4
5/// Useful for validating wasm bytes coming from tests.
6///
7/// Allows executors to provide an adequate error.
8pub fn check_missing_wasm(wasm_bytes: &[u8]) -> Result<(), ExecutorError> {
9    if wasm_bytes.starts_with("MISSING:".as_bytes()) {
10        Err(Box::new(MissingWasmError(
11            String::from_utf8_lossy(wasm_bytes).to_string(),
12        )))
13    } else {
14        Ok(())
15    }
16}
17
18#[derive(Debug)]
19pub struct MissingWasmError(String);
20
21impl fmt::Display for MissingWasmError {
22    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23        write!(f, "Contract {}", &self.0)
24    }
25}
26
27impl Error for MissingWasmError {}