forked from bitcoinafterlife/bal-electrum-plugin
partial commit to fix wallet utils
this commit provide a lot of changes in will-settings including export to ics calendar file.
This commit is contained in:
121
willexecutors.py
121
willexecutors.py
@@ -1,9 +1,8 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
from aiohttp import ClientResponse
|
||||
from electrum import constants
|
||||
from electrum.i18n import _
|
||||
from electrum.logging import get_logger
|
||||
from electrum.network import Network
|
||||
@@ -14,11 +13,12 @@ DEFAULT_TIMEOUT = 5
|
||||
_logger = get_logger(__name__)
|
||||
|
||||
|
||||
chainname = constants.net.NET_NAME if constants.net.NET_NAME != "mainnet" else "bitcoin"
|
||||
chainname = BalPlugin.chainname
|
||||
|
||||
|
||||
class Willexecutors:
|
||||
|
||||
@staticmethod
|
||||
def save(bal_plugin, willexecutors):
|
||||
_logger.debug(f"save {willexecutors},{chainname}")
|
||||
aw = bal_plugin.WILLEXECUTORS.get()
|
||||
@@ -27,6 +27,7 @@ class Willexecutors:
|
||||
_logger.debug(f"saved: {aw}")
|
||||
# bal_plugin.WILLEXECUTORS.set(willexecutors)
|
||||
|
||||
@staticmethod
|
||||
def get_willexecutors(
|
||||
bal_plugin, update=False, bal_window=False, force=False, task=True
|
||||
):
|
||||
@@ -78,6 +79,7 @@ class Willexecutors:
|
||||
)
|
||||
return w_sorted
|
||||
|
||||
@staticmethod
|
||||
def is_selected(willexecutor, value=None):
|
||||
if not willexecutor:
|
||||
return False
|
||||
@@ -89,6 +91,7 @@ class Willexecutors:
|
||||
willexecutor["selected"] = False
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def get_willexecutor_transactions(will, force=False):
|
||||
willexecutors = {}
|
||||
for wid, willitem in will.items():
|
||||
@@ -124,6 +127,7 @@ class Willexecutors:
|
||||
# willexecutors[url]["txs"], url
|
||||
# )
|
||||
|
||||
@staticmethod
|
||||
def send_request(
|
||||
method, url, data=None, *, timeout=10, handle_response=None, count_reply=0
|
||||
):
|
||||
@@ -177,12 +181,14 @@ class Willexecutors:
|
||||
_logger.debug(f"--> {response}")
|
||||
return response
|
||||
|
||||
@staticmethod
|
||||
def get_we_url_from_response(resp):
|
||||
url_slices = str(resp.url).split("/")
|
||||
if len(url_slices) > 2:
|
||||
url_slices = url_slices[:-2]
|
||||
return "/".join(url_slices)
|
||||
|
||||
@staticmethod
|
||||
async def handle_response(resp: ClientResponse):
|
||||
r = await resp.text()
|
||||
try:
|
||||
@@ -196,9 +202,11 @@ class Willexecutors:
|
||||
pass
|
||||
return r
|
||||
|
||||
@staticmethod
|
||||
class AlreadyPresentException(Exception):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def push_transactions_to_willexecutor(willexecutor):
|
||||
out = True
|
||||
try:
|
||||
@@ -224,10 +232,12 @@ class Willexecutors:
|
||||
|
||||
return out
|
||||
|
||||
@staticmethod
|
||||
def ping_servers(willexecutors):
|
||||
for url, we in willexecutors.items():
|
||||
Willexecutors.get_info_task(url, we)
|
||||
|
||||
@staticmethod
|
||||
def get_info_task(url, willexecutor):
|
||||
w = None
|
||||
try:
|
||||
@@ -248,7 +258,9 @@ class Willexecutors:
|
||||
willexecutor["last_update"] = datetime.now().timestamp()
|
||||
return willexecutor
|
||||
|
||||
def initialize_willexecutor(willexecutor, url, status=None, old_willexecutor={}):
|
||||
@staticmethod
|
||||
def initialize_willexecutor(willexecutor, url, status=None, old_willexecutor=None):
|
||||
old_willexecutor=old_willexecutor if old_willexecutor is not None else {}
|
||||
willexecutor["url"] = url
|
||||
if status is not None:
|
||||
willexecutor["status"] = status
|
||||
@@ -260,11 +272,13 @@ class Willexecutors:
|
||||
|
||||
|
||||
|
||||
def download_list(old_willexecutors):
|
||||
@staticmethod
|
||||
def download_list(old_willexecutors,welist_server):
|
||||
try:
|
||||
welist_server = welist_server if welist_server[-1] == '/' else welist_server+'/'
|
||||
willexecutors = Willexecutors.send_request(
|
||||
"get",
|
||||
f"https://welist.bitcoin-after.life/data/{chainname}?page=0&limit=100",
|
||||
f"{welist_server}data/{chainname}?page=0&limit=100",
|
||||
)
|
||||
# del willexecutors["status"]
|
||||
for w in willexecutors:
|
||||
@@ -280,6 +294,7 @@ class Willexecutors:
|
||||
_logger.error(f"Failed to download willexecutors list: {e}")
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def get_willexecutors_list_from_json():
|
||||
try:
|
||||
with open("willexecutors.json") as f:
|
||||
@@ -294,6 +309,7 @@ class Willexecutors:
|
||||
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def check_transaction(txid, url):
|
||||
_logger.debug(f"{url}:{txid}")
|
||||
try:
|
||||
@@ -305,53 +321,54 @@ class Willexecutors:
|
||||
_logger.error(f"error contacting {url} for checking txs {e}")
|
||||
raise e
|
||||
|
||||
@staticmethod
|
||||
def compute_id(willexecutor):
|
||||
return "{}-{}".format(willexecutor.get("url"), willexecutor.get("chain"))
|
||||
|
||||
|
||||
class WillExecutor:
|
||||
def __init__(
|
||||
self,
|
||||
url,
|
||||
base_fee,
|
||||
chain,
|
||||
info,
|
||||
version,
|
||||
status,
|
||||
is_selected=False,
|
||||
promo_code="",
|
||||
):
|
||||
self.url = url
|
||||
self.base_fee = base_fee
|
||||
self.chain = chain
|
||||
self.info = info
|
||||
self.version = version
|
||||
self.status = status
|
||||
self.promo_code = promo_code
|
||||
self.is_selected = is_selected
|
||||
self.id = self.compute_id()
|
||||
|
||||
def from_dict(d):
|
||||
return WillExecutor(
|
||||
url=d.get("url", "http://localhost:8000"),
|
||||
base_fee=d.get("base_fee", 1000),
|
||||
chain=d.get("chain", chainname),
|
||||
info=d.get("info", ""),
|
||||
version=d.get("version", 0),
|
||||
status=d.get("status", "Ko"),
|
||||
is_selected=d.get("is_selected", "False"),
|
||||
promo_code=d.get("promo_code", ""),
|
||||
)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"url": self.url,
|
||||
"base_fee": self.base_fee,
|
||||
"chain": self.chain,
|
||||
"info": self.info,
|
||||
"version": self.version,
|
||||
"promo_code": self.promo_code,
|
||||
}
|
||||
|
||||
def compute_id(self):
|
||||
return f"{self.url}-{self.chain}"
|
||||
#class WillExecutor:
|
||||
# def __init__(
|
||||
# self,
|
||||
# url,
|
||||
# base_fee,
|
||||
# chain,
|
||||
# info,
|
||||
# version,
|
||||
# status,
|
||||
# is_selected=False,
|
||||
# promo_code="",
|
||||
# ):
|
||||
# self.url = url
|
||||
# self.base_fee = base_fee
|
||||
# self.chain = chain
|
||||
# self.info = info
|
||||
# self.version = version
|
||||
# self.status = status
|
||||
# self.promo_code = promo_code
|
||||
# self.is_selected = is_selected
|
||||
# self.id = self.compute_id()
|
||||
#
|
||||
# def from_dict(d):
|
||||
# return WillExecutor(
|
||||
# url=d.get("url", "http://localhost:8000"),
|
||||
# base_fee=d.get("base_fee", 1000),
|
||||
# chain=d.get("chain", chainname),
|
||||
# info=d.get("info", ""),
|
||||
# version=d.get("version", 0),
|
||||
# status=d.get("status", "Ko"),
|
||||
# is_selected=d.get("is_selected", "False"),
|
||||
# promo_code=d.get("promo_code", ""),
|
||||
# )
|
||||
#
|
||||
# def to_dict(self):
|
||||
# return {
|
||||
# "url": self.url,
|
||||
# "base_fee": self.base_fee,
|
||||
# "chain": self.chain,
|
||||
# "info": self.info,
|
||||
# "version": self.version,
|
||||
# "promo_code": self.promo_code,
|
||||
# }
|
||||
#
|
||||
# def compute_id(self):
|
||||
# return f"{self.url}-{self.chain}"
|
||||
|
||||
Reference in New Issue
Block a user