Handle inviting friends
This commit is contained in:
parent
c17333e5c0
commit
849ca52f89
32
src/main.rs
32
src/main.rs
|
@ -8,6 +8,7 @@ use curve25519_dalek::scalar::Scalar;
|
|||
use getopts::Options;
|
||||
use lox_library::bridge_table::BridgeLine;
|
||||
use lox_library::bridge_table::MAX_BRIDGES_PER_BUCKET;
|
||||
use lox_library::scalar_u32;
|
||||
use lox_library::IssuerPubKey;
|
||||
use serde::Serialize;
|
||||
use std::env::args;
|
||||
|
@ -42,6 +43,7 @@ async fn main() {
|
|||
"increase server days by NUM_DAYS",
|
||||
"NUM_DAYS",
|
||||
);
|
||||
opts.optflag("I", "invite", "generate invitation for a friend");
|
||||
opts.optflag("L", "level-up", "increase trust level");
|
||||
opts.optflag("N", "new-lox-cred", "get a new Lox Credential");
|
||||
opts.optopt(
|
||||
|
@ -171,4 +173,34 @@ async fn main() {
|
|||
} else {
|
||||
lox_cred
|
||||
};
|
||||
|
||||
// Invite a friend
|
||||
let lox_cred = if matches.opt_present("I") {
|
||||
if scalar_u32(&lox_cred.invites_remaining).unwrap() > 0 {
|
||||
let (cred, invite) = issue_invite(
|
||||
&net,
|
||||
&lox_cred,
|
||||
&get_reachability_credential(&net).await,
|
||||
get_lox_pub(&lox_auth_pubkeys),
|
||||
get_reachability_pub(&lox_auth_pubkeys),
|
||||
get_invitation_pub(&lox_auth_pubkeys),
|
||||
)
|
||||
.await;
|
||||
// TODO: Make this unique per-run (e.g., add timestamp)
|
||||
let invite_filename = "invite.json";
|
||||
save_object(&invite, &invite_filename);
|
||||
save_object(&cred, &lox_cred_filename);
|
||||
println!("Invite saved in {}", &invite_filename);
|
||||
println!(
|
||||
"Invites left: {}",
|
||||
scalar_u32(&cred.invites_remaining).unwrap()
|
||||
);
|
||||
cred
|
||||
} else {
|
||||
println!("No invites left");
|
||||
lox_cred
|
||||
}
|
||||
} else {
|
||||
lox_cred
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue