Skip to content

Commit

Permalink
use json value (MystenLabs#2413)
Browse files Browse the repository at this point in the history
  • Loading branch information
longbowlu authored Jun 4, 2022
1 parent 38b2a2c commit 1189548
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 8 additions & 6 deletions crates/sui-core/src/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ impl EventHandler {
Event::MoveEvent { .. } => {
debug!(event =? event, "Process MoveEvent.");
match event.extract_move_struct(&self.module_cache) {
Ok(Some(move_struct)) => EventEnvelope::new(
get_unixtime_ms(),
None,
event.clone(),
Some(move_struct),
),
Ok(Some(move_struct)) => {
let json_value = serde_json::to_value(&move_struct).map_err(|e| {
SuiError::ObjectSerializationError {
error: e.to_string(),
}
})?;
EventEnvelope::new(get_unixtime_ms(), None, event.clone(), Some(json_value))
}
Ok(None) => unreachable!("Expect a MoveStruct from a MoveEvent."),
Err(e) => return Err(e),
}
Expand Down
9 changes: 5 additions & 4 deletions crates/sui-types/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use move_core_types::{
};
use name_variant::NamedVariant;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_with::{serde_as, Bytes};
use strum_macros::EnumDiscriminants;

Expand All @@ -27,22 +28,22 @@ pub struct EventEnvelope {
tx_digest: Option<TransactionDigest>,
/// Specific event type
pub event: Event,
/// MoveStruct (for MoveEvent only)
pub move_struct: Option<MoveStruct>,
/// json value for MoveStruct (for MoveEvent only)
pub move_struct_json_value: Option<Value>,
}

impl EventEnvelope {
pub fn new(
timestamp: u64,
tx_digest: Option<TransactionDigest>,
event: Event,
move_struct: Option<MoveStruct>,
move_struct_json_value: Option<Value>,
) -> Self {
Self {
timestamp,
tx_digest,
event,
move_struct,
move_struct_json_value,
}
}

Expand Down

0 comments on commit 1189548

Please sign in to comment.