fix send_request version message
This commit is contained in:
19
bal.py
19
bal.py
@@ -47,18 +47,19 @@ class BalConfig:
|
||||
|
||||
|
||||
class BalPlugin(BasePlugin):
|
||||
LATEST_VERSION = "1"
|
||||
KNOWN_VERSIONS = ("0", "1")
|
||||
assert LATEST_VERSION in KNOWN_VERSIONS
|
||||
_version=None
|
||||
|
||||
def version():
|
||||
def version(self):
|
||||
if not self._version:
|
||||
try:
|
||||
f = ""
|
||||
with open("VERSION", "r") as fi:
|
||||
f = str(fi.readline())
|
||||
return f
|
||||
except Exception:
|
||||
return "unknown"
|
||||
with open("{}/VERSION".format(self.plugin_dir), "r") as fi:
|
||||
f = str(fi.read())
|
||||
self._version = f.strip()
|
||||
except Exception as e:
|
||||
_logger.error(f"failed to get version: {e}")
|
||||
self._version="unknown"
|
||||
return self._version
|
||||
|
||||
SIZE = (159, 97)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "BAL",
|
||||
"fullname": "Bitcoin After Life",
|
||||
"description": "Provides free and decentralized inheritance support<br> Version: 0.2.5",
|
||||
"description": "Provides free and decentralized inheritance support<br> Version: 0.2.6",
|
||||
"author":"Svatantrya",
|
||||
"available_for": ["qt"],
|
||||
"icon":"icons/bal32x32.png"
|
||||
|
||||
33
qt.py
33
qt.py
@@ -1046,7 +1046,7 @@ class BalWindow(Logger):
|
||||
self.waiting_dialog.exe()
|
||||
|
||||
def push_transactions_to_willexecutors(self, force=False):
|
||||
willexecutors = Willexecutors.get_willexecutor_transactions(self.willitems)
|
||||
willexecutors = Willexecutors.get_willexecutor_transactions(self.bal_plugin, self.willitems)
|
||||
|
||||
def getMsg(willexecutors):
|
||||
msg = "Broadcasting Transactions to Will-Executors:\n"
|
||||
@@ -1060,7 +1060,7 @@ class BalWindow(Logger):
|
||||
self.waiting_dialog.update(getMsg(willexecutors))
|
||||
if "txs" in willexecutor:
|
||||
try:
|
||||
if Willexecutors.push_transactions_to_willexecutor(
|
||||
if Willexecutors.push_transactions_to_willexecutor(self.bal_plugin,
|
||||
willexecutors[url]
|
||||
):
|
||||
for wid in willexecutors[url]["txsids"]:
|
||||
@@ -1079,7 +1079,14 @@ class BalWindow(Logger):
|
||||
self.willitems[wid].we["url"], wid, "Waiting"
|
||||
)
|
||||
)
|
||||
self.willitems[wid].check_willexecutor()
|
||||
w = self.willitems[wid]
|
||||
w.set_check_willexecutor(
|
||||
Willexecutors.check_transaction(
|
||||
self.bal_plugin,
|
||||
w._id,
|
||||
w.we["url"]
|
||||
)
|
||||
)
|
||||
self.waiting_dialog.update(
|
||||
"checked {} - {} : {}".format(
|
||||
self.willitems[wid].we["url"],
|
||||
@@ -1128,7 +1135,8 @@ class BalWindow(Logger):
|
||||
self.waiting_dialog.update(
|
||||
"checking transaction: {}\n willexecutor: {}".format(wid, w.we["url"])
|
||||
)
|
||||
w.check_willexecutor()
|
||||
w.set_check_willexecutor(Willexecutors.check_transaction(self.bal_plugin,w._id, w.we["url"]))
|
||||
|
||||
|
||||
if time.time() - start < 3:
|
||||
time.sleep(3 - (time.time() - start))
|
||||
@@ -1176,7 +1184,7 @@ class BalWindow(Logger):
|
||||
self.waiting_dialog.update(get_title())
|
||||
except Exception:
|
||||
pass
|
||||
wes[url] = Willexecutors.get_info_task(url, we)
|
||||
wes[url] = Willexecutors.get_info_task(self.bal_plugin, url, we)
|
||||
if wes[url]["status"] == "KO":
|
||||
failed.append(url)
|
||||
else:
|
||||
@@ -2048,6 +2056,7 @@ class BalBuildWillDialog(BalDialog):
|
||||
self.parent = parent
|
||||
self.updatemessage.connect(self.update)
|
||||
self.bal_window = bal_window
|
||||
self.bal_plugin = bal_window.bal_plugin
|
||||
self.message_label = QLabel(_("Building Will:"))
|
||||
self.vbox = QVBoxLayout(self)
|
||||
self.vbox.addWidget(self.message_label)
|
||||
@@ -2237,7 +2246,7 @@ class BalBuildWillDialog(BalDialog):
|
||||
self.bal_window.willexecutors.get(url)
|
||||
):
|
||||
_logger.debug(f"{url}: {willexecutor}")
|
||||
if not Willexecutors.push_transactions_to_willexecutor(
|
||||
if not Willexecutors.push_transactions_to_willexecutor(self.bal_plugin,
|
||||
willexecutor
|
||||
):
|
||||
for wid in willexecutor["txsids"]:
|
||||
@@ -2257,7 +2266,9 @@ class BalBuildWillDialog(BalDialog):
|
||||
self.bal_window.willitems[wid].we["url"], wid, "Waiting"
|
||||
)
|
||||
)
|
||||
self.bal_window.willitems[wid].check_willexecutor()
|
||||
self.bal_plugin = bal_window.bal_plugin
|
||||
w = self.bal_window.willitems[wid]
|
||||
w.set_check_willexecutor(Willexecutors.check_transaction(self.bal_plugin,w._id, w.we["url"]))
|
||||
row = self.msg_edit_row(
|
||||
"checked {} - {} : {}".format(
|
||||
self.bal_window.willitems[wid].we["url"],
|
||||
@@ -2509,6 +2520,7 @@ class HeirList(MyTreeView, MessageBoxMixin):
|
||||
self.decimal_point = bal_window.window.get_decimal_point()
|
||||
self.bal_window = bal_window
|
||||
|
||||
|
||||
try:
|
||||
self.setModel(QStandardItemModel(self))
|
||||
self.sortByColumn(self.Columns.NAME, Qt.SortOrder.AscendingOrder)
|
||||
@@ -2592,12 +2604,6 @@ class HeirList(MyTreeView, MessageBoxMixin):
|
||||
menu.addAction(_("Delete"), lambda: self.delete_heirs(selected_keys))
|
||||
menu.exec(self.viewport().mapToGlobal(position))
|
||||
|
||||
# def get_selected_keys(self):
|
||||
# selected_keys = []
|
||||
# for s_idx in self.selected_in_column(self.Columns.NAME):
|
||||
# sel_key = self.model().itemFromIndex(s_idx).data(0)
|
||||
# selected_keys.append(sel_key)
|
||||
# return selected_keys
|
||||
def update(self):
|
||||
current_key = self.get_role_data_for_current_item(
|
||||
col=self.Columns.NAME, role=self.ROLE_HEIR_KEY
|
||||
@@ -2747,6 +2753,7 @@ class HeirList(MyTreeView, MessageBoxMixin):
|
||||
self.heir_tx_fees.setValue(int(self.bal_window.will_settings["baltx_fees"]))
|
||||
|
||||
except Exception as e:
|
||||
pass
|
||||
_logger.debug(f"Exception update_will_settings {e}")
|
||||
|
||||
def build_transactions(self):
|
||||
|
||||
4
will.py
4
will.py
@@ -793,9 +793,9 @@ class WillItem(Logger):
|
||||
iw = inp[1]
|
||||
self.set_anticipate(iw)
|
||||
|
||||
def check_willexecutor(self):
|
||||
def set_check_willexecutor(self,resp):
|
||||
try:
|
||||
if resp := Willexecutors.check_transaction(self._id, self.we["url"]):
|
||||
if resp :
|
||||
if "tx" in resp and resp["tx"] == str(self.tx):
|
||||
self.set_status("PUSHED")
|
||||
self.set_status("CHECKED")
|
||||
|
||||
@@ -125,14 +125,14 @@ class Willexecutors:
|
||||
# )
|
||||
|
||||
def send_request(
|
||||
method, url, data=None, *, timeout=10, handle_response=None, count_reply=0
|
||||
bal_plugin,method, url, data=None, *, timeout=10, handle_response=None, count_reply=0
|
||||
):
|
||||
network = Network.get_instance()
|
||||
if not network:
|
||||
raise Exception("You are offline.")
|
||||
_logger.debug(f"<-- {method} {url} {data}")
|
||||
headers = {}
|
||||
headers["user-agent"] = f"BalPlugin v:{BalPlugin.version()}"
|
||||
headers["user-agent"] = f"BalPlugin v:{bal_plugin.version()}"
|
||||
headers["Content-Type"] = "text/plain"
|
||||
if not handle_response:
|
||||
handle_response = Willexecutors.handle_response
|
||||
@@ -162,6 +162,7 @@ class Willexecutors:
|
||||
_logger.debug(f"timeout({count_reply}) error: retry in 3 sec...")
|
||||
time.sleep(3)
|
||||
return Willexecutors.send_request(
|
||||
bal_plugin,
|
||||
method,
|
||||
url,
|
||||
data,
|
||||
@@ -199,11 +200,12 @@ class Willexecutors:
|
||||
class AlreadyPresentException(Exception):
|
||||
pass
|
||||
|
||||
def push_transactions_to_willexecutor(willexecutor):
|
||||
def push_transactions_to_willexecutor(bal_plugin, willexecutor):
|
||||
out = True
|
||||
try:
|
||||
_logger.debug(f"{willexecutor['url']}: {willexecutor['txs']}")
|
||||
if w := Willexecutors.send_request(
|
||||
bal_plugin,
|
||||
"post",
|
||||
willexecutor["url"] + "/" + chainname + "/pushtxs",
|
||||
data=willexecutor["txs"].encode("ascii"),
|
||||
@@ -224,16 +226,16 @@ class Willexecutors:
|
||||
|
||||
return out
|
||||
|
||||
def ping_servers(willexecutors):
|
||||
def ping_servers(bal_plugin, willexecutors):
|
||||
for url, we in willexecutors.items():
|
||||
Willexecutors.get_info_task(url, we)
|
||||
Willexecutors.get_info_task(bal_plugin,url, we)
|
||||
|
||||
def get_info_task(url, willexecutor):
|
||||
def get_info_task(bal_plugin,url, willexecutor):
|
||||
w = None
|
||||
try:
|
||||
_logger.info("GETINFO_WILLEXECUTOR")
|
||||
_logger.debug(url)
|
||||
w = Willexecutors.send_request("get", url + "/" + chainname + "/info")
|
||||
w = Willexecutors.send_request(bal_plugin,"get", url + "/" + chainname + "/info")
|
||||
if isinstance(w, dict):
|
||||
willexecutor["url"] = url
|
||||
willexecutor["status"] = 200
|
||||
@@ -263,6 +265,7 @@ class Willexecutors:
|
||||
def download_list(bal_plugin,old_willexecutors):
|
||||
try:
|
||||
willexecutors = Willexecutors.send_request(
|
||||
bal_plugin,
|
||||
"get",
|
||||
f"https://welist.bitcoin-after.life/data/{chainname}?page=0&limit=100",
|
||||
)
|
||||
@@ -294,10 +297,11 @@ class Willexecutors:
|
||||
|
||||
return {}
|
||||
|
||||
def check_transaction(txid, url):
|
||||
def check_transaction(bal_plugin,txid, url):
|
||||
_logger.debug(f"{url}:{txid}")
|
||||
try:
|
||||
w = Willexecutors.send_request(
|
||||
bal_plugin,
|
||||
"post", url + "/searchtx", data=txid.encode("ascii")
|
||||
)
|
||||
return w
|
||||
|
||||
Reference in New Issue
Block a user