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
use serde::Deserialize;
use std::error::Error;
use std::io;
use std::process;
#[derive(Debug, Deserialize)]
struct ValidatorRecord {
id: u64,
tokens: f64,
adjective: String,
noun: String,
identity_pubkey: String,
vote_pubkey: String,
}
fn parse_csv() -> Result<(), Box<dyn Error>> {
let mut rdr = csv::Reader::from_reader(io::stdin());
for result in rdr.deserialize() {
let record: ValidatorRecord = result?;
println!(
r#"ValidatorInfo {{name: "{adjective} {noun}", node: "{identity_pubkey}", node_sol: {tokens:.1}, vote: "{vote_pubkey}", commission: 0}},"#,
tokens = &record.tokens,
adjective = &record.adjective,
noun = &record.noun,
identity_pubkey = &record.identity_pubkey,
vote_pubkey = &record.vote_pubkey,
);
}
Ok(())
}
fn main() {
if let Err(err) = parse_csv() {
println!("error: {}", err);
process::exit(1);
}
}