From bba4dbb4b4c3b55d4cc61e024aeed39aaebe8abc Mon Sep 17 00:00:00 2001 From: politeWall <138504353+politeWall@users.noreply.github.com> Date: Thu, 30 Nov 2023 16:12:41 +0100 Subject: [PATCH] fix: replace attributes event_type to event --- src/action/execute/cancel_margin_order.rs | 7 ++++--- src/action/execute/cancel_spot_order.rs | 3 +-- src/action/execute/create_margin_order.rs | 14 ++++++++------ src/action/execute/create_spot_order.rs | 6 ++++-- src/action/mod.rs | 1 + src/action/reply/close_margin_position.rs | 9 +++++---- .../reply/create_margin_order_market_close.rs | 7 ++++--- .../reply/create_margin_order_market_open.rs | 7 ++++--- src/action/reply/open_margin_position.rs | 9 +++++---- src/action/reply/spot_order.rs | 6 +++--- src/action/reply/spot_order_market.rs | 6 +++--- 11 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/action/execute/cancel_margin_order.rs b/src/action/execute/cancel_margin_order.rs index 9c1db83..d49c3dc 100644 --- a/src/action/execute/cancel_margin_order.rs +++ b/src/action/execute/cancel_margin_order.rs @@ -34,9 +34,10 @@ pub fn cancel_margin_order( amount: vec![order.collateral.clone()], }; - let resp = Response::new() - .add_attribute("event_type", "cancel_margin_order") - .add_attribute("margin_order_id", order.order_id.to_string()); + let resp = Response::new().add_event( + Event::new("cancel_margin_order") + .add_attribute("margin_order_id", order.order_id.to_string()), + ); MARGIN_ORDER.save(deps.storage, &orders)?; diff --git a/src/action/execute/cancel_spot_order.rs b/src/action/execute/cancel_spot_order.rs index 37fce15..aae5e44 100644 --- a/src/action/execute/cancel_spot_order.rs +++ b/src/action/execute/cancel_spot_order.rs @@ -36,8 +36,7 @@ pub fn cancel_spot_order( let resp = Response::new() .add_message(CosmosMsg::Bank(refund_msg)) - .add_attribute("event_type", "cancel_spot_order") - .add_attribute("order_id", order_id.to_string()); + .add_event(Event::new("cancel_spot_order").add_attribute("order_id", order_id.to_string())); SPOT_ORDER.save(deps.storage, &orders_list)?; diff --git a/src/action/execute/create_margin_order.rs b/src/action/execute/create_margin_order.rs index 0bbaea8..4de2213 100644 --- a/src/action/execute/create_margin_order.rs +++ b/src/action/execute/create_margin_order.rs @@ -136,9 +136,10 @@ fn create_margin_open_order( MARGIN_ORDER.save(deps.storage, &orders)?; - let resp = Response::new() - .add_attribute("event_type", "create_margin_open_order") - .add_attribute("margin_order_id", order_id.to_string()); + let resp = Response::new().add_event( + Event::new("create_margin_open_order") + .add_attribute("margin_order_id", order_id.to_string()), + ); if order_type != MarketOpen { return Ok(resp); @@ -225,9 +226,10 @@ fn create_margin_close_order( MARGIN_ORDER.save(deps.storage, &orders)?; - let resp = Response::new() - .add_attribute("event_type", "create_margin_close_order") - .add_attribute("margin_order_id", order_id.to_string()); + let resp = Response::new().add_event( + Event::new("create_margin_close_order") + .add_attribute("margin_order_id", order_id.to_string()), + ); if order_type != MarketClose { return Ok(resp); diff --git a/src/action/execute/create_spot_order.rs b/src/action/execute/create_spot_order.rs index c8065ec..b28179b 100644 --- a/src/action/execute/create_spot_order.rs +++ b/src/action/execute/create_spot_order.rs @@ -112,8 +112,10 @@ fn create_resp( in_route: Vec, ) -> StdResult> { let resp = Response::new() - .add_attribute("event_type", "create_spot_order") - .add_attribute("order_id", new_order.order_id.to_string()) + .add_event( + Event::new("create_spot_order") + .add_attribute("order_id", new_order.order_id.to_string()), + ) .add_message(bank_msg); // information message if new_order.order_type != SpotOrderType::MarketBuy { diff --git a/src/action/mod.rs b/src/action/mod.rs index edfd0a0..822e415 100644 --- a/src/action/mod.rs +++ b/src/action/mod.rs @@ -1,4 +1,5 @@ use crate::{states::*, types::*, ContractError}; +use cosmwasm_std::Event; use cosmwasm_std::{BankMsg, CosmosMsg, DepsMut, Env, MessageInfo, Response}; use elys_bindings::*; diff --git a/src/action/reply/close_margin_position.rs b/src/action/reply/close_margin_position.rs index 678ee04..0acddd2 100644 --- a/src/action/reply/close_margin_position.rs +++ b/src/action/reply/close_margin_position.rs @@ -31,10 +31,11 @@ pub fn reply_to_close_margin_order( MARGIN_ORDER.save(deps.storage, &orders)?; - let resp: Response = Response::new() - .add_attribute("event_type", "reply_to_close_margin_order") - .add_attribute("margin_order_id", order_id.to_string()) - .add_attribute("margin_trading_position_closed_id", res.id.to_string()); + let resp: Response = Response::new().add_event( + Event::new("reply_to_close_margin_order") + .add_attribute("margin_order_id", order_id.to_string()) + .add_attribute("margin_trading_position_closed_id", res.id.to_string()), + ); Ok(resp) } diff --git a/src/action/reply/create_margin_order_market_close.rs b/src/action/reply/create_margin_order_market_close.rs index 35e8e90..3dcd716 100644 --- a/src/action/reply/create_margin_order_market_close.rs +++ b/src/action/reply/create_margin_order_market_close.rs @@ -34,9 +34,10 @@ pub fn reply_to_create_margin_market_close( order.status = Status::Processed; - let resp = Response::new() - .add_attribute("event_type", "reply_to_create_margin_market_close") - .add_attribute("margin_trading_position_id", margin_resp.id.to_string()); + let resp = Response::new().add_event( + Event::new("reply_to_create_margin_market_close") + .add_attribute("margin_trading_position_id", margin_resp.id.to_string()), + ); Ok(resp) } diff --git a/src/action/reply/create_margin_order_market_open.rs b/src/action/reply/create_margin_order_market_open.rs index 910165e..7dfae2b 100644 --- a/src/action/reply/create_margin_order_market_open.rs +++ b/src/action/reply/create_margin_order_market_open.rs @@ -35,9 +35,10 @@ pub fn reply_to_create_margin_market_open( order.status = Status::Processed; order.position_id = Some(margin_resp.id); - let resp = Response::new() - .add_attribute("event_type", "reply_to_create_margin_market_open") - .add_attribute("margin_trading_position_id", margin_resp.id.to_string()); + let resp = Response::new().add_event( + Event::new("reply_to_create_margin_market_open") + .add_attribute("margin_trading_position_id", margin_resp.id.to_string()), + ); Ok(resp) } diff --git a/src/action/reply/open_margin_position.rs b/src/action/reply/open_margin_position.rs index 2eee40b..65efc28 100644 --- a/src/action/reply/open_margin_position.rs +++ b/src/action/reply/open_margin_position.rs @@ -31,10 +31,11 @@ pub fn reply_to_open_margin_position( MARGIN_ORDER.save(deps.storage, &orders)?; - let resp: Response = Response::new() - .add_attribute("event_type", "reply_to_open_margin_position") - .add_attribute("margin_order_id", order_id.to_string()) - .add_attribute("margin_trading_position_opened_id", res.id.to_string()); + let resp: Response = Response::new().add_event( + Event::new("reply_to_open_margin_position") + .add_attribute("margin_order_id", order_id.to_string()) + .add_attribute("margin_trading_position_opened_id", res.id.to_string()), + ); Ok(resp) } diff --git a/src/action/reply/spot_order.rs b/src/action/reply/spot_order.rs index f057643..9281514 100644 --- a/src/action/reply/spot_order.rs +++ b/src/action/reply/spot_order.rs @@ -31,9 +31,9 @@ pub fn reply_to_spot_order( SPOT_ORDER.save(deps.storage, &orders)?; - let resp: Response = Response::new() - .add_attribute("event_type", "reply_to_spot_order") - .add_attribute("order_id", order_id.to_string()); + let resp: Response = Response::new().add_event( + Event::new("reply_to_spot_order").add_attribute("order_id", order_id.to_string()), + ); Ok(resp) } diff --git a/src/action/reply/spot_order_market.rs b/src/action/reply/spot_order_market.rs index c3b812d..a7fcf16 100644 --- a/src/action/reply/spot_order_market.rs +++ b/src/action/reply/spot_order_market.rs @@ -26,9 +26,9 @@ pub fn reply_to_spot_order_market( SPOT_ORDER.save(deps.storage, &orders)?; - let resp: Response = Response::new() - .add_attribute("event_type", "reply_to_spot_order_market") - .add_attribute("order_id", order_id.to_string()); + let resp: Response = Response::new().add_event( + Event::new("reply_to_spot_order_market").add_attribute("order_id", order_id.to_string()), + ); Ok(resp) }