OSDN Git Service

add chain id
authorHAOYUatHZ <haoyu@protonmail.com>
Sat, 8 Jun 2019 15:05:52 +0000 (23:05 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Sat, 8 Jun 2019 15:05:52 +0000 (23:05 +0800)
docs/federation/federation.sql
federation/synchron/detach_block_processor.go

index 1057de4..d6336aa 100644 (file)
@@ -72,10 +72,10 @@ CREATE TABLE `cross_transactions` (
   `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   PRIMARY KEY (`id`),
-  UNIQUE KEY `mux_id` (`mux_id`),
-  UNIQUE KEY `tx_hash` (`tx_hash`),
+  UNIQUE KEY `mux_id` (`chain_id`,`mux_id`),
+  UNIQUE KEY `tx_hash` (`chain_id`,`tx_hash`),
   UNIQUE KEY `raw_transaction` (`raw_transaction`),
-  UNIQUE KEY `blockhash_txidx` (`block_hash`,`tx_index`),
+  UNIQUE KEY `blockhash_txidx` (`chain_id`,`block_hash`,`tx_index`),
   UNIQUE KEY `blockheight_txidx` (`chain_id`,`block_height`,`tx_index`),
   CONSTRAINT `transactions_ibfk_1` FOREIGN KEY (`chain_id`) REFERENCES `chains` (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
index 4b44bcc..d07fd8e 100644 (file)
@@ -28,11 +28,11 @@ func (p *detachBlockProcessor) getBlock() interface{} {
 }
 
 func (p *detachBlockProcessor) processWithdrawalToMainchain(txIndex uint64, tx *btmTypes.Tx) error {
-       return p.db.Delete(&orm.CrossTransaction{TxHash: tx.ID.String()}).Error
+       return p.db.Delete(&orm.CrossTransaction{ChainID: p.chain.ID, TxHash: tx.ID.String()}).Error
 }
 
 func (p *detachBlockProcessor) processDepositFromMainchain(txIndex uint64, tx *btmTypes.Tx) error {
-       ormTx := &orm.CrossTransaction{TxHash: tx.ID.String()}
+       ormTx := &orm.CrossTransaction{ChainID: p.chain.ID, TxHash: tx.ID.String()}
        if err := p.db.Where(tx).First(tx).Error; err != nil {
                return errors.Wrap(err, "db query transaction")
        }