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