From 7513804cc4e204d9a7bccb56b76ec34decb072d1 Mon Sep 17 00:00:00 2001 From: Evan Han Date: Wed, 27 Jan 2021 10:55:27 +0800 Subject: [PATCH] Merge PR: fix stream panic (#601) --- x/backend/types/tx.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/x/backend/types/tx.go b/x/backend/types/tx.go index bbe23f9fd6..fa31ed92e2 100644 --- a/x/backend/types/tx.go +++ b/x/backend/types/tx.go @@ -18,18 +18,24 @@ func GenerateTx(tx *auth.StdTx, txHash string, ctx sdk.Context, orderKeeper Orde for _, msg := range tx.GetMsgs() { switch msg.Type() { case "send": // token/send - txFrom, txTo := buildTransactionsTransfer(tx, msg.(tokenTypes.MsgSend), txHash, timestamp) - txs = append(txs, txFrom, txTo) + if sendMsg, ok := msg.(tokenTypes.MsgSend); ok { + txFrom, txTo := buildTransactionsTransfer(tx, sendMsg, txHash, timestamp) + txs = append(txs, txFrom, txTo) + } case "new": // order/new - transaction := buildTransactionNew(orderHandlerTxResult[idx], msg.(orderTypes.MsgNewOrders), - txHash, ctx, timestamp) - txs = append(txs, transaction...) - idx++ + if orderMsg, ok := msg.(orderTypes.MsgNewOrders); ok { + transaction := buildTransactionNew(orderHandlerTxResult[idx], orderMsg, + txHash, ctx, timestamp) + txs = append(txs, transaction...) + idx++ + } case "cancel": // order/cancel - transaction := buildTransactionCancel(orderHandlerTxResult[idx], msg.(orderTypes.MsgCancelOrders), - txHash, ctx, orderKeeper, timestamp) - txs = append(txs, transaction...) - idx++ + if cancelMsg, ok := msg.(orderTypes.MsgCancelOrders); ok { + transaction := buildTransactionCancel(orderHandlerTxResult[idx], cancelMsg, + txHash, ctx, orderKeeper, timestamp) + txs = append(txs, transaction...) + idx++ + } default: // In other cases, do nothing continue }