-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThread.py
More file actions
59 lines (45 loc) · 1.5 KB
/
Thread.py
File metadata and controls
59 lines (45 loc) · 1.5 KB
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
import time
import requests
from PySide6.QtCore import QThread, Signal
from chaindb import UserClient, blockchain
ConfirmationScore = 5
class Thread(QThread):
sigMsg = Signal(str)
sigSendSuccess = Signal()
def __init__(self, parent=None):
super().__init__(parent)
self.currentNonce = -1
self.running = True
self.msg = None
self.chaindb = UserClient()
def run(self):
while True:
if not self.running:
break
time.sleep(1)
try:
self.recv()
self.send()
except Exception as e:
print(e)
def recv(self):
arr = self.chaindb.ListTransactionsOwnedBy(10086, confirmations=ConfirmationScore)
arr.sort(key=lambda tx: tx.Transaction.Nonce)
for tx in arr:
if tx.Transaction.Nonce <= self.currentNonce:
continue
if tx.ConfirmationScore < ConfirmationScore:
continue
self.sigMsg.emit(tx.Transaction.Data)
self.currentNonce = tx.Transaction.Nonce
def send(self):
if not self.msg:
return
if not self.chaindb.Insert(blockchain.Transaction(
OwnerID=10086,
Nonce=self.currentNonce + 1,
Data=self.msg,
), confirmations=ConfirmationScore):
return
self.msg = None
self.sigSendSuccess.emit()