Skip to content

Commit

Permalink
re-gen
Browse files Browse the repository at this point in the history
  • Loading branch information
albertchon committed Dec 27, 2021
1 parent f6eaa10 commit 7af3dff
Show file tree
Hide file tree
Showing 2 changed files with 394 additions and 132 deletions.
35 changes: 22 additions & 13 deletions chain/exchange/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,22 +971,31 @@ func (msg MsgBatchUpdateOrders) ValidateBasic() error {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Sender)
}

subaccountAddress, ok := IsValidSubaccountID(msg.SubaccountId)
if !ok {
return sdkerrors.Wrap(ErrBadSubaccountID, msg.SubaccountId)
}
if !bytes.Equal(subaccountAddress.Bytes(), sender.Bytes()) {
return sdkerrors.Wrap(ErrBadSubaccountID, msg.Sender)
}
hasCancelAllMarketId := len(msg.SpotMarketIdsToCancelAll) > 0 || len(msg.DerivativeMarketIdsToCancelAll) > 0
hasSubaccountIdForCancelAll := msg.SubaccountId != ""

hasDuplicateSpotMarketIds := HasDuplicatesHexHash(msg.SpotMarketIdsToCancelAll)
if hasDuplicateSpotMarketIds {
return sdkerrors.Wrap(ErrInvalidBatchMsgUpdate, "msg contains duplicate cancel all spot market ids")
if hasCancelAllMarketId && !hasSubaccountIdForCancelAll {
return sdkerrors.Wrap(ErrInvalidBatchMsgUpdate, "msg contains cancel all market id but no subaccount id")
}

hasDuplicateDerivativesMarketIds := HasDuplicatesHexHash(msg.DerivativeMarketIdsToCancelAll)
if hasDuplicateDerivativesMarketIds {
return sdkerrors.Wrap(ErrInvalidBatchMsgUpdate, "msg contains duplicate cancel all derivative market ids")
if hasSubaccountIdForCancelAll {
subaccountAddress, ok := IsValidSubaccountID(msg.SubaccountId)
if !ok {
return sdkerrors.Wrap(ErrBadSubaccountID, msg.SubaccountId)
}
if !bytes.Equal(subaccountAddress.Bytes(), sender.Bytes()) {
return sdkerrors.Wrap(ErrBadSubaccountID, msg.Sender)
}

hasDuplicateSpotMarketIds := HasDuplicatesHexHash(msg.SpotMarketIdsToCancelAll)
if hasDuplicateSpotMarketIds {
return sdkerrors.Wrap(ErrInvalidBatchMsgUpdate, "msg contains duplicate cancel all spot market ids")
}

hasDuplicateDerivativesMarketIds := HasDuplicatesHexHash(msg.DerivativeMarketIdsToCancelAll)
if hasDuplicateDerivativesMarketIds {
return sdkerrors.Wrap(ErrInvalidBatchMsgUpdate, "msg contains duplicate cancel all derivative market ids")
}
}

hasDuplicateSpotOrderToCancel := HasDuplicatesOrder(msg.SpotOrdersToCancel)
Expand Down
Loading

0 comments on commit 7af3dff

Please sign in to comment.