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
use bc_envelope::prelude::*;
use anyhow::{Error, Result};

use crate::{DELETE_ACCOUNT_FUNCTION, util::FlankedFunction};

//
// Request
//

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeleteAccount ();

impl DeleteAccount {
    pub fn new() -> Self {
        Self ()
    }
}

impl Default for DeleteAccount {
    fn default() -> Self {
        Self::new()
    }
}

impl From<DeleteAccount> for Expression {
    fn from(_: DeleteAccount) -> Self {
        Expression::new(DELETE_ACCOUNT_FUNCTION)
    }
}

impl TryFrom<Expression> for DeleteAccount {
    type Error = Error;

    fn try_from(_: Expression) -> Result<Self> {
        Ok(Self::new())
    }
}

impl std::fmt::Display for DeleteAccount {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_fmt(format_args!("{}",
            "deleteAccount".flanked_function(),
        ))
    }
}

#[cfg(test)]
mod tests {
    use indoc::indoc;

    use super::*;

    #[test]
    fn test_request() {
        let request = DeleteAccount::new();
        let expression: Expression = request.clone().into();
        let request_envelope = expression.to_envelope();

        // println!("{}", request_envelope.format());
        assert_eq!(request_envelope.format(),
        indoc! {r#"
        «"deleteAccount"»
        "#}.trim());
        let decoded_expression = Expression::try_from(request_envelope).unwrap();
        let decoded = DeleteAccount::try_from(decoded_expression).unwrap();
        assert_eq!(request, decoded);
    }
}