OSDN Git Service

haoba
authorHAOYUatHZ <haoyu@protonmail.com>
Sun, 16 Jun 2019 02:17:42 +0000 (10:17 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Sun, 16 Jun 2019 02:17:42 +0000 (10:17 +0800)
federation/service/node.go
main.go

index 4dc0af0..322d10e 100644 (file)
@@ -2,6 +2,7 @@ package service
 
 import (
        "encoding/json"
+       "log"
 
        btmTypes "github.com/bytom/protocol/bc/types"
 
@@ -84,12 +85,14 @@ func (n *Node) SubmitTx(tx interface{} /*, isMainchain bool*/) (string, error) {
                if err != nil {
                        return "", errors.Wrap(err, "json marshal")
                }
+               log.Println("btmTypes")
 
        case *vaporTypes.Tx:
                payload, err = json.Marshal(submitSidechainTxReq{Tx: tx})
                if err != nil {
                        return "", errors.Wrap(err, "json marshal")
                }
+               log.Println("vaporTypes")
 
        default:
                return "", errors.New("unknown tx type")
diff --git a/main.go b/main.go
index 06f25b7..e6bcfa2 100644 (file)
--- a/main.go
+++ b/main.go
@@ -5,6 +5,7 @@ import (
        // "database/sql"
        "fmt"
 
+       btmTypes "github.com/bytom/protocol/bc/types"
        _ "github.com/go-sql-driver/mysql"
        "github.com/jinzhu/gorm"
        log "github.com/sirupsen/logrus"
@@ -14,6 +15,8 @@ import (
        // "github.com/vapor/federation/database"
        "github.com/vapor/federation/common"
        "github.com/vapor/federation/database/orm"
+       "github.com/vapor/federation/service"
+       vaporTypes "github.com/vapor/protocol/bc/types"
        // "github.com/vapor/federation/synchron"
 )
 
@@ -31,13 +34,18 @@ func main() {
        // log.Info(reqs)
 
        txs := []*orm.CrossTransaction{}
-       // if err := db.Preload("Chain").Preload("Reqs").Model(&orm.CrossTransaction{}).Where("status = ?", common.CrossTxPendingStatus).Find(&txs).Error; err == gorm.ErrRecordNotFound {
-       if err := db.Preload("Chain").Preload("Reqs").Where(&orm.CrossTransaction{Status: common.CrossTxPendingStatus}).Find(&txs).Error; err == gorm.ErrRecordNotFound {
+       if err := db.Preload("Chain").Preload("Reqs").Model(&orm.CrossTransaction{}).Where("status = ?", common.CrossTxPendingStatus).Find(&txs).Error; err == gorm.ErrRecordNotFound {
                log.Warnln("ErrRecordNotFound")
        } else if err != nil {
                log.Warnln("collectUnsubmittedTx", err)
        }
 
+       node := service.NewNode("http://127.0.0.1")
+       tx1 := &btmTypes.Tx{}
+       tx2 := &vaporTypes.Tx{}
+       node.SubmitTx(tx1)
+       node.SubmitTx(tx2)
+
        // ormTx := &orm.CrossTransaction{
        //      ChainID:              1,
        //      SourceBlockHeight:    2,