OSDN Git Service

sign
authorHAOYUatHZ <haoyu@protonmail.com>
Fri, 21 Jun 2019 02:40:24 +0000 (10:40 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Fri, 21 Jun 2019 02:40:24 +0000 (10:40 +0800)
federation/warder.go

index 00330fc..b3216a0 100644 (file)
@@ -6,6 +6,7 @@ import (
        "encoding/json"
        "time"
 
+       btmBc "github.com/bytom/protocol/bc"
        btmTypes "github.com/bytom/protocol/bc/types"
        "github.com/jinzhu/gorm"
        log "github.com/sirupsen/logrus"
@@ -278,7 +279,6 @@ func (w *warder) initDestTxSigns(destTx interface{}, ormTx *orm.CrossTransaction
                }).Error
 }
 
-// TODO:
 func (w *warder) getSigns(destTx interface{}, ormTx *orm.CrossTransaction) ([]string, error) {
        if ormTx.Status != common.CrossTxPendingStatus || !ormTx.DestTxHash.Valid {
                return nil, errors.New("cross-chain tx status error")
@@ -291,15 +291,28 @@ func (w *warder) getSigns(destTx interface{}, ormTx *orm.CrossTransaction) ([]st
 
        var signs []string
        for _, data := range signData {
+               var sign []byte
                switch destTx.(type) {
                case *vaporTypes.Tx:
+                       msg := &vaporBc.Hash{}
+                       if err := msg.UnmarshalText([]byte(data)); err != nil {
+                               return nil, errors.Wrap(err, "Unmarshal signData")
+                       }
+
+                       sign = w.xprv.Sign([]byte(msg.String()))
+
                case *btmTypes.Tx:
+                       msg := &btmBc.Hash{}
+                       if err := msg.UnmarshalText([]byte(data)); err != nil {
+                               return nil, errors.Wrap(err, "Unmarshal signData")
+                       }
+
+                       sign = w.xprv.Sign([]byte(msg.String()))
+
                default:
                        return nil, errUnknownTxType
                }
-               // TODO: sign it
-               msg := []byte{}
-               sign := w.xprv.Sign(msg)
+
                signs = append(signs, hex.EncodeToString(sign))
        }