`id` int(11) NOT NULL AUTO_INCREMENT,
`tx_id` int(11) NOT NULL,
`source_pos` int(11) NOT NULL,
+ `asset_id` int(11) NOT NULL,
+ `asset_amount` bigint(20) DEFAULT '0',
`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_1` FOREIGN KEY (`tx_id`) REFERENCES `cross_transactions` (`id`),
+ CONSTRAINT `cross_transaction_inputs_ibfk_2` FOREIGN KEY (`asset_id`) REFERENCES `assets` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
LOCK TABLES `cross_transaction_inputs` WRITE;
)
type CrossTransactionInput struct {
- ID uint64 `gorm:"primary_key"`
- TxID uint64
- SourcePos uint64
- CreatedAt types.Timestamp
- UpdatedAt types.Timestamp
+ ID uint64 `gorm:"primary_key"`
+ TxID uint64
+ SourcePos uint64
+ AssetID uint64
+ AssetAmount uint64
+ CreatedAt types.Timestamp
+ UpdatedAt types.Timestamp
CrossTransaction *CrossTransaction `gorm:"foreignkey:TxID"`
+ Asset *Asset `gorm:"foreignkey:AssetID"`
}
// txStatus *btmBc.TransactionStatus
}
+func (p *attachBlockProcessor) getCfg() *config.Chain {
+ return p.cfg
+}
+
func (p *attachBlockProcessor) processIssuing(db *gorm.DB, txs []*btmTypes.Tx) error {
return addIssueAssets(db, txs)
}
// "github.com/blockcenter/config"
// "github.com/blockcenter/types"
"github.com/vapor/errors"
+ "github.com/vapor/federation/config"
"github.com/vapor/federation/database/orm"
)
var ErrInconsistentDB = errors.New("inconsistent db status")
type blockProcessor interface {
+ getCfg() *config.Chain
processIssuing(db *gorm.DB, txs []*btmTypes.Tx) error
processChainInfo() error
// getBlock() *btmTypes.Block
func updateBlock(db *gorm.DB, bp blockProcessor) error {
// txs := bp.getBlock().Transactions
- // if err := bp.processIssuing(db, txs, bp.getCoin().ID); err != nil {
- // return err
- // }
+ if bp.getCfg().IsMainchain {
+ if err := bp.processIssuing(db, txs); err != nil {
+ return err
+ }
+ }
// addressTxMappings, err := GetAddressTxMappings(cfg, txs, bp.getTxStatus(), db)
// if err != nil {
// return err
// }
- // if err := updateDeletedTransaction(db); err != nil {
- // return err
- // }
+ if err := updateDeletedTransaction(db); err != nil {
+ return err
+ }
return bp.processChainInfo()
}
+
+// 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
+}
// txStatus *bc.TransactionStatus
}
+func (p *detachBlockProcessor) getCfg() *config.Chain {
+ return p.cfg
+}
+
func (p *detachBlockProcessor) processIssuing(db *gorm.DB, txs []*btmTypes.Tx) error {
return nil
}