htlcswitch/payment_result: add (de)serialization of networkResult + test

This commit is contained in:
Johan T. Halseth
2019-06-07 16:42:25 +02:00
parent f5dee02ff4
commit df3f5d02ad
2 changed files with 123 additions and 0 deletions

View File

@@ -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
}