OSDN Git Service

add script
authorHAOYUatHZ <haoyu@protonmail.com>
Fri, 7 Jun 2019 12:52:26 +0000 (20:52 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Fri, 7 Jun 2019 12:52:26 +0000 (20:52 +0800)
docs/federation/federation.sql
federation/database/orm/cross_transaction_input.go
federation/database/orm/cross_transaction_output.go [new file with mode: 0644]
federation/synchron/block_processor.go

index 9fae138..eb1567c 100644 (file)
@@ -88,22 +88,46 @@ UNLOCK TABLES;
 # ------------------------------------------------------------
 CREATE TABLE `cross_transaction_inputs` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
-  `tx_id` int(11) NOT NULL,
+  `mainchain_tx_id` int(11) NOT NULL,
+  `sidechain_tx_id` int(11) DEFAULT NULL,
   `source_pos` int(11) NOT NULL,
   `asset_id` int(11) NOT NULL,
   `asset_amount` bigint(20) DEFAULT '0',
+  `script` varchar(128) NOT NULL,
   `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 `input_id` (`tx_id`,`source_pos`),
-  CONSTRAINT `cross_transaction_inputs_ibfk_1` FOREIGN KEY (`tx_id`) REFERENCES `cross_transactions` (`id`),
-  CONSTRAINT `cross_transaction_inputs_ibfk_2` FOREIGN KEY (`asset_id`) REFERENCES `assets` (`id`)
+  CONSTRAINT `cross_transaction_inputs_ibfk_1` FOREIGN KEY (`mainchain_tx_id`) REFERENCES `cross_transactions` (`id`),
+  CONSTRAINT `cross_transaction_inputs_ibfk_2` FOREIGN KEY (`sidechain_tx_id`) REFERENCES `cross_transactions` (`id`),
+  CONSTRAINT `cross_transaction_inputs_ibfk_3` FOREIGN KEY (`asset_id`) REFERENCES `assets` (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 LOCK TABLES `cross_transaction_inputs` WRITE;
 UNLOCK TABLES;
 
 
+# Dump of table cross_transaction_outputs
+# ------------------------------------------------------------
+CREATE TABLE `cross_transaction_outputs` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `sidechain_tx_id` int(11) NOT NULL,
+  `mainchain_tx_id` int(11) DEFAULT NULL,
+  `asset_id` int(11) NOT NULL,
+  `asset_amount` bigint(20) DEFAULT '0',
+  `script` varchar(128) NOT NULL,
+  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+  PRIMARY KEY (`id`),
+  CONSTRAINT `cross_transaction_outputs_ibfk_1` FOREIGN KEY (`sidechain_tx_id`) REFERENCES `cross_transactions` (`id`),
+  CONSTRAINT `cross_transaction_outputs_ibfk_2` FOREIGN KEY (`mainchain_tx_id`) REFERENCES `cross_transactions` (`id`),
+  CONSTRAINT `cross_transaction_outputs_ibfk_3` FOREIGN KEY (`asset_id`) REFERENCES `assets` (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+LOCK TABLES `cross_transaction_outputs` WRITE;
+UNLOCK TABLES;
+
+
 # Dump of table cross_transaction_signs
 # ------------------------------------------------------------
 CREATE TABLE `cross_transaction_signs` (
index 6ac771f..6d2571b 100644 (file)
@@ -1,18 +1,23 @@
 package orm
 
 import (
+       "database/sql"
+
        "github.com/vapor/federation/types"
 )
 
 type CrossTransactionInput struct {
-       ID          uint64 `gorm:"primary_key"`
-       TxID        uint64
-       SourcePos   uint64
-       AssetID     uint64
-       AssetAmount uint64
-       CreatedAt   types.Timestamp
-       UpdatedAt   types.Timestamp
+       ID            uint64 `gorm:"primary_key"`
+       MainchainTxID uint64
+       SidechainTxID sql.NullInt64
+       SourcePos     uint64
+       AssetID       uint64
+       AssetAmount   uint64
+       Script        string
+       CreatedAt     types.Timestamp
+       UpdatedAt     types.Timestamp
 
-       CrossTransaction *CrossTransaction `gorm:"foreignkey:TxID"`
-       Asset            *Asset            `gorm:"foreignkey:AssetID"`
+       MainchainTransaction *CrossTransaction `gorm:"foreignkey:MainchainTxID"`
+       SidechainTransaction *CrossTransaction `gorm:"foreignkey:SidechainTxID"`
+       Asset                *Asset            `gorm:"foreignkey:AssetID"`
 }
diff --git a/federation/database/orm/cross_transaction_output.go b/federation/database/orm/cross_transaction_output.go
new file mode 100644 (file)
index 0000000..6430619
--- /dev/null
@@ -0,0 +1,22 @@
+package orm
+
+import (
+       "database/sql"
+
+       "github.com/vapor/federation/types"
+)
+
+type CrossTransactionOutput struct {
+       ID            uint64 `gorm:"primary_key"`
+       SidechainTxID uint64
+       MainchainTxID sql.NullInt64
+       AssetID       uint64
+       AssetAmount   uint64
+       Script        string
+       CreatedAt     types.Timestamp
+       UpdatedAt     types.Timestamp
+
+       SidechainTransaction *CrossTransaction `gorm:"foreignkey:SidechainTxID"`
+       MainchainTransaction *CrossTransaction `gorm:"foreignkey:MainchainTxID"`
+       Asset                *Asset            `gorm:"foreignkey:AssetID"`
+}
index b07e931..da9f9ff 100644 (file)
@@ -75,9 +75,9 @@ func addIssueAssets(db *gorm.DB, txs []*btmTypes.Tx) error {
 func updateBlock(db *gorm.DB, bp blockProcessor) error {
        // txs := bp.getBlock().Transactions
        if bp.getCfg().IsMainchain {
-               if err := bp.processIssuing(db, txs); err != nil {
-                       return err
-               }
+               // if err := bp.processIssuing(db, txs); err != nil {
+               //      return err
+               // }
        }
 
        // addressTxMappings, err := GetAddressTxMappings(cfg, txs, bp.getTxStatus(), db)