mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-13 11:09:23 +01:00
channeldb: extract deserializeChanEdgePolicyRaw
Allows for pure deserialization without depending on a database connection.
This commit is contained in:
parent
aff9685a61
commit
54324d554a
1 changed files with 23 additions and 6 deletions
|
@ -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.
|
||||||
|
|
Loading…
Add table
Reference in a new issue