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
use cadence_json::ValueOwned;
use otopr::DecodableMessage;
#[derive(DecodableMessage, Default)]
pub struct Event {
pub ty: String,
pub transaction_id: Box<[u8]>,
pub transaction_index: u32,
pub event_index: u32,
pub payload: Box<[u8]>,
}
impl Event {
pub fn parse_payload_as_value(&self) -> serde_json::Result<cadence_json::ValueOwned> {
serde_json::from_slice(&self.payload)
}
pub fn parse_payload(&self) -> serde_json::Result<cadence_json::CompositeOwned> {
match self.parse_payload_as_value()? {
ValueOwned::Event(composite) => Ok(composite),
_ => panic!("Invalid payload for Event"),
}
}
}