OSDN Git Service

add
authorHAOYUatHZ <haoyu@protonmail.com>
Sat, 8 Jun 2019 14:39:12 +0000 (22:39 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Sat, 8 Jun 2019 14:39:12 +0000 (22:39 +0800)
federation/synchron/block_processor.go
federation/synchron/detach_block_processor.go

index 1e51ff3..943ce14 100644 (file)
@@ -115,10 +115,6 @@ func updateBlock(db *gorm.DB, bp blockProcessor) error {
        //      return err
        // }
 
-       if err := updateDeletedTransaction(db); err != nil {
-               return err
-       }
-
        return bp.processChainInfo()
 }
 
@@ -213,9 +209,3 @@ func getRawCrossChainOutputs(tx *vaporTypes.Tx) []*orm.CrossTransactionOutput {
        }
        return outputs
 }
-
-// An expired unconfirmed transaction will be marked as deleted, but the latter transaction was packaged into block,
-// the deleted_at flag must be removed. In addition, the gorm can't support update deleted_at field directly, can only use raw sql.
-func updateDeletedTransaction(db *gorm.DB) error {
-       return db.Exec("UPDATE cross_transactions SET deleted_at = NULL WHERE block_height > 0 AND deleted_at IS NOT NULL").Error
-}
index 02b033b..12e5a00 100644 (file)
@@ -6,6 +6,7 @@ import (
        btmTypes "github.com/bytom/protocol/bc/types"
        "github.com/jinzhu/gorm"
 
+       "github.com/vapor/errors"
        "github.com/vapor/federation/config"
        "github.com/vapor/federation/database/orm"
        vaporTypes "github.com/vapor/protocol/bc/types"
@@ -28,7 +29,16 @@ func (p *detachBlockProcessor) getBlock() interface{} {
 }
 
 func (p *detachBlockProcessor) processDepositFromMainchain(txIndex uint64, tx *btmTypes.Tx) error {
-       return nil
+       ormTx := &orm.CrossTransaction{TxHash: tx.ID.String()}
+       if err := p.db.Where(tx).First(tx).Error; err != nil {
+               return errors.Wrap(err, "db query transaction")
+       }
+
+       if err := p.db.Delete(&orm.CrossTransactionInput{}, "MainchainTxID = ?", ormTx.ID).Error; err != nil {
+               return errors.Wrap(err, "db delete CrossTransactionInput")
+       }
+
+       return p.db.Delete(ormTx).Error
 }
 
 func (p *detachBlockProcessor) processIssuing(db *gorm.DB, txs []*btmTypes.Tx) error {