Golang implemented sidechain for Bytom
Revision | 87a50cf38000cb22d2c6b6853675d79f4e85b4c9 (tree) |
---|---|
Time | 2019-09-09 15:34:32 |
Author | shenao78 <shenao.78@163....> |
Commiter | shenao78 |
fix mainchain keeper
@@ -125,10 +125,9 @@ func (m *mainchainKeeper) isWithdrawalTx(tx *types.Tx) bool { | ||
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | - if sourceTxHash := locateSideChainTx(tx.Outputs[len(tx.Outputs)-1]); sourceTxHash == "" { | |
129 | - return false | |
130 | - } | |
131 | - return true | |
128 | + sourceTxHash := locateSideChainTx(tx.Outputs[len(tx.Outputs)-1]) | |
129 | + _, err := hex.DecodeString(sourceTxHash) | |
130 | + return err == nil && len(sourceTxHash) == 64 | |
132 | 131 | } |
133 | 132 | |
134 | 133 | func locateSideChainTx(output *types.TxOutput) string { |
@@ -257,7 +256,7 @@ func (m *mainchainKeeper) processWithdrawalTx(db *gorm.DB, block *types.Block, t | ||
257 | 256 | blockHash := block.Hash() |
258 | 257 | tx := block.Transactions[txIndex] |
259 | 258 | |
260 | - stmt := db.Model(&orm.CrossTransaction{}).Where(&orm.CrossTransaction{ | |
259 | + return db.Model(&orm.CrossTransaction{}).Where(&orm.CrossTransaction{ | |
261 | 260 | SourceTxHash: locateSideChainTx(tx.Outputs[len(tx.Outputs)-1]), |
262 | 261 | Status: common.CrossTxPendingStatus, |
263 | 262 | }).UpdateColumn(&orm.CrossTransaction{ |
@@ -267,15 +266,7 @@ func (m *mainchainKeeper) processWithdrawalTx(db *gorm.DB, block *types.Block, t | ||
267 | 266 | DestTxIndex: sql.NullInt64{int64(txIndex), true}, |
268 | 267 | DestTxHash: sql.NullString{tx.ID.String(), true}, |
269 | 268 | Status: common.CrossTxCompletedStatus, |
270 | - }) | |
271 | - if stmt.Error != nil { | |
272 | - return stmt.Error | |
273 | - } | |
274 | - | |
275 | - if stmt.RowsAffected != 1 { | |
276 | - return ErrInconsistentDB | |
277 | - } | |
278 | - return nil | |
269 | + }).Error | |
279 | 270 | } |
280 | 271 | |
281 | 272 | func (m *mainchainKeeper) syncBlock() (bool, error) { |