1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use crate::sandbox::utils::{
contains_module, is_bytecode_file, on_disk_state_view::OnDiskStateView,
};
use anyhow::{bail, Result};
use std::path::Path;
pub fn view(state: &OnDiskStateView, file: &str) -> Result<()> {
let path = Path::new(&file);
if state.is_resource_path(path) {
match state.view_resource(path)? {
Some(resource) => println!("{}", resource),
None => println!("Resource not found."),
}
} else if state.is_event_path(path) {
let events = state.view_events(path)?;
if events.is_empty() {
println!("Events not found.")
} else {
for event in events {
println!("{}", event)
}
}
} else if is_bytecode_file(path) {
let bytecode_opt = if contains_module(path) {
OnDiskStateView::view_module(path)?
} else {
OnDiskStateView::view_script(path)?
};
match bytecode_opt {
Some(bytecode) => println!("{}", bytecode),
None => println!("Bytecode not found."),
}
} else {
bail!("`move view <file>` must point to a valid file under storage")
}
Ok(())
}