fluence_spell_dtos/
trigger_config.rs

1use crate::value::SpellValueT;
2use marine_rs_sdk::marine;
3use serde::{Deserialize, Serialize};
4
5#[marine]
6#[derive(Default, Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
7pub struct TriggerConfigValue {
8    pub config: TriggerConfig,
9    pub success: bool,
10    pub error: String,
11}
12
13impl SpellValueT for TriggerConfigValue {
14    fn is_success(&self) -> bool {
15        self.success
16    }
17
18    fn take_error(self) -> String {
19        self.error
20    }
21}
22
23#[marine]
24#[derive(Default, Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
25pub struct TriggerConfig {
26    /// Trigger spell by clock
27    pub clock: ClockConfig,
28    /// Trigger spell on connect/disconnect events
29    pub connections: ConnectionPoolConfig,
30    /// Trigger spell on blockchain blocks
31    pub blockchain: BlockChainConfig,
32}
33
34#[marine]
35#[derive(Default, Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
36pub struct ClockConfig {
37    /// Defines when to start trigger spell.
38    /// Unix time. 0 means 'do not run'
39    pub start_sec: u32,
40    /// Defines when to stop trigger spell. Will not trigger after that timestamp.
41    /// Unix time. 0 means 'never stop'
42    pub end_sec: u32,
43    /// Defines how often to trigger spell
44    /// 0 means 'do not subscribe'
45    /// NOTE: Subject to host clock resolution limitations.
46    ///       If small period is set, host may override it to a bigger one
47    pub period_sec: u32,
48}
49
50#[marine]
51#[derive(Default, Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
52pub struct BlockChainConfig {
53    /// Defines since what block to start trigger spell
54    /// 0 means 'do not subscribe'
55    /// TODO: what about blocks in the past? will host replay them?
56    pub start_block: u32,
57    /// Defines until what block to keep trigger spell. Will not trigger after that block.
58    /// 0 means 'never stop'
59    pub end_block: u32,
60}
61
62#[marine]
63#[derive(Default, Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
64pub struct ConnectionPoolConfig {
65    /// Defines whether to trigger spell on connect events
66    pub connect: bool,
67    /// Defines whether to trigger spell on disconnect events
68    pub disconnect: bool,
69}