patch prepare msig orchestration jwp injection

This commit is contained in:
creating2morrow 2023-07-14 09:29:40 -04:00
parent f82c92769a
commit 87847ad01d
3 changed files with 28 additions and 8 deletions

View file

@ -49,7 +49,7 @@
* the `check status` button will show current jwp for each contact
* `clear stale jwp` will purge data in case of timeout issues
* don't keep large amounts in neveko just enough for fees and jwps
* once a valid jwp is created (takes a few minutes) the `compose` button will be visible
* once a valid jwp is created (takes a few seconds) the `compose` button will be visible
* you need to click `check status` on contacts before sending to refresh jwp expiration check
* draft a plain text message, dont be shy
* verify recipient (.b32.i2p address) and press `send`

View file

@ -116,6 +116,11 @@ pub fn encrypt(name: String, body: &Vec<u8>) -> Result<Vec<u8>, Box<dyn Error>>
}
pub fn decrypt(mid: &String, body: &Vec<u8>) -> Result<Vec<u8>, Box<dyn Error>> {
// bad things will happen if we get empty bytes
if body.is_empty() {
log::error!("no bytes to decrypt");
return Ok(Vec::new());
}
let proto = Protocol::OpenPgp;
let mut ctx = Context::from_protocol(proto)?;
ctx.set_armor(true);

View file

@ -229,7 +229,6 @@ impl eframe::App for MarketApp {
}
}
// TODO(c2m): extract from db after initialization
if let Ok(our_prepare_info) = self.our_prepare_info_rx.try_recv() {
self.msig.prepare_info = our_prepare_info;
self.is_loading = false;
@ -349,7 +348,6 @@ impl eframe::App for MarketApp {
send_prepare_info_req(
self.our_prepare_info_tx.clone(),
ctx.clone(),
self.vendor_status.jwp.clone(),
mediator,
&self.m_order.orid.clone(),
vendor,
@ -1266,19 +1264,36 @@ fn submit_order_req(
fn send_prepare_info_req(
tx: Sender<String>,
ctx: egui::Context,
jwp: String,
mediator: String,
orid: &String,
vendor: String,
) {
let m_orid: String = String::from(orid);
let v_orid: String = String::from(orid);
let w_orid: String = String::from(orid);
tokio::spawn(async move {
let m_jwp: String = utils::search_gui_db(
String::from(crate::GUI_JWP_DB_KEY),
String::from(&mediator),
);
let v_jwp: String = utils::search_gui_db(
String::from(crate::GUI_JWP_DB_KEY),
String::from(&vendor),
);
let wallet_password =
std::env::var(neveko_core::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password"));
monero::create_wallet(&w_orid, &wallet_password).await;
let m_wallet = monero::open_wallet(&w_orid, &wallet_password).await;
if !m_wallet {
log::error!("failed to open wallet");
return;
}
let prepare_info = monero::prepare_wallet().await;
monero::close_wallet(&w_orid, &wallet_password).await;
let ref_prepare_info: &String = &prepare_info.result.multisig_info;
utils::write_gui_db(
String::from(crate::GUI_MSIG_PREPARE_DB_KEY),
utils::empty_string(),
String::from(&w_orid),
String::from(ref_prepare_info),
);
// Request mediator and vendor while we're at it
@ -1291,15 +1306,15 @@ fn send_prepare_info_req(
msig_type: String::from(message::PREPARE_MSIG),
orid: String::from(v_orid),
};
let _v_result = message::d_trigger_msig_info(&vendor, &jwp, &v_msig_request).await;
let _v_result = message::d_trigger_msig_info(&vendor, &v_jwp, &v_msig_request).await;
let m_msig_request: reqres::MultisigInfoRequest = reqres::MultisigInfoRequest {
contact: i2p::get_destination(None),
info: Vec::new(),
init_mediator: false,
init_mediator: true,
msig_type: String::from(message::PREPARE_MSIG),
orid: String::from(m_orid),
};
let _m_result = message::d_trigger_msig_info(&mediator, &jwp, &m_msig_request).await;
let _m_result = message::d_trigger_msig_info(&mediator, &m_jwp, &m_msig_request).await;
let _ = tx.send(String::from(ref_prepare_info));
});
ctx.request_repaint();