multi: update btcsuite API's to latest upstream changes
This commit makes a large number of minor changes concerning API usage within the deamon to match the latest version on the upstream btcsuite libraries. The major changes are the switch from wire.ShaHash to chainhash.Hash, and that wire.NewMsgTx() now takes a paramter indicating the version of the transaction to be created.
This commit is contained in:
40 files changed
+234
-211
No files matched your search
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
)
|
||||
|
||||
// ChannelAnnouncement message is used to announce the existence of a channel
|
||||
@@ -56,12 +56,12 @@ func (a *ChannelAnnouncement) Validate() error {
|
||||
|
||||
var sigHash []byte
|
||||
|
||||
sigHash = wire.DoubleSha256(a.FirstNodeID.SerializeCompressed())
|
||||
sigHash = chainhash.DoubleHashB(a.FirstNodeID.SerializeCompressed())
|
||||
if !a.FirstBitcoinSig.Verify(sigHash, a.FirstBitcoinKey) {
|
||||
return errors.New("can't verify first bitcoin signature")
|
||||
}
|
||||
|
||||
sigHash = wire.DoubleSha256(a.SecondNodeID.SerializeCompressed())
|
||||
sigHash = chainhash.DoubleHashB(a.SecondNodeID.SerializeCompressed())
|
||||
if !a.SecondBitcoinSig.Verify(sigHash, a.SecondBitcoinKey) {
|
||||
return errors.New("can't verify second bitcoin signature")
|
||||
}
|
||||
@@ -70,7 +70,7 @@ func (a *ChannelAnnouncement) Validate() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dataHash := wire.DoubleSha256(data)
|
||||
dataHash := chainhash.DoubleHashB(data)
|
||||
|
||||
if !a.FirstNodeSig.Verify(dataHash, a.FirstNodeID) {
|
||||
return errors.New("can't verify data in first node signature")
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
)
|
||||
|
||||
func TestChannelAnnoucementEncodeDecode(t *testing.T) {
|
||||
@@ -60,10 +60,10 @@ func TestChannelAnnoucementValidation(t *testing.T) {
|
||||
|
||||
var hash []byte
|
||||
|
||||
hash = wire.DoubleSha256(firstNodePubKey.SerializeCompressed())
|
||||
hash = chainhash.DoubleHashB(firstNodePubKey.SerializeCompressed())
|
||||
firstBitcoinSig, _ := firstBitcoinPrivKey.Sign(hash)
|
||||
|
||||
hash = wire.DoubleSha256(secondNodePubKey.SerializeCompressed())
|
||||
hash = chainhash.DoubleHashB(secondNodePubKey.SerializeCompressed())
|
||||
secondBitcoinSig, _ := secondBitcoinPrivKey.Sign(hash)
|
||||
|
||||
ca := &ChannelAnnouncement{
|
||||
@@ -77,7 +77,7 @@ func TestChannelAnnoucementValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
dataToSign, _ := ca.DataToSign()
|
||||
hash = wire.DoubleSha256(dataToSign)
|
||||
hash = chainhash.DoubleHashB(dataToSign)
|
||||
|
||||
firstNodeSign, _ := firstNodePrivKey.Sign(hash)
|
||||
ca.FirstNodeSig = firstNodeSign
|
||||
|
||||
+6
-5
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
"github.com/roasbeef/btcd/txscript"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcutil"
|
||||
@@ -175,7 +176,7 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
if _, err = w.Write(b[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
case *wire.ShaHash:
|
||||
case *chainhash.Hash:
|
||||
if _, err := w.Write(e[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -425,8 +426,8 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
*e = btcutil.Amount(int64(binary.BigEndian.Uint64(b[:])))
|
||||
case **wire.ShaHash:
|
||||
var b wire.ShaHash
|
||||
case **chainhash.Hash:
|
||||
var b chainhash.Hash
|
||||
if _, err := io.ReadFull(r, b[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -576,7 +577,7 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
if _, err = io.ReadFull(r, h[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
hash, err := wire.NewShaHash(h[:])
|
||||
hash, err := chainhash.NewHash(h[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -596,7 +597,7 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
if _, err = io.ReadFull(r, h[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
hash, err := wire.NewShaHash(h[:])
|
||||
hash, err := chainhash.NewHash(h[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"net"
|
||||
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
"github.com/roasbeef/btcd/txscript"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
)
|
||||
@@ -63,18 +64,18 @@ var (
|
||||
// echo -n | openssl sha256
|
||||
// This stuff gets reversed!!!
|
||||
shaHash1Bytes, _ = hex.DecodeString("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
|
||||
shaHash1, _ = wire.NewShaHash(shaHash1Bytes)
|
||||
shaHash1, _ = chainhash.NewHash(shaHash1Bytes)
|
||||
outpoint1 = wire.NewOutPoint(shaHash1, 0)
|
||||
// echo | openssl sha256
|
||||
// This stuff gets reversed!!!
|
||||
shaHash2Bytes, _ = hex.DecodeString("01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b")
|
||||
shaHash2, _ = wire.NewShaHash(shaHash2Bytes)
|
||||
shaHash2, _ = chainhash.NewHash(shaHash2Bytes)
|
||||
outpoint2 = wire.NewOutPoint(shaHash2, 1)
|
||||
// create inputs from outpoint1 and outpoint2
|
||||
inputs = []*wire.TxIn{wire.NewTxIn(outpoint1, nil, nil), wire.NewTxIn(outpoint2, nil, nil)}
|
||||
|
||||
// Commitment Signature
|
||||
tx = wire.NewMsgTx()
|
||||
tx = wire.NewMsgTx(1)
|
||||
emptybytes = new([]byte)
|
||||
sigStr, _ = txscript.RawTxInSignature(tx, 0, *emptybytes, txscript.SigHashAll, privKey)
|
||||
commitSig, _ = btcec.ParseSignature(sigStr, btcec.S256())
|
||||
@@ -93,7 +94,7 @@ var (
|
||||
ptrFundingTXSigs = append(*new([]*btcec.Signature), commitSig1, commitSig2)
|
||||
|
||||
// TxID
|
||||
txid = new(wire.ShaHash)
|
||||
txid = new(chainhash.Hash)
|
||||
// Reversed when displayed
|
||||
txidBytes, _ = hex.DecodeString("fd95c6e5c9d5bcf9cfc7231b6a438e46c518c724d0b04b75cc8fddf84a254e3a")
|
||||
_ = copy(txid[:], txidBytes)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -119,7 +119,7 @@ func (a *NodeAnnouncement) Validate() error {
|
||||
return err
|
||||
}
|
||||
|
||||
dataHash := wire.DoubleSha256(data)
|
||||
dataHash := chainhash.DoubleHashB(data)
|
||||
if !a.Signature.Verify(dataHash, a.NodeID) {
|
||||
return errors.New("can't check the node annoucement signature")
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
)
|
||||
|
||||
func TestNodeAnnouncementEncodeDecode(t *testing.T) {
|
||||
@@ -58,7 +58,7 @@ func TestNodeAnnoucementValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
dataToSign, _ := na.DataToSign()
|
||||
hash = wire.DoubleSha256(dataToSign)
|
||||
hash = chainhash.DoubleHashB(dataToSign)
|
||||
|
||||
signature, _ := nodePrivKey.Sign(hash)
|
||||
na.Signature = signature
|
||||
|
||||
Reference in new issue
Block a user