-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathworker.py
78 lines (61 loc) · 2.02 KB
/
worker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from PyQt6.QtCore import QObject, pyqtSignal, pyqtSlot
import time
from cashu.core.base import Invoice
import asyncio
class CheckInvoiceWorker(QObject):
"""
Worker that periodically checks whether an invoice has been paid.
"""
def __init__(self, mint, invoice: Invoice):
super().__init__()
self.invoice = invoice
self.mint = mint
finished = pyqtSignal()
intReady = pyqtSignal(int)
strReady = pyqtSignal(str)
@pyqtSlot()
def procCounter(self): # A slot takes no params
print(f"Checking invoice hash {self.invoice.hash}")
for i in range(1, 10):
try:
asyncio.run(self.mint(self.invoice.amount, self.invoice.hash))
self.strReady.emit("paid")
break
except Exception as e:
self.strReady.emit(str(e))
pass
time.sleep(5)
self.finished.emit()
def stop(self):
print("terminating thread")
self.terminate()
class LoadMintWorker(QObject):
"""
Worker that loads the mint in a separate thread. Necessary
for example for starting Tor which takes a certain time.
"""
def __init__(self, mint):
super().__init__()
self.mint = mint
finished = pyqtSignal()
@pyqtSlot()
def procLoadMint(self): # A slot takes no params
asyncio.run(self.mint.load_mint())
self.finished.emit()
class UpdateWalletStateWorker(QObject):
"""
Worker that periodically sends a signal if the mint is loaded.
"""
def __init__(self, wallet):
super().__init__()
self.wallet = wallet
update = pyqtSignal()
@pyqtSlot()
def procCheckWalletState(self): # A slot takes no params
while True:
time.sleep(3)
# this is the check that the mint is loaded, very ugly
# might break in the future
if hasattr(self.wallet, "keys"):
# if mint is loaded send out a regular update signal
self.update.emit()