mirror of
https://github.com/creating2morrow/neveko.git
synced 2024-10-30 00:27:36 +00:00
run format script
This commit is contained in:
parent
3612e61bfa
commit
79f526d211
8 changed files with 62 additions and 44 deletions
|
@ -6,8 +6,9 @@ use crate::{
|
|||
i2p,
|
||||
models::*,
|
||||
monero,
|
||||
order,
|
||||
reqres,
|
||||
utils, order,
|
||||
utils,
|
||||
};
|
||||
use log::{
|
||||
debug,
|
||||
|
|
|
@ -87,6 +87,7 @@ enum RpcFields {
|
|||
Open,
|
||||
Prepare,
|
||||
Refresh,
|
||||
Sign,
|
||||
SignMultisig,
|
||||
SubmitMultisig,
|
||||
SweepAll,
|
||||
|
@ -120,6 +121,7 @@ impl RpcFields {
|
|||
RpcFields::Open => String::from("open_wallet"),
|
||||
RpcFields::Prepare => String::from("prepare_multisig"),
|
||||
RpcFields::Refresh => String::from("refresh"),
|
||||
RpcFields::Sign => String::from("sign"),
|
||||
RpcFields::SignMultisig => String::from("sign_multisig"),
|
||||
RpcFields::SubmitMultisig => String::from("submit_multisig"),
|
||||
RpcFields::SweepAll => String::from("sweep_all"),
|
||||
|
@ -613,7 +615,11 @@ pub async fn change_wallet_password(new_password: &String) -> bool {
|
|||
Ok(response) => {
|
||||
// The result from wallet operation is empty
|
||||
let res = response.text().await;
|
||||
debug!("{} response: {:?}", RpcFields::ChangeWalletPassword.value(), res);
|
||||
debug!(
|
||||
"{} response: {:?}",
|
||||
RpcFields::ChangeWalletPassword.value(),
|
||||
res
|
||||
);
|
||||
match res {
|
||||
Ok(r) => {
|
||||
if r.contains("-1") {
|
||||
|
|
|
@ -8,6 +8,7 @@ use crate::{
|
|||
message,
|
||||
models::*,
|
||||
monero,
|
||||
order,
|
||||
product,
|
||||
reqres,
|
||||
utils,
|
||||
|
@ -192,8 +193,8 @@ pub fn modify(o: Json<Order>) -> Order {
|
|||
}
|
||||
let u_order = Order::update(String::from(&f_order.orid), &o);
|
||||
let s = db::Interface::open();
|
||||
db::Interface::delete(&s.env, &s.handle, &u_order.pid);
|
||||
db::Interface::write(&s.env, &s.handle, &u_order.pid, &Order::to_db(&u_order));
|
||||
db::Interface::delete(&s.env, &s.handle, &u_order.orid);
|
||||
db::Interface::write(&s.env, &s.handle, &u_order.orid, &Order::to_db(&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 price = m_product.price;
|
||||
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();
|
||||
monero::open_wallet(&orid, &wallet_password).await;
|
||||
let r_import = monero::import_multisig_info(v_info).await;
|
||||
// check balance and unlock_time
|
||||
let r_balance = monero::get_balance().await;
|
||||
monero::close_wallet(&orid, &wallet_password).await;
|
||||
// update the order status to multisig complete
|
||||
let ready_to_ship: bool = r_import.result.n_outputs > 0
|
||||
&& r_balance.result.balance >= total as u128
|
||||
let ready_to_ship: bool = r_balance.result.balance >= total as u128
|
||||
&& r_balance.result.blocks_to_unlock < monero::LockTimeLimit::Blocks.value();
|
||||
if ready_to_ship {
|
||||
m_order.status = StatusType::MulitsigComplete.value();
|
||||
db::Interface::async_delete(&s.env, &s.handle, &m_order.orid).await;
|
||||
db::Interface::async_write(&s.env, &s.handle, &m_order.orid, &Order::to_db(&m_order)).await;
|
||||
m_order.status = StatusType::Shipped.value();
|
||||
order::modify(Json(m_order));
|
||||
}
|
||||
ready_to_ship
|
||||
}
|
||||
|
|
|
@ -537,7 +537,7 @@ pub struct XmrRpcIsMultisigResult {
|
|||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct XmrRpcGetHeightResult {
|
||||
pub height: u64
|
||||
pub height: u64,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
@ -1132,9 +1132,7 @@ pub struct XmrRpcGetHeightResponse {
|
|||
impl Default for XmrRpcGetHeightResponse {
|
||||
fn default() -> Self {
|
||||
XmrRpcGetHeightResponse {
|
||||
result: XmrRpcGetHeightResult {
|
||||
height: 0,
|
||||
},
|
||||
result: XmrRpcGetHeightResult { height: 0 },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -266,7 +266,8 @@ impl eframe::App for AddressBookApp {
|
|||
ui.label(format!("amount: {} piconero(s)", amount));
|
||||
ui.label(format!("expiration: {} blocks", expire));
|
||||
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 show_approve {
|
||||
if ui.button("Approve").clicked() {
|
||||
|
|
|
@ -13,6 +13,7 @@ pub struct MultisigManagement {
|
|||
pub completed_export: bool,
|
||||
pub completed_funding: bool,
|
||||
pub completed_prepare: bool,
|
||||
pub completed_shipping_request: bool,
|
||||
pub completed_make: bool,
|
||||
pub exchange_multisig_keys: String,
|
||||
pub export_info: String,
|
||||
|
@ -33,6 +34,7 @@ impl Default for MultisigManagement {
|
|||
completed_export: false,
|
||||
completed_funding: false,
|
||||
completed_prepare: false,
|
||||
completed_shipping_request: false,
|
||||
completed_make: false,
|
||||
exchange_multisig_keys: utils::empty_string(),
|
||||
export_info: utils::empty_string(),
|
||||
|
@ -394,6 +396,7 @@ impl eframe::App for MarketApp {
|
|||
}
|
||||
}
|
||||
});
|
||||
// msig mgmt gaurds
|
||||
if !self.msig.completed_prepare {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Prepare: \t\t\t\t\t");
|
||||
|
@ -572,7 +575,7 @@ impl eframe::App for MarketApp {
|
|||
&contact,
|
||||
&self.m_order.orid,
|
||||
self.order_funded_tx.clone(),
|
||||
ctx.clone()
|
||||
ctx.clone(),
|
||||
)
|
||||
}
|
||||
});
|
||||
|
@ -586,7 +589,8 @@ impl eframe::App for MarketApp {
|
|||
let vendor =
|
||||
utils::search_gui_db(vendor_prefix, self.m_order.orid.clone());
|
||||
// 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(
|
||||
self.our_make_info_tx.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.label("Release Payment: \t");
|
||||
// if ui.button("Sign Txset").clicked() {}
|
||||
|
@ -750,8 +767,7 @@ impl eframe::App for MarketApp {
|
|||
ui.label("loading...");
|
||||
}
|
||||
let mediator_prefix = String::from(crate::GUI_MSIG_MEDIATOR_DB_KEY);
|
||||
let mediator =
|
||||
utils::search_gui_db(mediator_prefix, self.m_order.orid.clone());
|
||||
let mediator = utils::search_gui_db(mediator_prefix, self.m_order.orid.clone());
|
||||
ui.label(format!("customer id: {}", self.new_order.cid));
|
||||
ui.label(format!("mediator id: {}", mediator));
|
||||
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 l_contact = String::from(contact);
|
||||
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(
|
||||
tx: Sender<String>,
|
||||
ctx: egui::Context,
|
||||
orid: &String,
|
||||
vendor: String,
|
||||
) {
|
||||
fn send_import_info_req(tx: Sender<String>, ctx: egui::Context, orid: &String, vendor: String) {
|
||||
let v_orid: String = String::from(orid);
|
||||
let w_orid: String = String::from(orid);
|
||||
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;
|
||||
if v_export == utils::empty_string() {
|
||||
log::debug!(
|
||||
"constructing vendor {} msig messages",
|
||||
message::EXPORT_MSIG
|
||||
);
|
||||
log::debug!("constructing vendor {} msig messages", message::EXPORT_MSIG);
|
||||
let v_msig_request: reqres::MultisigInfoRequest = reqres::MultisigInfoRequest {
|
||||
contact: i2p::get_destination(None),
|
||||
info,
|
||||
|
|
|
@ -3,7 +3,10 @@ use sha2::{
|
|||
Digest,
|
||||
Sha512,
|
||||
};
|
||||
use std::sync::mpsc::{Receiver, Sender};
|
||||
use std::sync::mpsc::{
|
||||
Receiver,
|
||||
Sender,
|
||||
};
|
||||
|
||||
use crate::CREDENTIAL_KEY;
|
||||
|
||||
|
@ -68,7 +71,11 @@ impl eframe::App for SettingsApp {
|
|||
let result = hasher.finalize();
|
||||
db::Interface::write(&s.env, &s.handle, &k, &hex::encode(&result[..]));
|
||||
// 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();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -176,9 +176,9 @@ pub async fn rx_multisig_message(
|
|||
|
||||
/// 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
|
||||
#[post("/ship/<orid>")]
|
||||
|
|
Loading…
Reference in a new issue