run format script

This commit is contained in:
creating2morrow 2023-11-25 07:39:54 -05:00
parent 3612e61bfa
commit 79f526d211
8 changed files with 62 additions and 44 deletions

View file

@ -6,8 +6,9 @@ use crate::{
i2p, i2p,
models::*, models::*,
monero, monero,
order,
reqres, reqres,
utils, order, utils,
}; };
use log::{ use log::{
debug, debug,
@ -597,9 +598,9 @@ pub async fn send_export_info(orid: &String, contact: &String) {
} }
/// The customer or vendor (dispute only) needs to export /// The customer or vendor (dispute only) needs to export
/// ///
/// multisig info after funding. Once the info is imported /// multisig info after funding. Once the info is imported
/// ///
/// successfully the order needs to be updated to `MultisigComplete`. /// successfully the order needs to be updated to `MultisigComplete`.
pub async fn send_import_info(orid: &String, info: &Vec<String>) { pub async fn send_import_info(orid: &String, info: &Vec<String>) {
let wallet_name = String::from(orid); let wallet_name = String::from(orid);

View file

@ -87,6 +87,7 @@ enum RpcFields {
Open, Open,
Prepare, Prepare,
Refresh, Refresh,
Sign,
SignMultisig, SignMultisig,
SubmitMultisig, SubmitMultisig,
SweepAll, SweepAll,
@ -120,6 +121,7 @@ impl RpcFields {
RpcFields::Open => String::from("open_wallet"), RpcFields::Open => String::from("open_wallet"),
RpcFields::Prepare => String::from("prepare_multisig"), RpcFields::Prepare => String::from("prepare_multisig"),
RpcFields::Refresh => String::from("refresh"), RpcFields::Refresh => String::from("refresh"),
RpcFields::Sign => String::from("sign"),
RpcFields::SignMultisig => String::from("sign_multisig"), RpcFields::SignMultisig => String::from("sign_multisig"),
RpcFields::SubmitMultisig => String::from("submit_multisig"), RpcFields::SubmitMultisig => String::from("submit_multisig"),
RpcFields::SweepAll => String::from("sweep_all"), RpcFields::SweepAll => String::from("sweep_all"),
@ -588,7 +590,7 @@ pub async fn close_wallet(filename: &String, password: &String) -> bool {
/// Performs the xmr rpc 'change_wallet_password' method /// Performs the xmr rpc 'change_wallet_password' method
pub async fn change_wallet_password(new_password: &String) -> bool { pub async fn change_wallet_password(new_password: &String) -> bool {
info!("executing {}", RpcFields::ChangeWalletPassword.value()); info!("executing {}", RpcFields::ChangeWalletPassword.value());
let old_password: String = let old_password: String =
std::env::var(crate::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password")); std::env::var(crate::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password"));
let new_password: String = String::from(new_password); let new_password: String = String::from(new_password);
let client = reqwest::Client::new(); let client = reqwest::Client::new();
@ -613,7 +615,11 @@ pub async fn change_wallet_password(new_password: &String) -> bool {
Ok(response) => { Ok(response) => {
// The result from wallet operation is empty // The result from wallet operation is empty
let res = response.text().await; let res = response.text().await;
debug!("{} response: {:?}", RpcFields::ChangeWalletPassword.value(), res); debug!(
"{} response: {:?}",
RpcFields::ChangeWalletPassword.value(),
res
);
match res { match res {
Ok(r) => { Ok(r) => {
if r.contains("-1") { if r.contains("-1") {

View file

@ -8,6 +8,7 @@ use crate::{
message, message,
models::*, models::*,
monero, monero,
order,
product, product,
reqres, reqres,
utils, utils,
@ -192,8 +193,8 @@ pub fn modify(o: Json<Order>) -> Order {
} }
let u_order = Order::update(String::from(&f_order.orid), &o); let u_order = Order::update(String::from(&f_order.orid), &o);
let s = db::Interface::open(); let s = db::Interface::open();
db::Interface::delete(&s.env, &s.handle, &u_order.pid); db::Interface::delete(&s.env, &s.handle, &u_order.orid);
db::Interface::write(&s.env, &s.handle, &u_order.pid, &Order::to_db(&u_order)); db::Interface::write(&s.env, &s.handle, &u_order.orid, &Order::to_db(&u_order));
return u_order; return u_order;
} }
@ -253,26 +254,17 @@ pub async fn validate_order_for_ship(orid: &String) -> bool {
let m_product: Product = product::find(&m_order.pid); let m_product: Product = product::find(&m_order.pid);
let price = m_product.price; let price = m_product.price;
let total = price * m_order.quantity; let total = price * m_order.quantity;
// import multisig info
let s = db::Interface::open();
let key = format!("export-{}-{}", orid, &m_order.cid);
let info_str = db::Interface::async_read(&s.env, &s.handle, &key).await;
let info_split = info_str.split(":");
let v_info: Vec<String> = info_split.map(|s| String::from(s)).collect();
let wallet_password = utils::empty_string(); let wallet_password = utils::empty_string();
monero::open_wallet(&orid, &wallet_password).await; monero::open_wallet(&orid, &wallet_password).await;
let r_import = monero::import_multisig_info(v_info).await;
// check balance and unlock_time // check balance and unlock_time
let r_balance = monero::get_balance().await; let r_balance = monero::get_balance().await;
monero::close_wallet(&orid, &wallet_password).await; monero::close_wallet(&orid, &wallet_password).await;
// update the order status to multisig complete // update the order status to multisig complete
let ready_to_ship: bool = r_import.result.n_outputs > 0 let ready_to_ship: bool = r_balance.result.balance >= total as u128
&& r_balance.result.balance >= total as u128
&& r_balance.result.blocks_to_unlock < monero::LockTimeLimit::Blocks.value(); && r_balance.result.blocks_to_unlock < monero::LockTimeLimit::Blocks.value();
if ready_to_ship { if ready_to_ship {
m_order.status = StatusType::MulitsigComplete.value(); m_order.status = StatusType::Shipped.value();
db::Interface::async_delete(&s.env, &s.handle, &m_order.orid).await; order::modify(Json(m_order));
db::Interface::async_write(&s.env, &s.handle, &m_order.orid, &Order::to_db(&m_order)).await;
} }
ready_to_ship ready_to_ship
} }

View file

@ -537,7 +537,7 @@ pub struct XmrRpcIsMultisigResult {
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
pub struct XmrRpcGetHeightResult { pub struct XmrRpcGetHeightResult {
pub height: u64 pub height: u64,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -1132,9 +1132,7 @@ pub struct XmrRpcGetHeightResponse {
impl Default for XmrRpcGetHeightResponse { impl Default for XmrRpcGetHeightResponse {
fn default() -> Self { fn default() -> Self {
XmrRpcGetHeightResponse { XmrRpcGetHeightResponse {
result: XmrRpcGetHeightResult { result: XmrRpcGetHeightResult { height: 0 },
height: 0,
},
} }
} }
} }

View file

@ -266,7 +266,8 @@ impl eframe::App for AddressBookApp {
ui.label(format!("amount: {} piconero(s)", amount)); ui.label(format!("amount: {} piconero(s)", amount));
ui.label(format!("expiration: {} blocks", expire)); ui.label(format!("expiration: {} blocks", expire));
let show_approve = self.s_invoice.address != utils::empty_string() let show_approve = self.s_invoice.address != utils::empty_string()
&& self.can_transfer && !self.is_estimating_fee; && self.can_transfer
&& !self.is_estimating_fee;
if !self.is_loading { if !self.is_loading {
if show_approve { if show_approve {
if ui.button("Approve").clicked() { if ui.button("Approve").clicked() {

View file

@ -13,6 +13,7 @@ pub struct MultisigManagement {
pub completed_export: bool, pub completed_export: bool,
pub completed_funding: bool, pub completed_funding: bool,
pub completed_prepare: bool, pub completed_prepare: bool,
pub completed_shipping_request: bool,
pub completed_make: bool, pub completed_make: bool,
pub exchange_multisig_keys: String, pub exchange_multisig_keys: String,
pub export_info: String, pub export_info: String,
@ -33,6 +34,7 @@ impl Default for MultisigManagement {
completed_export: false, completed_export: false,
completed_funding: false, completed_funding: false,
completed_prepare: false, completed_prepare: false,
completed_shipping_request: false,
completed_make: false, completed_make: false,
exchange_multisig_keys: utils::empty_string(), exchange_multisig_keys: utils::empty_string(),
export_info: utils::empty_string(), export_info: utils::empty_string(),
@ -291,7 +293,7 @@ impl eframe::App for MarketApp {
self.msig.completed_funding = funded; self.msig.completed_funding = funded;
self.is_loading = false; self.is_loading = false;
} }
// Vendor status window // Vendor status window
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
let mut is_showing_vendor_status = self.is_showing_vendor_status; let mut is_showing_vendor_status = self.is_showing_vendor_status;
@ -394,6 +396,7 @@ impl eframe::App for MarketApp {
} }
} }
}); });
// msig mgmt gaurds
if !self.msig.completed_prepare { if !self.msig.completed_prepare {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("Prepare: \t\t\t\t\t"); ui.label("Prepare: \t\t\t\t\t");
@ -572,7 +575,7 @@ impl eframe::App for MarketApp {
&contact, &contact,
&self.m_order.orid, &self.m_order.orid,
self.order_funded_tx.clone(), self.order_funded_tx.clone(),
ctx.clone() ctx.clone(),
) )
} }
}); });
@ -586,7 +589,8 @@ impl eframe::App for MarketApp {
let vendor = let vendor =
utils::search_gui_db(vendor_prefix, self.m_order.orid.clone()); utils::search_gui_db(vendor_prefix, self.m_order.orid.clone());
// not much orchestration here afaik, just send the output to the vendor // not much orchestration here afaik, just send the output to the vendor
// TODO(c2m): 'idk remember why this tx.clone() is being reused' but not nothing breaks for now... // TODO(c2m): 'idk remember why this tx.clone() is being reused' but not
// nothing breaks for now...
send_import_info_req( send_import_info_req(
self.our_make_info_tx.clone(), self.our_make_info_tx.clone(),
ctx.clone(), ctx.clone(),
@ -605,6 +609,19 @@ impl eframe::App for MarketApp {
} }
}); });
} }
// TODO: implement SOR (secure order retrieval) validate order is MultisigComplete
// cache the new order and then implement the async shipping request
// use SOR to cache the order and validate order is status Shipped
// also the sign api is missing hahaha
if self.msig.completed_export && !self.msig.completed_shipping_request {
ui.horizontal(|ui| {
ui.label("Request Shipping: \t");
if ui.button("Send").clicked() {}
if ui.button("Check").clicked() {}
});
}
// ui.horizontal(|ui| { // ui.horizontal(|ui| {
// ui.label("Release Payment: \t"); // ui.label("Release Payment: \t");
// if ui.button("Sign Txset").clicked() {} // if ui.button("Sign Txset").clicked() {}
@ -750,8 +767,7 @@ impl eframe::App for MarketApp {
ui.label("loading..."); ui.label("loading...");
} }
let mediator_prefix = String::from(crate::GUI_MSIG_MEDIATOR_DB_KEY); let mediator_prefix = String::from(crate::GUI_MSIG_MEDIATOR_DB_KEY);
let mediator = let mediator = utils::search_gui_db(mediator_prefix, self.m_order.orid.clone());
utils::search_gui_db(mediator_prefix, self.m_order.orid.clone());
ui.label(format!("customer id: {}", self.new_order.cid)); ui.label(format!("customer id: {}", self.new_order.cid));
ui.label(format!("mediator id: {}", mediator)); ui.label(format!("mediator id: {}", mediator));
ui.label(format!("product id: {}", self.new_order.pid)); ui.label(format!("product id: {}", self.new_order.pid));
@ -2001,7 +2017,12 @@ fn set_order_address(orid: &String, tx: Sender<reqres::XmrRpcAddressResponse>, c
}); });
} }
fn verify_order_wallet_funded(contact: &String, orid: &String, tx: Sender<bool>, ctx: egui::Context) { fn verify_order_wallet_funded(
contact: &String,
orid: &String,
tx: Sender<bool>,
ctx: egui::Context,
) {
let order_id = String::from(orid); let order_id = String::from(orid);
let l_contact = String::from(contact); let l_contact = String::from(contact);
tokio::spawn(async move { tokio::spawn(async move {
@ -2037,12 +2058,7 @@ fn verify_order_wallet_funded(contact: &String, orid: &String, tx: Sender<bool>,
}); });
} }
fn send_import_info_req( fn send_import_info_req(tx: Sender<String>, ctx: egui::Context, orid: &String, vendor: String) {
tx: Sender<String>,
ctx: egui::Context,
orid: &String,
vendor: String,
) {
let v_orid: String = String::from(orid); let v_orid: String = String::from(orid);
let w_orid: String = String::from(orid); let w_orid: String = String::from(orid);
tokio::spawn(async move { tokio::spawn(async move {
@ -2076,10 +2092,7 @@ fn send_import_info_req(
); );
let v_export = db::Interface::async_read(&s.env, &s.handle, &v_msig_key).await; let v_export = db::Interface::async_read(&s.env, &s.handle, &v_msig_key).await;
if v_export == utils::empty_string() { if v_export == utils::empty_string() {
log::debug!( log::debug!("constructing vendor {} msig messages", message::EXPORT_MSIG);
"constructing vendor {} msig messages",
message::EXPORT_MSIG
);
let v_msig_request: reqres::MultisigInfoRequest = reqres::MultisigInfoRequest { let v_msig_request: reqres::MultisigInfoRequest = reqres::MultisigInfoRequest {
contact: i2p::get_destination(None), contact: i2p::get_destination(None),
info, info,

View file

@ -3,7 +3,10 @@ use sha2::{
Digest, Digest,
Sha512, Sha512,
}; };
use std::sync::mpsc::{Receiver, Sender}; use std::sync::mpsc::{
Receiver,
Sender,
};
use crate::CREDENTIAL_KEY; use crate::CREDENTIAL_KEY;
@ -68,7 +71,11 @@ impl eframe::App for SettingsApp {
let result = hasher.finalize(); let result = hasher.finalize();
db::Interface::write(&s.env, &s.handle, &k, &hex::encode(&result[..])); db::Interface::write(&s.env, &s.handle, &k, &hex::encode(&result[..]));
// update wallet rpc // update wallet rpc
change_wallet_password(self.change_wallet_password_tx.clone(), &self.credential, ctx.clone()); change_wallet_password(
self.change_wallet_password_tx.clone(),
&self.credential,
ctx.clone(),
);
self.credential = utils::empty_string(); self.credential = utils::empty_string();
} }
}); });

View file

@ -176,9 +176,9 @@ pub async fn rx_multisig_message(
/// Customer can request shipment after the wallet is funded /// Customer can request shipment after the wallet is funded
/// ///
/// with the amount of the order. The vendor will then request export /// with the amount of the order. The vendor will then check
/// ///
/// multisig info, check balance and sanity check `unlock_time`. /// balance and sanity check `unlock_time`.
/// ///
/// Protected: true /// Protected: true
#[post("/ship/<orid>")] #[post("/ship/<orid>")]