Skip to content

Commit

Permalink
Merge PR: Restrict the use of placing or cancelling order in the mess…
Browse files Browse the repository at this point in the history
…age 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: [email protected] <[email protected]>
  • Loading branch information
summerpro and [email protected] authored Aug 19, 2020
1 parent 811f2b5 commit 808fa9b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions app/protocol/protocol_v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 808fa9b

Please sign in to comment.