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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
mod block;
mod message;
mod node;
mod utxo;
mod vote;

use crate::jcli::command::TransactionCommand;
pub use block::BlockCommand;
pub use message::MessageCommand;
pub use node::NodeCommand;
use std::process::Command;
pub use utxo::UtxOCommand;
pub use vote::VoteCommand;

pub struct V0Command {
    command: Command,
}

impl V0Command {
    pub fn new(command: Command) -> Self {
        Self { command }
    }

    pub fn node(mut self) -> NodeCommand {
        self.command.arg("node");
        NodeCommand::new(self.command)
    }

    pub fn utxo(mut self) -> UtxOCommand {
        self.command.arg("utxo");
        UtxOCommand::new(self.command)
    }

    pub fn message(mut self) -> MessageCommand {
        self.command.arg("message");
        MessageCommand::new(self.command)
    }

    pub fn block(mut self) -> BlockCommand {
        self.command.arg("block");
        BlockCommand::new(self.command)
    }

    pub fn vote(mut self) -> VoteCommand {
        self.command.arg("vote");
        VoteCommand::new(self.command)
    }

    pub fn transaction(mut self) -> TransactionCommand {
        self.command.arg("transaction");
        TransactionCommand::new(self.command)
    }

    pub fn leadership_log<S: Into<String>>(mut self, host: S) -> Self {
        self.command
            .arg("leaders")
            .arg("logs")
            .arg("get")
            .arg("--host")
            .arg(host.into());
        self
    }

    pub fn tip<S: Into<String>>(mut self, host: S) -> Self {
        self.command
            .arg("tip")
            .arg("get")
            .arg("--host")
            .arg(host.into());
        self
    }

    pub fn account_stats<S: Into<String>, P: Into<String>>(mut self, address: S, host: P) -> Self {
        self.command
            .arg("account")
            .arg("get")
            .arg(address.into())
            .arg("--host")
            .arg(host.into());
        self
    }

    pub fn shutdown<S: Into<String>>(mut self, host: S) -> Self {
        self.command
            .arg("shutdown")
            .arg("post")
            .arg("--host")
            .arg(host.into());
        self
    }

    pub fn settings<S: Into<String>>(mut self, host: S) -> Self {
        self.command
            .arg("settings")
            .arg("get")
            .arg("--host")
            .arg(host.into());
        self
    }

    pub fn stake_pools<S: Into<String>>(mut self, host: S) -> Self {
        self.command
            .arg("stake-pools")
            .arg("get")
            .arg("--host")
            .arg(host.into());
        self
    }

    pub fn stake_pool<S: Into<String>, P: Into<String>>(
        mut self,
        stake_pool_id: S,
        host: P,
    ) -> Self {
        self.command
            .arg("stake-pool")
            .arg("get")
            .arg(stake_pool_id.into())
            .arg("--host")
            .arg(host.into());
        self
    }

    pub fn build(self) -> Command {
        println!("{:?}", self.command);
        self.command
    }
}