start prototyping customer txset release

This commit is contained in:
creating2morrow 2023-12-12 21:16:40 -05:00
parent c0e4cbd59d
commit 92ccd3836e
2 changed files with 21 additions and 42 deletions

View file

@ -5,7 +5,7 @@ use crate::{
db, db,
gpg, gpg,
i2p, i2p,
message,
models::*, models::*,
monero, monero,
order, order,
@ -284,6 +284,7 @@ pub async fn validate_order_for_ship(orid: &String) -> reqres::FinalizeOrderResp
reqres::FinalizeOrderResponse { reqres::FinalizeOrderResponse {
orid: String::from(orid), orid: String::from(orid),
delivery_info: hex::decode(delivery_info).unwrap_or(Vec::new()), delivery_info: hex::decode(delivery_info).unwrap_or(Vec::new()),
vendor_update_success: false,
} }
} }
@ -377,48 +378,21 @@ pub async fn upload_delivery_info(
FinalizeOrderResponse { FinalizeOrderResponse {
delivery_info: delivery_info.to_vec(), delivery_info: delivery_info.to_vec(),
orid: String::from(orid), orid: String::from(orid),
vendor_update_success: false,
} }
} }
/// The vendor will first search for an encrypted multisig message in the form /// Vendor will very txset submission and then update the order to `Delivered`
/// ///
/// txset-{order id}-{.b32.i2p} /// status type. Then customer will update the status on the neveko instanced
///
/// upon a `vendor_update_success: true` response
pub async fn finalize_order(orid: &String) -> reqres::FinalizeOrderResponse { pub async fn finalize_order(orid: &String) -> reqres::FinalizeOrderResponse {
info!("finalizing order"); info!("finalizing order: {}", orid);
let mut m_order: Order = find(orid);
let s = db::Interface::async_open().await;
let key = format!("{}-{}-{}", message::TXSET_MSIG, orid, &m_order.cid);
let txset = db::Interface::async_read(&s.env, &s.handle, &key).await;
// describe transer to check amount, address and unlock_time
let wallet_password = utils::empty_string();
monero::open_wallet(&orid, &wallet_password).await;
let r_describe: reqres::XmrRpcDescribeTransferResponse =
monero::describe_transfer(&txset).await;
let m_product: Product = product::find(&m_order.pid);
let total: u128 = m_product.price * m_order.quantity;
let description: &reqres::TransferDescription = &r_describe.result.desc[0];
let is_valid_payment: bool = description.amount_out + description.fee >= total
&& description.unlock_time < monero::LockTimeLimit::Blocks.value();
if !is_valid_payment {
return Default::default();
}
let r_submit: reqres::XmrRpcSubmitMultisigResponse =
sign_and_submit_multisig(orid, &txset).await;
monero::close_wallet(&orid, &wallet_password).await;
if r_submit.result.tx_hash_list.is_empty() {
return Default::default();
}
// lookup delivery info
let delivery_key = format!("delivery-{}", orid);
let r_delivery_info: String = db::Interface::async_read(&s.env, &s.handle, &delivery_key).await;
let delivery_info: Vec<u8> = hex::decode(r_delivery_info).unwrap_or(Vec::new());
// update the order
m_order.status = StatusType::Delivered.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;
reqres::FinalizeOrderResponse { reqres::FinalizeOrderResponse {
orid: String::from(orid), ..Default::default()
delivery_info,
} }
} }
@ -459,7 +433,7 @@ pub async fn transmit_ship_request(
contact: &String, contact: &String,
jwp: &String, jwp: &String,
orid: &String, orid: &String,
) -> Result<Order, Box<dyn Error>> { ) -> Result<FinalizeOrderResponse, Box<dyn Error>> {
info!("executing transmit_ship_request"); info!("executing transmit_ship_request");
let host = utils::get_i2p_http_proxy(); let host = utils::get_i2p_http_proxy();
let proxy = reqwest::Proxy::http(&host)?; let proxy = reqwest::Proxy::http(&host)?;
@ -471,7 +445,7 @@ pub async fn transmit_ship_request(
.await .await
{ {
Ok(response) => { Ok(response) => {
let res = response.json::<Order>().await; let res = response.json::<FinalizeOrderResponse>().await;
debug!("ship request response: {:?}", res); debug!("ship request response: {:?}", res);
match res { match res {
Ok(r) => Ok(r), Ok(r) => Ok(r),
@ -485,8 +459,6 @@ pub async fn transmit_ship_request(
} }
} }
// TODO: sor is injecting order id instead of base 32 address FIX IT!
/// Executes GET /order/retrieve/orid/signature returning the order information /// Executes GET /order/retrieve/orid/signature returning the order information
/// ///
/// from the vendor. /// from the vendor.
@ -564,6 +536,10 @@ pub async fn d_trigger_ship_request(contact: &String, orid: &String) -> Order {
error!("failure to decompose trigger_ship_request"); error!("failure to decompose trigger_ship_request");
return Default::default(); return Default::default();
} }
let u_ship_res = ship_res.unwrap_or(Default::default());
let hex_delivery_info: String = hex::encode(u_ship_res.delivery_info);
let key = format!("{}-{}", crate::DELIVERY_INFO_DB_KEY, orid);
db::Interface::write(&s.env, &s.handle, &key, &hex_delivery_info);
} }
trigger trigger
} }

View file

@ -1315,6 +1315,8 @@ pub struct FinalizeOrderResponse {
pub orid: String, pub orid: String,
/// This is encrypted by the customer NEVEKO gpg key /// This is encrypted by the customer NEVEKO gpg key
pub delivery_info: Vec<u8>, pub delivery_info: Vec<u8>,
/// This is used to finalize delivery confirmations
pub vendor_update_success: bool,
} }
impl Default for FinalizeOrderResponse { impl Default for FinalizeOrderResponse {
@ -1322,6 +1324,7 @@ impl Default for FinalizeOrderResponse {
FinalizeOrderResponse { FinalizeOrderResponse {
orid: utils::empty_string(), orid: utils::empty_string(),
delivery_info: Vec::new(), delivery_info: Vec::new(),
vendor_update_success: false,
} }
} }
} }