From 5a63e49f3b3b6c347c04e7f43249ce871943618d Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:27:08 +0100 Subject: [PATCH] =?UTF-8?q?Enhance=20CreateSpotOrder=20to=20emit=20events?= =?UTF-8?q?=20and=20return=20OrderId=20on=20market=20b=E2=80=A6=20(#1045)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enhance CreateSpotOrder to emit events and return OrderId on market buy execution - Updated the CreateSpotOrder function to emit an event upon successful execution of a market buy order. - Modified the response to include the OrderId of the pending spot order, improving the feedback provided to the user. - These changes enhance the order processing flow and provide better tracking of executed orders. --- x/tradeshield/keeper/msg_server_spot_order.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/x/tradeshield/keeper/msg_server_spot_order.go b/x/tradeshield/keeper/msg_server_spot_order.go index cbbfbfc89..9b1f6277d 100644 --- a/x/tradeshield/keeper/msg_server_spot_order.go +++ b/x/tradeshield/keeper/msg_server_spot_order.go @@ -25,11 +25,16 @@ func (k msgServer) CreateSpotOrder(goCtx context.Context, msg *types.MsgCreateSp // if the order is market buy, execute it immediately if msg.OrderType == types.SpotOrderType_MARKETBUY { - _, err := k.ExecuteMarketBuyOrder(ctx, pendingSpotOrder) + res, err := k.ExecuteMarketBuyOrder(ctx, pendingSpotOrder) if err != nil { return nil, err } - return &types.MsgCreateSpotOrderResponse{}, nil + + ctx.EventManager().EmitEvent(types.NewExecuteSpotOrderEvt(pendingSpotOrder, res)) + + return &types.MsgCreateSpotOrderResponse{ + OrderId: pendingSpotOrder.OrderId, + }, nil } // add the order to the pending orders