Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion contrib/pyln-proto/pyln/proto/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,12 @@ def decode(cls, b):
data_length = len(tagdata) / 5

if tag == 'r':
inv.route_hints = RouteHintSet.from_bytes(trim_to_bytes(tagdata))
# There can be several `r` fields, don't let the last one win.
hints = RouteHintSet.from_bytes(trim_to_bytes(tagdata))
if inv.route_hints is None:
inv.route_hints = hints
else:
inv.route_hints.route_hints.extend(hints.route_hints)
continue
if data_length != 82:
inv.unknown_tags.append((tag, tagdata))
Expand Down
19 changes: 19 additions & 0 deletions contrib/pyln-proto/tests/test_invoice.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pyln.proto import Invoice
from pyln.proto.invoice import RouteHint, RouteHintSet
from decimal import Decimal
from bitstring import ConstBitStream
import binascii
Expand All @@ -25,3 +26,21 @@ def test_encode():
privkey = 'c28a9f80738f770d527803a566cf6fc3edf6cea586c4fc4a5223a5ad797e1ac3'
i = inv.encode(privkey)
assert(i == 'lnbc1u1p0zyt04pp5wcnjhxu4k98td0kw8ng9zqrd3246cc7r559a063tk5mp9v9fxf9sdpqw3jhxazlwpshjhmjda6hgetzdahhxapjxqyjw5q0s43wfg4f6yl200hc805kc9u97dp7m6j98fz33uzf4t6kp73trcz8fxkrpass063j2j4quxjr4th2r72lk27tm2aw383zgnl8zpgajsq5kmll8')


def test_decode_multiple_route_hints():
"""Every `r` field is its own route, so decoding must keep all of them."""
inv = Invoice(paymenthash=bytes(32), tags=[('d', 'two hints')], date=1579298293)
inv.route_hints = RouteHintSet()
for n in (1, 2):
rh = RouteHint()
rh.pubkey = bytes([2] + [n] * 32)
rh.short_channel_id = n
rh.fee_base_msat = 1000
rh.fee_proportional_millionths = 10
rh.cltv_expiry_delta = 6
inv.route_hints.add(rh)

privkey = 'c28a9f80738f770d527803a566cf6fc3edf6cea586c4fc4a5223a5ad797e1ac3'
decoded = Invoice.decode(inv.encode(privkey))
assert [rh.short_channel_id for rh in decoded.route_hints.route_hints] == [1, 2]