pub mod bytecode;
pub mod runtime;
pub mod translator;
pub use bytecode::{
parse_move_bytecode, validate_move_bytecode, BytecodeVersion, FieldDef, FunctionDef,
MoveModule, MoveOpcode, StructDef, TypeTag,
};
pub use runtime::{global_storage_key, signer_to_checkwitness, ResourceError, ResourceTracker};
pub use translator::translate_to_wasm;
use anyhow::Result;
pub struct MoveTranslation {
pub wasm: Vec<u8>,
pub metadata: MoveModuleMetadata,
}
#[derive(Debug, Clone, Default)]
pub struct MoveModuleMetadata {
pub name: String,
pub functions: Vec<String>,
pub resources: Vec<String>,
}
pub fn translate_move_to_wasm(bytecode: &[u8], module_name: &str) -> Result<MoveTranslation> {
let module = parse_move_bytecode(bytecode)?;
let wasm = translate_to_wasm(&module)?;
let metadata = MoveModuleMetadata {
name: module_name.to_string(),
functions: module
.functions
.iter()
.filter(|f| f.is_public || f.is_entry)
.map(|f| f.name.clone())
.collect(),
resources: module
.structs
.iter()
.filter(|s| s.abilities.is_resource())
.map(|s| s.name.clone())
.collect(),
};
Ok(MoveTranslation { wasm, metadata })
}
pub fn is_move_bytecode(bytes: &[u8]) -> bool {
validate_move_bytecode(bytes)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_move_bytecode() {
assert!(is_move_bytecode(&[
0xa1, 0x1c, 0xeb, 0x0b, 0x00, 0x00, 0x00, 0x00
]));
assert!(!is_move_bytecode(&[0x00, 0x61, 0x73, 0x6d]));
}
}