OSDN Git Service

ffofo
authorHAOYUatHZ <haoyu@protonmail.com>
Thu, 6 Jun 2019 01:26:05 +0000 (09:26 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Thu, 6 Jun 2019 01:26:05 +0000 (09:26 +0800)
federation/synchron/unconfirmed_tx_keeper.go

index ece31f9..2ccfa5b 100644 (file)
@@ -2,6 +2,7 @@ package synchron
 
 import (
        // "time"
+       "encoding/json"
 
        // "github.com/bytom/errors"
        // "github.com/bytom/protocol/bc"
@@ -35,5 +36,40 @@ func (u *unconfirmedTxKeeper) Run() {
                log.WithField("err", err).Fatal("subscribe new transaction fail")
        }
 
-       // u.receiveTransactions()
+       u.receiveTransactions()
+}
+
+// TODO: FK
+type TxDesc struct {
+       // Tx         *btmTypes.Tx `json:"transaction"`
+       StatusFail bool `json:"status_fail"`
+}
+
+func (u *unconfirmedTxKeeper) receiveTransactions() {
+       for resp := range u.processTxCh {
+               if resp.NotificationType != service.ResponseNewTransaction {
+                       log.Warn("receive non new transaction message")
+                       continue
+               }
+
+               txDesc := &TxDesc{}
+               if err := json.Unmarshal([]byte(resp.Data), txDesc); err != nil {
+                       log.WithField("err", err).Error("unmarshal transaction error")
+                       continue
+               }
+
+               // coin := &orm.Coin{Name: u.coinName}
+               // if err := u.db.Where(coin).First(coin).Error; err != nil {
+               //      log.WithField("err", err).Error("query coin fail")
+               //      continue
+               // }
+
+               // if err := addIssueAssets(u.db, []*btmTypes.Tx{txDesc.Tx}, coin.ID); err != nil {
+               //      log.WithField("err", err).Error("fail on adding issue assets")
+               // }
+
+               // if err := u.AddUnconfirmedTx(coin, txDesc); err != nil {
+               //      log.WithField("err", err).Error("fail on adding unconfirmed transaction")
+               // }
+       }
 }