Skip to content

Commit d485f8e

Browse files
committed
[move] add a native for reading from the events cacheo
this is useful if we want to understand what event was emitted during testing, for example.
1 parent 2759c32 commit d485f8e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

third_party/move/move-vm/runtime/src/data_cache.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,14 @@ impl<'r> TransactionDataCache<'r> {
295295
let ty_layout = loader.type_to_type_layout(&ty)?;
296296
Ok(self.event_data.push((guid, seq_num, ty, ty_layout, val)))
297297
}
298+
299+
pub(crate) fn emitted_events(&self, guid: Vec<u8>, ty: Type) -> PartialVMResult<Vec<Value>> {
300+
let mut events = vec![];
301+
for event in self.event_data.iter() {
302+
if event.0 == guid && event.2 == ty {
303+
events.push(event.4.copy_value()?);
304+
}
305+
}
306+
Ok(events)
307+
}
298308
}

third_party/move/move-vm/runtime/src/native_functions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ impl<'a, 'b, 'c> NativeContext<'a, 'b, 'c> {
156156
}
157157
}
158158

159+
pub fn emitted_events(&self, guid: Vec<u8>, ty: Type) -> PartialVMResult<Vec<Value>> {
160+
self.data_store.emitted_events(guid, ty)
161+
}
162+
159163
pub fn type_to_type_tag(&self, ty: &Type) -> PartialVMResult<TypeTag> {
160164
self.resolver.loader().type_to_type_tag(ty)
161165
}

0 commit comments

Comments
 (0)