channeldb+migration: export commonly used methods

This commit exports several commonly used methods that can be used by
later migrations. It also adds a channel commit deserializer.
This commit is contained in:
yyforyongyu committed 2022-04-20 01:18:12 +08:00
1 parent 22f8f6ed4a
commit 8b289e79f5
7 files changed
+109 -20

No files matched your search

+6 -6
View File
@@ -15,9 +15,9 @@ import (
"github.com/lightningnetwork/lnd/shachain"
)
// writeOutpoint writes an outpoint to the passed writer using the minimal
// WriteOutpoint writes an outpoint to the passed writer using the minimal
// amount of bytes possible.
func writeOutpoint(w io.Writer, o *wire.OutPoint) error {
func WriteOutpoint(w io.Writer, o *wire.OutPoint) error {
if _, err := w.Write(o.Hash[:]); err != nil {
return err
}
@@ -28,9 +28,9 @@ func writeOutpoint(w io.Writer, o *wire.OutPoint) error {
return nil
}
// readOutpoint reads an outpoint from the passed reader that was previously
// ReadOutpoint reads an outpoint from the passed reader that was previously
// written using the writeOutpoint struct.
func readOutpoint(r io.Reader, o *wire.OutPoint) error {
func ReadOutpoint(r io.Reader, o *wire.OutPoint) error {
if _, err := io.ReadFull(r, o.Hash[:]); err != nil {
return err
}
@@ -88,7 +88,7 @@ func WriteElement(w io.Writer, element interface{}) error {
}
case wire.OutPoint:
return writeOutpoint(w, &e)
return WriteOutpoint(w, &e)
case lnwire.ShortChannelID:
if err := binary.Write(w, byteOrder, e.ToUint64()); err != nil {
@@ -258,7 +258,7 @@ func ReadElement(r io.Reader, element interface{}) error {
}
case *wire.OutPoint:
return readOutpoint(r, e)
return ReadOutpoint(r, e)
case *lnwire.ShortChannelID:
var a uint64