From 06cab5460e215a89fc7fb59e3fdfb2a7bcac90cd Mon Sep 17 00:00:00 2001 From: creating2morrow Date: Tue, 30 May 2023 05:34:16 -0400 Subject: [PATCH] remove unused enum variant --- nevmes-core/src/models.rs | 38 ++++++++++++++++++++-------- nevmes-core/src/monero.rs | 7 +----- nevmes-core/src/utils.rs | 4 +-- nevmes-market/src/controller.rs | 44 ++++++++++++++------------------- nevmes-market/src/dispute.rs | 14 ++++++++--- nevmes-market/src/lib.rs | 6 ++--- nevmes-market/src/main.rs | 10 ++++++-- nevmes-market/src/order.rs | 2 -- nevmes-market/src/product.rs | 17 ++++++++++--- src/controller.rs | 26 +++---------------- src/main.rs | 1 - 11 files changed, 88 insertions(+), 81 deletions(-) diff --git a/nevmes-core/src/models.rs b/nevmes-core/src/models.rs index 6f776d4..107efee 100644 --- a/nevmes-core/src/models.rs +++ b/nevmes-core/src/models.rs @@ -374,12 +374,33 @@ impl Order { pub fn to_db(o: &Order) -> String { format!( "{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}:{}", - o.cid, o.pid, o.cust_kex_1, o.cust_kex_2, o.cust_kex_3, o.cust_msig_make, - o.cust_msig_prepare, o.cust_msig_txset, o.date, o.deliver_date, - o.hash, o.mediator_msig_make, o.mediator_msig_prepare, o.mediator_kex_1, - o.mediator_kex_2, o.mediator_kex_3, o.ship_date, o.subaddress, o.status, - o.quantity, o.vend_kex_1, o.vend_kex_2, o.vend_kex_3, o.vend_msig_make, - o.vend_msig_prepare, o.vend_msig_txset, o.xmr_address, + o.cid, + o.pid, + o.cust_kex_1, + o.cust_kex_2, + o.cust_kex_3, + o.cust_msig_make, + o.cust_msig_prepare, + o.cust_msig_txset, + o.date, + o.deliver_date, + o.hash, + o.mediator_msig_make, + o.mediator_msig_prepare, + o.mediator_kex_1, + o.mediator_kex_2, + o.mediator_kex_3, + o.ship_date, + o.subaddress, + o.status, + o.quantity, + o.vend_kex_1, + o.vend_kex_2, + o.vend_kex_3, + o.vend_msig_make, + o.vend_msig_prepare, + o.vend_msig_txset, + o.xmr_address, ) } pub fn from_db(k: String, v: String) -> Order { @@ -456,10 +477,7 @@ impl Order { xmr_address, } } - pub fn update( - orid: String, - o: Order, - ) -> Order { + pub fn update(orid: String, o: Order) -> Order { Order { orid, cid: String::from(&o.cid), diff --git a/nevmes-core/src/monero.rs b/nevmes-core/src/monero.rs index 46f2fb5..92a4af1 100644 --- a/nevmes-core/src/monero.rs +++ b/nevmes-core/src/monero.rs @@ -30,7 +30,6 @@ enum RpcFields { CreateWallet, ExchangeMultisigKeys, Export, - Finalize, GetTxProof, GetTxById, GetVersion, @@ -58,7 +57,6 @@ impl RpcFields { RpcFields::CreateWallet => String::from("create_wallet"), RpcFields::ExchangeMultisigKeys => String::from("exchange_multisig_keys"), RpcFields::Export => String::from("export_multisig_info"), - RpcFields::Finalize => String::from("finalize_multisig"), RpcFields::GetTxProof => String::from("get_tx_proof"), RpcFields::GetTxById => String::from("get_transfer_by_txid"), RpcFields::GetVersion => String::from("get_version"), @@ -400,10 +398,7 @@ pub async fn close_wallet(filename: String, password: String) -> bool { info!("executing {}", RpcFields::Close.value()); let client = reqwest::Client::new(); let host = get_rpc_host(); - let params = reqres::XmrRpcOpenWalletParams { - filename, - password, - }; + let params = reqres::XmrRpcOpenWalletParams { filename, password }; let req = reqres::XmrRpcOpenRequest { jsonrpc: RpcFields::JsonRpcVersion.value(), id: RpcFields::Id.value(), diff --git a/nevmes-core/src/utils.rs b/nevmes-core/src/utils.rs index c55cbd3..b6b9f32 100644 --- a/nevmes-core/src/utils.rs +++ b/nevmes-core/src/utils.rs @@ -419,8 +419,8 @@ pub async fn start_up() { // wait for rpc server for a bit tokio::time::sleep(std::time::Duration::new(5, 0)).await; monero::check_rpc_connection().await; - let wallet_password = std::env::var(crate::MONERO_WALLET_PASSWORD) - .unwrap_or(String::from("password")); + let wallet_password = + std::env::var(crate::MONERO_WALLET_PASSWORD).unwrap_or(String::from("password")); gen_app_wallet(&wallet_password).await; i2p::start().await; gen_app_gpg().await; diff --git a/nevmes-market/src/controller.rs b/nevmes-market/src/controller.rs index caa0531..b346520 100644 --- a/nevmes-market/src/controller.rs +++ b/nevmes-market/src/controller.rs @@ -1,11 +1,18 @@ -use rocket::http::Status; -use rocket::response::status::Custom; -use rocket::serde::json::Json; -use rocket::{get, patch, post}; +use rocket::{ + get, + http::Status, + patch, + post, + response::status::Custom, + serde::json::Json, +}; use nevmes_core::*; -use crate::{dispute, product}; +use crate::{ + dispute, + product, +}; // JSON APIs @@ -16,24 +23,18 @@ pub async fn create_product( _token: auth::BearerToken, ) -> Custom> { let m_product: models::Product = product::create(req_product); - Custom( - Status::Ok, - Json(m_product), - ) + Custom(Status::Ok, Json(m_product)) } /// Update product information -#[patch("/<_address>/update", data="")] +#[patch("/<_address>/update", data = "")] pub async fn update_product( _address: String, product: Json, _token: auth::BearerToken, ) -> Custom> { let m_product: models::Product = product::modify(product); - Custom( - Status::Ok, - Json(m_product), - ) + Custom(Status::Ok, Json(m_product)) } // /// Initialize order @@ -89,22 +90,13 @@ pub async fn create_dispute( _token: auth::BearerToken, ) -> Custom> { let m_dispute: models::Dispute = dispute::create(dispute); - Custom( - Status::Ok, - Json(m_dispute), - ) + Custom(Status::Ok, Json(m_dispute)) } /// Create a dispute #[get("/")] -pub async fn get_dispute( - _token: auth::BearerToken, - did: String, -) -> Custom> { +pub async fn get_dispute(_token: auth::BearerToken, did: String) -> Custom> { let m_dispute: models::Dispute = dispute::find(&did); - Custom( - Status::Ok, - Json(m_dispute), - ) + Custom(Status::Ok, Json(m_dispute)) } // END JSON APIs diff --git a/nevmes-market/src/dispute.rs b/nevmes-market/src/dispute.rs index b5183db..a055233 100644 --- a/nevmes-market/src/dispute.rs +++ b/nevmes-market/src/dispute.rs @@ -1,6 +1,14 @@ -use nevmes_core::{db, models::*, utils}; +use log::{ + debug, + error, + info, +}; +use nevmes_core::{ + db, + models::*, + utils, +}; use rocket::serde::json::Json; -use log::{debug, error, info}; /// Create a new dispute pub fn create(d: Json) -> Dispute { @@ -25,7 +33,7 @@ pub fn find(did: &String) -> Dispute { let r = db::Interface::read(&s.env, &s.handle, &String::from(did)); if r == utils::empty_string() { error!("dispute not found"); - return Default::default() + return Default::default(); } Dispute::from_db(String::from(did), r) } diff --git a/nevmes-market/src/lib.rs b/nevmes-market/src/lib.rs index 8d5cea4..6f167f4 100755 --- a/nevmes-market/src/lib.rs +++ b/nevmes-market/src/lib.rs @@ -1,6 +1,6 @@ pub mod controller; // HTTP entry point -pub mod dispute; // Dispute repo/service layer -pub mod order; // Order repo/service layer -pub mod product; // Product repo/service layer +pub mod dispute; // Dispute repo/service layer +pub mod order; // Order repo/service layer +pub mod product; // Product repo/service layer // DO NOT EDIT BELOW THIS LINE diff --git a/nevmes-market/src/main.rs b/nevmes-market/src/main.rs index 3bba908..9be8950 100755 --- a/nevmes-market/src/main.rs +++ b/nevmes-market/src/main.rs @@ -15,8 +15,14 @@ async fn rocket() -> _ { env_logger::init(); log::info!("nevmes-auth is online"); rocket::custom(&config) - .mount("/dispute", routes![controller::create_dispute, controller::get_dispute]) + .mount( + "/dispute", + routes![controller::create_dispute, controller::get_dispute], + ) // .mount("/order", routes![controller::initialize_order, controller::update_order]) // .mount("/orders", routes![controller::get_orders]) - .mount("/product", routes![controller::create_product, controller::update_product]) + .mount( + "/product", + routes![controller::create_product, controller::update_product], + ) } diff --git a/nevmes-market/src/order.rs b/nevmes-market/src/order.rs index 1c2e264..a61933d 100644 --- a/nevmes-market/src/order.rs +++ b/nevmes-market/src/order.rs @@ -21,7 +21,6 @@ // } // } - // /// Create a skeleton for order // pub fn create(cid: String, pid: String) -> models::Order { // let ts = chrono::offset::Utc::now().timestamp(); @@ -78,7 +77,6 @@ // new_order // } - // /// Lookup order // pub fn find(oid: String) -> models::Order { // let s = db::Interface::open(); diff --git a/nevmes-market/src/product.rs b/nevmes-market/src/product.rs index 5a2418f..e36cf45 100644 --- a/nevmes-market/src/product.rs +++ b/nevmes-market/src/product.rs @@ -1,6 +1,14 @@ // Product repo/service layer -use nevmes_core::{db, models::*, utils}; -use log::{debug, error, info}; +use log::{ + debug, + error, + info, +}; +use nevmes_core::{ + db, + models::*, + utils, +}; use rocket::serde::json::Json; /// Create a new product @@ -26,7 +34,10 @@ pub fn create(d: Json) -> Product { debug!("creating product index"); } let product_list = [r, String::from(&pid)].join(","); - debug!("writing product index {} for id: {}", product_list, list_key); + debug!( + "writing product index {} for id: {}", + product_list, list_key + ); db::Interface::write(&s.env, &s.handle, &String::from(list_key), &product_list); new_product } diff --git a/src/controller.rs b/src/controller.rs index 097067a..5058f3c 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -21,21 +21,6 @@ pub async fn get_version(_jwp: proof::PaymentProof) -> Custom Custom> { - let mut v: Vec = Vec::new(); - v.push("t1".to_string()); - v.push("t2".to_string()); - v.push("t3".to_string()); - let u: models::User = models::User { - uid: v.remove(0), - xmr_address: v.remove(0), - name: v.remove(0), - }; - Custom(Status::Ok, Json(u)) -} - - /// If i2p not in the state of rejecting tunnels this will return `open: true` /// /// Protected: false @@ -94,15 +79,10 @@ pub async fn gen_jwp(proof: Json) -> Custom> { //----------------------------------------------- /// Get all products by passing vendor address -/// +/// /// Protected: true #[get("/products")] -pub async fn get_products( - _jwp: proof::PaymentProof, -) -> Custom>> { +pub async fn get_products(_jwp: proof::PaymentProof) -> Custom>> { let m_products: Vec = product::find_all(); - Custom( - Status::Ok, - Json(m_products), - ) + Custom(Status::Ok, Json(m_products)) } diff --git a/src/main.rs b/src/main.rs index cb0db73..dd30550 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,5 +59,4 @@ async fn rocket() -> _ { .mount("/i2p", routes![controller::get_i2p_status]) .mount("/xmr/rpc", routes![controller::get_version]) .mount("/market", routes![controller::get_products]) - .mount("/test", routes![controller::test]) }