-
Notifications
You must be signed in to change notification settings - Fork 39
/
cli.rs
218 lines (209 loc) · 7.77 KB
/
cli.rs
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
use clap::{Parser, Subcommand};
use simperby_core::*;
/**
Welcome to the Simperby CLI!
*/
#[derive(Debug, Parser)]
#[clap(name = "simperby")]
#[clap(about = "A Simperby client CLI", long_about = None)]
pub struct Cli {
pub path: std::path::PathBuf,
#[clap(subcommand)]
pub command: Commands,
}
#[derive(Debug, Subcommand)]
pub enum CreateCommands {
/// An extra-agenda transaction that delegates the consensus voting power.
TxDelegate {
delegator: String,
delegatee: String,
/// Whether to delegate the governance voting power too.
governance: bool,
block_height: BlockHeight,
proof: String,
chain_name: String,
},
/// An extra-agenda transaction that undelegates the consensus voting power and
/// the governance voting power (if delegated).
TxUndelegate {
delegator: String,
block_height: BlockHeight,
proof: String,
chain_name: String,
},
/// An extra-agenda transaction that reports a misbehaving validator.
TxReport, // TODO
/// A block waiting for finalization.
Block,
/// An agenda waiting for governance approval.
Agenda,
}
#[derive(Debug, Subcommand)]
pub enum PeerCommands {
/// Add a peer with the given name and address.
Add { name: String, address: String },
/// Remove the peer with the given name.
Remove { name: String },
/// Updates the peer list using the peer discovery protocol.
/// This may leave some remote repositories with the prefix `>`.
Update,
/// Prints the status of the discovered peers.
Status,
}
#[derive(Debug, Subcommand)]
pub enum SignCommands {
TxDelegate {
delegator: MemberName,
delegatee: MemberName,
/// Whether to delegate the governance voting power too.
governance: bool,
target_height: u64,
chain_name: String,
},
TxUndelegate {
delegator: MemberName,
target_height: u64,
chain_name: String,
},
Custom {
hash: String,
},
}
#[derive(Debug, Subcommand)]
pub enum Commands {
// ----- Initialization Commands ----- //
/// Create a genesis commit and initialize a Simberby repository
/// from the given existing Git repository.
///
/// This will seek the reserved state, verify it, and add a genesis commit.
/// You have to run `init` after this to initialize the Simperby node.
Genesis,
/// Initialize a new Simperby node from the given existing Simperby repository.
Init,
/// Clone a remote Simperby repository to the current directory,
/// and initialize a new Simperby node after verification.
///
/// This is same as `git clone && cd <directory> && simperby init`.
Clone {
/// The URL of the remote repository.
url: String,
},
// ----- Modification Commands ----- //
/// Clean the repository, removing all the outdated (incompatible with `finalized`) commits.
Clean {
/// If enabled, it will remove
/// 1. all branches except `finalized` and `fp`
/// 2. all remote repositories
/// 3. all orphan commits
#[clap(long, action)]
hard: bool,
},
/// Create a new commit on top of the HEAD.
#[command(subcommand)]
Create(CreateCommands),
/// Vote on the agenda, broadcasting to the network.
/// It will also leave a `vote` tag on the given commit (with some postfix).
Vote { revision: String },
/// Veto the round.
///
/// It will be broadcasted to the network as a nil-vote
/// in the next `consensus`, if the conditions are met.
/// You can check whether the round is vetoed by running `consensus --show`.
Veto {
/// If specified, it vetoes a specific block proposal,
/// leaving a `veto` tag on the given commit (with some postfix).
/// It fails if the commit is already set to `proposal`.
/// If the commit is already set to `veto`, it will be removed.
revision: Option<String>,
},
/// Make a progress on the consensus.
Consensus {
/// If enabled, it shows the status of the consensus instead of making a progress.
///
/// Unlike the governance which is performed on each agenda,
/// the consensus is 'global' so this option is not associated with any commit.
#[clap(long, action)]
show: bool,
},
// ----- Information Commands ----- //
/// Show the overall information of the given commit.
Show { revision: String },
/// Show the status of the Simperby repository.
///
/// It checkes the following for the current directory:
///
/// 1. Is it a valid Git repository?
/// 2. Does it contain a valid `.simperby/` directory?
/// 3. Does it have a valid `reserved/` directory and `.gitignore`?
/// 4. Does it have all the protected branches and tags?
/// 5. Does the reserved state at `finalized` branch match the block header?
/// 6. What phase is HEAD in?
/// 7. Does the `fp` branch match the last block header?
/// 8. Isn't your repository behind the latest consensus status? (finalized but not yet received the actual commits)
Status {
/// If enabled, it performs a full verification of the entire history
/// of the chain, starting from the genesis commit.
#[clap(long, action)]
full: bool,
},
// ----- Network Commands ----- //
/// Show the current status of the p2p network.
Network,
/// Manages the peer list for the p2p network.
/// Note that this is independent from the Git remotes.
#[command(subcommand)]
Peer(PeerCommands),
/// Become a server node indefinitely, serving all message propagations and Git requests.
/// This is same as regularly running the `update` and `broadcast` commands.
///
/// You cannot perform any other operations while running this command;
/// you have to run another shell to perform client-side, synchronous operations.
Serve,
/// Update the node state by fetching data from the p2p network,
/// verifying incoming data, and applying to the repository and consensus & governance status.
Update {
/// If enabled, it performs only local updates without fetching data from the network.
///
/// "Local updates" means changes (new commits) that have been manually created or git-fetched by the user.
#[clap(long, action)]
_no_network: bool,
},
/// Broadcast relevant data to the p2p network.
///
/// This may contain
///
/// 1. Newly created commits
/// 2. Consensus progress
/// 3. Governance votes
/// 5. Known peers
/// 6. All of the above, sent from other peers.
Broadcast,
// ----- Miscellaneous Commands ----- //
/// Chat on the P2P network.
Chat {
/// The message to say. If not specified, it prints the chat log.
message: Option<String>,
/// Off-the-Record. If enabled, it will not be recorded on the blockchain.
#[clap(short, long, action)]
otr: bool,
/// Start an interactive chat session.
#[clap(short, long, action)]
interactive: bool,
},
/// Sign a message with the configured private key.
#[command(subcommand)]
Sign(SignCommands),
/// A special command triggered by the Git hook, which is used to verify the push request.
CheckPush {
/// The revision of the branch that is being pushed.
revision: String,
/// The name of the branch that is being pushed.
branch_name: String,
/// The Unix timestamp of the push request. This is for preventing replay attacks.
timestamp: u64,
/// The signature by the pusher.
signature: String,
},
/// A special command triggered by the Git hook, which is used to notify the push request.
NotifyPush { commit: String },
}