Compare commits
9 Commits
ef0ab56de4
...
0.2.8
| Author | SHA1 | Date | |
|---|---|---|---|
|
dff508c25b
|
|||
|
2056ffae7f
|
|||
|
c8ab85b735
|
|||
|
e2de4a3afa
|
|||
|
3a44b492e4
|
|||
|
9737221914
|
|||
|
a022c413cc
|
|||
|
716d4dd5c5
|
|||
|
b012dd7a68
|
32
bal.py
32
bal.py
@@ -47,18 +47,19 @@ class BalConfig:
|
|||||||
|
|
||||||
|
|
||||||
class BalPlugin(BasePlugin):
|
class BalPlugin(BasePlugin):
|
||||||
LATEST_VERSION = "1"
|
_version=None
|
||||||
KNOWN_VERSIONS = ("0", "1")
|
__version__ = "0.2.7" #AUTOMATICALLY GENERATED DO NOT EDIT
|
||||||
assert LATEST_VERSION in KNOWN_VERSIONS
|
def version(self):
|
||||||
|
if not self._version:
|
||||||
def version():
|
|
||||||
try:
|
try:
|
||||||
f = ""
|
f = ""
|
||||||
with open("VERSION", "r") as fi:
|
with open("{}/VERSION".format(self.plugin_dir), "r") as fi:
|
||||||
f = str(fi.readline())
|
f = str(fi.read())
|
||||||
return f
|
self._version = f.strip()
|
||||||
except:
|
except Exception as e:
|
||||||
return "unknown"
|
_logger.error(f"failed to get version: {e}")
|
||||||
|
self._version="unknown"
|
||||||
|
return self._version
|
||||||
|
|
||||||
SIZE = (159, 97)
|
SIZE = (159, 97)
|
||||||
|
|
||||||
@@ -104,6 +105,15 @@ class BalPlugin(BasePlugin):
|
|||||||
"bal_willexecutors",
|
"bal_willexecutors",
|
||||||
{
|
{
|
||||||
"mainnet": {
|
"mainnet": {
|
||||||
|
"https://we.bitcoin-after.life": {
|
||||||
|
"base_fee": 100000,
|
||||||
|
"status": "New",
|
||||||
|
"info": "Bitcoin After Life Will Executor",
|
||||||
|
"address": "bc1qusymuetsz2psaqzqxv8qmzcy64d9meckj3lxxf",
|
||||||
|
"selected": True,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"testnet": {
|
||||||
"https://we.bitcoin-after.life": {
|
"https://we.bitcoin-after.life": {
|
||||||
"base_fee": 100000,
|
"base_fee": 100000,
|
||||||
"status": "New",
|
"status": "New",
|
||||||
@@ -111,7 +121,7 @@ class BalPlugin(BasePlugin):
|
|||||||
"address": "bcrt1qa5cntu4hgadw8zd3n6sq2nzjy34sxdtd9u0gp7",
|
"address": "bcrt1qa5cntu4hgadw8zd3n6sq2nzjy34sxdtd9u0gp7",
|
||||||
"selected": True,
|
"selected": True,
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
self.WILL_SETTINGS = BalConfig(
|
self.WILL_SETTINGS = BalConfig(
|
||||||
|
|||||||
128
heirs.py
128
heirs.py
@@ -1,23 +1,37 @@
|
|||||||
import datetime
|
# import datetime
|
||||||
import json
|
# import json
|
||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
import urllib.parse
|
|
||||||
import urllib.request
|
# import urllib.parse
|
||||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple
|
# import urllib.request
|
||||||
|
from typing import (
|
||||||
|
TYPE_CHECKING,
|
||||||
|
Any,
|
||||||
|
Dict,
|
||||||
|
# List,
|
||||||
|
Optional,
|
||||||
|
# Sequence,
|
||||||
|
Tuple,
|
||||||
|
)
|
||||||
|
|
||||||
import dns
|
import dns
|
||||||
from dns.exception import DNSException
|
from dns.exception import DNSException
|
||||||
from electrum import bitcoin, constants, descriptor, dnssec
|
from electrum import (
|
||||||
|
bitcoin,
|
||||||
|
constants,
|
||||||
|
# descriptor,
|
||||||
|
dnssec,
|
||||||
|
)
|
||||||
from electrum.logging import Logger, get_logger
|
from electrum.logging import Logger, get_logger
|
||||||
from electrum.transaction import (
|
from electrum.transaction import (
|
||||||
PartialTransaction,
|
PartialTransaction,
|
||||||
PartialTxInput,
|
PartialTxInput,
|
||||||
PartialTxOutput,
|
PartialTxOutput,
|
||||||
TxOutpoint,
|
TxOutpoint,
|
||||||
TxOutput,
|
# TxOutput,
|
||||||
)
|
)
|
||||||
from electrum.util import (
|
from electrum.util import (
|
||||||
bfh,
|
bfh,
|
||||||
@@ -30,11 +44,11 @@ from electrum.util import (
|
|||||||
from .util import Util
|
from .util import Util
|
||||||
from .willexecutors import Willexecutors
|
from .willexecutors import Willexecutors
|
||||||
from electrum.util import BitcoinException
|
from electrum.util import BitcoinException
|
||||||
from electrum import constants
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .simple_config import SimpleConfig
|
from .simple_config import SimpleConfig
|
||||||
from .wallet_db import WalletDB
|
|
||||||
|
# from .wallet_db import WalletDB
|
||||||
|
|
||||||
|
|
||||||
_logger = get_logger(__name__)
|
_logger = get_logger(__name__)
|
||||||
@@ -87,7 +101,7 @@ def prepare_transactions(locktimes, available_utxos, fees, wallet):
|
|||||||
x.value_sats(), x.prevout.txid, x.prevout.out_idx
|
x.value_sats(), x.prevout.txid, x.prevout.out_idx
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
total_used_utxos = []
|
# total_used_utxos = []
|
||||||
txsout = {}
|
txsout = {}
|
||||||
locktime, _ = Util.get_lowest_locktimes(locktimes)
|
locktime, _ = Util.get_lowest_locktimes(locktimes)
|
||||||
if not locktime:
|
if not locktime:
|
||||||
@@ -105,7 +119,7 @@ def prepare_transactions(locktimes, available_utxos, fees, wallet):
|
|||||||
outputs = []
|
outputs = []
|
||||||
paid_heirs = {}
|
paid_heirs = {}
|
||||||
for name, heir in heirs.items():
|
for name, heir in heirs.items():
|
||||||
if len(heir) > HEIR_REAL_AMOUNT and not "DUST" in str(
|
if len(heir) > HEIR_REAL_AMOUNT and "DUST" not in str(
|
||||||
heir[HEIR_REAL_AMOUNT]
|
heir[HEIR_REAL_AMOUNT]
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
@@ -200,7 +214,7 @@ def get_utxos_from_inputs(tx_inputs, tx, utxos):
|
|||||||
|
|
||||||
# TODO calculate de minimum inputs to be invalidated
|
# TODO calculate de minimum inputs to be invalidated
|
||||||
def invalidate_inheritance_transactions(wallet):
|
def invalidate_inheritance_transactions(wallet):
|
||||||
listids = []
|
# listids = []
|
||||||
utxos = {}
|
utxos = {}
|
||||||
dtxs = {}
|
dtxs = {}
|
||||||
for k, v in wallet.get_all_labels().items():
|
for k, v in wallet.get_all_labels().items():
|
||||||
@@ -229,7 +243,7 @@ def invalidate_inheritance_transactions(wallet):
|
|||||||
for key, value in utxos:
|
for key, value in utxos:
|
||||||
for tx in value["txs"]:
|
for tx in value["txs"]:
|
||||||
txid = tx.txid()
|
txid = tx.txid()
|
||||||
if not txid in invalidated:
|
if txid not in invalidated:
|
||||||
invalidated.append(tx.txid())
|
invalidated.append(tx.txid())
|
||||||
remaining[key] = value
|
remaining[key] = value
|
||||||
|
|
||||||
@@ -237,10 +251,10 @@ def invalidate_inheritance_transactions(wallet):
|
|||||||
def print_transaction(heirs, tx, locktimes, tx_fees):
|
def print_transaction(heirs, tx, locktimes, tx_fees):
|
||||||
jtx = tx.to_json()
|
jtx = tx.to_json()
|
||||||
print(f"TX: {tx.txid()}\t-\tLocktime: {jtx['locktime']}")
|
print(f"TX: {tx.txid()}\t-\tLocktime: {jtx['locktime']}")
|
||||||
print(f"---")
|
print("---")
|
||||||
for inp in jtx["inputs"]:
|
for inp in jtx["inputs"]:
|
||||||
print(f"{inp['address']}: {inp['value_sats']}")
|
print(f"{inp['address']}: {inp['value_sats']}")
|
||||||
print(f"---")
|
print("---")
|
||||||
for out in jtx["outputs"]:
|
for out in jtx["outputs"]:
|
||||||
heirname = ""
|
heirname = ""
|
||||||
for key in heirs.keys():
|
for key in heirs.keys():
|
||||||
@@ -262,7 +276,7 @@ def print_transaction(heirs, tx, locktimes, tx_fees):
|
|||||||
print()
|
print()
|
||||||
try:
|
try:
|
||||||
print(tx.serialize_to_network())
|
print(tx.serialize_to_network())
|
||||||
except:
|
except Exception:
|
||||||
print("impossible to serialize")
|
print("impossible to serialize")
|
||||||
print()
|
print()
|
||||||
|
|
||||||
@@ -285,7 +299,7 @@ class Heirs(dict, Logger):
|
|||||||
d = self.db.get("heirs", {})
|
d = self.db.get("heirs", {})
|
||||||
try:
|
try:
|
||||||
self.update(d)
|
self.update(d)
|
||||||
except e as Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
def invalidate_transactions(self, wallet):
|
def invalidate_transactions(self, wallet):
|
||||||
@@ -357,10 +371,10 @@ class Heirs(dict, Logger):
|
|||||||
def amount_to_float(self, amount):
|
def amount_to_float(self, amount):
|
||||||
try:
|
try:
|
||||||
return float(amount)
|
return float(amount)
|
||||||
except:
|
except Exception:
|
||||||
try:
|
try:
|
||||||
return float(amount[:-1])
|
return float(amount[:-1])
|
||||||
except:
|
except Exception:
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
def fixed_percent_lists_amount(self, from_locktime, dust_threshold, reverse=False):
|
def fixed_percent_lists_amount(self, from_locktime, dust_threshold, reverse=False):
|
||||||
@@ -375,7 +389,11 @@ class Heirs(dict, Logger):
|
|||||||
Util.parse_locktime_string(self[key][HEIR_LOCKTIME]) - from_locktime
|
Util.parse_locktime_string(self[key][HEIR_LOCKTIME]) - from_locktime
|
||||||
)
|
)
|
||||||
if cmp <= 0:
|
if cmp <= 0:
|
||||||
_logger.debug("cmp < 0 {} {} {} ".format(cmp, key, self[key][HEIR_LOCKTIME], from_locktime))
|
_logger.debug(
|
||||||
|
"cmp < 0 {} {} {} {}".format(
|
||||||
|
cmp, key, self[key][HEIR_LOCKTIME], from_locktime
|
||||||
|
)
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
if Util.is_perc(self[key][HEIR_AMOUNT]):
|
if Util.is_perc(self[key][HEIR_AMOUNT]):
|
||||||
percent_amount += float(self[key][HEIR_AMOUNT][:-1])
|
percent_amount += float(self[key][HEIR_AMOUNT][:-1])
|
||||||
@@ -389,15 +407,25 @@ class Heirs(dict, Logger):
|
|||||||
fixed_heirs[key].insert(HEIR_REAL_AMOUNT, heir_amount)
|
fixed_heirs[key].insert(HEIR_REAL_AMOUNT, heir_amount)
|
||||||
else:
|
else:
|
||||||
fixed_heirs[key] = list(self[key])
|
fixed_heirs[key] = list(self[key])
|
||||||
fixed_heirs[key].insert(HEIR_REAL_AMOUNT, f"DUST: {heir_amount}")
|
fixed_heirs[key].insert(
|
||||||
|
HEIR_REAL_AMOUNT, f"DUST: {heir_amount}"
|
||||||
|
)
|
||||||
fixed_heirs[key].insert(HEIR_DUST_AMOUNT, heir_amount)
|
fixed_heirs[key].insert(HEIR_DUST_AMOUNT, heir_amount)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.error(e)
|
_logger.error(e)
|
||||||
return fixed_heirs, fixed_amount, percent_heirs, percent_amount, fixed_amount_with_dust
|
return (
|
||||||
|
fixed_heirs,
|
||||||
|
fixed_amount,
|
||||||
|
percent_heirs,
|
||||||
|
percent_amount,
|
||||||
|
fixed_amount_with_dust,
|
||||||
|
)
|
||||||
|
|
||||||
def prepare_lists(
|
def prepare_lists(
|
||||||
self, balance, total_fees, wallet, willexecutor=False, from_locktime=0
|
self, balance, total_fees, wallet, willexecutor=False, from_locktime=0
|
||||||
):
|
):
|
||||||
|
if balance<total_fees or balance < wallet.dust_threshold():
|
||||||
|
raise BalanceTooLowException(balance,wallet.dust_threshold(),total_fees)
|
||||||
willexecutors_amount = 0
|
willexecutors_amount = 0
|
||||||
willexecutors = {}
|
willexecutors = {}
|
||||||
heir_list = {}
|
heir_list = {}
|
||||||
@@ -418,7 +446,7 @@ class Heirs(dict, Logger):
|
|||||||
willexecutors[
|
willexecutors[
|
||||||
'w!ll3x3c"' + willexecutor["url"] + '"' + str(locktime)
|
'w!ll3x3c"' + willexecutor["url"] + '"' + str(locktime)
|
||||||
] = h
|
] = h
|
||||||
except Exception as e:
|
except Exception:
|
||||||
return [], False
|
return [], False
|
||||||
else:
|
else:
|
||||||
_logger.error(
|
_logger.error(
|
||||||
@@ -428,11 +456,13 @@ class Heirs(dict, Logger):
|
|||||||
newbalance -= willexecutors_amount
|
newbalance -= willexecutors_amount
|
||||||
if newbalance < 0:
|
if newbalance < 0:
|
||||||
raise WillExecutorFeeException(willexecutor)
|
raise WillExecutorFeeException(willexecutor)
|
||||||
a=list(self.fixed_percent_lists_amount(from_locktime, wallet.dust_threshold()))
|
(
|
||||||
fixed_heirs, fixed_amount, percent_heirs, percent_amount,fixed_amount_with_dust = (
|
fixed_heirs,
|
||||||
self.fixed_percent_lists_amount(from_locktime, wallet.dust_threshold())
|
fixed_amount,
|
||||||
)
|
percent_heirs,
|
||||||
|
percent_amount,
|
||||||
|
fixed_amount_with_dust,
|
||||||
|
) = self.fixed_percent_lists_amount(from_locktime, wallet.dust_threshold())
|
||||||
if fixed_amount > newbalance:
|
if fixed_amount > newbalance:
|
||||||
fixed_amount = self.normalize_perc(
|
fixed_amount = self.normalize_perc(
|
||||||
fixed_heirs, newbalance, fixed_amount, wallet
|
fixed_heirs, newbalance, fixed_amount, wallet
|
||||||
@@ -442,14 +472,12 @@ class Heirs(dict, Logger):
|
|||||||
heir_list.update(fixed_heirs)
|
heir_list.update(fixed_heirs)
|
||||||
|
|
||||||
newbalance -= fixed_amount
|
newbalance -= fixed_amount
|
||||||
|
|
||||||
if newbalance > 0:
|
if newbalance > 0:
|
||||||
perc_amount = self.normalize_perc(
|
perc_amount = self.normalize_perc(
|
||||||
percent_heirs, newbalance, percent_amount, wallet
|
percent_heirs, newbalance, percent_amount, wallet
|
||||||
)
|
)
|
||||||
newbalance -= perc_amount
|
newbalance -= perc_amount
|
||||||
heir_list.update(percent_heirs)
|
heir_list.update(percent_heirs)
|
||||||
|
|
||||||
if newbalance > 0:
|
if newbalance > 0:
|
||||||
newbalance += fixed_amount
|
newbalance += fixed_amount
|
||||||
fixed_amount = self.normalize_perc(
|
fixed_amount = self.normalize_perc(
|
||||||
@@ -466,7 +494,7 @@ class Heirs(dict, Logger):
|
|||||||
locktimes = {}
|
locktimes = {}
|
||||||
for key, value in heir_list:
|
for key, value in heir_list:
|
||||||
locktime = Util.parse_locktime_string(value[HEIR_LOCKTIME])
|
locktime = Util.parse_locktime_string(value[HEIR_LOCKTIME])
|
||||||
if not locktime in locktimes:
|
if locktime not in locktimes:
|
||||||
locktimes[locktime] = {key: value}
|
locktimes[locktime] = {key: value}
|
||||||
else:
|
else:
|
||||||
locktimes[locktime][key] = value
|
locktimes[locktime][key] = value
|
||||||
@@ -508,7 +536,7 @@ class Heirs(dict, Logger):
|
|||||||
break
|
break
|
||||||
elif 0 <= j:
|
elif 0 <= j:
|
||||||
url, willexecutor = willexecutorsitems[j]
|
url, willexecutor = willexecutorsitems[j]
|
||||||
if not Willexecutors.is_selected(willexecutor):
|
if not Willexecutors.is_selected(willexecutor) or willexecutor["base_fee"] < wallet.dust_threshold():
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
willexecutor["url"] = url
|
willexecutor["url"] = url
|
||||||
@@ -527,12 +555,12 @@ class Heirs(dict, Logger):
|
|||||||
total_fees = 0
|
total_fees = 0
|
||||||
for fee in fees:
|
for fee in fees:
|
||||||
total_fees += int(fees[fee])
|
total_fees += int(fees[fee])
|
||||||
newbalance = balance
|
# newbalance = balance
|
||||||
try:
|
try:
|
||||||
locktimes, onlyfixed = self.prepare_lists(
|
locktimes, onlyfixed = self.prepare_lists(
|
||||||
balance, total_fees, wallet, willexecutor, from_locktime
|
balance, total_fees, wallet, willexecutor, from_locktime
|
||||||
)
|
)
|
||||||
except WillExecutorFeeException as e:
|
except WillExecutorFeeException:
|
||||||
i = 10
|
i = 10
|
||||||
continue
|
continue
|
||||||
if locktimes:
|
if locktimes:
|
||||||
@@ -543,12 +571,16 @@ class Heirs(dict, Logger):
|
|||||||
if not txs:
|
if not txs:
|
||||||
return {}
|
return {}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.error(f"build transactions: error preparing transactions: {e}")
|
_logger.error(
|
||||||
|
f"build transactions: error preparing transactions: {e}"
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
if "w!ll3x3c" in e.heirname:
|
if "w!ll3x3c" in e.heirname:
|
||||||
Willexecutors.is_selected(willexecutors[w], False)
|
Willexecutors.is_selected(
|
||||||
|
e.heirname[len("w!ll3x3c") :], False
|
||||||
|
)
|
||||||
break
|
break
|
||||||
except:
|
except Exception:
|
||||||
raise e
|
raise e
|
||||||
total_fees = 0
|
total_fees = 0
|
||||||
total_fees_real = 0
|
total_fees_real = 0
|
||||||
@@ -563,7 +595,7 @@ class Heirs(dict, Logger):
|
|||||||
rfee = tx.input_value() - tx.output_value()
|
rfee = tx.input_value() - tx.output_value()
|
||||||
if rfee < fee or rfee > fee + wallet.dust_threshold():
|
if rfee < fee or rfee > fee + wallet.dust_threshold():
|
||||||
redo = True
|
redo = True
|
||||||
oldfees = fees.get(tx.my_locktime, 0)
|
# oldfees = fees.get(tx.my_locktime, 0)
|
||||||
fees[tx.my_locktime] = fee
|
fees[tx.my_locktime] = fee
|
||||||
|
|
||||||
if balance - total_in > wallet.dust_threshold():
|
if balance - total_in > wallet.dust_threshold():
|
||||||
@@ -573,7 +605,9 @@ class Heirs(dict, Logger):
|
|||||||
if i >= 10:
|
if i >= 10:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
_logger.info(f"no locktimes for willexecutor {willexecutor} skipped")
|
_logger.info(
|
||||||
|
f"no locktimes for willexecutor {willexecutor} skipped"
|
||||||
|
)
|
||||||
break
|
break
|
||||||
alltxs.update(txs)
|
alltxs.update(txs)
|
||||||
|
|
||||||
@@ -733,10 +767,24 @@ class HeirExpiredException(LocktimeNotValid):
|
|||||||
|
|
||||||
class HeirAmountIsDustException(Exception):
|
class HeirAmountIsDustException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NoHeirsException(Exception):
|
class NoHeirsException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class WillExecutorFeeException(Exception):
|
class WillExecutorFeeException(Exception):
|
||||||
def __init__(self, willexecutor):
|
def __init__(self, willexecutor):
|
||||||
self.willexecutor = willexecutor
|
self.willexecutor = willexecutor
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "WillExecutorFeeException: {} fee:{}".format(self.willexecutor['url'],self.willexecutor['base_fee'])
|
return "WillExecutorFeeException: {} fee:{}".format(
|
||||||
|
self.willexecutor["url"], self.willexecutor["base_fee"]
|
||||||
|
)
|
||||||
|
class BalanceTooLowException(Exception):
|
||||||
|
def __init__(self,balance, dust_threshold, fees):
|
||||||
|
self.balance=balance
|
||||||
|
self.dust_threshold = dust_threshold
|
||||||
|
self.fees = fees
|
||||||
|
def __str__(self):
|
||||||
|
return f"Balance too low, balance: {self.balance}, dust threshold: {self.dust_threshold}, fees: {self.fees}"
|
||||||
|
|||||||
@@ -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.4",
|
"description": "Provides free and decentralized inheritance support<br> Version: 0.2.7",
|
||||||
"author":"Svatantrya",
|
"author":"Svatantrya",
|
||||||
"available_for": ["qt"],
|
"available_for": ["qt"],
|
||||||
"icon":"icons/bal32x32.png"
|
"icon":"icons/bal32x32.png"
|
||||||
|
|||||||
82
util.py
82
util.py
@@ -1,12 +1,10 @@
|
|||||||
import bisect
|
import bisect
|
||||||
import urllib.parse
|
|
||||||
import urllib.request
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from electrum.gui.qt.util import getSaveFileName
|
from electrum.gui.qt.util import getSaveFileName
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.transaction import PartialTxOutput
|
from electrum.transaction import PartialTxOutput
|
||||||
from electrum.util import FileExportFailed, FileImportFailed, write_json_file
|
from electrum.util import FileExportFailed
|
||||||
|
|
||||||
LOCKTIME_THRESHOLD = 500000000
|
LOCKTIME_THRESHOLD = 500000000
|
||||||
|
|
||||||
@@ -19,7 +17,7 @@ class Util:
|
|||||||
dt = datetime.fromtimestamp(locktime).isoformat()
|
dt = datetime.fromtimestamp(locktime).isoformat()
|
||||||
return dt
|
return dt
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return str(locktime)
|
return str(locktime)
|
||||||
|
|
||||||
@@ -29,7 +27,7 @@ class Util:
|
|||||||
return locktime
|
return locktime
|
||||||
else:
|
else:
|
||||||
return int(locktime)
|
return int(locktime)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
dt_object = datetime.fromisoformat(locktime)
|
dt_object = datetime.fromisoformat(locktime)
|
||||||
timestamp = dt_object.timestamp()
|
timestamp = dt_object.timestamp()
|
||||||
@@ -39,7 +37,7 @@ class Util:
|
|||||||
try:
|
try:
|
||||||
return int(locktime)
|
return int(locktime)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
@@ -58,7 +56,7 @@ class Util:
|
|||||||
height = Util.get_current_height(w.network)
|
height = Util.get_current_height(w.network)
|
||||||
locktime += int(height)
|
locktime += int(height)
|
||||||
return int(locktime)
|
return int(locktime)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -77,7 +75,7 @@ class Util:
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
return int(float(amount) * pow(10, decimal_point))
|
return int(float(amount) * pow(10, decimal_point))
|
||||||
except:
|
except Exception:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def decode_amount(amount, decimal_point):
|
def decode_amount(amount, decimal_point):
|
||||||
@@ -87,24 +85,24 @@ class Util:
|
|||||||
basestr = "{{:0.{}f}}".format(decimal_point)
|
basestr = "{{:0.{}f}}".format(decimal_point)
|
||||||
try:
|
try:
|
||||||
return basestr.format(float(amount) / pow(10, decimal_point))
|
return basestr.format(float(amount) / pow(10, decimal_point))
|
||||||
except:
|
except Exception:
|
||||||
return str(amount)
|
return str(amount)
|
||||||
|
|
||||||
def is_perc(value):
|
def is_perc(value):
|
||||||
try:
|
try:
|
||||||
return value[-1] == "%"
|
return value[-1] == "%"
|
||||||
except:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def cmp_array(heira, heirb):
|
def cmp_array(heira, heirb):
|
||||||
try:
|
try:
|
||||||
if not len(heira) == len(heirb):
|
if len(heira) != len(heirb):
|
||||||
return False
|
return False
|
||||||
for h in range(0, len(heira)):
|
for h in range(0, len(heira)):
|
||||||
if not heira[h] == heirb[h]:
|
if heira[h] != heirb[h]:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
except:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def cmp_heir(heira, heirb):
|
def cmp_heir(heira, heirb):
|
||||||
@@ -122,7 +120,7 @@ class Util:
|
|||||||
and willexecutora["base_fee"] == willexecutorb["base_fee"]
|
and willexecutora["base_fee"] == willexecutorb["base_fee"]
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
except:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -148,7 +146,7 @@ class Util:
|
|||||||
):
|
):
|
||||||
for heira in heirsa:
|
for heira in heirsa:
|
||||||
if (
|
if (
|
||||||
exclude_willexecutors and not 'w!ll3x3c"' in heira
|
exclude_willexecutors and 'w!ll3x3c"' not in heira
|
||||||
) or not exclude_willexecutors:
|
) or not exclude_willexecutors:
|
||||||
found = False
|
found = False
|
||||||
for heirb in heirsb:
|
for heirb in heirsb:
|
||||||
@@ -175,8 +173,8 @@ class Util:
|
|||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
for heir in heirsa:
|
for heir in heirsa:
|
||||||
if not 'w!ll3x3c"' in heir:
|
if 'w!ll3x3c"' not in heir:
|
||||||
if not heir in heirsb or not cmp_function(
|
if heir not in heirsb or not cmp_function(
|
||||||
heirsa[heir], heirsb[heir]
|
heirsa[heir], heirsb[heir]
|
||||||
):
|
):
|
||||||
if not Util.search_heir_by_values(heirsb, heirsa[heir], [0, 3]):
|
if not Util.search_heir_by_values(heirsb, heirsa[heir], [0, 3]):
|
||||||
@@ -215,7 +213,7 @@ class Util:
|
|||||||
|
|
||||||
def get_value_amount(txa, txb):
|
def get_value_amount(txa, txb):
|
||||||
outputsa = txa.outputs()
|
outputsa = txa.outputs()
|
||||||
outputsb = txb.outputs()
|
# outputsb = txb.outputs()
|
||||||
value_amount = 0
|
value_amount = 0
|
||||||
|
|
||||||
for outa in outputsa:
|
for outa in outputsa:
|
||||||
@@ -260,10 +258,10 @@ class Util:
|
|||||||
def cmp_locktime(locktimea, locktimeb):
|
def cmp_locktime(locktimea, locktimeb):
|
||||||
if locktimea == locktimeb:
|
if locktimea == locktimeb:
|
||||||
return 0
|
return 0
|
||||||
strlocktime = str(locktimea)
|
strlocktimea = str(locktimea)
|
||||||
strlocktimeb = str(locktimeb)
|
strlocktimeb = str(locktimeb)
|
||||||
intlocktimea = Util.str_to_locktime(strlocktimea)
|
# intlocktimea = Util.str_to_locktime(strlocktimea)
|
||||||
intlocktimeb = Util.str_to_locktime(strlocktimeb)
|
# intlocktimeb = Util.str_to_locktime(strlocktimeb)
|
||||||
if locktimea[-1] in "ydb":
|
if locktimea[-1] in "ydb":
|
||||||
if locktimeb[-1] == locktimea[-1]:
|
if locktimeb[-1] == locktimea[-1]:
|
||||||
return int(strlocktimea[-1]) - int(strlocktimeb[-1])
|
return int(strlocktimea[-1]) - int(strlocktimeb[-1])
|
||||||
@@ -284,12 +282,12 @@ class Util:
|
|||||||
def get_lowest_locktimes(locktimes):
|
def get_lowest_locktimes(locktimes):
|
||||||
sorted_timestamp = []
|
sorted_timestamp = []
|
||||||
sorted_block = []
|
sorted_block = []
|
||||||
for l in locktimes:
|
for locktime in locktimes:
|
||||||
l = Util.parse_locktime_string(l)
|
locktime = Util.parse_locktime_string(locktime)
|
||||||
if l < LOCKTIME_THRESHOLD:
|
if locktime < LOCKTIME_THRESHOLD:
|
||||||
bisect.insort(sorted_block, l)
|
bisect.insort(sorted_block, locktime)
|
||||||
else:
|
else:
|
||||||
bisect.insort(sorted_timestamp, l)
|
bisect.insort(sorted_timestamp, locktime)
|
||||||
|
|
||||||
return sorted(sorted_timestamp), sorted(sorted_block)
|
return sorted(sorted_timestamp), sorted(sorted_block)
|
||||||
|
|
||||||
@@ -315,11 +313,11 @@ class Util:
|
|||||||
def utxo_to_str(utxo):
|
def utxo_to_str(utxo):
|
||||||
try:
|
try:
|
||||||
return utxo.to_str()
|
return utxo.to_str()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
return utxo.prevout.to_str()
|
return utxo.prevout.to_str()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return str(utxo)
|
return str(utxo)
|
||||||
|
|
||||||
@@ -382,7 +380,7 @@ class Util:
|
|||||||
out.is_change = True
|
out.is_change = True
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def get_current_height(network: "Network"):
|
def get_current_height(network):
|
||||||
# if no network or not up to date, just set locktime to zero
|
# if no network or not up to date, just set locktime to zero
|
||||||
if not network:
|
if not network:
|
||||||
return 0
|
return 0
|
||||||
@@ -405,38 +403,34 @@ class Util:
|
|||||||
|
|
||||||
def print_var(var, name="", veryverbose=False):
|
def print_var(var, name="", veryverbose=False):
|
||||||
print(f"---{name}---")
|
print(f"---{name}---")
|
||||||
if not var is None:
|
if var is not None:
|
||||||
try:
|
|
||||||
print("doc:", doc(var))
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
try:
|
try:
|
||||||
print("str:", str(var))
|
print("str:", str(var))
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
print("repr", repr(var))
|
print("repr", repr(var))
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
print("dict", dict(var))
|
print("dict", dict(var))
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
print("dir", dir(var))
|
print("dir", dir(var))
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
print("type", type(var))
|
print("type", type(var))
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
print("to_json", var.to_json())
|
print("to_json", var.to_json())
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
print("__slotnames__", var.__slotnames__)
|
print("__slotnames__", var.__slotnames__)
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print(f"---end {name}---")
|
print(f"---end {name}---")
|
||||||
@@ -458,11 +452,11 @@ class Util:
|
|||||||
Util.print_var(prevout._asdict())
|
Util.print_var(prevout._asdict())
|
||||||
print(f"---prevout-end {name}---")
|
print(f"---prevout-end {name}---")
|
||||||
|
|
||||||
def export_meta_gui(electrum_window: "ElectrumWindow", title, exporter):
|
def export_meta_gui(electrum_window, title, exporter):
|
||||||
filter_ = "All files (*)"
|
filter_ = "All files (*)"
|
||||||
filename = getSaveFileName(
|
filename = getSaveFileName(
|
||||||
parent=electrum_window,
|
parent=electrum_window,
|
||||||
title=_("Select file to save your {}").format(title),
|
title=_("Select file to save your {}".format(title)),
|
||||||
filename="BALplugin_{}".format(title),
|
filename="BALplugin_{}".format(title),
|
||||||
filter=filter_,
|
filter=filter_,
|
||||||
config=electrum_window.config,
|
config=electrum_window.config,
|
||||||
@@ -475,7 +469,7 @@ class Util:
|
|||||||
electrum_window.show_critical(str(e))
|
electrum_window.show_critical(str(e))
|
||||||
else:
|
else:
|
||||||
electrum_window.show_message(
|
electrum_window.show_message(
|
||||||
_("Your {0} were exported to '{1}'").format(title, str(filename))
|
_("Your {0} were exported to '{1}'".format(title, str(filename)))
|
||||||
)
|
)
|
||||||
|
|
||||||
def copy(dicto, dictfrom):
|
def copy(dicto, dictfrom):
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!env/bin/python3
|
#!env/bin/python3
|
||||||
from electrum.storage import WalletStorage
|
from electrum.storage import WalletStorage
|
||||||
from electrum.util import MyEncoder
|
|
||||||
import json
|
import json
|
||||||
|
from electrum.util import MyEncoder
|
||||||
import sys
|
import sys
|
||||||
import getpass
|
import getpass
|
||||||
import os
|
import os
|
||||||
@@ -47,12 +47,12 @@ def save(json_wallet, storage):
|
|||||||
def read_wallet(path, password=False):
|
def read_wallet(path, password=False):
|
||||||
storage = WalletStorage(path)
|
storage = WalletStorage(path)
|
||||||
if storage.is_encrypted():
|
if storage.is_encrypted():
|
||||||
if password == False:
|
if not password:
|
||||||
password = getpass.getpass("Enter wallet password: ", stream=None)
|
password = getpass.getpass("Enter wallet password: ", stream=None)
|
||||||
storage.decrypt(password)
|
storage.decrypt(password)
|
||||||
data = storage.read()
|
data = storage.read()
|
||||||
json_wallet = json.loads("[" + data + "]")[0]
|
json_wallet = json.loads("[" + data + "]")[0]
|
||||||
return json_wallet
|
return json_wallet, storage
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -65,7 +65,7 @@ if __name__ == "__main__":
|
|||||||
exit(1)
|
exit(1)
|
||||||
command = sys.argv[1]
|
command = sys.argv[1]
|
||||||
path = sys.argv[2]
|
path = sys.argv[2]
|
||||||
json_wallet = read_wallet(path)
|
json_wallet, storage = read_wallet(path)
|
||||||
have_to_save = False
|
have_to_save = False
|
||||||
if command == "fix":
|
if command == "fix":
|
||||||
have_to_save = fix_will_settings_tx_fees(json_wallet)
|
have_to_save = fix_will_settings_tx_fees(json_wallet)
|
||||||
|
|||||||
@@ -15,10 +15,8 @@ from PyQt6.QtWidgets import (
|
|||||||
QGroupBox,
|
QGroupBox,
|
||||||
QTextEdit,
|
QTextEdit,
|
||||||
)
|
)
|
||||||
from PyQt6.QtCore import Qt
|
|
||||||
from electrum.storage import WalletStorage
|
from electrum.storage import WalletStorage
|
||||||
from electrum.util import MyEncoder
|
from bal_wallet_utils import fix_will_settings_tx_fees, uninstall_bal, save
|
||||||
from bal_wallet_utils import fix_will_settings_tx_fees, uninstall_bal, read_wallet, save
|
|
||||||
|
|
||||||
|
|
||||||
class WalletUtilityGUI(QMainWindow):
|
class WalletUtilityGUI(QMainWindow):
|
||||||
@@ -190,14 +188,6 @@ class WalletUtilityGUI(QMainWindow):
|
|||||||
def main():
|
def main():
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
# Check if dependencies are available
|
|
||||||
try:
|
|
||||||
from electrum.storage import WalletStorage
|
|
||||||
from electrum.util import MyEncoder
|
|
||||||
except ImportError as e:
|
|
||||||
print(f"ERROR: Cannot import Electrum dependencies: {str(e)}")
|
|
||||||
return 1
|
|
||||||
|
|
||||||
window = WalletUtilityGUI()
|
window = WalletUtilityGUI()
|
||||||
window.show()
|
window.show()
|
||||||
|
|
||||||
|
|||||||
107
will.py
107
will.py
@@ -12,11 +12,7 @@ from electrum.transaction import (
|
|||||||
tx_from_any,
|
tx_from_any,
|
||||||
)
|
)
|
||||||
from electrum.util import (
|
from electrum.util import (
|
||||||
FileImportFailed,
|
|
||||||
bfh,
|
bfh,
|
||||||
decimal_point_to_base_unit_name,
|
|
||||||
read_json_file,
|
|
||||||
write_json_file,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from .util import Util
|
from .util import Util
|
||||||
@@ -85,7 +81,7 @@ class Will:
|
|||||||
txin._trusted_value_sats = change.value
|
txin._trusted_value_sats = change.value
|
||||||
try:
|
try:
|
||||||
txin.script_descriptor = change.script_descriptor
|
txin.script_descriptor = change.script_descriptor
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
txin.is_mine = True
|
txin.is_mine = True
|
||||||
txin._TxInput__address = change.address
|
txin._TxInput__address = change.address
|
||||||
@@ -132,8 +128,8 @@ class Will:
|
|||||||
to_delete.append(wid)
|
to_delete.append(wid)
|
||||||
to_add[ow.tx.txid()] = ow.to_dict()
|
to_add[ow.tx.txid()] = ow.to_dict()
|
||||||
|
|
||||||
for eid, err in errors.items():
|
# for eid, err in errors.items():
|
||||||
new_txid = err.tx.txid()
|
# new_txid = err.tx.txid()
|
||||||
|
|
||||||
for k, w in to_add.items():
|
for k, w in to_add.items():
|
||||||
will[k] = w
|
will[k] = w
|
||||||
@@ -201,7 +197,7 @@ class Will:
|
|||||||
outputs = w.tx.outputs()
|
outputs = w.tx.outputs()
|
||||||
found = False
|
found = False
|
||||||
old_txid = w.tx.txid()
|
old_txid = w.tx.txid()
|
||||||
ntx = None
|
# ntx = None
|
||||||
for i in range(0, len(inputs)):
|
for i in range(0, len(inputs)):
|
||||||
if (
|
if (
|
||||||
inputs[i].prevout.txid.hex() == otxid
|
inputs[i].prevout.txid.hex() == otxid
|
||||||
@@ -212,7 +208,7 @@ class Will:
|
|||||||
will[wid].tx.set_rbf(True)
|
will[wid].tx.set_rbf(True)
|
||||||
will[wid].tx._inputs[i] = Will.new_input(wid, idx, change)
|
will[wid].tx._inputs[i] = Will.new_input(wid, idx, change)
|
||||||
found = True
|
found = True
|
||||||
if found == True:
|
if found:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
new_txid = will[wid].tx.txid()
|
new_txid = will[wid].tx.txid()
|
||||||
@@ -239,7 +235,7 @@ class Will:
|
|||||||
for i in inputs:
|
for i in inputs:
|
||||||
prevout_str = i.prevout.to_str()
|
prevout_str = i.prevout.to_str()
|
||||||
inp = [w, will[w], i]
|
inp = [w, will[w], i]
|
||||||
if not prevout_str in all_inputs:
|
if prevout_str not in all_inputs:
|
||||||
all_inputs[prevout_str] = [inp]
|
all_inputs[prevout_str] = [inp]
|
||||||
else:
|
else:
|
||||||
all_inputs[prevout_str].append(inp)
|
all_inputs[prevout_str].append(inp)
|
||||||
@@ -252,7 +248,7 @@ class Will:
|
|||||||
min_locktime = min(values, key=lambda x: x[1].tx.locktime)[1].tx.locktime
|
min_locktime = min(values, key=lambda x: x[1].tx.locktime)[1].tx.locktime
|
||||||
for w in values:
|
for w in values:
|
||||||
if w[1].tx.locktime == min_locktime:
|
if w[1].tx.locktime == min_locktime:
|
||||||
if not i in all_inputs_min_locktime:
|
if i not in all_inputs_min_locktime:
|
||||||
all_inputs_min_locktime[i] = [w]
|
all_inputs_min_locktime[i] = [w]
|
||||||
else:
|
else:
|
||||||
all_inputs_min_locktime[i].append(w)
|
all_inputs_min_locktime[i].append(w)
|
||||||
@@ -290,7 +286,7 @@ class Will:
|
|||||||
for w in to_delete:
|
for w in to_delete:
|
||||||
try:
|
try:
|
||||||
del will[w]
|
del will[w]
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
for k, w in to_append.items():
|
for k, w in to_append.items():
|
||||||
will[k] = w
|
will[k] = w
|
||||||
@@ -300,8 +296,8 @@ class Will:
|
|||||||
|
|
||||||
def update_will(old_will, new_will):
|
def update_will(old_will, new_will):
|
||||||
all_old_inputs = Will.get_all_inputs(old_will, only_valid=True)
|
all_old_inputs = Will.get_all_inputs(old_will, only_valid=True)
|
||||||
all_inputs_min_locktime = Will.get_all_inputs_min_locktime(all_old_inputs)
|
# all_inputs_min_locktime = Will.get_all_inputs_min_locktime(all_old_inputs)
|
||||||
all_new_inputs = Will.get_all_inputs(new_will)
|
# all_new_inputs = Will.get_all_inputs(new_will)
|
||||||
# check if the new input is already spent by other transaction
|
# check if the new input is already spent by other transaction
|
||||||
# if it is use the same locktime, or anticipate.
|
# if it is use the same locktime, or anticipate.
|
||||||
Will.search_anticipate_rec(new_will, all_old_inputs)
|
Will.search_anticipate_rec(new_will, all_old_inputs)
|
||||||
@@ -343,15 +339,18 @@ class Will:
|
|||||||
utxos = wallet.get_utxos()
|
utxos = wallet.get_utxos()
|
||||||
filtered_inputs = []
|
filtered_inputs = []
|
||||||
prevout_to_spend = []
|
prevout_to_spend = []
|
||||||
|
current_height = Util.get_current_height(wallet.network)
|
||||||
for prevout_str, ws in inputs.items():
|
for prevout_str, ws in inputs.items():
|
||||||
for w in ws:
|
for w in ws:
|
||||||
if not w[0] in filtered_inputs:
|
if w[0] not in filtered_inputs:
|
||||||
filtered_inputs.append(w[0])
|
filtered_inputs.append(w[0])
|
||||||
if not prevout_str in prevout_to_spend:
|
if prevout_str not in prevout_to_spend:
|
||||||
prevout_to_spend.append(prevout_str)
|
prevout_to_spend.append(prevout_str)
|
||||||
balance = 0
|
balance = 0
|
||||||
utxo_to_spend = []
|
utxo_to_spend = []
|
||||||
for utxo in utxos:
|
for utxo in utxos:
|
||||||
|
if utxo.is_coinbase_output() and utxo.block_height < current_height+100:
|
||||||
|
continue
|
||||||
utxo_str = utxo.prevout.to_str()
|
utxo_str = utxo.prevout.to_str()
|
||||||
if utxo_str in prevout_to_spend:
|
if utxo_str in prevout_to_spend:
|
||||||
balance += inputs[utxo_str][0][2].value_sats()
|
balance += inputs[utxo_str][0][2].value_sats()
|
||||||
@@ -360,7 +359,7 @@ class Will:
|
|||||||
change_addresses = wallet.get_change_addresses_for_new_transaction()
|
change_addresses = wallet.get_change_addresses_for_new_transaction()
|
||||||
out = PartialTxOutput.from_address_and_value(change_addresses[0], balance)
|
out = PartialTxOutput.from_address_and_value(change_addresses[0], balance)
|
||||||
out.is_change = True
|
out.is_change = True
|
||||||
locktime = Util.get_current_height(wallet.network)
|
locktime = current_height
|
||||||
tx = PartialTransaction.from_io(
|
tx = PartialTransaction.from_io(
|
||||||
utxo_to_spend, [out], locktime=locktime, version=2
|
utxo_to_spend, [out], locktime=locktime, version=2
|
||||||
)
|
)
|
||||||
@@ -391,7 +390,7 @@ class Will:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def search_rai(all_inputs, all_utxos, will, wallet):
|
def search_rai(all_inputs, all_utxos, will, wallet):
|
||||||
will_only_valid = Will.only_valid_or_replaced_list(will)
|
# will_only_valid = Will.only_valid_or_replaced_list(will)
|
||||||
for inp, ws in all_inputs.items():
|
for inp, ws in all_inputs.items():
|
||||||
inutxo = Util.in_utxo(inp, all_utxos)
|
inutxo = Util.in_utxo(inp, all_utxos)
|
||||||
for w in ws:
|
for w in ws:
|
||||||
@@ -429,7 +428,7 @@ class Will:
|
|||||||
def set_invalidate(wid, will=[]):
|
def set_invalidate(wid, will=[]):
|
||||||
will[wid].set_status("INVALIDATED", True)
|
will[wid].set_status("INVALIDATED", True)
|
||||||
if will[wid].children:
|
if will[wid].children:
|
||||||
for c in self.children.items():
|
for c in will[wid].children.items():
|
||||||
Will.set_invalidate(c[0], will)
|
Will.set_invalidate(c[0], will)
|
||||||
|
|
||||||
def check_tx_height(tx, wallet):
|
def check_tx_height(tx, wallet):
|
||||||
@@ -446,7 +445,7 @@ class Will:
|
|||||||
):
|
):
|
||||||
for inp in w.tx.inputs():
|
for inp in w.tx.inputs():
|
||||||
inp_str = Util.utxo_to_str(inp)
|
inp_str = Util.utxo_to_str(inp)
|
||||||
if not inp_str in utxos_list:
|
if inp_str not in utxos_list:
|
||||||
if wallet:
|
if wallet:
|
||||||
height = Will.check_tx_height(w.tx, wallet)
|
height = Will.check_tx_height(w.tx, wallet)
|
||||||
if height < 0:
|
if height < 0:
|
||||||
@@ -456,18 +455,18 @@ class Will:
|
|||||||
else:
|
else:
|
||||||
w.set_status("CONFIRMED", True)
|
w.set_status("CONFIRMED", True)
|
||||||
|
|
||||||
def reflect_to_children(treeitem):
|
# def reflect_to_children(treeitem):
|
||||||
if not treeitem.get_status("VALID"):
|
# if not treeitem.get_status("VALID"):
|
||||||
_logger.debug(f"{tree:item._id} status not valid looking for children")
|
# _logger.debug(f"{tree:item._id} status not valid looking for children")
|
||||||
for child in treeitem.children:
|
# for child in treeitem.children:
|
||||||
wc = willtree[child]
|
# wc = willtree[child]
|
||||||
if wc.get_status("VALID"):
|
# if wc.get_status("VALID"):
|
||||||
if treeitem.get_status("INVALIDATED"):
|
# if treeitem.get_status("INVALIDATED"):
|
||||||
wc.set_status("INVALIDATED", True)
|
# wc.set_status("INVALIDATED", True)
|
||||||
if treeitem.get_status("REPLACED"):
|
# if treeitem.get_status("REPLACED"):
|
||||||
wc.set_status("REPLACED", True)
|
# wc.set_status("REPLACED", True)
|
||||||
if wc.children:
|
# if wc.children:
|
||||||
Will.reflect_to_children(wc)
|
# Will.reflect_to_children(wc)
|
||||||
|
|
||||||
def check_amounts(heirs, willexecutors, all_utxos, timestamp_to_check, dust):
|
def check_amounts(heirs, willexecutors, all_utxos, timestamp_to_check, dust):
|
||||||
fixed_heirs, fixed_amount, perc_heirs, perc_amount, fixed_amount_with_dust = (
|
fixed_heirs, fixed_amount, perc_heirs, perc_amount, fixed_amount_with_dust = (
|
||||||
@@ -564,17 +563,20 @@ class Will:
|
|||||||
raise WillExpiredException(
|
raise WillExpiredException(
|
||||||
f"Will Expired {wid[0][0]}: {locktime}<{timestamp_to_check}"
|
f"Will Expired {wid[0][0]}: {locktime}<{timestamp_to_check}"
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
from datetime import datetime
|
||||||
|
_logger.debug(f"Will Not Expired {wid[0][0]}: {datetime.fromtimestamp(locktime).isoformat()} > {datetime.fromtimestamp(timestamp_to_check).isoformat()}")
|
||||||
|
|
||||||
def check_all_input_spent_are_in_wallet():
|
# def check_all_input_spent_are_in_wallet():
|
||||||
_logger.info("check all input spent are in wallet or valid txs")
|
# _logger.info("check all input spent are in wallet or valid txs")
|
||||||
for inp, ws in all_inputs.items():
|
# for inp, ws in all_inputs.items():
|
||||||
if not Util.in_utxo(inp, all_utxos):
|
# if not Util.in_utxo(inp, all_utxos):
|
||||||
for w in ws:
|
# for w in ws:
|
||||||
if w[1].get_status("VALID"):
|
# if w[1].get_status("VALID"):
|
||||||
prevout_id = w[2].prevout.txid.hex()
|
# prevout_id = w[2].prevout.txid.hex()
|
||||||
parentwill = will.get(prevout_id, False)
|
# parentwill = will.get(prevout_id, False)
|
||||||
if not parentwill or not parentwill.get_status("VALID"):
|
# if not parentwill or not parentwill.get_status("VALID"):
|
||||||
w[1].set_status("INVALIDATED", True)
|
# w[1].set_status("INVALIDATED", True)
|
||||||
|
|
||||||
def only_valid_list(will):
|
def only_valid_list(will):
|
||||||
out = {}
|
out = {}
|
||||||
@@ -637,7 +639,7 @@ class Will:
|
|||||||
|
|
||||||
if Util.parse_locktime_string(heirs[h][2]) >= check_date:
|
if Util.parse_locktime_string(heirs[h][2]) >= check_date:
|
||||||
count_heirs += 1
|
count_heirs += 1
|
||||||
if not h in heirs_found:
|
if h not in heirs_found:
|
||||||
_logger.debug(f"heir: {h} not found")
|
_logger.debug(f"heir: {h} not found")
|
||||||
raise HeirNotFoundException(h)
|
raise HeirNotFoundException(h)
|
||||||
if not count_heirs:
|
if not count_heirs:
|
||||||
@@ -646,7 +648,7 @@ class Will:
|
|||||||
raise NoWillExecutorNotPresent("Backup tx")
|
raise NoWillExecutorNotPresent("Backup tx")
|
||||||
for url, we in willexecutors.items():
|
for url, we in willexecutors.items():
|
||||||
if Willexecutors.is_selected(we):
|
if Willexecutors.is_selected(we):
|
||||||
if not url in willexecutors_found:
|
if url not in willexecutors_found:
|
||||||
_logger.debug(f"will-executor: {url} not fount")
|
_logger.debug(f"will-executor: {url} not fount")
|
||||||
raise WillExecutorNotPresent(url)
|
raise WillExecutorNotPresent(url)
|
||||||
_logger.info("will is coherent with heirs and will-executors")
|
_logger.info("will is coherent with heirs and will-executors")
|
||||||
@@ -797,9 +799,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")
|
||||||
@@ -839,7 +841,12 @@ class WillItem(Logger):
|
|||||||
|
|
||||||
|
|
||||||
class WillException(Exception):
|
class WillException(Exception):
|
||||||
pass
|
def __init__(self,msg="WillException"):
|
||||||
|
self.msg=msg
|
||||||
|
Exception.__init__(self)
|
||||||
|
def __str__(self):
|
||||||
|
return self.msg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class WillExpiredException(WillException):
|
class WillExpiredException(WillException):
|
||||||
@@ -876,8 +883,6 @@ class WillExecutorNotPresent(NotCompleteWillException):
|
|||||||
|
|
||||||
class NoHeirsException(WillException):
|
class NoHeirsException(WillException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AmountException(WillException):
|
class AmountException(WillException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -888,7 +893,3 @@ class PercAmountException(AmountException):
|
|||||||
|
|
||||||
class FixedAmountException(AmountException):
|
class FixedAmountException(AmountException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test_check_invalidated():
|
|
||||||
Will.check_invalidated(will, utxos_list, wallet)
|
|
||||||
|
|||||||
192
willexecutors.py
192
willexecutors.py
@@ -1,33 +1,37 @@
|
|||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import partial
|
import time
|
||||||
|
|
||||||
from aiohttp import ClientResponse
|
from aiohttp import ClientResponse
|
||||||
from electrum import constants
|
from electrum import constants
|
||||||
from electrum.gui.qt.util import WaitingDialog
|
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.logging import get_logger
|
from electrum.logging import get_logger
|
||||||
from electrum.network import Network
|
from electrum.network import Network
|
||||||
|
|
||||||
from .bal import BalPlugin
|
from .bal import BalPlugin
|
||||||
from .util import Util
|
|
||||||
|
|
||||||
DEFAULT_TIMEOUT = 5
|
DEFAULT_TIMEOUT = 5
|
||||||
_logger = get_logger(__name__)
|
_logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
chainname = constants.net.NET_NAME if constants.net.NET_NAME != "mainnet" else "bitcoin"
|
||||||
|
|
||||||
|
|
||||||
class Willexecutors:
|
class Willexecutors:
|
||||||
|
|
||||||
def save(bal_plugin, willexecutors):
|
def save(bal_plugin, willexecutors):
|
||||||
|
_logger.debug(f"save {willexecutors},{chainname}")
|
||||||
aw = bal_plugin.WILLEXECUTORS.get()
|
aw = bal_plugin.WILLEXECUTORS.get()
|
||||||
aw[constants.net.NET_NAME] = willexecutors
|
aw[chainname] = willexecutors
|
||||||
bal_plugin.WILLEXECUTORS.set(aw)
|
bal_plugin.WILLEXECUTORS.set(aw)
|
||||||
|
_logger.debug(f"saved: {aw}")
|
||||||
|
# bal_plugin.WILLEXECUTORS.set(willexecutors)
|
||||||
|
|
||||||
def get_willexecutors(
|
def get_willexecutors(
|
||||||
bal_plugin, update=False, bal_window=False, force=False, task=True
|
bal_plugin, update=False, bal_window=False, force=False, task=True
|
||||||
):
|
):
|
||||||
willexecutors = bal_plugin.WILLEXECUTORS.get()
|
willexecutors = bal_plugin.WILLEXECUTORS.get()
|
||||||
willexecutors = willexecutors.get(constants.net.NET_NAME, {})
|
willexecutors = willexecutors.get(chainname, {})
|
||||||
to_del = []
|
to_del = []
|
||||||
for w in willexecutors:
|
for w in willexecutors:
|
||||||
if not isinstance(willexecutors[w], dict):
|
if not isinstance(willexecutors[w], dict):
|
||||||
@@ -36,12 +40,14 @@ class Willexecutors:
|
|||||||
Willexecutors.initialize_willexecutor(willexecutors[w], w)
|
Willexecutors.initialize_willexecutor(willexecutors[w], w)
|
||||||
for w in to_del:
|
for w in to_del:
|
||||||
_logger.error(
|
_logger.error(
|
||||||
"error Willexecutor to delete type:{} ", type(willexecutor[w]), w
|
"error Willexecutor to delete type:{} {}".format(
|
||||||
|
type(willexecutors[w]), w
|
||||||
|
)
|
||||||
)
|
)
|
||||||
del willexecutors[w]
|
del willexecutors[w]
|
||||||
bal = bal_plugin.WILLEXECUTORS.default.get(constants.net.NET_NAME, {})
|
bal = bal_plugin.WILLEXECUTORS.default.get(chainname, {})
|
||||||
for bal_url, bal_executor in bal.items():
|
for bal_url, bal_executor in bal.items():
|
||||||
if not bal_url in willexecutors:
|
if bal_url not in willexecutors:
|
||||||
_logger.debug(f"force add {bal_url} willexecutor")
|
_logger.debug(f"force add {bal_url} willexecutor")
|
||||||
willexecutors[bal_url] = bal_executor
|
willexecutors[bal_url] = bal_executor
|
||||||
# if update:
|
# if update:
|
||||||
@@ -75,11 +81,11 @@ class Willexecutors:
|
|||||||
def is_selected(willexecutor, value=None):
|
def is_selected(willexecutor, value=None):
|
||||||
if not willexecutor:
|
if not willexecutor:
|
||||||
return False
|
return False
|
||||||
if not value is None:
|
if value is not None:
|
||||||
willexecutor["selected"] = value
|
willexecutor["selected"] = value
|
||||||
try:
|
try:
|
||||||
return willexecutor["selected"]
|
return willexecutor["selected"]
|
||||||
except:
|
except Exception:
|
||||||
willexecutor["selected"] = False
|
willexecutor["selected"] = False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -92,7 +98,7 @@ class Willexecutors:
|
|||||||
if willexecutor := willitem.we:
|
if willexecutor := willitem.we:
|
||||||
url = willexecutor["url"]
|
url = willexecutor["url"]
|
||||||
if willexecutor and Willexecutors.is_selected(willexecutor):
|
if willexecutor and Willexecutors.is_selected(willexecutor):
|
||||||
if not url in willexecutors:
|
if url not in willexecutors:
|
||||||
willexecutor["txs"] = ""
|
willexecutor["txs"] = ""
|
||||||
willexecutor["txsids"] = []
|
willexecutor["txsids"] = []
|
||||||
willexecutor["broadcast_status"] = _("Waiting...")
|
willexecutor["broadcast_status"] = _("Waiting...")
|
||||||
@@ -102,31 +108,34 @@ class Willexecutors:
|
|||||||
|
|
||||||
return willexecutors
|
return willexecutors
|
||||||
|
|
||||||
def only_selected_list(willexecutors):
|
# def only_selected_list(willexecutors):
|
||||||
out = {}
|
# out = {}
|
||||||
for url, v in willexecutors.items():
|
# for url, v in willexecutors.items():
|
||||||
if Willexecutors.is_selected(willexecutor):
|
# if Willexecutors.is_selected(url):
|
||||||
out[url] = v
|
# out[url] = v
|
||||||
|
|
||||||
def push_transactions_to_willexecutors(will):
|
# def push_transactions_to_willexecutors(will):
|
||||||
willexecutors = get_transactions_to_be_pushed()
|
# willexecutors = Willexecutors.get_transactions_to_be_pushed()
|
||||||
for url in willexecutors:
|
# for url in willexecutors:
|
||||||
willexecutor = willexecutors[url]
|
# willexecutor = willexecutors[url]
|
||||||
if Willexecutors.is_selected(willexecutor):
|
# if Willexecutors.is_selected(willexecutor):
|
||||||
if "txs" in willexecutor:
|
# if "txs" in willexecutor:
|
||||||
Willexecutors.push_transactions_to_willexecutor(
|
# Willexecutors.push_transactions_to_willexecutor(
|
||||||
willexecutors[url]["txs"], url
|
# willexecutors[url]["txs"], url
|
||||||
)
|
# )
|
||||||
|
|
||||||
def send_request(method, url, data=None, *, timeout=10):
|
def send_request(
|
||||||
|
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:{BalPlugin.__version__}"
|
||||||
headers["Content-Type"] = "text/plain"
|
headers["Content-Type"] = "text/plain"
|
||||||
|
if not handle_response:
|
||||||
|
handle_response = Willexecutors.handle_response
|
||||||
try:
|
try:
|
||||||
if method == "get":
|
if method == "get":
|
||||||
response = Network.send_http_on_proxy(
|
response = Network.send_http_on_proxy(
|
||||||
@@ -134,7 +143,7 @@ class Willexecutors:
|
|||||||
url,
|
url,
|
||||||
params=data,
|
params=data,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
on_finish=Willexecutors.handle_response,
|
on_finish=handle_response,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
elif method == "post":
|
elif method == "post":
|
||||||
@@ -143,26 +152,47 @@ class Willexecutors:
|
|||||||
url,
|
url,
|
||||||
body=data,
|
body=data,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
on_finish=Willexecutors.handle_response,
|
on_finish=handle_response,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise Exception(f"unexpected {method=!r}")
|
raise Exception(f"unexpected {method=!r}")
|
||||||
|
except TimeoutError:
|
||||||
|
if count_reply < 10:
|
||||||
|
_logger.debug(f"timeout({count_reply}) error: retry in 3 sec...")
|
||||||
|
time.sleep(3)
|
||||||
|
return Willexecutors.send_request(
|
||||||
|
method,
|
||||||
|
url,
|
||||||
|
data,
|
||||||
|
timeout=timeout,
|
||||||
|
handle_response=handle_response,
|
||||||
|
count_reply=count_reply + 1,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
_logger.debug(f"Too many timeouts: {count_reply}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.error(f"exception sending request {e}")
|
|
||||||
raise e
|
raise e
|
||||||
else:
|
else:
|
||||||
_logger.debug(f"--> {response}")
|
_logger.debug(f"--> {response}")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
async def handle_response(resp: ClientResponse):
|
async def handle_response(resp: ClientResponse):
|
||||||
r = await resp.text()
|
r = await resp.text()
|
||||||
try:
|
try:
|
||||||
|
|
||||||
r = json.loads(r)
|
r = json.loads(r)
|
||||||
r["status"] = resp.status
|
# url = Willexecutors.get_we_url_from_response(resp)
|
||||||
r["selected"] = Willexecutors.is_selected(willexecutor)
|
# r["url"]= url
|
||||||
r["url"] = url
|
# r["status"]=resp.status
|
||||||
except:
|
except Exception as e:
|
||||||
|
_logger.debug(f"error handling response:{e}")
|
||||||
pass
|
pass
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@@ -175,7 +205,7 @@ class Willexecutors:
|
|||||||
_logger.debug(f"{willexecutor['url']}: {willexecutor['txs']}")
|
_logger.debug(f"{willexecutor['url']}: {willexecutor['txs']}")
|
||||||
if w := Willexecutors.send_request(
|
if w := Willexecutors.send_request(
|
||||||
"post",
|
"post",
|
||||||
willexecutor["url"] + "/" + constants.net.NET_NAME + "/pushtxs",
|
willexecutor["url"] + "/" + chainname + "/pushtxs",
|
||||||
data=willexecutor["txs"].encode("ascii"),
|
data=willexecutor["txs"].encode("ascii"),
|
||||||
):
|
):
|
||||||
willexecutor["broadcast_status"] = _("Success")
|
willexecutor["broadcast_status"] = _("Success")
|
||||||
@@ -203,18 +233,14 @@ class Willexecutors:
|
|||||||
try:
|
try:
|
||||||
_logger.info("GETINFO_WILLEXECUTOR")
|
_logger.info("GETINFO_WILLEXECUTOR")
|
||||||
_logger.debug(url)
|
_logger.debug(url)
|
||||||
netname = "bitcoin"
|
w = Willexecutors.send_request("get", url + "/" + chainname + "/info")
|
||||||
if constants.net.NET_NAME != "mainnet":
|
if isinstance(w, dict):
|
||||||
netname = constants.net.NET_NAME
|
|
||||||
w = Willexecutors.send_request("get", url + "/" + netname + "/info")
|
|
||||||
|
|
||||||
willexecutor["url"] = url
|
willexecutor["url"] = url
|
||||||
willexecutor["status"] = w["status"]
|
willexecutor["status"] = 200
|
||||||
willexecutor["base_fee"] = w["base_fee"]
|
willexecutor["base_fee"] = w["base_fee"]
|
||||||
willexecutor["address"] = w["address"]
|
willexecutor["address"] = w["address"]
|
||||||
if not willexecutor["info"]:
|
|
||||||
willexecutor["info"] = w["info"]
|
willexecutor["info"] = w["info"]
|
||||||
_logger.debug(f"response_data {w['address']}")
|
_logger.debug(f"response_data {w}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.error(f"error {e} contacting {url}: {w}")
|
_logger.error(f"error {e} contacting {url}: {w}")
|
||||||
willexecutor["status"] = "KO"
|
willexecutor["status"] = "KO"
|
||||||
@@ -222,30 +248,39 @@ class Willexecutors:
|
|||||||
willexecutor["last_update"] = datetime.now().timestamp()
|
willexecutor["last_update"] = datetime.now().timestamp()
|
||||||
return willexecutor
|
return willexecutor
|
||||||
|
|
||||||
def initialize_willexecutor(willexecutor, url, status=None, selected=None):
|
def initialize_willexecutor(willexecutor, url, status=None, old_willexecutor={}):
|
||||||
willexecutor["url"] = url
|
willexecutor["url"] = url
|
||||||
if not status is None:
|
if status is not None:
|
||||||
willexecutor["status"] = status
|
willexecutor["status"] = status
|
||||||
willexecutor["selected"] = Willexecutors.is_selected(willexecutor, selected)
|
else:
|
||||||
|
willexecutor["status"] = old_willexecutor.get("status",willexecutor.get("status","Ko"))
|
||||||
|
willexecutor["selected"]=Willexecutors.is_selected(old_willexecutor) or willexecutor.get("selected",False)
|
||||||
|
willexecutor["address"]=old_willexecutor.get("address",willexecutor.get("address",""))
|
||||||
|
willexecutor["promo_code"]=old_willexecutor.get("promo_code",willexecutor.get("promo_code"))
|
||||||
|
|
||||||
def download_list(bal_plugin):
|
|
||||||
|
|
||||||
|
def download_list(old_willexecutors):
|
||||||
try:
|
try:
|
||||||
l = Willexecutors.send_request(
|
willexecutors = Willexecutors.send_request(
|
||||||
"get", "https://welist.bitcoin-after.life/data/bitcoin?page=0&limit=100"
|
"get",
|
||||||
|
f"https://welist.bitcoin-after.life/data/{chainname}?page=0&limit=100",
|
||||||
|
)
|
||||||
|
# del willexecutors["status"]
|
||||||
|
for w in willexecutors:
|
||||||
|
if w not in ("status", "url"):
|
||||||
|
Willexecutors.initialize_willexecutor(
|
||||||
|
willexecutors[w], w, None, old_willexecutors.get(w,{})
|
||||||
)
|
)
|
||||||
del l["status"]
|
|
||||||
for w in l:
|
|
||||||
willexecutor = l[w]
|
|
||||||
Willexecutors.initialize_willexecutor(willexecutor, w, "New", False)
|
|
||||||
# bal_plugin.WILLEXECUTORS.set(l)
|
# bal_plugin.WILLEXECUTORS.set(l)
|
||||||
# bal_plugin.config.set_key(bal_plugin.WILLEXECUTORS,l,save=True)
|
# bal_plugin.config.set_key(bal_plugin.WILLEXECUTORS,l,save=True)
|
||||||
return l
|
return willexecutors
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.error(f"Failed to download willexecutors list: {e}")
|
_logger.error(f"Failed to download willexecutors list: {e}")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_willexecutors_list_from_json(bal_plugin):
|
def get_willexecutors_list_from_json():
|
||||||
try:
|
try:
|
||||||
with open("willexecutors.json") as f:
|
with open("willexecutors.json") as f:
|
||||||
willexecutors = json.load(f)
|
willexecutors = json.load(f)
|
||||||
@@ -253,7 +288,7 @@ class Willexecutors:
|
|||||||
willexecutor = willexecutors[w]
|
willexecutor = willexecutors[w]
|
||||||
Willexecutors.initialize_willexecutor(willexecutor, w, "New", False)
|
Willexecutors.initialize_willexecutor(willexecutor, w, "New", False)
|
||||||
# bal_plugin.WILLEXECUTORS.set(willexecutors)
|
# bal_plugin.WILLEXECUTORS.set(willexecutors)
|
||||||
return h
|
return willexecutors
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.error(f"error opening willexecutors json: {e}")
|
_logger.error(f"error opening willexecutors json: {e}")
|
||||||
|
|
||||||
@@ -270,14 +305,53 @@ class Willexecutors:
|
|||||||
_logger.error(f"error contacting {url} for checking txs {e}")
|
_logger.error(f"error contacting {url} for checking txs {e}")
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
def compute_id(willexecutor):
|
||||||
|
return "{}-{}".format(willexecutor.get("url"), willexecutor.get("chain"))
|
||||||
|
|
||||||
|
|
||||||
class WillExecutor:
|
class WillExecutor:
|
||||||
def __init__(self, url, base_fee, chain, info, version):
|
def __init__(
|
||||||
|
self,
|
||||||
|
url,
|
||||||
|
base_fee,
|
||||||
|
chain,
|
||||||
|
info,
|
||||||
|
version,
|
||||||
|
status,
|
||||||
|
is_selected=False,
|
||||||
|
promo_code="",
|
||||||
|
):
|
||||||
self.url = url
|
self.url = url
|
||||||
self.base_fee = base_fee
|
self.base_fee = base_fee
|
||||||
self.chain = chain
|
self.chain = chain
|
||||||
self.info = info
|
self.info = info
|
||||||
self.version = version
|
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):
|
def from_dict(d):
|
||||||
we = WillExecutor(d["url"], d["base_fee"], d["chain"], d["info"], d["version"])
|
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