From 7ee218498a8562ab097f653754f923756e2be38f Mon Sep 17 00:00:00 2001 From: Artem Pikulin Date: Tue, 22 Sep 2020 14:18:23 +0700 Subject: [PATCH] Return order_type in buy/sell responses #725. --- mm2src/lp_ordermatch.rs | 16 +++++++++++++--- mm2src/mm2_tests.rs | 6 +++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/mm2src/lp_ordermatch.rs b/mm2src/lp_ordermatch.rs index f0dd321c46..e0f88dd97b 100644 --- a/mm2src/lp_ordermatch.rs +++ b/mm2src/lp_ordermatch.rs @@ -315,7 +315,7 @@ impl Default for MatchBy { fn default() -> Self { MatchBy::Any } } -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[serde(tag = "type", content = "data")] enum OrderType { FillOrKill, @@ -1271,6 +1271,13 @@ struct TakerMatch { last_updated: u64, } +#[derive(Serialize)] +struct LpautobuyResult<'a> { + #[serde(flatten)] + request: &'a TakerRequest, + order_type: OrderType, +} + pub fn lp_auto_buy( ctx: &MmArc, base_coin: &MmCoinEnum, @@ -1308,7 +1315,10 @@ pub fn lp_auto_buy( .with_sender_pubkey(H256Json::from(our_public_id.bytes)); let request = try_s!(request_builder.build()); ctx.broadcast_p2p_msg(P2PMessage::from_serialize_with_default_addr(&request)); - let result = json!({ "result": request }).to_string(); + let result = json!({ "result": LpautobuyResult { + request: &request, + order_type: input.order_type, + } }); let order = TakerOrder { created_at: now_ms(), matches: HashMap::new(), @@ -1318,7 +1328,7 @@ pub fn lp_auto_buy( save_my_taker_order(ctx, &order); my_taker_orders.insert(order.request.uuid, order); drop(my_taker_orders); - Ok(result) + Ok(result.to_string()) } fn price_ping_sig_hash(timestamp: u32, pubsecp: &[u8], pubkey: &[u8], base: &[u8], rel: &[u8], price64: u64) -> H256 { diff --git a/mm2src/mm2_tests.rs b/mm2src/mm2_tests.rs index 16e05a49e1..a7d7f5b13c 100644 --- a/mm2src/mm2_tests.rs +++ b/mm2src/mm2_tests.rs @@ -2338,7 +2338,11 @@ fn test_fill_or_kill_taker_order_should_not_transform_to_maker() { "type": "FillOrKill" } })))); - assert!(rc.0.is_success(), "!setprice: {}", rc.1); + assert!(rc.0.is_success(), "!sell: {}", rc.1); + let sell_json: Json = json::from_str(&rc.1).unwrap(); + let order_type = sell_json["result"]["order_type"]["type"].as_str(); + assert_eq!(order_type, Some("FillOrKill")); + log!("Wait for 40 seconds for Bob order to be cancelled"); thread::sleep(Duration::from_secs(40));