sui_rpc_api/proto/types/
events.rs

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use super::TryFromProtoError;

//
// Event
//

impl From<sui_sdk_types::Event> for super::Event {
    fn from(value: sui_sdk_types::Event) -> Self {
        Self {
            package_id: Some(value.package_id.into()),
            module: Some(value.module.into()),
            sender: Some(value.sender.into()),
            event_type: Some(value.type_.into()),
            contents: Some(value.contents.into()),
        }
    }
}

impl TryFrom<&super::Event> for sui_sdk_types::Event {
    type Error = TryFromProtoError;

    fn try_from(value: &super::Event) -> Result<Self, Self::Error> {
        let package_id = value
            .package_id
            .as_ref()
            .ok_or_else(|| TryFromProtoError::missing("package_id"))?
            .try_into()?;

        let module = value
            .module
            .as_ref()
            .ok_or_else(|| TryFromProtoError::missing("module"))?
            .try_into()?;

        let sender = value
            .sender
            .as_ref()
            .ok_or_else(|| TryFromProtoError::missing("sender"))?
            .try_into()?;

        let type_ = value
            .event_type
            .as_ref()
            .ok_or_else(|| TryFromProtoError::missing("event_type"))?
            .try_into()?;

        let contents = value
            .contents
            .as_ref()
            .ok_or_else(|| TryFromProtoError::missing("contents"))?
            .to_vec();

        Ok(Self {
            package_id,
            module,
            sender,
            type_,
            contents,
        })
    }
}

//
// TransactionEvents
//

impl From<sui_sdk_types::TransactionEvents> for super::TransactionEvents {
    fn from(value: sui_sdk_types::TransactionEvents) -> Self {
        Self {
            events: value.0.into_iter().map(Into::into).collect(),
        }
    }
}

impl TryFrom<&super::TransactionEvents> for sui_sdk_types::TransactionEvents {
    type Error = TryFromProtoError;

    fn try_from(value: &super::TransactionEvents) -> Result<Self, Self::Error> {
        Ok(Self(
            value
                .events
                .iter()
                .map(TryInto::try_into)
                .collect::<Result<_, _>>()?,
        ))
    }
}