diff --git a/nevmes-core/src/message.rs b/nevmes-core/src/message.rs index 76e8e46..2f2b027 100644 --- a/nevmes-core/src/message.rs +++ b/nevmes-core/src/message.rs @@ -17,6 +17,11 @@ use reqwest::StatusCode; use rocket::serde::json::Json; use std::error::Error; +pub const EXCHANGE_MSIG: &str = "exchange"; +pub const EXPORT_MSIG: &str = "export"; +pub const MAKE_MSIG: &str = "make"; +pub const PREPARE_MSIG: &str = "prepare"; + #[derive(PartialEq)] pub enum MessageType { Normal, @@ -425,19 +430,37 @@ fn is_fts_clear(r: String) -> bool { v.len() >= 2 && v[v.len() - 1] == utils::empty_string() && v[0] == utils::empty_string() } -pub async fn send_prepare_info(orid:String, contact:String) { +pub async fn send_prepare_info(orid: &String, contact: &String) { let s = db::Interface::open(); let prepare_info = monero::prepare_wallet().await; - let k = format!("{}-{}", "fts-jwp", &contact); + let k = format!("{}-{}", "fts-jwp", contact); let jwp = db::Interface::read(&s.env, &s.handle, &k); - let body_str = format!("prepare:{}:{}", &orid, &prepare_info.result.multisig_info); + let body_str = format!("{}:{}:{}", PREPARE_MSIG, orid, &prepare_info.result.multisig_info); let message: Message = Message { mid: utils::empty_string(), uid: utils::empty_string(), body: body_str.into_bytes(), created: chrono::Utc::now().timestamp(), from: utils::empty_string(), - to: String::from(&contact), + to: String::from(contact), + }; + let j_message: Json = utils::message_to_json(&message); + create(j_message, jwp, MessageType::Multisig).await; +} + +pub async fn send_make_info(orid: &String, contact: &String, info: Vec) { + let s = db::Interface::open(); + let make_info = monero::make_wallet(info).await; + let k = format!("{}-{}", "fts-jwp", contact); + let jwp = db::Interface::read(&s.env, &s.handle, &k); + let body_str = format!("{}:{}:{}", MAKE_MSIG, orid, &make_info.result.multisig_info); + let message: Message = Message { + mid: utils::empty_string(), + uid: utils::empty_string(), + body: body_str.into_bytes(), + created: chrono::Utc::now().timestamp(), + from: utils::empty_string(), + to: String::from(contact), }; let j_message: Json = utils::message_to_json(&message); create(j_message, jwp, MessageType::Multisig).await; diff --git a/nevmes-core/src/reqres.rs b/nevmes-core/src/reqres.rs index d55cecf..707eabc 100644 --- a/nevmes-core/src/reqres.rs +++ b/nevmes-core/src/reqres.rs @@ -1081,7 +1081,7 @@ impl Default for ErrorResponse { } } -/// Handle intial information for request +/// Handle intial order information for request #[derive(Serialize, Deserialize, Debug)] #[serde(crate = "rocket::serde")] pub struct OrderRequest { @@ -1100,4 +1100,26 @@ impl Default for OrderRequest { quantity: 0, } } -} \ No newline at end of file +} + +/// Handle multisig info requests +#[derive(Serialize, Deserialize, Debug)] +#[serde(crate = "rocket::serde")] +pub struct MultisigInfoRequest { + pub contact: String, + /// Send empty array on prepare info request + pub info: Vec, + pub msig_type: String, + pub orid: String, +} + +impl Default for MultisigInfoRequest { + fn default() -> Self { + MultisigInfoRequest { + contact: utils::empty_string(), + info: Vec::new(), + msig_type: utils::empty_string(), + orid: utils::empty_string(), + } + } +} diff --git a/src/controller.rs b/src/controller.rs index 48bc8b6..89ddef3 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -117,16 +117,20 @@ pub async fn retrieve_order( Custom(Status::Created, Json(m_order)) } -/// Create order +/// Send multisig info for contact's order /// /// Protected: true -#[get("/multisig/prepare//")] -pub async fn get_prepare_multisig_info( - orid: String, - contact: String, +#[post("/multisig/info", data = "")] +pub async fn get_multisig_info( + r_info: Json, _jwp: proof::PaymentProof) -> Custom> { - // TODO(c2m): create a multisig message - message::send_prepare_info(orid, contact).await; + if r_info.msig_type == String::from(message::PREPARE_MSIG) { + message::send_prepare_info(&r_info.orid, &r_info.contact ).await; + } else { + let info: Vec = r_info.info.iter().cloned().collect(); + message::send_make_info(&r_info.orid, &r_info.contact, info).await; + } + Custom(Status::Ok, Json(Default::default())) }