Handle request and state more reasonably

This commit is contained in:
onyinyang 2023-01-26 14:16:41 -05:00
parent a2e329ddf5
commit d0388c841a
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
2 changed files with 14 additions and 5 deletions

View File

@ -13,6 +13,7 @@ crate-type = ["cdylib"]
lox = { git = "https://gitlab.torproject.org/onyinyang/lox.git", branch = "master" } lox = { git = "https://gitlab.torproject.org/onyinyang/lox.git", branch = "master" }
wasm-bindgen = "0.2" wasm-bindgen = "0.2"
serde_json = "1.0.87" serde_json = "1.0.87"
serde = "1"
serde-wasm-bindgen = "0.4.5" serde-wasm-bindgen = "0.4.5"
console_error_panic_hook = "0.1.7" console_error_panic_hook = "0.1.7"

View File

@ -2,11 +2,18 @@ use lox::bridge_table::BridgeLine;
use lox::proto::open_invite; use lox::proto::open_invite;
use lox::{IssuerPubKey, OPENINV_LENGTH}; use lox::{IssuerPubKey, OPENINV_LENGTH};
use serde_json; use serde_json;
use serde::{Deserialize,Serialize};
//use serde_wasm_bindgen; //use serde_wasm_bindgen;
use std::array::TryFromSliceError; use std::array::TryFromSliceError;
use std::panic; use std::panic;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
#[derive(Debug,Deserialize, Serialize)]
struct ReqState {
request: String,
state: String,
}
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(js_namespace = console)] #[wasm_bindgen(js_namespace = console)]
@ -28,16 +35,17 @@ pub fn open_invite(invite: &[u8]) -> Result<String, JsValue> {
Err(e) => return Err(JsValue::from(e.to_string())), Err(e) => return Err(JsValue::from(e.to_string())),
}; };
let (request, state) = open_invite::request(&token); let (request, state) = open_invite::request(&token);
let serialized_request = serde_json::to_string(&request).unwrap(); let req_state = ReqState {
let serialized_state = serde_json::to_string(&state).unwrap(); request: serde_json::to_string(&request).unwrap(),
state: serde_json::to_string(&state).unwrap(),
};
unsafe { unsafe {
log(&format!( log(&format!(
"Formatted open invite request: {}", "Formatted open invite request: {}",
serialized_request serde_json::to_string(&req_state).unwrap()
)); ));
} }
let open_lox_result = concat_string(serialized_request, serialized_state); Ok(serde_json::to_string(&req_state).unwrap())
Ok(open_lox_result)
} }
fn concat_string(request: String, state: String) -> String { fn concat_string(request: String, state: String) -> String {