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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! Copyright (c) 2022 MASSA LABS <info@massa.net>
//! All the structures that are used everywhere
//!

#![warn(missing_docs)]
#![warn(unused_crate_dependencies)]

use crate::page::PageRequest;
use massa_time::MassaTime;
use serde::{Deserialize, Serialize};

/// address related structures
pub mod address;
/// block-related structures
pub mod block;
/// node configuration
pub mod config;
/// datastore serialization / deserialization
pub mod datastore;
/// endorsements
pub mod endorsement;
/// models error
pub mod error;
/// execution
pub mod execution;
/// ledger structures
pub mod ledger;
/// node related structure
pub mod node;
/// operations
pub mod operation;
/// page
pub mod page;
/// rolls
pub mod rolls;
/// slots
pub mod slot;

/// Dumb utils function to display nicely boolean value
fn display_if_true(value: bool, text: &str) -> String {
    if value {
        format!("[{}]", text)
    } else {
        String::from("")
    }
}

/// Help to format Optional bool
fn display_option_bool(
    value: Option<bool>,
    text_true: &str,
    text_false: &str,
    text_none: &str,
) -> String {
    match value {
        Some(true) => {
            format!("[{}]", text_true)
        }
        Some(false) => {
            format!("[{}]", text_false)
        }
        None => {
            format!("[{}]", text_none)
        }
    }
}

/// Just a wrapper with a optional beginning and end
#[derive(Debug, Deserialize, Clone, Copy, Serialize)]
pub struct TimeInterval {
    /// optional start slot
    pub start: Option<MassaTime>,
    /// optional end slot
    pub end: Option<MassaTime>,
}

/// SCRUD operations
#[derive(strum::Display)]
#[strum(serialize_all = "snake_case")]
pub enum ScrudOperation {
    /// search operation
    Search,
    /// create operation
    Create,
    /// read operation
    Read,
    /// update operation
    Update,
    /// delete operation
    Delete,
}

/// Bootstrap lists types
#[derive(strum::Display)]
#[strum(serialize_all = "snake_case")]
pub enum ListType {
    /// contains banned entry
    Blacklist,
    /// contains allowed entry
    Whitelist,
}

/// Wrap request params into struct for ApiV2 method
#[derive(Deserialize, Serialize)]
pub struct ApiRequest {
    /// pagination
    pub page_request: Option<PageRequest>,
}