Add redeem invite option. TODO: Get bucket
This commit is contained in:
parent
849ca52f89
commit
4140419cb0
37
src/main.rs
37
src/main.rs
|
@ -34,6 +34,12 @@ fn save_object<T: Serialize>(obj: T, filename: &str) {
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let args: Vec<String> = args().collect();
|
let args: Vec<String> = args().collect();
|
||||||
|
|
||||||
|
// files used to store various data
|
||||||
|
let bucket_filename = "bucket.json";
|
||||||
|
let invite_filename = "invite.json";
|
||||||
|
let lox_auth_pubkeys_filename = "lox_auth_pubkeys.json";
|
||||||
|
let lox_cred_filename = "lox_cred.json";
|
||||||
|
|
||||||
let mut opts = Options::new();
|
let mut opts = Options::new();
|
||||||
opts.optflag("h", "help", "print this help menu");
|
opts.optflag("h", "help", "print this help menu");
|
||||||
//#[cfg(test)]
|
//#[cfg(test)]
|
||||||
|
@ -46,6 +52,7 @@ async fn main() {
|
||||||
opts.optflag("I", "invite", "generate invitation for a friend");
|
opts.optflag("I", "invite", "generate invitation for a friend");
|
||||||
opts.optflag("L", "level-up", "increase trust level");
|
opts.optflag("L", "level-up", "increase trust level");
|
||||||
opts.optflag("N", "new-lox-cred", "get a new Lox Credential");
|
opts.optflag("N", "new-lox-cred", "get a new Lox Credential");
|
||||||
|
opts.optflag("R", "redeem", "redeem invitation");
|
||||||
opts.optopt(
|
opts.optopt(
|
||||||
"",
|
"",
|
||||||
"server",
|
"server",
|
||||||
|
@ -84,9 +91,6 @@ async fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Lox Authority public keys
|
// Get Lox Authority public keys
|
||||||
// TODO: Make this filename configurable
|
|
||||||
let lox_auth_pubkeys_filename = "lox_auth_pubkeys.json";
|
|
||||||
|
|
||||||
let lox_auth_pubkeys: Vec<IssuerPubKey> = if Path::new(lox_auth_pubkeys_filename).exists() {
|
let lox_auth_pubkeys: Vec<IssuerPubKey> = if Path::new(lox_auth_pubkeys_filename).exists() {
|
||||||
// read in file
|
// read in file
|
||||||
let lox_auth_pubkeys_infile = File::open(lox_auth_pubkeys_filename).unwrap();
|
let lox_auth_pubkeys_infile = File::open(lox_auth_pubkeys_filename).unwrap();
|
||||||
|
@ -99,10 +103,26 @@ async fn main() {
|
||||||
pubkeys
|
pubkeys
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get Lox Credential and BridgeLine
|
// Get Lox Credential and Bucket
|
||||||
let lox_cred_filename = "lox_cred.json";
|
let (lox_cred, bucket) = if matches.opt_present("R") && Path::new(invite_filename).exists() {
|
||||||
let bucket_filename = "bucket.json";
|
// redeem invite
|
||||||
let (lox_cred, bucket) = if matches.opt_present("N")
|
let invite_infile = File::open(invite_filename).unwrap();
|
||||||
|
let invite = serde_json::from_reader(invite_infile).unwrap();
|
||||||
|
let cred = redeem_invite(
|
||||||
|
&net,
|
||||||
|
&invite,
|
||||||
|
get_lox_pub(&lox_auth_pubkeys),
|
||||||
|
get_invitation_pub(&lox_auth_pubkeys),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let bucket = [BridgeLine::default(); MAX_BRIDGES_PER_BUCKET];
|
||||||
|
//TODO: let bucket = get_bucket();
|
||||||
|
|
||||||
|
// save to files for future use
|
||||||
|
save_object(&cred, &lox_cred_filename);
|
||||||
|
save_object(&bucket, &bucket_filename);
|
||||||
|
(cred, bucket)
|
||||||
|
} else if matches.opt_present("N")
|
||||||
|| !Path::new(lox_cred_filename).exists()
|
|| !Path::new(lox_cred_filename).exists()
|
||||||
|| !Path::new(bucket_filename).exists()
|
|| !Path::new(bucket_filename).exists()
|
||||||
{
|
{
|
||||||
|
@ -115,7 +135,7 @@ async fn main() {
|
||||||
// default (zeroed out) bridgelines
|
// default (zeroed out) bridgelines
|
||||||
bucket[0] = bl;
|
bucket[0] = bl;
|
||||||
|
|
||||||
// save to files for next time
|
// save to files for future use
|
||||||
save_object(&cred, &lox_cred_filename);
|
save_object(&cred, &lox_cred_filename);
|
||||||
save_object(&bucket, &bucket_filename);
|
save_object(&bucket, &bucket_filename);
|
||||||
(cred, bucket)
|
(cred, bucket)
|
||||||
|
@ -187,7 +207,6 @@ async fn main() {
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
// TODO: Make this unique per-run (e.g., add timestamp)
|
// TODO: Make this unique per-run (e.g., add timestamp)
|
||||||
let invite_filename = "invite.json";
|
|
||||||
save_object(&invite, &invite_filename);
|
save_object(&invite, &invite_filename);
|
||||||
save_object(&cred, &lox_cred_filename);
|
save_object(&cred, &lox_cred_filename);
|
||||||
println!("Invite saved in {}", &invite_filename);
|
println!("Invite saved in {}", &invite_filename);
|
||||||
|
|
Loading…
Reference in New Issue