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
43
44
use crate::{
move_vm_ext::{MoveResolverExt, SessionExt, SessionId},
natives::aptos_natives,
};
use move_deps::{
move_binary_format::errors::VMResult,
move_table_extension::NativeTableContext,
move_vm_runtime::{move_vm::MoveVM, native_extensions::NativeContextExtensions},
};
use std::ops::Deref;
pub struct MoveVmExt {
inner: MoveVM,
}
impl MoveVmExt {
pub fn new() -> VMResult<Self> {
Ok(Self {
inner: MoveVM::new(aptos_natives())?,
})
}
pub fn new_session<'r, S: MoveResolverExt>(
&self,
remote: &'r S,
session_id: SessionId,
) -> SessionExt<'r, '_, S> {
let mut extensions = NativeContextExtensions::default();
extensions.add(NativeTableContext::new(session_id.as_uuid(), remote));
SessionExt::new(self.inner.new_session_with_extensions(remote, extensions))
}
}
impl Deref for MoveVmExt {
type Target = MoveVM;
fn deref(&self) -> &Self::Target {
&self.inner
}
}