From 808fa9b55530affc7a3a1a1bb8384c58eb6d3512 Mon Sep 17 00:00:00 2001 From: Pierre <974741468@qq.com> Date: Wed, 19 Aug 2020 13:58:29 +0800 Subject: [PATCH] Merge PR: Restrict the use of placing or cancelling order in the message array (#315) * It is not expected that msgs with placeOrder type or cancelOrder type in the msg array * fix bug from validateMsgHook * Optimize the code in validateMsgHook Co-authored-by: lei.ji@okcoin.com --- app/protocol/protocol_v0.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/protocol/protocol_v0.go b/app/protocol/protocol_v0.go index 1ebb5b3c23..98cec79e81 100644 --- a/app/protocol/protocol_v0.go +++ b/app/protocol/protocol_v0.go @@ -474,16 +474,34 @@ func MakeCodec() *codec.Codec { } func validateMsgHook(orderKeeper order.Keeper) auth.ValidateMsgHandler { - return func(newCtx sdk.Context, msgs []sdk.Msg) sdk.Result { + return func(newCtx sdk.Context, msgs []sdk.Msg) (res sdk.Result) { + + wrongMsgRes := sdk.Result{ + Code: sdk.CodeUnknownRequest, + Log: "It is not allowed that a transaction with more than one message contains placeOrder or cancelOrder message", + } + for _, msg := range msgs { switch assertedMsg := msg.(type) { case order.MsgNewOrders: - return order.ValidateMsgNewOrders(newCtx, orderKeeper, assertedMsg) + if len(msgs) > 1 { + res = wrongMsgRes + break + } + res = order.ValidateMsgNewOrders(newCtx, orderKeeper, assertedMsg) case order.MsgCancelOrders: - return order.ValidateMsgCancelOrders(newCtx, orderKeeper, assertedMsg) + if len(msgs) > 1 { + res = wrongMsgRes + break + } + res = order.ValidateMsgCancelOrders(newCtx, orderKeeper, assertedMsg) + } + + if !res.IsOK() { + break } } - return sdk.Result{} + return } }