mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-19 12:01:27 +02: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:
@@ -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
|
||||
|
Reference in New Issue
Block a user