mirror of
https://github.com/creating2morrow/neveko.git
synced 2024-12-22 19:49:24 +00:00
add make multisig info orchestration
This commit is contained in:
parent
e97f3394bc
commit
d21b76df25
3 changed files with 62 additions and 13 deletions
|
@ -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<Message> = utils::message_to_json(&message);
|
||||
create(j_message, jwp, MessageType::Multisig).await;
|
||||
}
|
||||
|
||||
pub async fn send_make_info(orid: &String, contact: &String, info: Vec<String>) {
|
||||
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<Message> = utils::message_to_json(&message);
|
||||
create(j_message, jwp, MessageType::Multisig).await;
|
||||
|
|
|
@ -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 {
|
||||
|
@ -1101,3 +1101,25 @@ impl Default for OrderRequest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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<String>,
|
||||
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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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/<orid>/<contact>")]
|
||||
pub async fn get_prepare_multisig_info(
|
||||
orid: String,
|
||||
contact: String,
|
||||
#[post("/multisig/info", data = "<r_info>")]
|
||||
pub async fn get_multisig_info(
|
||||
r_info: Json<reqres::MultisigInfoRequest>,
|
||||
_jwp: proof::PaymentProof) -> Custom<Json<models::Order>> {
|
||||
// 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<String> = r_info.info.iter().cloned().collect();
|
||||
message::send_make_info(&r_info.orid, &r_info.contact, info).await;
|
||||
}
|
||||
|
||||
Custom(Status::Ok, Json(Default::default()))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue