channeldb: rename Encode/Decode to serializeLogUpdate/deserializeLogUpdate
To more easily use different version of it post-/pre-migration, we rename the method and make it take the LogUpdate as an argument.
This commit is contained in:
parent
7569cca19b
commit
90d36dbdd4
@ -1791,14 +1791,19 @@ type LogUpdate struct {
|
||||
UpdateMsg lnwire.Message
|
||||
}
|
||||
|
||||
// Encode writes a log update to the provided io.Writer.
|
||||
func (l *LogUpdate) Encode(w io.Writer) error {
|
||||
// serializeLogUpdate writes a log update to the provided io.Writer.
|
||||
func serializeLogUpdate(w io.Writer, l *LogUpdate) error {
|
||||
return WriteElements(w, l.LogIndex, l.UpdateMsg)
|
||||
}
|
||||
|
||||
// Decode reads a log update from the provided io.Reader.
|
||||
func (l *LogUpdate) Decode(r io.Reader) error {
|
||||
return ReadElements(r, &l.LogIndex, &l.UpdateMsg)
|
||||
// deserializeLogUpdate reads a log update from the provided io.Reader.
|
||||
func deserializeLogUpdate(r io.Reader) (*LogUpdate, error) {
|
||||
l := &LogUpdate{}
|
||||
if err := ReadElements(r, &l.LogIndex, &l.UpdateMsg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return l, nil
|
||||
}
|
||||
|
||||
// CircuitKey is used by a channel to uniquely identify the HTLCs it receives
|
||||
|
@ -487,7 +487,7 @@ func (*ChannelPackager) AddFwdPkg(tx kvdb.RwTx, fwdPkg *FwdPkg) error {
|
||||
// putLogUpdate writes an htlc to the provided `bkt`, using `index` as the key.
|
||||
func putLogUpdate(bkt kvdb.RwBucket, idx uint16, htlc *LogUpdate) error {
|
||||
var b bytes.Buffer
|
||||
if err := htlc.Encode(&b); err != nil {
|
||||
if err := serializeLogUpdate(&b, htlc); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -541,7 +541,7 @@ func loadChannelFwdPkgs(tx kvdb.RTx, source lnwire.ShortChannelID) ([]*FwdPkg, e
|
||||
return fwdPkgs, nil
|
||||
}
|
||||
|
||||
// loadFwPkg reads the packager's fwd pkg at a given height, and determines the
|
||||
// loadFwdPkg reads the packager's fwd pkg at a given height, and determines the
|
||||
// appropriate FwdState.
|
||||
func loadFwdPkg(fwdPkgBkt kvdb.RBucket, source lnwire.ShortChannelID,
|
||||
height uint64) (*FwdPkg, error) {
|
||||
@ -652,12 +652,12 @@ func loadFwdPkg(fwdPkgBkt kvdb.RBucket, source lnwire.ShortChannelID,
|
||||
func loadHtlcs(bkt kvdb.RBucket) ([]LogUpdate, error) {
|
||||
var htlcs []LogUpdate
|
||||
if err := bkt.ForEach(func(_, v []byte) error {
|
||||
var htlc LogUpdate
|
||||
if err := htlc.Decode(bytes.NewReader(v)); err != nil {
|
||||
htlc, err := deserializeLogUpdate(bytes.NewReader(v))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
htlcs = append(htlcs, htlc)
|
||||
htlcs = append(htlcs, *htlc)
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user