Remove time manipulation and other fmt fixes

This commit is contained in:
onyinyang 2023-11-21 18:41:53 -05:00
parent fdde186c92
commit 88a865d04c
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
2 changed files with 15 additions and 57 deletions

View File

@ -1,4 +1,3 @@
use std::fs::OpenOptions;
use std::sync::{Arc, Mutex};
use crate::metrics::Metrics;

View File

@ -1,11 +1,10 @@
use chrono::{Duration, Utc};
use chrono::Utc;
use julianday::JulianDay;
use lox_library::cred::{Invitation, Lox, Migration};
use lox_library::cred::{Invitation, Migration};
use lox_library::proto::{
blockage_migration, check_blockage, issue_invite, level_up, migration, open_invite,
redeem_invite, trust_promotion,
};
use lox_library::scalar_u32;
use std::panic;
use wasm_bindgen::prelude::*;
@ -15,26 +14,6 @@ fn today() -> u32 {
JulianDay::from(naive_now).inner().try_into().unwrap()
}
// This should only be used for testing, use today in production
fn test_today(days: i64) -> u32 {
let naive_now_plus = (Utc::now() + Duration::days(days)).date_naive();
JulianDay::from(naive_now_plus).inner().try_into().unwrap()
}
fn calc_test_days(lox_cred: &Lox) -> Result<i64, String> {
let trust_level: i64 = match scalar_u32(&lox_cred.trust_level) {
Some(v) => v as i64,
None => return Err("Error: Trust level does not exist".to_string()),
};
let mut total = 31;
// for level in 0..trust_level {
// let level_interval: u32 = LEVEL_INTERVAL[trust_level as usize];
// total += level_interval;
total += trust_level * 85;
// }
Ok(total)
}
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
@ -105,15 +84,8 @@ pub fn handle_new_lox_credential(
pub fn trust_promotion(open_lox_cred: String, lox_pub: String) -> Result<String, JsValue> {
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&open_lox_cred).unwrap();
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
// To test creation of the credential we need to advance the day to 30
// in production this should just use the today() function
log(&format!(
"TEST ONLY: Add 31 days to today's date: {}",
test_today(31)
));
let tp_result =
//CHANGE add_today(31) to today() for production
match trust_promotion::request(&lox_cred.lox_credential, &pubkeys.lox_pub, test_today(31)) {
match trust_promotion::request(&lox_cred.lox_credential, &pubkeys.lox_pub, today()) {
Ok(tp_result) => tp_result,
Err(e) => {
log(&format!("Error: {:?}", e.to_string()));
@ -229,32 +201,19 @@ pub fn level_up(
let reach_cred =
lox_utils::generate_reachability_cred(&lox_cred.lox_credential, encrypted_table);
// To test level up of the credential we need to advance the day to the correct interval
// In this case, the maximum of 85 can be used to test all level ups
// in production this should just use the today() function
// decrypt trust level and use to calculate the correct date for now
// The trust level has to be at least 1
let test_cumulative_days = match calc_test_days(&lox_cred.lox_credential) {
Ok(v) => v,
let lu_result = match level_up::request(
&lox_cred.lox_credential,
&reach_cred,
&pubkeys.lox_pub,
&pubkeys.reachability_pub,
today(),
) {
Ok(lu_result) => lu_result,
Err(e) => {
log(&format!("Error: {:?}", e));
return Err(JsValue::from(e));
log(&format!("Error: {:?}", e.to_string()));
return Err(JsValue::from(e.to_string()));
}
};
log(&format!(
"TEST ONLY: Add 31 (open invitation) + Trust Level*85 days to today's date: {}",
test_today(test_cumulative_days)
));
let lu_result =
//CHANGE add_today(31) to today() for production
match level_up::request(&lox_cred.lox_credential, &reach_cred, &pubkeys.lox_pub, &pubkeys.reachability_pub, test_today(test_cumulative_days)) {
Ok(lu_result) => lu_result,
Err(e) => {
log(&format!("Error: {:?}", e.to_string()));
return Err(JsValue::from(e.to_string()));
}
};
let req_state = lox_utils::LevelupReqState {
request: lu_result.0,
state: lu_result.1,
@ -314,7 +273,7 @@ pub fn issue_invite(
&reach_cred,
&pubkeys.lox_pub,
&pubkeys.reachability_pub,
test_today(371),
today(),
) {
Ok(issue_result) => issue_result,
Err(e) => {
@ -386,7 +345,7 @@ pub fn redeem_invite(invitation: String, lox_pub: String) -> Result<String, JsVa
let invitation_cred: Invitation = serde_json::from_str(&invitation).unwrap();
let pubkeys: lox_utils::PubKeys = serde_json::from_str(&lox_pub).unwrap();
let redeem_result =
match redeem_invite::request(&invitation_cred, &pubkeys.invitation_pub, test_today(371)) {
match redeem_invite::request(&invitation_cred, &pubkeys.invitation_pub, today()) {
Ok(redeem_result) => redeem_result,
Err(e) => {
log(&format!("Error: {:?}", e.to_string()));