mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-03 19:53:09 +02:00
htlcswitch/payment_result: add (de)serialization of networkResult + test
This commit is contained in:
@@ -2,7 +2,9 @@ package htlcswitch
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
@@ -46,3 +48,34 @@ type networkResult struct {
|
||||
// which the failure reason might not be included.
|
||||
isResolution bool
|
||||
}
|
||||
|
||||
// serializeNetworkResult serializes the networkResult.
|
||||
func serializeNetworkResult(w io.Writer, n *networkResult) error {
|
||||
if _, err := lnwire.WriteMessage(w, n.msg, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return channeldb.WriteElements(w, n.unencrypted, n.isResolution)
|
||||
}
|
||||
|
||||
// deserializeNetworkResult deserializes the networkResult.
|
||||
func deserializeNetworkResult(r io.Reader) (*networkResult, error) {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
n := &networkResult{}
|
||||
|
||||
n.msg, err = lnwire.ReadMessage(r, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := channeldb.ReadElements(r,
|
||||
&n.unencrypted, &n.isResolution,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user