1use crate::Digest;
5use gprimitives::{ActorId, CodeId, H256};
6use parity_scale_codec::{Decode, Encode};
7use scale_info::TypeInfo;
8
9#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq, PartialOrd, Ord, Hash)]
12pub struct BatchCommittedEvent {
13 pub digest: Digest,
14}
15
16#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq, PartialOrd, Ord, Hash)]
19pub struct MBCommittedEvent(pub H256);
20
21#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq, PartialOrd, Ord, Hash)]
23pub struct EBCommittedEvent(pub H256);
24
25#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq, PartialOrd, Ord, Hash)]
26pub struct CodeGotValidatedEvent {
27 pub code_id: CodeId,
28 pub valid: bool,
29}
30
31#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq, PartialOrd, Ord, Hash)]
32#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
33pub struct CodeValidationRequestedEvent {
34 pub code_id: CodeId,
35 pub timestamp: u64,
36 pub tx_hash: H256,
37}
38
39#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq, PartialOrd, Ord, Hash)]
40#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
41pub struct ComputationSettingsChangedEvent {
42 pub threshold: u64,
43 pub wvara_per_second: u128,
44}
45
46#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq, PartialOrd, Ord, Hash)]
47#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
48pub struct ProgramCreatedEvent {
49 pub actor_id: ActorId,
50 pub code_id: CodeId,
51}
52
53#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq, PartialOrd, Ord, Hash)]
54#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
55pub struct StorageSlotChangedEvent {
56 pub slot: H256,
57}
58
59#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq, PartialOrd, Ord, Hash)]
60#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
61pub struct ValidatorsCommittedForEraEvent {
62 pub era_index: u64,
63}
64
65#[derive(Clone, Debug, Encode, Decode, TypeInfo, PartialEq, Eq, PartialOrd, Ord, Hash)]
66pub enum Event {
67 BatchCommitted(BatchCommittedEvent),
68 MBCommitted(MBCommittedEvent),
69 EBCommitted(EBCommittedEvent),
70 CodeGotValidated(CodeGotValidatedEvent),
71 CodeValidationRequested(CodeValidationRequestedEvent),
72 ComputationSettingsChanged(ComputationSettingsChangedEvent),
73 ProgramCreated(ProgramCreatedEvent),
74 StorageSlotChanged(StorageSlotChangedEvent),
76 ValidatorsCommittedForEra(ValidatorsCommittedForEraEvent),
77}
78
79impl Event {
80 pub fn to_request(self) -> Option<RequestEvent> {
81 Some(match self {
82 Self::CodeValidationRequested(event) => RequestEvent::CodeValidationRequested(event),
83 Self::ComputationSettingsChanged(event) => {
84 RequestEvent::ComputationSettingsChanged(event)
85 }
86 Self::ProgramCreated(event) => RequestEvent::ProgramCreated(event),
87 Self::StorageSlotChanged(event) => RequestEvent::StorageSlotChanged(event),
88 Self::ValidatorsCommittedForEra(event) => {
89 RequestEvent::ValidatorsCommittedForEra(event)
90 }
91 Self::CodeGotValidated { .. }
92 | Self::MBCommitted(_)
93 | Self::EBCommitted(_)
94 | Self::BatchCommitted { .. } => return None,
95 })
96 }
97}
98
99#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq)]
100#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
101pub enum RequestEvent {
102 CodeValidationRequested(CodeValidationRequestedEvent),
103 ComputationSettingsChanged(ComputationSettingsChangedEvent),
104 ProgramCreated(ProgramCreatedEvent),
105 StorageSlotChanged(StorageSlotChangedEvent),
106 ValidatorsCommittedForEra(ValidatorsCommittedForEraEvent),
107}