Make wasm getter functions return Result
This commit is contained in:
parent
c8b6bb9fdd
commit
364b55dc4c
|
@ -509,7 +509,7 @@ pub fn handle_blockage_migration(
|
|||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_last_upgrade_time(lox_cred_str: String) -> String {
|
||||
pub fn get_last_upgrade_time(lox_cred_str: String) -> Result<String, JsValue> {
|
||||
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
|
||||
let upgrade_date = scalar_u32(&lox_cred.lox_credential.level_since).unwrap();
|
||||
let date_time = JulianDay::new(upgrade_date as i32).to_date();
|
||||
|
@ -517,33 +517,42 @@ pub fn get_last_upgrade_time(lox_cred_str: String) -> String {
|
|||
"Time of last upgrade {}",
|
||||
serde_json::to_string(&date_time).unwrap()
|
||||
));
|
||||
serde_json::to_string(&date_time).unwrap()
|
||||
match serde_json::to_string(&date_time) {
|
||||
Ok(date_str) => Ok(date_str),
|
||||
Err(e) => Err(JsValue::from(e.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_trust_level(lox_cred_str: String) -> String {
|
||||
pub fn get_trust_level(lox_cred_str: String) -> Result<String, JsValue> {
|
||||
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
|
||||
let trust_level = scalar_u32(&lox_cred.lox_credential.trust_level).unwrap();
|
||||
log(&format!(
|
||||
"Trust level {}",
|
||||
serde_json::to_string(&trust_level).unwrap()
|
||||
));
|
||||
serde_json::to_string(&trust_level).unwrap()
|
||||
match serde_json::to_string(&trust_level) {
|
||||
Ok(trust_str) => Ok(trust_str),
|
||||
Err(e) => Err(JsValue::from(e.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_invites_remaining(lox_cred_str: String) -> String {
|
||||
pub fn get_invites_remaining(lox_cred_str: String) -> Result<String, JsValue> {
|
||||
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
|
||||
let invites = scalar_u32(&lox_cred.lox_credential.invites_remaining);
|
||||
log(&format!(
|
||||
"Invites remaining {}",
|
||||
serde_json::to_string(&invites).unwrap()
|
||||
));
|
||||
serde_json::to_string(&invites).unwrap()
|
||||
match serde_json::to_string(&invites) {
|
||||
Ok(invite_str) => Ok(invite_str),
|
||||
Err(e) => Err(JsValue::from(e.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_issued_invite_expiry(lox_cred_str: String) -> String {
|
||||
pub fn get_issued_invite_expiry(lox_cred_str: String) -> Result<String, JsValue> {
|
||||
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
|
||||
match lox_cred.invitation {
|
||||
Some(invitation) => {
|
||||
|
@ -554,14 +563,18 @@ pub fn get_issued_invite_expiry(lox_cred_str: String) -> String {
|
|||
"Invitation Expiry {}",
|
||||
serde_json::to_string(&date_time).unwrap()
|
||||
));
|
||||
serde_json::to_string(&date_time).unwrap()
|
||||
let inv_date_str = match serde_json::to_string(&date_time) {
|
||||
Ok(inv_date_str) => Ok(inv_date_str),
|
||||
Err(e) => Err(JsValue::from(e.to_string())),
|
||||
};
|
||||
inv_date_str
|
||||
}
|
||||
None => serde_json::to_string("No Invitation Issued").unwrap(),
|
||||
None => Err(JsValue::from("No Invitation Issued")),
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_received_invite_expiry(invite_cred_str: String) -> String {
|
||||
pub fn get_received_invite_expiry(invite_cred_str: String) -> Result<String, JsValue> {
|
||||
let invite_cred: lox_utils::IssuedInvitation = serde_json::from_str(&invite_cred_str).unwrap();
|
||||
let expiry = (scalar_u32(&invite_cred.invitation.date).unwrap() + 15) as i32;
|
||||
let date_time = JulianDay::new(expiry).to_date();
|
||||
|
@ -570,11 +583,17 @@ pub fn get_received_invite_expiry(invite_cred_str: String) -> String {
|
|||
"Invitation Expiry {}",
|
||||
serde_json::to_string(&date_time).unwrap()
|
||||
));
|
||||
serde_json::to_string(&date_time).unwrap()
|
||||
match serde_json::to_string(&date_time) {
|
||||
Ok(date_str) => Ok(date_str),
|
||||
Err(e) => Err(JsValue::from(e.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn get_bridgelines_from_bucket(lox_cred_str: String, encrypted_table: String) -> String {
|
||||
pub fn get_bridgelines_from_bucket(
|
||||
lox_cred_str: String,
|
||||
encrypted_table: String,
|
||||
) -> Result<String, JsValue> {
|
||||
let lox_cred: lox_utils::LoxCredential = serde_json::from_str(&lox_cred_str).unwrap();
|
||||
let bridgelines =
|
||||
lox_utils::get_credential_bridgelines(&lox_cred.lox_credential, encrypted_table);
|
||||
|
@ -582,9 +601,15 @@ pub fn get_bridgelines_from_bucket(lox_cred_str: String, encrypted_table: String
|
|||
"Lox BridgeLines Expiry {}",
|
||||
serde_json::to_string(&bridgelines).unwrap()
|
||||
));
|
||||
serde_json::to_string(&bridgelines).unwrap()
|
||||
match serde_json::to_string(&bridgelines) {
|
||||
Ok(bridgelines_str) => Ok(bridgelines_str),
|
||||
Err(e) => Err(JsValue::from(e.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_constants() -> String {
|
||||
serde_json::to_string(&lox_utils::LOX_SYSTEM_INFO).unwrap()
|
||||
pub fn get_constants() -> Result<String, JsValue> {
|
||||
match serde_json::to_string(&lox_utils::LOX_SYSTEM_INFO) {
|
||||
Ok(system_info_str) => Ok(system_info_str),
|
||||
Err(e) => Err(JsValue::from(e.to_string())),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue