(minor) fix typos and indentation
This commit is contained in:
@@ -261,15 +261,18 @@ def new_onion_packet(payment_path_pubkeys: Sequence[bytes], session_key: bytes,
|
|||||||
hmac=next_hmac)
|
hmac=next_hmac)
|
||||||
|
|
||||||
|
|
||||||
def calc_hops_data_for_payment(route: 'LNPaymentRoute', amount_msat: int, final_cltv: int, *,
|
def calc_hops_data_for_payment(
|
||||||
total_msat=None, payment_secret: bytes = None) \
|
route: 'LNPaymentRoute',
|
||||||
-> Tuple[List[OnionHopsDataSingle], int, int]:
|
amount_msat: int,
|
||||||
|
final_cltv: int, *,
|
||||||
|
total_msat=None,
|
||||||
|
payment_secret: bytes = None) -> Tuple[List[OnionHopsDataSingle], int, int]:
|
||||||
|
|
||||||
"""Returns the hops_data to be used for constructing an onion packet,
|
"""Returns the hops_data to be used for constructing an onion packet,
|
||||||
and the amount_msat and cltv to be used on our immediate channel.
|
and the amount_msat and cltv to be used on our immediate channel.
|
||||||
"""
|
"""
|
||||||
if len(route) > NUM_MAX_EDGES_IN_PAYMENT_PATH:
|
if len(route) > NUM_MAX_EDGES_IN_PAYMENT_PATH:
|
||||||
raise PaymentFailure(f"too long route ({len(route)} edges)")
|
raise PaymentFailure(f"too long route ({len(route)} edges)")
|
||||||
|
|
||||||
# payload that will be seen by the last hop:
|
# payload that will be seen by the last hop:
|
||||||
amt = amount_msat
|
amt = amount_msat
|
||||||
cltv = final_cltv
|
cltv = final_cltv
|
||||||
@@ -277,7 +280,7 @@ def calc_hops_data_for_payment(route: 'LNPaymentRoute', amount_msat: int, final_
|
|||||||
"amt_to_forward": {"amt_to_forward": amt},
|
"amt_to_forward": {"amt_to_forward": amt},
|
||||||
"outgoing_cltv_value": {"outgoing_cltv_value": cltv},
|
"outgoing_cltv_value": {"outgoing_cltv_value": cltv},
|
||||||
}
|
}
|
||||||
# for multipart payments we need to tell the reciever about the total and
|
# for multipart payments we need to tell the receiver about the total and
|
||||||
# partial amounts
|
# partial amounts
|
||||||
if payment_secret is not None:
|
if payment_secret is not None:
|
||||||
hop_payload["payment_data"] = {
|
hop_payload["payment_data"] = {
|
||||||
@@ -285,8 +288,8 @@ def calc_hops_data_for_payment(route: 'LNPaymentRoute', amount_msat: int, final_
|
|||||||
"total_msat": total_msat,
|
"total_msat": total_msat,
|
||||||
"amount_msat": amt
|
"amount_msat": amt
|
||||||
}
|
}
|
||||||
hops_data = [OnionHopsDataSingle(is_tlv_payload=route[-1].has_feature_varonion(),
|
hops_data = [OnionHopsDataSingle(
|
||||||
payload=hop_payload)]
|
is_tlv_payload=route[-1].has_feature_varonion(), payload=hop_payload)]
|
||||||
# payloads, backwards from last hop (but excluding the first edge):
|
# payloads, backwards from last hop (but excluding the first edge):
|
||||||
for edge_index in range(len(route) - 1, 0, -1):
|
for edge_index in range(len(route) - 1, 0, -1):
|
||||||
route_edge = route[edge_index]
|
route_edge = route[edge_index]
|
||||||
|
|||||||
@@ -1419,7 +1419,7 @@ class LNWallet(LNWorker):
|
|||||||
self.logger.info(f'adding route {part_amount_msat} {delta_fee} {margin}')
|
self.logger.info(f'adding route {part_amount_msat} {delta_fee} {margin}')
|
||||||
routes.append((route, part_amount_msat_with_fees, bucket_amount_with_fees, bucket_cltv_delta, bucket_payment_secret, trampoline_onion))
|
routes.append((route, part_amount_msat_with_fees, bucket_amount_with_fees, bucket_cltv_delta, bucket_payment_secret, trampoline_onion))
|
||||||
if trampoline_fee > 0:
|
if trampoline_fee > 0:
|
||||||
self.logger.info('not enough marging to pay trampoline fee')
|
self.logger.info('not enough margin to pay trampoline fee')
|
||||||
raise NoPathFound()
|
raise NoPathFound()
|
||||||
else:
|
else:
|
||||||
# then we need bucket_amount_msat that includes the trampoline fees.. then create small routes here
|
# then we need bucket_amount_msat that includes the trampoline fees.. then create small routes here
|
||||||
@@ -1526,43 +1526,42 @@ class LNWallet(LNWorker):
|
|||||||
|
|
||||||
@log_exceptions
|
@log_exceptions
|
||||||
async def create_invoice(
|
async def create_invoice(
|
||||||
self,
|
self, *,
|
||||||
*,
|
|
||||||
amount_msat: Optional[int],
|
amount_msat: Optional[int],
|
||||||
message,
|
message: str,
|
||||||
expiry: int,
|
expiry: int) -> Tuple[LnAddr, str]:
|
||||||
) -> Tuple[LnAddr, str]:
|
|
||||||
timestamp = int(time.time())
|
timestamp = int(time.time())
|
||||||
routing_hints = await self._calc_routing_hints_for_invoice(amount_msat)
|
routing_hints = await self._calc_routing_hints_for_invoice(amount_msat)
|
||||||
if not routing_hints:
|
if not routing_hints:
|
||||||
self.logger.info("Warning. No routing hints added to invoice. "
|
self.logger.info(
|
||||||
"Other clients will likely not be able to send to us.")
|
"Warning. No routing hints added to invoice. "
|
||||||
|
"Other clients will likely not be able to send to us.")
|
||||||
# if not all hints are trampoline, do not create trampoline invoice
|
# if not all hints are trampoline, do not create trampoline invoice
|
||||||
invoice_features = self.features.for_invoice()
|
invoice_features = self.features.for_invoice()
|
||||||
#
|
|
||||||
trampoline_hints = []
|
trampoline_hints = []
|
||||||
for r in routing_hints:
|
for r in routing_hints:
|
||||||
node_id, short_channel_id, fee_base_msat, fee_proportional_millionths, cltv_expiry_delta = r[1][0]
|
node_id, short_channel_id, fee_base_msat, fee_proportional_millionths, cltv_expiry_delta = r[1][0]
|
||||||
if len(r[1])== 1 and self.is_trampoline_peer(node_id):
|
if len(r[1])== 1 and self.is_trampoline_peer(node_id):
|
||||||
trampoline_hints.append(('t', (node_id, fee_base_msat, fee_proportional_millionths, cltv_expiry_delta)))
|
trampoline_hints.append(('t', (node_id, fee_base_msat, fee_proportional_millionths, cltv_expiry_delta)))
|
||||||
|
|
||||||
payment_preimage = os.urandom(32)
|
payment_preimage = os.urandom(32)
|
||||||
payment_hash = sha256(payment_preimage)
|
payment_hash = sha256(payment_preimage)
|
||||||
info = PaymentInfo(payment_hash, amount_msat, RECEIVED, PR_UNPAID)
|
info = PaymentInfo(payment_hash, amount_msat, RECEIVED, PR_UNPAID)
|
||||||
amount_btc = amount_msat/Decimal(COIN*1000) if amount_msat else None
|
amount_btc = amount_msat/Decimal(COIN*1000) if amount_msat else None
|
||||||
if expiry == 0:
|
if expiry == 0:
|
||||||
expiry = LN_EXPIRY_NEVER
|
expiry = LN_EXPIRY_NEVER
|
||||||
lnaddr = LnAddr(paymenthash=payment_hash,
|
lnaddr = LnAddr(
|
||||||
amount=amount_btc,
|
paymenthash=payment_hash,
|
||||||
tags=[('d', message),
|
amount=amount_btc,
|
||||||
('c', MIN_FINAL_CLTV_EXPIRY_FOR_INVOICE),
|
tags=[
|
||||||
('x', expiry),
|
('d', message),
|
||||||
('9', invoice_features)]
|
('c', MIN_FINAL_CLTV_EXPIRY_FOR_INVOICE),
|
||||||
+ routing_hints
|
('x', expiry),
|
||||||
+ trampoline_hints,
|
('9', invoice_features)]
|
||||||
date=timestamp,
|
+ routing_hints
|
||||||
payment_secret=derive_payment_secret_from_payment_preimage(payment_preimage))
|
+ trampoline_hints,
|
||||||
|
date=timestamp,
|
||||||
|
payment_secret=derive_payment_secret_from_payment_preimage(payment_preimage))
|
||||||
invoice = lnencode(lnaddr, self.node_keypair.privkey)
|
invoice = lnencode(lnaddr, self.node_keypair.privkey)
|
||||||
self.save_preimage(payment_hash, payment_preimage)
|
self.save_preimage(payment_hash, payment_preimage)
|
||||||
self.save_payment_info(info)
|
self.save_payment_info(info)
|
||||||
@@ -1573,8 +1572,7 @@ class LNWallet(LNWorker):
|
|||||||
lnaddr, invoice = await self.create_invoice(
|
lnaddr, invoice = await self.create_invoice(
|
||||||
amount_msat=amount_msat,
|
amount_msat=amount_msat,
|
||||||
message=message,
|
message=message,
|
||||||
expiry=expiry,
|
expiry=expiry)
|
||||||
)
|
|
||||||
key = bh2u(lnaddr.paymenthash)
|
key = bh2u(lnaddr.paymenthash)
|
||||||
req = LNInvoice.from_bech32(invoice)
|
req = LNInvoice.from_bech32(invoice)
|
||||||
self.wallet.add_payment_request(req)
|
self.wallet.add_payment_request(req)
|
||||||
@@ -1759,13 +1757,15 @@ class LNWallet(LNWorker):
|
|||||||
cltv_expiry_delta = policy.cltv_expiry_delta
|
cltv_expiry_delta = policy.cltv_expiry_delta
|
||||||
missing_info = False
|
missing_info = False
|
||||||
if missing_info:
|
if missing_info:
|
||||||
self.logger.info(f"Warning. Missing channel update for our channel {chan_id}; "
|
self.logger.info(
|
||||||
f"filling invoice with incorrect data.")
|
f"Warning. Missing channel update for our channel {chan_id}; "
|
||||||
routing_hints.append(('r', [(chan.node_id,
|
f"filling invoice with incorrect data.")
|
||||||
chan_id,
|
routing_hints.append(('r', [(
|
||||||
fee_base_msat,
|
chan.node_id,
|
||||||
fee_proportional_millionths,
|
chan_id,
|
||||||
cltv_expiry_delta)]))
|
fee_base_msat,
|
||||||
|
fee_proportional_millionths,
|
||||||
|
cltv_expiry_delta)]))
|
||||||
return routing_hints
|
return routing_hints
|
||||||
|
|
||||||
def delete_payment(self, payment_hash_hex: str):
|
def delete_payment(self, payment_hash_hex: str):
|
||||||
@@ -1778,8 +1778,9 @@ class LNWallet(LNWorker):
|
|||||||
|
|
||||||
def get_balance(self):
|
def get_balance(self):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
return Decimal(sum(chan.balance(LOCAL) if not chan.is_closed() else 0
|
return Decimal(sum(
|
||||||
for chan in self.channels.values())) / 1000
|
chan.balance(LOCAL) if not chan.is_closed() else 0
|
||||||
|
for chan in self.channels.values())) / 1000
|
||||||
|
|
||||||
def num_sats_can_send(self) -> Decimal:
|
def num_sats_can_send(self) -> Decimal:
|
||||||
can_send = Decimal(0)
|
can_send = Decimal(0)
|
||||||
@@ -1918,8 +1919,7 @@ class LNWallet(LNWorker):
|
|||||||
return 'channel_backup:' + encrypted
|
return 'channel_backup:' + encrypted
|
||||||
|
|
||||||
async def request_remote_force_close(
|
async def request_remote_force_close(
|
||||||
self, *, funding_txid: str, funding_index: int, connect_str: str,
|
self, *, funding_txid: str, funding_index: int, connect_str: str):
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
Requests the remote to force close a channel. Can be used without
|
Requests the remote to force close a channel. Can be used without
|
||||||
having state or any backup for the channel.
|
having state or any backup for the channel.
|
||||||
|
|||||||
Reference in New Issue
Block a user