OSDN Git Service

add status fail for websocket nofify new transaction (#1582)
authormuscle_boy <shenao.78@163.com>
Thu, 21 Feb 2019 09:01:42 +0000 (17:01 +0800)
committerPaladz <yzhu101@uottawa.ca>
Thu, 21 Feb 2019 09:01:42 +0000 (17:01 +0800)
net/websocket/wsnotificationmaneger.go
node/node.go
protocol/txpool.go

index 87ac8ff..ff1e05f 100644 (file)
@@ -15,7 +15,7 @@ import (
 // Notification types
 type notificationBlockConnected types.Block
 type notificationBlockDisconnected types.Block
-type notificationTxAcceptedByMempool types.Tx
+type notificationTxDescAcceptedByMempool protocol.TxDesc
 
 // Notification control requests
 type notificationRegisterClient WSClient
@@ -214,13 +214,13 @@ func (m *WSNotificationManager) NotifyBlockDisconnected(block *types.Block) {
        }
 }
 
-// NotifyMempoolTx passes a transaction accepted by mempool to the
+// NotifyMempoolTx passes a transaction desc accepted by mempool to the
 // notification manager for transaction notification processing.  If
 // isNew is true, the tx is is a new transaction, rather than one
 // added to the mempool during a reorg.
-func (m *WSNotificationManager) NotifyMempoolTx(tx *types.Tx) {
+func (m *WSNotificationManager) NotifyMempoolTx(txDesc *protocol.TxDesc) {
        select {
-       case m.queueNotification <- (*notificationTxAcceptedByMempool)(tx):
+       case m.queueNotification <- (*notificationTxDescAcceptedByMempool)(txDesc):
        case <-m.quit:
        }
 }
@@ -252,10 +252,10 @@ out:
                                        m.notifyBlockDisconnected(blockNotifications, block)
                                }
 
-                       case *notificationTxAcceptedByMempool:
-                               tx := (*types.Tx)(n)
+                       case *notificationTxDescAcceptedByMempool:
+                               txDesc := (*protocol.TxDesc)(n)
                                if len(txNotifications) != 0 {
-                                       m.notifyForNewTx(txNotifications, tx)
+                                       m.notifyForNewTx(txNotifications, txDesc)
                                }
 
                        case *notificationRegisterBlocks:
@@ -368,8 +368,8 @@ func (m *WSNotificationManager) UnregisterNewMempoolTxsUpdates(wsc *WSClient) {
 
 // notifyForNewTx notifies websocket clients that have registered for updates
 // when a new transaction is added to the memory pool.
-func (m *WSNotificationManager) notifyForNewTx(clients map[chan struct{}]*WSClient, tx *types.Tx) {
-       resp := NewWSResponse(NTNewTransaction.String(), tx, nil)
+func (m *WSNotificationManager) notifyForNewTx(clients map[chan struct{}]*WSClient, txDesc *protocol.TxDesc) {
+       resp := NewWSResponse(NTNewTransaction.String(), txDesc, nil)
        marshalledJSON, err := json.Marshal(resp)
        if err != nil {
                log.WithFields(log.Fields{"module": logModule, "error": err}).Error("Failed to marshal tx notification")
index 65b742d..f75814d 100644 (file)
@@ -176,7 +176,7 @@ func newPoolTxListener(txPool *protocol.TxPool, syncManager *netsync.SyncManager
                        if wallet != nil {
                                wallet.AddUnconfirmedTx(msg.TxDesc)
                        }
-                       notificationMgr.NotifyMempoolTx(msg.Tx)
+                       notificationMgr.NotifyMempoolTx(msg.TxDesc)
                case protocol.MsgRemoveTx:
                        if wallet != nil {
                                wallet.RemoveUnconfirmedTx(msg.TxDesc)
index 6924e5b..605e718 100644 (file)
@@ -38,12 +38,12 @@ var (
 
 // TxDesc store tx and related info for mining strategy
 type TxDesc struct {
-       Tx         *types.Tx
-       Added      time.Time
-       StatusFail bool
-       Height     uint64
-       Weight     uint64
-       Fee        uint64
+       Tx         *types.Tx `json:"transaction"`
+       Added      time.Time `json:"-"`
+       StatusFail bool      `json:"status_fail"`
+       Height     uint64    `json:"-"`
+       Weight     uint64    `json:"-"`
+       Fee        uint64    `json:"-"`
 }
 
 // TxPoolMsg is use for notify pool changes