Browse Source

lnworker: fix some type hints re hold_invoices

master
SomberNight 2 years ago
parent
commit
a560841f3f
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 8
      electrum/lnworker.py
  2. 8
      electrum/plugins/swapserver/server.py
  3. 2
      electrum/submarine_swaps.py

8
electrum/lnworker.py

@ -11,7 +11,7 @@ import operator
import enum import enum
from enum import IntEnum, Enum from enum import IntEnum, Enum
from typing import (Optional, Sequence, Tuple, List, Set, Dict, TYPE_CHECKING, from typing import (Optional, Sequence, Tuple, List, Set, Dict, TYPE_CHECKING,
NamedTuple, Union, Mapping, Any, Iterable, AsyncGenerator, DefaultDict, Callable) NamedTuple, Union, Mapping, Any, Iterable, AsyncGenerator, DefaultDict, Callable, Awaitable)
import threading import threading
import socket import socket
import aiohttp import aiohttp
@ -842,8 +842,8 @@ class LNWallet(LNWorker):
self.final_onion_forwarding_failures = {} # todo: should be persisted self.final_onion_forwarding_failures = {} # todo: should be persisted
# map forwarded htlcs (fw_info=(scid_hex, htlc_id)) to originating peer pubkeys # map forwarded htlcs (fw_info=(scid_hex, htlc_id)) to originating peer pubkeys
self.downstream_htlc_to_upstream_peer_map = {} # type: Dict[Tuple[str, int], bytes] self.downstream_htlc_to_upstream_peer_map = {} # type: Dict[Tuple[str, int], bytes]
# payment_hash -> callback, timeout: # payment_hash -> callback:
self.hold_invoice_callbacks = {} # type: Dict[bytes, Tuple[Callable[[bytes], None], int]] self.hold_invoice_callbacks = {} # type: Dict[bytes, Callable[[bytes], Awaitable[None]]]
self.payment_bundles = [] # lists of hashes. todo:persist self.payment_bundles = [] # lists of hashes. todo:persist
self.swap_manager = SwapManager(wallet=self.wallet, lnworker=self) self.swap_manager = SwapManager(wallet=self.wallet, lnworker=self)
@ -2070,7 +2070,7 @@ class LNWallet(LNWorker):
info = PaymentInfo(payment_hash, lightning_amount_sat * 1000, RECEIVED, PR_UNPAID) info = PaymentInfo(payment_hash, lightning_amount_sat * 1000, RECEIVED, PR_UNPAID)
self.save_payment_info(info, write_to_disk=False) self.save_payment_info(info, write_to_disk=False)
def register_callback_for_hold_invoice(self, payment_hash: bytes, cb: Callable[[bytes], None]): def register_callback_for_hold_invoice(self, payment_hash: bytes, cb: Callable[[bytes], Awaitable[None]]):
self.hold_invoice_callbacks[payment_hash] = cb self.hold_invoice_callbacks[payment_hash] = cb
def save_payment_info(self, info: PaymentInfo, *, write_to_disk: bool = True) -> None: def save_payment_info(self, info: PaymentInfo, *, write_to_disk: bool = True) -> None:

8
electrum/plugins/swapserver/server.py

@ -1,6 +1,7 @@
import os import os
import asyncio import asyncio
from collections import defaultdict from collections import defaultdict
from typing import TYPE_CHECKING
from aiohttp import web from aiohttp import web
@ -9,6 +10,11 @@ from electrum.logging import Logger
from electrum.util import EventListener from electrum.util import EventListener
from electrum.lnaddr import lndecode from electrum.lnaddr import lndecode
if TYPE_CHECKING:
from electrum.simple_config import SimpleConfig
from electrum.wallet import Abstract_Wallet
class SwapServer(Logger, EventListener): class SwapServer(Logger, EventListener):
""" """
public API: public API:
@ -18,7 +24,7 @@ class SwapServer(Logger, EventListener):
WWW_DIR = os.path.join(os.path.dirname(__file__), 'www') WWW_DIR = os.path.join(os.path.dirname(__file__), 'www')
def __init__(self, config, wallet): def __init__(self, config: 'SimpleConfig', wallet: 'Abstract_Wallet'):
Logger.__init__(self) Logger.__init__(self)
self.config = config self.config = config
self.wallet = wallet self.wallet = wallet

2
electrum/submarine_swaps.py

@ -361,7 +361,7 @@ class SwapManager(Logger):
callback = lambda: self._claim_swap(swap) callback = lambda: self._claim_swap(swap)
self.lnwatcher.add_callback(swap.lockup_address, callback) self.lnwatcher.add_callback(swap.lockup_address, callback)
async def hold_invoice_callback(self, payment_hash): async def hold_invoice_callback(self, payment_hash: bytes) -> None:
# note: this assumes the keystore is not encrypted # note: this assumes the keystore is not encrypted
key = payment_hash.hex() key = payment_hash.hex()
if key in self.swaps: if key in self.swaps:

Loading…
Cancel
Save