mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-18 13:52:02 +01:00
routing+channeldb: let Vertex implement tlv.RecordProducer
So that we can use it in TLV encoding. Also add this to the codec for channeldb migration 32 since we will be using it there in an upcoming adjustment commit.
This commit is contained in:
parent
a5f3fa17e7
commit
d9a073ad7e
@ -29,6 +29,32 @@ const VertexSize = 33
|
||||
// public key.
|
||||
type Vertex [VertexSize]byte
|
||||
|
||||
// Record returns a TLV record that can be used to encode/decode a Vertex
|
||||
// to/from a TLV stream.
|
||||
func (v *Vertex) Record() tlv.Record {
|
||||
return tlv.MakeStaticRecord(
|
||||
0, v, VertexSize, encodeVertex, decodeVertex,
|
||||
)
|
||||
}
|
||||
|
||||
func encodeVertex(w io.Writer, val interface{}, _ *[8]byte) error {
|
||||
if b, ok := val.(*Vertex); ok {
|
||||
_, err := w.Write(b[:])
|
||||
return err
|
||||
}
|
||||
|
||||
return tlv.NewTypeForEncodingErr(val, "Vertex")
|
||||
}
|
||||
|
||||
func decodeVertex(r io.Reader, val interface{}, _ *[8]byte, l uint64) error {
|
||||
if b, ok := val.(*Vertex); ok {
|
||||
_, err := io.ReadFull(r, b[:])
|
||||
return err
|
||||
}
|
||||
|
||||
return tlv.NewTypeForDecodingErr(val, "Vertex", l, VertexSize)
|
||||
}
|
||||
|
||||
// Route represents a path through the channel graph which runs over one or
|
||||
// more channels in succession. This struct carries all the information
|
||||
// required to craft the Sphinx onion packet, and send the payment along the
|
||||
|
@ -94,6 +94,32 @@ func (v Vertex) String() string {
|
||||
return fmt.Sprintf("%x", v[:])
|
||||
}
|
||||
|
||||
// Record returns a TLV record that can be used to encode/decode a Vertex
|
||||
// to/from a TLV stream.
|
||||
func (v *Vertex) Record() tlv.Record {
|
||||
return tlv.MakeStaticRecord(
|
||||
0, v, VertexSize, encodeVertex, decodeVertex,
|
||||
)
|
||||
}
|
||||
|
||||
func encodeVertex(w io.Writer, val interface{}, _ *[8]byte) error {
|
||||
if b, ok := val.(*Vertex); ok {
|
||||
_, err := w.Write(b[:])
|
||||
return err
|
||||
}
|
||||
|
||||
return tlv.NewTypeForEncodingErr(val, "Vertex")
|
||||
}
|
||||
|
||||
func decodeVertex(r io.Reader, val interface{}, _ *[8]byte, l uint64) error {
|
||||
if b, ok := val.(*Vertex); ok {
|
||||
_, err := io.ReadFull(r, b[:])
|
||||
return err
|
||||
}
|
||||
|
||||
return tlv.NewTypeForDecodingErr(val, "Vertex", l, VertexSize)
|
||||
}
|
||||
|
||||
// Hop represents an intermediate or final node of the route. This naming
|
||||
// is in line with the definition given in BOLT #4: Onion Routing Protocol.
|
||||
// The struct houses the channel along which this hop can be reached and
|
||||
|
Loading…
x
Reference in New Issue
Block a user