Skip to content

Commit b34be45

Browse files
committed
bolt12: don't use path_id, instead generate offer_id and store in offer_metadata
1 parent 0e28c99 commit b34be45

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

electrum/lnworker.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,15 +3829,16 @@ def get_forwarding_failure(self, payment_key: str) -> Tuple[Optional[bytes], Opt
38293829
def on_bolt12_invoice_request(self, recipient_data: dict, payload: dict):
38303830
# match to offer
38313831
self.logger.debug(f'on_bolt12_invoice_request: {recipient_data=} {payload=}')
3832-
offer_id = recipient_data['path_id']['data']
3833-
offer = self.wallet.get_offer(offer_id)
3834-
if offer is None:
3835-
self.logger.warning('no matching offer for invoice_request')
3836-
return
38373832

38383833
invreq_tlv = payload['invoice_request']['invoice_request']
38393834
invreq = bolt12.decode_invoice_request(invreq_tlv)
38403835
self.logger.info(f'invoice_request: {invreq=}')
3836+
3837+
offer_id = invreq.get('offer_metadata', {}).get('data')
3838+
offer = self.wallet.get_offer(offer_id)
3839+
if offer is None:
3840+
self.logger.warning('no matching offer for invoice_request')
3841+
return
38413842
self.logger.debug(f'invoice_request for {offer=}')
38423843

38433844
# two scenarios:

electrum/wallet.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,12 +3132,14 @@ def create_offer(self, amount, memo, expiry):
31323132
assert self.has_lightning(), 'not a lightning wallet'
31333133
assert self.has_channels(), 'no channels'
31343134

3135-
path_id = os.urandom(32)
3135+
path_id = os.urandom(32) # TODO: move path_id gen get_blinded_reply_paths, unique per path
31363136
reply_paths = get_blinded_reply_paths(self.lnworker, path_id, max_paths=1) # max 1 for now
31373137
if not len(reply_paths):
31383138
raise Exception('No suitable channels')
31393139

3140+
offer_id = os.urandom(16)
31403141
offer = {
3142+
'offer_metadata': {'data': offer_id},
31413143
'offer_description': {'description': memo},
31423144
'offer_issuer_id': {'id': self.lnworker.node_keypair.pubkey},
31433145
'offer_paths': {'paths': reply_paths},
@@ -3149,9 +3151,9 @@ def create_offer(self, amount, memo, expiry):
31493151
if expiry:
31503152
now = int(time.time())
31513153
offer['offer_absolute_expiry'] = {'seconds_from_epoch': now + expiry}
3152-
self._offers[path_id] = offer
3154+
self._offers[offer_id] = offer
31533155

3154-
return path_id
3156+
return offer_id
31553157

31563158
def get_offer(self, key) -> Optional[dict]:
31573159
return self._offers.get(key)

0 commit comments

Comments
 (0)