mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-28 05:42:37 +02:00
lnw+ba+utxon+cdb: reverts OutPoint and TxOut encoding
This commit is contained in:
committed by
Olaoluwa Osuntokun
parent
8698085e35
commit
6ffe33f01a
@@ -4,11 +4,13 @@ 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"
|
||||
)
|
||||
@@ -187,7 +189,21 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
}
|
||||
|
||||
case wire.OutPoint:
|
||||
if err := WriteOutPoint(w, &e); err != nil {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -463,10 +479,30 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
}
|
||||
*e = pkScript
|
||||
case *wire.OutPoint:
|
||||
if err := ReadOutPoint(r, e); err != nil {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
case *ChannelID:
|
||||
if _, err := io.ReadFull(r, e[:]); err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user