2022-10-26 21:38:39 -04:00
|
|
|
use lox::BridgeDb;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Write;
|
2022-11-16 15:45:27 -05:00
|
|
|
use std::path::Path;
|
2022-10-26 21:38:39 -04:00
|
|
|
|
|
|
|
fn main() {
|
2022-11-16 15:45:27 -05:00
|
|
|
let bridgedb_outfile_name = "bridgedb.json";
|
|
|
|
|
|
|
|
// If bridgedb has already been created, recreate it from file.
|
|
|
|
// Otherwise, create new bridgedb.
|
|
|
|
let bridgedb = if Path::new(bridgedb_outfile_name).exists() {
|
|
|
|
// read in file
|
|
|
|
let bridgedb_infile = File::open(bridgedb_outfile_name).unwrap();
|
|
|
|
serde_json::from_reader(bridgedb_infile).unwrap()
|
|
|
|
} else {
|
|
|
|
// create new bridgedb (implicitly generates keys)
|
2022-11-16 17:28:35 -05:00
|
|
|
let bridgedb = BridgeDb::new();
|
|
|
|
|
|
|
|
// output full serialized bridgedb
|
|
|
|
let mut bridgedb_outfile =
|
|
|
|
File::create(bridgedb_outfile_name).expect("Failed to create bridgedb.json");
|
|
|
|
let bridgedb_outfile_json = serde_json::to_string(&bridgedb).unwrap();
|
|
|
|
write!(bridgedb_outfile, "{}", bridgedb_outfile_json)
|
|
|
|
.expect("Failed to write to bridgedb.json");
|
2022-10-26 21:38:39 -04:00
|
|
|
|
2022-11-16 17:28:35 -05:00
|
|
|
// output bridgedb public key
|
|
|
|
let mut bridgedb_pubkey_outfile =
|
|
|
|
File::create("bridgedb_pubkey.json").expect("Failed to create bridgedb_pubkey.json");
|
|
|
|
write!(
|
|
|
|
bridgedb_pubkey_outfile,
|
|
|
|
"{}",
|
|
|
|
serde_json::to_string(&bridgedb.pubkey).unwrap()
|
|
|
|
)
|
|
|
|
.expect("Failed to write to bridgedb_pubkey.json");
|
2022-11-14 14:30:38 -05:00
|
|
|
|
2022-11-16 17:28:35 -05:00
|
|
|
// return bridgedb
|
|
|
|
bridgedb
|
|
|
|
};
|
2022-10-26 21:38:39 -04:00
|
|
|
}
|