mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-04 18:33:34 +02:00
channeldb: extract deserializeChanEdgePolicyRaw
Allows for pure deserialization without depending on a database connection.
This commit is contained in:
@@ -4652,6 +4652,27 @@ func serializeChanEdgePolicy(w io.Writer, edge *ChannelEdgePolicy,
|
|||||||
func deserializeChanEdgePolicy(r io.Reader,
|
func deserializeChanEdgePolicy(r io.Reader,
|
||||||
nodes kvdb.RBucket) (*ChannelEdgePolicy, error) {
|
nodes kvdb.RBucket) (*ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
|
// Deserialize the policy. Note that in case an optional field is not
|
||||||
|
// found, both an error and a populated policy object are returned.
|
||||||
|
edge, deserializeErr := deserializeChanEdgePolicyRaw(r)
|
||||||
|
if deserializeErr != nil &&
|
||||||
|
deserializeErr != ErrEdgePolicyOptionalFieldNotFound {
|
||||||
|
|
||||||
|
return nil, deserializeErr
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate full LightningNode struct.
|
||||||
|
pub := edge.Node.PubKeyBytes[:]
|
||||||
|
node, err := fetchLightningNode(nodes, pub)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to fetch node: %x, %v", pub, err)
|
||||||
|
}
|
||||||
|
edge.Node = &node
|
||||||
|
|
||||||
|
return edge, deserializeErr
|
||||||
|
}
|
||||||
|
|
||||||
|
func deserializeChanEdgePolicyRaw(r io.Reader) (*ChannelEdgePolicy, error) {
|
||||||
edge := &ChannelEdgePolicy{}
|
edge := &ChannelEdgePolicy{}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
@@ -4701,13 +4722,9 @@ func deserializeChanEdgePolicy(r io.Reader,
|
|||||||
if _, err := r.Read(pub[:]); err != nil {
|
if _, err := r.Read(pub[:]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
edge.Node = &LightningNode{
|
||||||
node, err := fetchLightningNode(nodes, pub[:])
|
PubKeyBytes: pub,
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unable to fetch node: %x, %v",
|
|
||||||
pub[:], err)
|
|
||||||
}
|
}
|
||||||
edge.Node = &node
|
|
||||||
|
|
||||||
// We'll try and see if there are any opaque bytes left, if not, then
|
// We'll try and see if there are any opaque bytes left, if not, then
|
||||||
// we'll ignore the EOF error and return the edge as is.
|
// we'll ignore the EOF error and return the edge as is.
|
||||||
|
Reference in New Issue
Block a user