lnwallet: move txout serialization out of lnwire

This commit is contained in:
Conner Fromknecht 2017-08-25 18:12:34 -07:00 committed by Olaoluwa Osuntokun
parent 4bae23a9a7
commit 8ef2263e46
3 changed files with 10 additions and 11 deletions

@ -5,7 +5,6 @@ import (
"errors"
"io"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/txscript"
"github.com/roasbeef/btcd/wire"
@ -104,7 +103,7 @@ func WriteSignDescriptor(w io.Writer, sd *SignDescriptor) error {
return err
}
if err := lnwire.WriteTxOut(w, sd.Output); err != nil {
if err := writeTxOut(w, sd.Output); err != nil {
return err
}
@ -174,7 +173,7 @@ func ReadSignDescriptor(r io.Reader, sd *SignDescriptor) error {
sd.WitnessScript = witnessScript
txOut := &wire.TxOut{}
if err := lnwire.ReadTxOut(r, txOut); err != nil {
if err := readTxOut(r, txOut); err != nil {
return err
}
sd.Output = txOut

@ -1,4 +1,4 @@
package lnwire
package lnwallet
import (
"encoding/binary"
@ -7,8 +7,8 @@ import (
"github.com/roasbeef/btcd/wire"
)
// WriteTxOut serializes a wire.TxOut struct into the passed io.Writer stream.
func WriteTxOut(w io.Writer, txo *wire.TxOut) error {
// writeTxOut serializes a wire.TxOut struct into the passed io.Writer stream.
func writeTxOut(w io.Writer, txo *wire.TxOut) error {
var scratch [8]byte
binary.BigEndian.PutUint64(scratch[:], uint64(txo.Value))
@ -23,8 +23,8 @@ func WriteTxOut(w io.Writer, txo *wire.TxOut) error {
return nil
}
// ReadTxOut deserializes a wire.TxOut struct from the passed io.Reader stream.
func ReadTxOut(r io.Reader, txo *wire.TxOut) error {
// readTxOut deserializes a wire.TxOut struct from the passed io.Reader stream.
func readTxOut(r io.Reader, txo *wire.TxOut) error {
var scratch [8]byte
if _, err := io.ReadFull(r, scratch[:]); err != nil {

@ -1,4 +1,4 @@
package lnwire
package lnwallet
import (
"bytes"
@ -28,12 +28,12 @@ func TestTxOutSerialization(t *testing.T) {
var buf bytes.Buffer
if err := WriteTxOut(&buf, &txo); err != nil {
if err := writeTxOut(&buf, &txo); err != nil {
t.Fatalf("unable to serialize txout: %v", err)
}
var deserializedTxo wire.TxOut
if err := ReadTxOut(&buf, &deserializedTxo); err != nil {
if err := readTxOut(&buf, &deserializedTxo); err != nil {
t.Fatalf("unable to deserialize txout: %v", err)
}