channeldb+utxonursery+lnwire: use lnwire's OutPoint,TxOut serialization

This commit is contained in:
Philip Hayes
2017-05-07 03:34:00 -07:00
committed by Olaoluwa Osuntokun
parent 7f575b688e
commit f0aa186a56
10 changed files with 232 additions and 174 deletions

View File

@@ -4,13 +4,11 @@ import (
"encoding/binary"
"fmt"
"io"
"math"
"net"
"github.com/go-errors/errors"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg/chainhash"
"github.com/roasbeef/btcd/wire"
"github.com/roasbeef/btcutil"
)
@@ -189,21 +187,7 @@ func writeElement(w io.Writer, element interface{}) error {
}
case wire.OutPoint:
var h [32]byte
copy(h[:], e.Hash[:])
if _, err := w.Write(h[:]); err != nil {
return err
}
if e.Index > math.MaxUint16 {
return fmt.Errorf("index for outpoint (%v) is "+
"greater than max index of %v", e.Index,
math.MaxUint16)
}
var idx [2]byte
binary.BigEndian.PutUint16(idx[:], uint16(e.Index))
if _, err := w.Write(idx[:]); err != nil {
if err := WriteOutPoint(w, &e); err != nil {
return err
}
@@ -479,28 +463,7 @@ func readElement(r io.Reader, element interface{}) error {
}
*e = pkScript
case *wire.OutPoint:
var h [32]byte
if _, err = io.ReadFull(r, h[:]); err != nil {
return err
}
hash, err := chainhash.NewHash(h[:])
if err != nil {
return err
}
var idxBytes [2]byte
_, err = io.ReadFull(r, idxBytes[:])
if err != nil {
return err
}
index := binary.BigEndian.Uint16(idxBytes[:])
*e = wire.OutPoint{
Hash: *hash,
Index: uint32(index),
}
case *FailCode:
if err := readElement(r, (*uint16)(e)); err != nil {
if err := ReadOutPoint(r, e); err != nil {
return err
}