OSDN Git Service

fk
authorHAOYUatHZ <haoyu@protonmail.com>
Thu, 13 Jun 2019 13:50:50 +0000 (21:50 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Thu, 13 Jun 2019 13:50:50 +0000 (21:50 +0800)
docs/federation/federation.sql
main.go [new file with mode: 0644]

index 1d6f894..35b67f0 100644 (file)
@@ -6,6 +6,8 @@
 /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
 /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
 
+DROP DATABASE `federation`;
+
 CREATE SCHEMA IF NOT EXISTS `federation`;
 
 USE `federation`;
@@ -13,8 +15,6 @@ USE `federation`;
 # Dump of table warders
 # ------------------------------------------------------------
 
-DROP TABLE IF EXISTS `warders`;
-
 CREATE TABLE `warders` (
   `id` tinyint(1) unsigned NOT NULL AUTO_INCREMENT,
   `pubkey` varchar(64) NOT NULL,
@@ -77,12 +77,11 @@ CREATE TABLE `cross_transactions` (
   PRIMARY KEY (`id`),
   UNIQUE KEY `source_mux_id` (`chain_id`,`source_mux_id`),
   UNIQUE KEY `source_tx_hash` (`chain_id`,`source_tx_hash`),
-  UNIQUE KEY `source_raw_transaction` (`source_raw_transaction`),
-  UNIQUE KEY `source_blockhash_txidx` (`chain_id`,`source_block_hash`,`tx_index`),
-  UNIQUE KEY `source_blockheight_txidx` (`chain_id`,`source_block_height`,`tx_index`),
+  UNIQUE KEY `source_blockhash_txidx` (`chain_id`,`source_block_hash`,`source_tx_index`),
+  UNIQUE KEY `source_blockheight_txidx` (`chain_id`,`source_block_height`,`source_tx_index`),
   UNIQUE KEY `dest_tx_hash` (`chain_id`,`dest_tx_hash`),
-  UNIQUE KEY `dest_blockhash_txidx` (`chain_id`,`dest_block_hash`,`tx_index`),
-  UNIQUE KEY `dest_blockheight_txidx` (`chain_id`,`dest_block_height`,`tx_index`),
+  UNIQUE KEY `dest_blockhash_txidx` (`chain_id`,`dest_block_hash`,`dest_tx_index`),
+  UNIQUE KEY `dest_blockheight_txidx` (`chain_id`,`dest_block_height`,`dest_tx_index`),
   CONSTRAINT `cross_transactions_ibfk_1` FOREIGN KEY (`chain_id`) REFERENCES `chains` (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
@@ -134,8 +133,6 @@ UNLOCK TABLES;
 # Dump of table assets
 # ------------------------------------------------------------
 
-DROP TABLE IF EXISTS `assets`;
-
 CREATE TABLE `assets` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `asset_id` varchar(64) NOT NULL,
diff --git a/main.go b/main.go
new file mode 100644 (file)
index 0000000..68ceb1a
--- /dev/null
+++ b/main.go
@@ -0,0 +1,36 @@
+package main
+
+import (
+       "database/sql"
+       "fmt"
+
+       _ "github.com/go-sql-driver/mysql"
+       "github.com/jinzhu/gorm"
+
+       "github.com/vapor/federation/common"
+       // "github.com/vapor/federation/config"
+       "github.com/vapor/federation/database/orm"
+)
+
+func main() {
+       dsnTemplate := "%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=true&loc=Local"
+       dsn := fmt.Sprintf(dsnTemplate, "root", "toor", "127.0.0.1", 3306, "federation")
+       db, err := gorm.Open("mysql", dsn)
+       if err != nil {
+               panic(err)
+       }
+
+       if err := db.Where(&orm.CrossTransaction{
+               ChainID:    1,
+               DestTxHash: sql.NullString{"tx.ID.String()", true},
+               Status:     common.CrossTxSubmittedStatus,
+       }).UpdateColumn(&orm.CrossTransaction{
+               DestBlockHeight: sql.NullInt64{int64(2), true},
+               DestBlockHash:   sql.NullString{"blockHash.String()", true},
+               DestTxIndex:     sql.NullInt64{int64(3), true},
+               Status:          common.CrossTxCompletedStatus,
+       }).Error; err != nil {
+               panic(err)
+       }
+
+}