Compare commits
13 Commits
refactorin
...
8e4e401d1b
| Author | SHA1 | Date | |
|---|---|---|---|
|
8e4e401d1b
|
|||
|
b8859ee5c1
|
|||
|
faeff1ff3c
|
|||
|
437105477d
|
|||
|
4c12136470
|
|||
|
a918c5564d
|
|||
|
d2280969de
|
|||
|
6cf12eec80
|
|||
|
936d4ef467
|
|||
|
5512ee0e61
|
|||
|
3e9a841e21
|
|||
|
5d9636cda1
|
|||
|
b384ac562c
|
145
bal.py
145
bal.py
@@ -1,78 +1,82 @@
|
|||||||
import random
|
|
||||||
import os
|
import os
|
||||||
import zipfile as zipfile_lib
|
#import random
|
||||||
|
#import zipfile as zipfile_lib
|
||||||
|
|
||||||
from electrum.plugin import BasePlugin
|
|
||||||
from electrum import json_db
|
from electrum import json_db
|
||||||
|
from electrum.logging import get_logger
|
||||||
|
from electrum.plugin import BasePlugin
|
||||||
from electrum.transaction import tx_from_any
|
from electrum.transaction import tx_from_any
|
||||||
|
|
||||||
import os
|
|
||||||
def get_will_settings(x):
|
|
||||||
print(x)
|
|
||||||
|
|
||||||
json_db.register_dict('heirs', tuple, None)
|
|
||||||
json_db.register_dict('will', dict,None)
|
|
||||||
json_db.register_dict('will_settings', lambda x:x,None)
|
|
||||||
#{'rubiconda': ['bcrt1qgv0wu4v6kjzef5mnxfh2m9z6y7mez0ja0tt8mu', '45%', '1y'], 'veronica': ['bcrt1q6vxuvwrt8x5c9u9u29y5uq7frscr0vgc2dy60j', '15%', '1y']}
|
|
||||||
from electrum.logging import get_logger
|
|
||||||
def get_will_settings(x):
|
def get_will_settings(x):
|
||||||
print(x)
|
#print(x)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
json_db.register_dict("heirs", tuple, None)
|
||||||
|
json_db.register_dict("will", dict, None)
|
||||||
|
json_db.register_dict("will_settings", lambda x: x, None)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_will(x):
|
def get_will(x):
|
||||||
try:
|
try:
|
||||||
x['tx']=tx_from_any(x['tx'])
|
x["tx"] = tx_from_any(x["tx"])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
return x
|
return x
|
||||||
|
|
||||||
class BalConfig():
|
|
||||||
|
class BalConfig:
|
||||||
def __init__(self, config, name, default):
|
def __init__(self, config, name, default):
|
||||||
print("init bal_config")
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.name = name
|
self.name = name
|
||||||
self.default = default
|
self.default = default
|
||||||
|
|
||||||
def get(self,default=None):
|
def get(self, default=None):
|
||||||
v = self.config.get(self.name, default)
|
v = self.config.get(self.name, default)
|
||||||
if v is None:
|
if v is None:
|
||||||
if not default is None:
|
if default is not None:
|
||||||
v = default
|
v = default
|
||||||
else:
|
else:
|
||||||
v = self.default
|
v = self.default
|
||||||
return v
|
return v
|
||||||
|
|
||||||
def set(self,value,save=True):
|
def set(self, value, save=True):
|
||||||
self.config.set_key(self.name,value,save=save)
|
self.config.set_key(self.name, value, save=save)
|
||||||
|
|
||||||
|
|
||||||
class BalPlugin(BasePlugin):
|
class BalPlugin(BasePlugin):
|
||||||
LATEST_VERSION = '1'
|
LATEST_VERSION = "1"
|
||||||
KNOWN_VERSIONS = ('0', '1')
|
KNOWN_VERSIONS = ("0", "1")
|
||||||
assert LATEST_VERSION in KNOWN_VERSIONS
|
assert LATEST_VERSION in KNOWN_VERSIONS
|
||||||
|
|
||||||
def version():
|
def version():
|
||||||
try:
|
try:
|
||||||
f=""
|
f = ""
|
||||||
with open("VERSION","r") as f:
|
with open("VERSION", "r") as fi:
|
||||||
f = str(f.readline())
|
f = str(fi.readline())
|
||||||
return f
|
return f
|
||||||
except:
|
except:
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
SIZE = (159, 97)
|
SIZE = (159, 97)
|
||||||
|
|
||||||
def __init__(self, parent, config, name):
|
def __init__(self, parent, config, name):
|
||||||
print("init bal_plugin")
|
|
||||||
self.logger = get_logger(__name__)
|
self.logger = get_logger(__name__)
|
||||||
BasePlugin.__init__(self, parent, config, name)
|
BasePlugin.__init__(self, parent, config, name)
|
||||||
self.base_dir = os.path.join(config.electrum_path(), 'bal')
|
self.base_dir = os.path.join(config.electrum_path(), "bal")
|
||||||
self.plugin_dir = os.path.split(os.path.realpath(__file__))[0]
|
self.plugin_dir = os.path.split(os.path.realpath(__file__))[0]
|
||||||
zipfile="/".join(self.plugin_dir.split("/")[:-1])
|
zipfile = "/".join(self.plugin_dir.split("/")[:-1])
|
||||||
#print("real path",os.path.realpath(__file__))
|
# print("real path",os.path.realpath(__file__))
|
||||||
#self.logger.info(self.base_dir)
|
# self.logger.info(self.base_dir)
|
||||||
#print("base_dir:", self.base_dir)
|
# print("base_dir:", self.base_dir)
|
||||||
#print("suca:",zipfile)
|
# print("suca:",zipfile)
|
||||||
#print("plugin_dir:", self.plugin_dir)
|
# print("plugin_dir:", self.plugin_dir)
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.path.insert(0, zipfile)
|
sys.path.insert(0, zipfile)
|
||||||
#print("sono state listate?")
|
# print("sono state listate?")
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.config = config
|
self.config = config
|
||||||
self.name = name
|
self.name = name
|
||||||
@@ -80,9 +84,11 @@ class BalPlugin(BasePlugin):
|
|||||||
self.ASK_BROADCAST = BalConfig(config, "bal_ask_broadcast", True)
|
self.ASK_BROADCAST = BalConfig(config, "bal_ask_broadcast", True)
|
||||||
self.BROADCAST = BalConfig(config, "bal_broadcast", True)
|
self.BROADCAST = BalConfig(config, "bal_broadcast", True)
|
||||||
self.LOCKTIME_TIME = BalConfig(config, "bal_locktime_time", 90)
|
self.LOCKTIME_TIME = BalConfig(config, "bal_locktime_time", 90)
|
||||||
self.LOCKTIME_BLOCKS = BalConfig(config, "bal_locktime_blocks", 144*90)
|
self.LOCKTIME_BLOCKS = BalConfig(config, "bal_locktime_blocks", 144 * 90)
|
||||||
self.LOCKTIMEDELTA_TIME = BalConfig(config, "bal_locktimedelta_time", 7)
|
self.LOCKTIMEDELTA_TIME = BalConfig(config, "bal_locktimedelta_time", 7)
|
||||||
self.LOCKTIMEDELTA_BLOCKS = BalConfig(config, "bal_locktimedelta_blocks", 144*7)
|
self.LOCKTIMEDELTA_BLOCKS = BalConfig(
|
||||||
|
config, "bal_locktimedelta_blocks", 144 * 7
|
||||||
|
)
|
||||||
self.ENABLE_MULTIVERSE = BalConfig(config, "bal_enable_multiverse", False)
|
self.ENABLE_MULTIVERSE = BalConfig(config, "bal_enable_multiverse", False)
|
||||||
self.TX_FEES = BalConfig(config, "bal_tx_fees", 100)
|
self.TX_FEES = BalConfig(config, "bal_tx_fees", 100)
|
||||||
self.INVALIDATE = BalConfig(config, "bal_invalidate", True)
|
self.INVALIDATE = BalConfig(config, "bal_invalidate", True)
|
||||||
@@ -90,36 +96,44 @@ class BalPlugin(BasePlugin):
|
|||||||
self.PREVIEW = BalConfig(config, "bal_preview", True)
|
self.PREVIEW = BalConfig(config, "bal_preview", True)
|
||||||
self.SAVE_TXS = BalConfig(config, "bal_save_txs", True)
|
self.SAVE_TXS = BalConfig(config, "bal_save_txs", True)
|
||||||
self.WILLEXECUTORS = BalConfig(config, "bal_willexecutors", True)
|
self.WILLEXECUTORS = BalConfig(config, "bal_willexecutors", True)
|
||||||
self.PING_WILLEXECUTORS = BalConfig(config, "bal_ping_willexecutors", True)
|
#self.PING_WILLEXECUTORS = BalConfig(config, "bal_ping_willexecutors", True)
|
||||||
self.ASK_PING_WILLEXECUTORS = BalConfig(config, "bal_ask_ping_willexecutors", True)
|
#self.ASK_PING_WILLEXECUTORS = BalConfig(
|
||||||
|
# config, "bal_ask_ping_willexecutors", True
|
||||||
|
#)
|
||||||
self.NO_WILLEXECUTOR = BalConfig(config, "bal_no_willexecutor", True)
|
self.NO_WILLEXECUTOR = BalConfig(config, "bal_no_willexecutor", True)
|
||||||
self.HIDE_REPLACED = BalConfig(config, "bal_hide_replaced", True)
|
self.HIDE_REPLACED = BalConfig(config, "bal_hide_replaced", True)
|
||||||
self.HIDE_INVALIDATED = BalConfig(config, "bal_hide_invalidated", True)
|
self.HIDE_INVALIDATED = BalConfig(config, "bal_hide_invalidated", True)
|
||||||
self.ALLOW_REPUSH = BalConfig(config, "bal_allow_repush", True)
|
self.ALLOW_REPUSH = BalConfig(config, "bal_allow_repush", True)
|
||||||
self.FIRST_EXECUTION = BalConfig(config, "bal_first_execution", True)
|
self.FIRST_EXECUTION = BalConfig(config, "bal_first_execution", True)
|
||||||
self.WILLEXECUTORS = BalConfig(config, "bal_willexecutors", {
|
self.WILLEXECUTORS = BalConfig(
|
||||||
|
config,
|
||||||
|
"bal_willexecutors",
|
||||||
|
{
|
||||||
"mainnet": {
|
"mainnet": {
|
||||||
'https://we.bitcoin-after.life': {
|
"https://we.bitcoin-after.life": {
|
||||||
"base_fee": 100000,
|
"base_fee": 100000,
|
||||||
"status": "New",
|
"status": "New",
|
||||||
"info":"Bitcoin After Life Will Executor",
|
"info": "Bitcoin After Life Will Executor",
|
||||||
"address":"bcrt1qa5cntu4hgadw8zd3n6sq2nzjy34sxdtd9u0gp7",
|
"address": "bcrt1qa5cntu4hgadw8zd3n6sq2nzjy34sxdtd9u0gp7",
|
||||||
"selected":True
|
"selected": True,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
self.WILL_SETTINGS = BalConfig(config, "bal_will_settings", {
|
)
|
||||||
'baltx_fees':100,
|
self.WILL_SETTINGS = BalConfig(
|
||||||
'threshold':'180d',
|
config,
|
||||||
'locktime':'1y',
|
"bal_will_settings",
|
||||||
})
|
{
|
||||||
|
"baltx_fees": 100,
|
||||||
|
"threshold": "180d",
|
||||||
|
"locktime": "1y",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
self._hide_invalidated = self.HIDE_INVALIDATED.get()
|
||||||
|
self._hide_replaced = self.HIDE_REPLACED.get()
|
||||||
|
|
||||||
self._hide_invalidated= self.HIDE_INVALIDATED.get()
|
def resource_path(self, *parts):
|
||||||
self._hide_replaced= self.HIDE_REPLACED.get()
|
|
||||||
|
|
||||||
|
|
||||||
def resource_path(self,*parts):
|
|
||||||
return os.path.join(self.plugin_dir, *parts)
|
return os.path.join(self.plugin_dir, *parts)
|
||||||
|
|
||||||
def hide_invalidated(self):
|
def hide_invalidated(self):
|
||||||
@@ -130,20 +144,17 @@ class BalPlugin(BasePlugin):
|
|||||||
self._hide_replaced = not self._hide_replaced
|
self._hide_replaced = not self._hide_replaced
|
||||||
self.HIDE_REPLACED.set(self._hide_replaced)
|
self.HIDE_REPLACED.set(self._hide_replaced)
|
||||||
|
|
||||||
def validate_will_settings(self,will_settings):
|
def validate_will_settings(self, will_settings):
|
||||||
print(type(will_settings))
|
# print(type(will_settings))
|
||||||
print(will_settings.get('baltx_fees',1),1)
|
# print(will_settings.get('baltx_fees',1),1)
|
||||||
if int(will_settings.get('baltx_fees',1))<1:
|
if int(will_settings.get("baltx_fees", 1)) < 1:
|
||||||
will_settings['baltx_fees']=1
|
will_settings["baltx_fees"] = 1
|
||||||
if not will_settings.get('threshold'):
|
if not will_settings.get("threshold"):
|
||||||
will_settings['threshold']='180d'
|
will_settings["threshold"] = "180d"
|
||||||
if not will_settings.get('locktime')=='':
|
if not will_settings.get("locktime") == "":
|
||||||
will_settings['locktime']='1y'
|
will_settings["locktime"] = "1y"
|
||||||
return will_settings
|
return will_settings
|
||||||
|
|
||||||
def default_will_settings(self):
|
def default_will_settings(self):
|
||||||
return {
|
return {"baltx_fees": 100, "threshold": "180d", "locktime": "1y"}
|
||||||
'baltx_fees':100,
|
|
||||||
'threshold':'180d',
|
|
||||||
'locktime':'1y'
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
PLUGIN_DIR = os.path.split(os.path.realpath(__file__))[0]
|
PLUGIN_DIR = os.path.split(os.path.realpath(__file__))[0]
|
||||||
DEFAULT_ICON = 'bal32x32.png'
|
DEFAULT_ICON = "bal32x32.png"
|
||||||
DEFAULT_ICON_PATH = ''
|
DEFAULT_ICON_PATH = "icons"
|
||||||
|
|
||||||
|
|
||||||
def icon_path(icon_basename: str = DEFAULT_ICON):
|
def icon_path(icon_basename: str = DEFAULT_ICON):
|
||||||
path = resource_path(DEFAULT_ICON_PATH,icon_basename)
|
path = resource_path(DEFAULT_ICON_PATH, icon_basename)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def resource_path(*parts):
|
def resource_path(*parts):
|
||||||
return os.path.join(PLUGIN_DIR, *parts)
|
return os.path.join(PLUGIN_DIR, *parts)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
#!env/bin/python3
|
|
||||||
#same as qt but for command line, useful if you are going to fix various wallet
|
|
||||||
#also easier to read the code
|
|
||||||
from electrum.storage import WalletStorage
|
|
||||||
from electrum.util import MyEncoder
|
|
||||||
import json
|
|
||||||
import sys
|
|
||||||
import getpass
|
|
||||||
import os
|
|
||||||
|
|
||||||
default_fees= 100
|
|
||||||
|
|
||||||
def fix_will_settings_tx_fees(json_wallet):
|
|
||||||
tx_fees = json_wallet.get('will_settings',{}).get('tx_fees',False)
|
|
||||||
if tx_fees:
|
|
||||||
json_wallet['will_settings']['baltx_fees']=json_wallet.get('will_settings',{}).get('tx_fees',default_fees)
|
|
||||||
del json_wallet['will_settings']['tx_fees']
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def uninstall_bal(json_wallet):
|
|
||||||
del json_wallet['will_settings']
|
|
||||||
del json_wallet['will']
|
|
||||||
del json_wallet['heirs']
|
|
||||||
return True
|
|
||||||
|
|
||||||
def save(json_wallet,storage):
|
|
||||||
human_readable=not storage.is_encrypted()
|
|
||||||
storage.write(json.dumps(
|
|
||||||
json_wallet,
|
|
||||||
indent=4 if human_readable else None,
|
|
||||||
sort_keys=bool(human_readable),
|
|
||||||
cls=MyEncoder,
|
|
||||||
))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
if len(sys.argv) <3:
|
|
||||||
print("usage: ./bal_wallet_utils <command> <wallet path>")
|
|
||||||
print("available commands: uninstall, fix")
|
|
||||||
exit(1)
|
|
||||||
if not os.path.exists(sys.argv[2]):
|
|
||||||
print("Error: wallet not found")
|
|
||||||
exit(1)
|
|
||||||
command = sys.argv[1]
|
|
||||||
path = sys.argv[2]
|
|
||||||
|
|
||||||
storage=WalletStorage(path)
|
|
||||||
if storage.is_encrypted():
|
|
||||||
password = getpass.getpass("Enter wallet password: ", stream = None)
|
|
||||||
storage.decrypt(password)
|
|
||||||
data=storage.read()
|
|
||||||
json_wallet=json.loads(data)
|
|
||||||
have_to_save=False
|
|
||||||
if command == 'fix':
|
|
||||||
have_to_save = fix_will_settings_tx_fees(json_wallet)
|
|
||||||
if command == 'uninstall':
|
|
||||||
have_to_save = uninstall_bal(json_wallet)
|
|
||||||
if have_to_save:
|
|
||||||
save(json_wallet,storage)
|
|
||||||
else:
|
|
||||||
print("nothing to do")
|
|
||||||
42
heirs.py
42
heirs.py
@@ -1,12 +1,11 @@
|
|||||||
# import json
|
import datetime
|
||||||
|
import json
|
||||||
import math
|
import math
|
||||||
|
|
||||||
# import datetime
|
|
||||||
# import urllib.request
|
|
||||||
# import urllib.parse
|
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
|
import urllib.parse
|
||||||
|
import urllib.request
|
||||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple
|
||||||
|
|
||||||
import dns
|
import dns
|
||||||
@@ -28,7 +27,7 @@ from electrum.util import (
|
|||||||
write_json_file,
|
write_json_file,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .util import *
|
from .util import Util
|
||||||
from .willexecutors import Willexecutors
|
from .willexecutors import Willexecutors
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -87,7 +86,7 @@ def prepare_transactions(locktimes, available_utxos, fees, wallet):
|
|||||||
)
|
)
|
||||||
total_used_utxos = []
|
total_used_utxos = []
|
||||||
txsout = {}
|
txsout = {}
|
||||||
locktime, _ = get_lowest_locktimes(locktimes)
|
locktime, _ = Util.get_lowest_locktimes(locktimes)
|
||||||
if not locktime:
|
if not locktime:
|
||||||
return
|
return
|
||||||
locktime = locktime[0]
|
locktime = locktime[0]
|
||||||
@@ -102,6 +101,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():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if len(heir) > HEIR_REAL_AMOUNT:
|
if len(heir) > HEIR_REAL_AMOUNT:
|
||||||
real_amount = heir[HEIR_REAL_AMOUNT]
|
real_amount = heir[HEIR_REAL_AMOUNT]
|
||||||
@@ -138,11 +138,10 @@ def prepare_transactions(locktimes, available_utxos, fees, wallet):
|
|||||||
outputs.append(change)
|
outputs.append(change)
|
||||||
for i in range(0, 100):
|
for i in range(0, 100):
|
||||||
random.shuffle(outputs)
|
random.shuffle(outputs)
|
||||||
print(outputs)
|
|
||||||
tx = PartialTransaction.from_io(
|
tx = PartialTransaction.from_io(
|
||||||
used_utxos,
|
used_utxos,
|
||||||
outputs,
|
outputs,
|
||||||
locktime=parse_locktime_string(locktime, wallet),
|
locktime=Util.parse_locktime_string(locktime, wallet),
|
||||||
version=2,
|
version=2,
|
||||||
)
|
)
|
||||||
if len(description) > 0:
|
if len(description) > 0:
|
||||||
@@ -263,6 +262,7 @@ def get_change_output(wallet, in_amount, out_amount, fee):
|
|||||||
|
|
||||||
|
|
||||||
class Heirs(dict, Logger):
|
class Heirs(dict, Logger):
|
||||||
|
|
||||||
def __init__(self, db: "WalletDB"):
|
def __init__(self, db: "WalletDB"):
|
||||||
Logger.__init__(self)
|
Logger.__init__(self)
|
||||||
self.db = db
|
self.db = db
|
||||||
@@ -300,7 +300,7 @@ class Heirs(dict, Logger):
|
|||||||
def get_locktimes(self, from_locktime, a=False):
|
def get_locktimes(self, from_locktime, a=False):
|
||||||
locktimes = {}
|
locktimes = {}
|
||||||
for key in self.keys():
|
for key in self.keys():
|
||||||
locktime = parse_locktime_string(self[key][HEIR_LOCKTIME])
|
locktime = Util.parse_locktime_string(self[key][HEIR_LOCKTIME])
|
||||||
if locktime > from_locktime and not a or locktime <= from_locktime and a:
|
if locktime > from_locktime and not a or locktime <= from_locktime and a:
|
||||||
locktimes[int(locktime)] = None
|
locktimes[int(locktime)] = None
|
||||||
return locktimes.keys()
|
return locktimes.keys()
|
||||||
@@ -348,10 +348,12 @@ class Heirs(dict, Logger):
|
|||||||
percent_amount = 0.0
|
percent_amount = 0.0
|
||||||
for key in self.keys():
|
for key in self.keys():
|
||||||
try:
|
try:
|
||||||
cmp = parse_locktime_string(self[key][HEIR_LOCKTIME]) - from_locktime
|
cmp = (
|
||||||
|
Util.parse_locktime_string(self[key][HEIR_LOCKTIME]) - from_locktime
|
||||||
|
)
|
||||||
if cmp <= 0:
|
if cmp <= 0:
|
||||||
continue
|
continue
|
||||||
if 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])
|
||||||
percent_heirs[key] = list(self[key])
|
percent_heirs[key] = list(self[key])
|
||||||
else:
|
else:
|
||||||
@@ -377,7 +379,7 @@ class Heirs(dict, Logger):
|
|||||||
locktimes = self.get_locktimes(from_locktime)
|
locktimes = self.get_locktimes(from_locktime)
|
||||||
if willexecutor:
|
if willexecutor:
|
||||||
for locktime in locktimes:
|
for locktime in locktimes:
|
||||||
if int(int_locktime(locktime)) > int(from_locktime):
|
if int(Util.int_locktime(locktime)) > int(from_locktime):
|
||||||
try:
|
try:
|
||||||
base_fee = int(willexecutor["base_fee"])
|
base_fee = int(willexecutor["base_fee"])
|
||||||
willexecutors_amount += base_fee
|
willexecutors_amount += base_fee
|
||||||
@@ -392,11 +394,9 @@ class Heirs(dict, Logger):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return [], False
|
return [], False
|
||||||
else:
|
else:
|
||||||
(
|
|
||||||
_logger.error(
|
_logger.error(
|
||||||
f"heir excluded from will locktime({locktime}){int_locktime(locktime)}<minimum{from_locktime}"
|
f"heir excluded from will locktime({locktime}){Util.int_locktime(locktime)}<minimum{from_locktime}"
|
||||||
),
|
),
|
||||||
)
|
|
||||||
heir_list.update(willexecutors)
|
heir_list.update(willexecutors)
|
||||||
newbalance -= willexecutors_amount
|
newbalance -= willexecutors_amount
|
||||||
fixed_heirs, fixed_amount, percent_heirs, percent_amount = (
|
fixed_heirs, fixed_amount, percent_heirs, percent_amount = (
|
||||||
@@ -429,12 +429,12 @@ class Heirs(dict, Logger):
|
|||||||
|
|
||||||
heir_list = sorted(
|
heir_list = sorted(
|
||||||
heir_list.items(),
|
heir_list.items(),
|
||||||
key=lambda item: parse_locktime_string(item[1][HEIR_LOCKTIME], wallet),
|
key=lambda item: Util.parse_locktime_string(item[1][HEIR_LOCKTIME], wallet),
|
||||||
)
|
)
|
||||||
|
|
||||||
locktimes = {}
|
locktimes = {}
|
||||||
for key, value in heir_list:
|
for key, value in heir_list:
|
||||||
locktime = parse_locktime_string(value[HEIR_LOCKTIME])
|
locktime = Util.parse_locktime_string(value[HEIR_LOCKTIME])
|
||||||
if not locktime in locktimes:
|
if not locktime in locktimes:
|
||||||
locktimes[locktime] = {key: value}
|
locktimes[locktime] = {key: value}
|
||||||
else:
|
else:
|
||||||
@@ -442,7 +442,7 @@ class Heirs(dict, Logger):
|
|||||||
return locktimes, onlyfixed
|
return locktimes, onlyfixed
|
||||||
|
|
||||||
def is_perc(self, key):
|
def is_perc(self, key):
|
||||||
return is_perc(self[key][HEIR_AMOUNT])
|
return Util.is_perc(self[key][HEIR_AMOUNT])
|
||||||
|
|
||||||
def buildTransactions(
|
def buildTransactions(
|
||||||
self, bal_plugin, wallet, tx_fees=None, utxos=None, from_locktime=0
|
self, bal_plugin, wallet, tx_fees=None, utxos=None, from_locktime=0
|
||||||
@@ -638,7 +638,7 @@ class Heirs(dict, Logger):
|
|||||||
|
|
||||||
def validate_amount(amount):
|
def validate_amount(amount):
|
||||||
try:
|
try:
|
||||||
famount = float(amount[:-1]) if is_perc(amount) else float(amount)
|
famount = float(amount[:-1]) if Util.is_perc(amount) else float(amount)
|
||||||
if famount <= 0.00000001:
|
if famount <= 0.00000001:
|
||||||
raise AmountNotValid(f"amount have to be positive {famount} < 0")
|
raise AmountNotValid(f"amount have to be positive {famount} < 0")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -648,7 +648,7 @@ class Heirs(dict, Logger):
|
|||||||
def validate_locktime(locktime, timestamp_to_check=False):
|
def validate_locktime(locktime, timestamp_to_check=False):
|
||||||
try:
|
try:
|
||||||
if timestamp_to_check:
|
if timestamp_to_check:
|
||||||
if parse_locktime_string(locktime, None) < timestamp_to_check:
|
if Util.parse_locktime_string(locktime, None) < timestamp_to_check:
|
||||||
raise HeirExpiredException()
|
raise HeirExpiredException()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise LocktimeNotValid(f"locktime string not properly formatted, {e}")
|
raise LocktimeNotValid(f"locktime string not properly formatted, {e}")
|
||||||
|
|||||||
BIN
icons/confirmed.png
Normal file
BIN
icons/confirmed.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 53 KiB |
BIN
icons/status_connected.png
Normal file
BIN
icons/status_connected.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 69 KiB |
BIN
icons/unconfirmed.png
Normal file
BIN
icons/unconfirmed.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@@ -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.2b",
|
"description": "Provides free and decentralized inheritance support<br> Version: 0.2.3",
|
||||||
"author":"Svatantrya",
|
"author":"Svatantrya",
|
||||||
"available_for": ["qt"],
|
"available_for": ["qt"],
|
||||||
"icon":"icons/bal32x32.png"
|
"icon":"icons/bal32x32.png"
|
||||||
|
|||||||
252
util.py
252
util.py
@@ -1,44 +1,45 @@
|
|||||||
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
|
from electrum.util import FileExportFailed, FileImportFailed, write_json_file
|
||||||
|
|
||||||
LOCKTIME_THRESHOLD = 500000000
|
LOCKTIME_THRESHOLD = 500000000
|
||||||
|
|
||||||
|
|
||||||
def locktime_to_str(locktime):
|
class Util:
|
||||||
|
def locktime_to_str(locktime):
|
||||||
try:
|
try:
|
||||||
locktime = int(locktime)
|
locktime = int(locktime)
|
||||||
if locktime > LOCKTIME_THRESHOLD:
|
if locktime > LOCKTIME_THRESHOLD:
|
||||||
dt = datetime.fromtimestamp(locktime).isoformat()
|
dt = datetime.fromtimestamp(locktime).isoformat()
|
||||||
return dt
|
return dt
|
||||||
|
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
return str(locktime)
|
return str(locktime)
|
||||||
|
|
||||||
|
def str_to_locktime(locktime):
|
||||||
def str_to_locktime(locktime):
|
|
||||||
try:
|
try:
|
||||||
if locktime[-1] in ("y", "d", "b"):
|
if locktime[-1] in ("y", "d", "b"):
|
||||||
return locktime
|
return locktime
|
||||||
else:
|
else:
|
||||||
return int(locktime)
|
return int(locktime)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
dt_object = datetime.fromisoformat(locktime)
|
dt_object = datetime.fromisoformat(locktime)
|
||||||
timestamp = dt_object.timestamp()
|
timestamp = dt_object.timestamp()
|
||||||
return int(timestamp)
|
return int(timestamp)
|
||||||
|
|
||||||
|
def parse_locktime_string(locktime, w=None):
|
||||||
def parse_locktime_string(locktime, w=None):
|
|
||||||
try:
|
try:
|
||||||
return int(locktime)
|
return int(locktime)
|
||||||
|
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
@@ -54,22 +55,24 @@ def parse_locktime_string(locktime, w=None):
|
|||||||
locktime = int(locktime[:-1])
|
locktime = int(locktime[:-1])
|
||||||
height = 0
|
height = 0
|
||||||
if w:
|
if w:
|
||||||
height = 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:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def int_locktime(seconds=0, minutes=0, hours=0, days=0, blocks=0):
|
||||||
def int_locktime(seconds=0, minutes=0, hours=0, days=0, blocks=0):
|
|
||||||
return int(
|
return int(
|
||||||
seconds + minutes * 60 + hours * 60 * 60 + days * 60 * 60 * 24 + blocks * 600
|
seconds
|
||||||
|
+ minutes * 60
|
||||||
|
+ hours * 60 * 60
|
||||||
|
+ days * 60 * 60 * 24
|
||||||
|
+ blocks * 600
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def encode_amount(amount, decimal_point):
|
||||||
def encode_amount(amount, decimal_point):
|
if Util.is_perc(amount):
|
||||||
if is_perc(amount):
|
|
||||||
return amount
|
return amount
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
@@ -77,24 +80,21 @@ def encode_amount(amount, decimal_point):
|
|||||||
except:
|
except:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def decode_amount(amount, decimal_point):
|
||||||
def decode_amount(amount, decimal_point):
|
if Util.is_perc(amount):
|
||||||
if is_perc(amount):
|
|
||||||
return amount
|
return amount
|
||||||
else:
|
else:
|
||||||
num = 8 - decimal_point
|
num = 8 - decimal_point
|
||||||
basestr = "{{:0{}.{}f}}".format(num, num)
|
basestr = "{{:0{}.{}f}}".format(num, num)
|
||||||
return "{:08.8f}".format(float(amount) / pow(10, decimal_point))
|
return "{:08.8f}".format(float(amount) / pow(10, decimal_point))
|
||||||
|
|
||||||
|
def is_perc(value):
|
||||||
def is_perc(value):
|
|
||||||
try:
|
try:
|
||||||
return value[-1] == "%"
|
return value[-1] == "%"
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def cmp_array(heira, heirb):
|
||||||
def cmp_array(heira, heirb):
|
|
||||||
try:
|
try:
|
||||||
if not len(heira) == len(heirb):
|
if not len(heira) == len(heirb):
|
||||||
return False
|
return False
|
||||||
@@ -105,14 +105,12 @@ def cmp_array(heira, heirb):
|
|||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def cmp_heir(heira, heirb):
|
||||||
def cmp_heir(heira, heirb):
|
|
||||||
if heira[0] == heirb[0] and heira[1] == heirb[1]:
|
if heira[0] == heirb[0] and heira[1] == heirb[1]:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def cmp_willexecutor(willexecutora, willexecutorb):
|
||||||
def cmp_willexecutor(willexecutora, willexecutorb):
|
|
||||||
if willexecutora == willexecutorb:
|
if willexecutora == willexecutorb:
|
||||||
return True
|
return True
|
||||||
try:
|
try:
|
||||||
@@ -126,8 +124,7 @@ def cmp_willexecutor(willexecutora, willexecutorb):
|
|||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def search_heir_by_values(heirs, heir, values):
|
||||||
def search_heir_by_values(heirs, heir, values):
|
|
||||||
for h, v in heirs.items():
|
for h, v in heirs.items():
|
||||||
found = False
|
found = False
|
||||||
for val in values:
|
for val in values:
|
||||||
@@ -138,29 +135,27 @@ def search_heir_by_values(heirs, heir, values):
|
|||||||
return h
|
return h
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def cmp_heir_by_values(heira, heirb, values):
|
||||||
def cmp_heir_by_values(heira, heirb, values):
|
|
||||||
for v in values:
|
for v in values:
|
||||||
if heira[v] != heirb[v]:
|
if heira[v] != heirb[v]:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def cmp_heirs_by_values(
|
||||||
def cmp_heirs_by_values(
|
|
||||||
heirsa, heirsb, values, exclude_willexecutors=False, reverse=True
|
heirsa, heirsb, values, exclude_willexecutors=False, reverse=True
|
||||||
):
|
):
|
||||||
for heira in heirsa:
|
for heira in heirsa:
|
||||||
if (
|
if (
|
||||||
exclude_willexecutors and 'w!ll3x3c"' not in heira
|
exclude_willexecutors and not 'w!ll3x3c"' in heira
|
||||||
) or not exclude_willexecutors:
|
) or not exclude_willexecutors:
|
||||||
found = False
|
found = False
|
||||||
for heirb in heirsb:
|
for heirb in heirsb:
|
||||||
if cmp_heir_by_values(heirsa[heira], heirsb[heirb], values):
|
if Util.cmp_heir_by_values(heirsa[heira], heirsb[heirb], values):
|
||||||
found = True
|
found = True
|
||||||
if not found:
|
if not found:
|
||||||
return False
|
return False
|
||||||
if reverse:
|
if reverse:
|
||||||
return cmp_heirs_by_values(
|
return Util.cmp_heirs_by_values(
|
||||||
heirsb,
|
heirsb,
|
||||||
heirsa,
|
heirsa,
|
||||||
values,
|
values,
|
||||||
@@ -170,62 +165,59 @@ def cmp_heirs_by_values(
|
|||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def cmp_heirs(
|
||||||
def cmp_heirs(
|
|
||||||
heirsa,
|
heirsa,
|
||||||
heirsb,
|
heirsb,
|
||||||
cmp_function=lambda x, y: x[0] == y[0] and x[3] == y[3],
|
cmp_function=lambda x, y: x[0] == y[0] and x[3] == y[3],
|
||||||
reverse=True,
|
reverse=True,
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
for heir in heirsa:
|
for heir in heirsa:
|
||||||
if 'w!ll3x3c"' not in heir:
|
if not 'w!ll3x3c"' in heir:
|
||||||
if heir not in heirsb or not cmp_function(heirsa[heir], heirsb[heir]):
|
if not heir in heirsb or not cmp_function(
|
||||||
if not search_heir_by_values(heirsb, heirsa[heir], [0, 3]):
|
heirsa[heir], heirsb[heir]
|
||||||
|
):
|
||||||
|
if not Util.search_heir_by_values(heirsb, heirsa[heir], [0, 3]):
|
||||||
return False
|
return False
|
||||||
if reverse:
|
if reverse:
|
||||||
return cmp_heirs(heirsb, heirsa, cmp_function, False)
|
return Util.cmp_heirs(heirsb, heirsa, cmp_function, False)
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def cmp_inputs(inputsa, inputsb):
|
||||||
def cmp_inputs(inputsa, inputsb):
|
|
||||||
if len(inputsa) != len(inputsb):
|
if len(inputsa) != len(inputsb):
|
||||||
return False
|
return False
|
||||||
for inputa in inputsa:
|
for inputa in inputsa:
|
||||||
if not in_utxo(inputa, inputsb):
|
if not Util.in_utxo(inputa, inputsb):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def cmp_outputs(outputsa, outputsb, willexecutor_output=None):
|
||||||
def cmp_outputs(outputsa, outputsb, willexecutor_output=None):
|
|
||||||
if len(outputsa) != len(outputsb):
|
if len(outputsa) != len(outputsb):
|
||||||
return False
|
return False
|
||||||
for outputa in outputsa:
|
for outputa in outputsa:
|
||||||
if not cmp_output(outputa, willexecutor_output):
|
if not Util.cmp_output(outputa, willexecutor_output):
|
||||||
if not in_output(outputa, outputsb):
|
if not Util.in_output(outputa, outputsb):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def cmp_txs(txa, txb):
|
||||||
def cmp_txs(txa, txb):
|
if not Util.cmp_inputs(txa.inputs(), txb.inputs()):
|
||||||
if not cmp_inputs(txa.inputs(), txb.inputs()):
|
|
||||||
return False
|
return False
|
||||||
if not cmp_outputs(txa.outputs(), txb.outputs()):
|
if not Util.cmp_outputs(txa.outputs(), txb.outputs()):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
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:
|
||||||
same_amount, same_address = in_output(outa, txb.outputs())
|
same_amount, same_address = Util.in_output(outa, txb.outputs())
|
||||||
if not (same_amount or same_address):
|
if not (same_amount or same_address):
|
||||||
return False
|
return False
|
||||||
if same_amount and same_address:
|
if same_amount and same_address:
|
||||||
@@ -237,8 +229,7 @@ def get_value_amount(txa, txb):
|
|||||||
|
|
||||||
return value_amount
|
return value_amount
|
||||||
|
|
||||||
|
def chk_locktime(timestamp_to_check, block_height_to_check, locktime):
|
||||||
def chk_locktime(timestamp_to_check, block_height_to_check, locktime):
|
|
||||||
# TODO BUG: WHAT HAPPEN AT THRESHOLD?
|
# TODO BUG: WHAT HAPPEN AT THRESHOLD?
|
||||||
locktime = int(locktime)
|
locktime = int(locktime)
|
||||||
if locktime > LOCKTIME_THRESHOLD and locktime > timestamp_to_check:
|
if locktime > LOCKTIME_THRESHOLD and locktime > timestamp_to_check:
|
||||||
@@ -248,8 +239,7 @@ def chk_locktime(timestamp_to_check, block_height_to_check, locktime):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def anticipate_locktime(locktime, blocks=0, hours=0, days=0):
|
||||||
def anticipate_locktime(locktime, blocks=0, hours=0, days=0):
|
|
||||||
locktime = int(locktime)
|
locktime = int(locktime)
|
||||||
out = 0
|
out = 0
|
||||||
if locktime > LOCKTIME_THRESHOLD:
|
if locktime > LOCKTIME_THRESHOLD:
|
||||||
@@ -265,39 +255,35 @@ def anticipate_locktime(locktime, blocks=0, hours=0, days=0):
|
|||||||
out = 1
|
out = 1
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
def cmp_locktime(locktimea, locktimeb):
|
||||||
def cmp_locktime(locktimea, locktimeb):
|
|
||||||
if locktimea == locktimeb:
|
if locktimea == locktimeb:
|
||||||
return 0
|
return 0
|
||||||
strlocktimea = str(locktimea)
|
strlocktime = str(locktimea)
|
||||||
strlocktimeb = str(locktimeb)
|
strlocktimeb = str(locktimeb)
|
||||||
intlocktimea = str_to_locktime(strlocktimea)
|
intlocktimea = Util.str_to_locktime(strlocktimea)
|
||||||
intlocktimeb = 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])
|
||||||
else:
|
else:
|
||||||
return int(locktimea) - (locktimeb)
|
return int(locktimea) - (locktimeb)
|
||||||
|
|
||||||
|
def get_lowest_valid_tx(available_utxos, will):
|
||||||
def get_lowest_valid_tx(available_utxos, will):
|
|
||||||
will = sorted(will.items(), key=lambda x: x[1]["tx"].locktime)
|
will = sorted(will.items(), key=lambda x: x[1]["tx"].locktime)
|
||||||
for txid, willitem in will.items():
|
for txid, willitem in will.items():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_locktimes(will):
|
||||||
def get_locktimes(will):
|
|
||||||
locktimes = {}
|
locktimes = {}
|
||||||
for txid, willitem in will.items():
|
for txid, willitem in will.items():
|
||||||
locktimes[willitem["tx"].locktime] = True
|
locktimes[willitem["tx"].locktime] = True
|
||||||
return locktimes.keys()
|
return locktimes.keys()
|
||||||
|
|
||||||
|
def get_lowest_locktimes(locktimes):
|
||||||
def get_lowest_locktimes(locktimes):
|
|
||||||
sorted_timestamp = []
|
sorted_timestamp = []
|
||||||
sorted_block = []
|
sorted_block = []
|
||||||
for l in locktimes:
|
for l in locktimes:
|
||||||
l = parse_locktime_string(l)
|
l = Util.parse_locktime_string(l)
|
||||||
if l < LOCKTIME_THRESHOLD:
|
if l < LOCKTIME_THRESHOLD:
|
||||||
bisect.insort(sorted_block, l)
|
bisect.insort(sorted_block, l)
|
||||||
else:
|
else:
|
||||||
@@ -305,83 +291,71 @@ def get_lowest_locktimes(locktimes):
|
|||||||
|
|
||||||
return sorted(sorted_timestamp), sorted(sorted_block)
|
return sorted(sorted_timestamp), sorted(sorted_block)
|
||||||
|
|
||||||
|
def get_lowest_locktimes_from_will(will):
|
||||||
|
return Util.get_lowest_locktimes(Util.get_locktimes(will))
|
||||||
|
|
||||||
def get_lowest_locktimes_from_will(will):
|
def search_willtx_per_io(will, tx):
|
||||||
return get_lowest_locktimes(get_locktimes(will))
|
|
||||||
|
|
||||||
|
|
||||||
def search_willtx_per_io(will, tx):
|
|
||||||
for wid, w in will.items():
|
for wid, w in will.items():
|
||||||
if cmp_txs(w["tx"], tx["tx"]):
|
if Util.cmp_txs(w["tx"], tx["tx"]):
|
||||||
return wid, w
|
return wid, w
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
def invalidate_will(will):
|
||||||
def invalidate_will(will):
|
|
||||||
raise Exception("not implemented")
|
raise Exception("not implemented")
|
||||||
|
|
||||||
|
def get_will_spent_utxos(will):
|
||||||
def get_will_spent_utxos(will):
|
|
||||||
utxos = []
|
utxos = []
|
||||||
for txid, willitem in will.items():
|
for txid, willitem in will.items():
|
||||||
utxos += willitem["tx"].inputs()
|
utxos += willitem["tx"].inputs()
|
||||||
|
|
||||||
return utxos
|
return utxos
|
||||||
|
|
||||||
|
def utxo_to_str(utxo):
|
||||||
def utxo_to_str(utxo):
|
|
||||||
try:
|
try:
|
||||||
return utxo.to_str()
|
return utxo.to_str()
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
return utxo.prevout.to_str()
|
return utxo.prevout.to_str()
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
return str(utxo)
|
return str(utxo)
|
||||||
|
|
||||||
|
def cmp_utxo(utxoa, utxob):
|
||||||
def cmp_utxo(utxoa, utxob):
|
utxoa = Util.utxo_to_str(utxoa)
|
||||||
utxoa = utxo_to_str(utxoa)
|
utxob = Util.utxo_to_str(utxob)
|
||||||
utxob = utxo_to_str(utxob)
|
|
||||||
if utxoa == utxob:
|
if utxoa == utxob:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def in_utxo(utxo, utxos):
|
||||||
def in_utxo(utxo, utxos):
|
|
||||||
for s_u in utxos:
|
for s_u in utxos:
|
||||||
if cmp_utxo(s_u, utxo):
|
if Util.cmp_utxo(s_u, utxo):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def txid_in_utxo(txid, utxos):
|
||||||
def txid_in_utxo(txid, utxos):
|
|
||||||
for s_u in utxos:
|
for s_u in utxos:
|
||||||
if s_u.prevout.txid == txid:
|
if s_u.prevout.txid == txid:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def cmp_output(outputa, outputb):
|
||||||
def cmp_output(outputa, outputb):
|
|
||||||
return outputa.address == outputb.address and outputa.value == outputb.value
|
return outputa.address == outputb.address and outputa.value == outputb.value
|
||||||
|
|
||||||
|
def in_output(output, outputs):
|
||||||
def in_output(output, outputs):
|
|
||||||
for s_o in outputs:
|
for s_o in outputs:
|
||||||
if cmp_output(s_o, output):
|
if Util.cmp_output(s_o, output):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# check all output with the same amount if none have the same address it can be a change
|
||||||
|
# return true true same address same amount
|
||||||
|
# return true false same amount different address
|
||||||
|
# return false false different amount, different address not found
|
||||||
|
|
||||||
# check all output with the same amount if none have the same address it can be a change
|
def din_output(out, outputs):
|
||||||
# return true true same address same amount
|
|
||||||
# return true false same amount different address
|
|
||||||
# return false false different amount, different address not found
|
|
||||||
|
|
||||||
|
|
||||||
def din_output(out, outputs):
|
|
||||||
same_amount = []
|
same_amount = []
|
||||||
for s_o in outputs:
|
for s_o in outputs:
|
||||||
if int(out.value) == int(s_o.value):
|
if int(out.value) == int(s_o.value):
|
||||||
@@ -396,17 +370,17 @@ def din_output(out, outputs):
|
|||||||
else:
|
else:
|
||||||
return False, False
|
return False, False
|
||||||
|
|
||||||
|
def get_change_output(wallet, in_amount, out_amount, fee):
|
||||||
def get_change_output(wallet, in_amount, out_amount, fee):
|
|
||||||
change_amount = int(in_amount - out_amount - fee)
|
change_amount = int(in_amount - out_amount - fee)
|
||||||
if change_amount > wallet.dust_threshold():
|
if change_amount > wallet.dust_threshold():
|
||||||
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], change_amount)
|
out = PartialTxOutput.from_address_and_value(
|
||||||
|
change_addresses[0], change_amount
|
||||||
|
)
|
||||||
out.is_change = True
|
out.is_change = True
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
def get_current_height(network: "Network"):
|
||||||
def get_current_height(network: "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
|
||||||
@@ -427,10 +401,9 @@ def get_current_height(network: "Network"):
|
|||||||
height = min(chain_height, server_height)
|
height = min(chain_height, server_height)
|
||||||
return height
|
return height
|
||||||
|
|
||||||
|
def print_var(var, name="", veryverbose=False):
|
||||||
def print_var(var, name="", veryverbose=False):
|
|
||||||
print(f"---{name}---")
|
print(f"---{name}---")
|
||||||
if var is not None:
|
if not var is None:
|
||||||
try:
|
try:
|
||||||
print("doc:", doc(var))
|
print("doc:", doc(var))
|
||||||
except:
|
except:
|
||||||
@@ -466,27 +439,24 @@ def print_var(var, name="", veryverbose=False):
|
|||||||
|
|
||||||
print(f"---end {name}---")
|
print(f"---end {name}---")
|
||||||
|
|
||||||
|
def print_utxo(utxo, name=""):
|
||||||
def print_utxo(utxo, name=""):
|
|
||||||
print(f"---utxo-{name}---")
|
print(f"---utxo-{name}---")
|
||||||
print_var(utxo, name)
|
Util.print_var(utxo, name)
|
||||||
print_prevout(utxo.prevout, name)
|
Util.print_prevout(utxo.prevout, name)
|
||||||
print_var(utxo.script_sig, f"{name}-script-sig")
|
Util.print_var(utxo.script_sig, f"{name}-script-sig")
|
||||||
print_var(utxo.witness, f"{name}-witness")
|
Util.print_var(utxo.witness, f"{name}-witness")
|
||||||
print("_TxInput__address:", utxo._TxInput__address)
|
print("_TxInput__address:", utxo._TxInput__address)
|
||||||
print("_TxInput__scriptpubkey:", utxo._TxInput__scriptpubkey)
|
print("_TxInput__scriptpubkey:", utxo._TxInput__scriptpubkey)
|
||||||
print("_TxInput__value_sats:", utxo._TxInput__value_sats)
|
print("_TxInput__value_sats:", utxo._TxInput__value_sats)
|
||||||
print(f"---utxo-end {name}---")
|
print(f"---utxo-end {name}---")
|
||||||
|
|
||||||
|
def print_prevout(prevout, name=""):
|
||||||
def print_prevout(prevout, name=""):
|
|
||||||
print(f"---prevout-{name}---")
|
print(f"---prevout-{name}---")
|
||||||
print_var(prevout, f"{name}-prevout")
|
Util.print_var(prevout, f"{name}-prevout")
|
||||||
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: "ElectrumWindow", title, exporter):
|
|
||||||
filter_ = "All files (*)"
|
filter_ = "All files (*)"
|
||||||
filename = getSaveFileName(
|
filename = getSaveFileName(
|
||||||
parent=electrum_window,
|
parent=electrum_window,
|
||||||
@@ -506,7 +476,25 @@ def export_meta_gui(electrum_window: "ElectrumWindow", title, exporter):
|
|||||||
_("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):
|
|
||||||
for k, v in dictfrom.items():
|
for k, v in dictfrom.items():
|
||||||
dicto[k] = v
|
dicto[k] = v
|
||||||
|
|
||||||
|
def fix_will_settings_tx_fees(will_settings):
|
||||||
|
tx_fees = will_settings.get("tx_fees", False)
|
||||||
|
have_to_update = False
|
||||||
|
if tx_fees:
|
||||||
|
will_settings["baltx_fees"] = tx_fees
|
||||||
|
del will_settings["tx_fees"]
|
||||||
|
have_to_update = True
|
||||||
|
return have_to_update
|
||||||
|
|
||||||
|
def fix_will_tx_fees(will):
|
||||||
|
have_to_update = False
|
||||||
|
for txid, willitem in will.items():
|
||||||
|
tx_fees = willitem.get("tx_fees", False)
|
||||||
|
if tx_fees:
|
||||||
|
will[txid]["baltx_fees"] = tx_fees
|
||||||
|
del will[txid]["tx_fees"]
|
||||||
|
have_to_update = True
|
||||||
|
return have_to_update
|
||||||
|
|||||||
77
wallet_util/bal_wallet_utils.py
Executable file
77
wallet_util/bal_wallet_utils.py
Executable file
@@ -0,0 +1,77 @@
|
|||||||
|
#!env/bin/python3
|
||||||
|
from electrum.storage import WalletStorage
|
||||||
|
from electrum.util import MyEncoder
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
import getpass
|
||||||
|
import os
|
||||||
|
|
||||||
|
default_fees = 100
|
||||||
|
|
||||||
|
|
||||||
|
def fix_will_settings_tx_fees(json_wallet):
|
||||||
|
tx_fees = json_wallet.get("will_settings", {}).get("tx_fees", False)
|
||||||
|
have_to_update = False
|
||||||
|
if tx_fees:
|
||||||
|
json_wallet["will_settings"]["baltx_fees"] = tx_fees
|
||||||
|
del json_wallet["will_settings"]["tx_fees"]
|
||||||
|
have_to_update = True
|
||||||
|
for txid, willitem in json_wallet["will"].items():
|
||||||
|
tx_fees = willitem.get("tx_fees", False)
|
||||||
|
if tx_fees:
|
||||||
|
json_wallet["will"][txid]["baltx_fees"] = tx_fees
|
||||||
|
del json_wallet["will"][txid]["tx_fees"]
|
||||||
|
have_to_update = True
|
||||||
|
return have_to_update
|
||||||
|
|
||||||
|
|
||||||
|
def uninstall_bal(json_wallet):
|
||||||
|
del json_wallet["will_settings"]
|
||||||
|
del json_wallet["will"]
|
||||||
|
del json_wallet["heirs"]
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def save(json_wallet, storage):
|
||||||
|
human_readable = not storage.is_encrypted()
|
||||||
|
storage.write(
|
||||||
|
json.dumps(
|
||||||
|
json_wallet,
|
||||||
|
indent=4 if human_readable else None,
|
||||||
|
sort_keys=bool(human_readable),
|
||||||
|
cls=MyEncoder,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def read_wallet(path, password=False):
|
||||||
|
storage = WalletStorage(path)
|
||||||
|
if storage.is_encrypted():
|
||||||
|
if password == False:
|
||||||
|
password = getpass.getpass("Enter wallet password: ", stream=None)
|
||||||
|
storage.decrypt(password)
|
||||||
|
data = storage.read()
|
||||||
|
json_wallet = json.loads("[" + data + "]")[0]
|
||||||
|
return json_wallet
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) < 3:
|
||||||
|
print("usage: ./bal_wallet_utils <command> <wallet path>")
|
||||||
|
print("available commands: uninstall, fix")
|
||||||
|
exit(1)
|
||||||
|
if not os.path.exists(sys.argv[2]):
|
||||||
|
print("Error: wallet not found")
|
||||||
|
exit(1)
|
||||||
|
command = sys.argv[1]
|
||||||
|
path = sys.argv[2]
|
||||||
|
json_wallet = read_wallet(path)
|
||||||
|
have_to_save = False
|
||||||
|
if command == "fix":
|
||||||
|
have_to_save = fix_will_settings_tx_fees(json_wallet)
|
||||||
|
if command == "uninstall":
|
||||||
|
have_to_save = uninstall_bal(json_wallet)
|
||||||
|
if have_to_save:
|
||||||
|
save(json_wallet, storage)
|
||||||
|
else:
|
||||||
|
print("nothing to do")
|
||||||
@@ -1,21 +1,25 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
#this script will help to fix tx_fees wallet bug
|
|
||||||
#also added an uninstall button to remove any bal data from wallet
|
|
||||||
#still very work in progress.
|
|
||||||
#
|
|
||||||
#have to be executed from electrum source code directory in example /home/user/projects/electrum/
|
|
||||||
#
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from PyQt6.QtWidgets import (QApplication, QMainWindow, QVBoxLayout, QHBoxLayout,
|
from PyQt6.QtWidgets import (
|
||||||
QLabel, QLineEdit, QPushButton, QWidget, QFileDialog,
|
QApplication,
|
||||||
QGroupBox, QTextEdit)
|
QMainWindow,
|
||||||
|
QVBoxLayout,
|
||||||
|
QHBoxLayout,
|
||||||
|
QLabel,
|
||||||
|
QLineEdit,
|
||||||
|
QPushButton,
|
||||||
|
QWidget,
|
||||||
|
QFileDialog,
|
||||||
|
QGroupBox,
|
||||||
|
QTextEdit,
|
||||||
|
)
|
||||||
from PyQt6.QtCore import Qt
|
from PyQt6.QtCore import Qt
|
||||||
from electrum.storage import WalletStorage
|
from electrum.storage import WalletStorage
|
||||||
from electrum.util import MyEncoder
|
from electrum.util import MyEncoder
|
||||||
|
from bal_wallet_utils import fix_will_settings_tx_fees, uninstall_bal, read_wallet, save
|
||||||
|
|
||||||
default_fees = 100
|
|
||||||
|
|
||||||
class WalletUtilityGUI(QMainWindow):
|
class WalletUtilityGUI(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -23,7 +27,7 @@ class WalletUtilityGUI(QMainWindow):
|
|||||||
self.initUI()
|
self.initUI()
|
||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
self.setWindowTitle('BAL Wallet Utility')
|
self.setWindowTitle("BAL Wallet Utility")
|
||||||
self.setFixedSize(500, 400)
|
self.setFixedSize(500, 400)
|
||||||
|
|
||||||
# Central widget
|
# Central widget
|
||||||
@@ -92,10 +96,7 @@ class WalletUtilityGUI(QMainWindow):
|
|||||||
|
|
||||||
def browse_wallet(self):
|
def browse_wallet(self):
|
||||||
file_path, _ = QFileDialog.getOpenFileName(
|
file_path, _ = QFileDialog.getOpenFileName(
|
||||||
self,
|
self, "Select Wallet", "*", "Electrum Wallet (*)"
|
||||||
"Select Wallet",
|
|
||||||
"",
|
|
||||||
"Electrum Wallet (*.dat)"
|
|
||||||
)
|
)
|
||||||
if file_path:
|
if file_path:
|
||||||
self.wallet_path_edit.setText(file_path)
|
self.wallet_path_edit.setText(file_path)
|
||||||
@@ -110,43 +111,14 @@ class WalletUtilityGUI(QMainWindow):
|
|||||||
def log_message(self, message):
|
def log_message(self, message):
|
||||||
self.output_text.append(message)
|
self.output_text.append(message)
|
||||||
|
|
||||||
def fix_will_settings_tx_fees(self, json_wallet):
|
|
||||||
tx_fees = json_wallet.get('will_settings',{}).get('tx_fees',False)
|
|
||||||
if tx_fees:
|
|
||||||
json_wallet['will_settings']['baltx_fees'] = json_wallet.get('will_settings',{}).get('tx_fees', default_fees)
|
|
||||||
del json_wallet['will_settings']['tx_fees']
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def uninstall_bal(self, json_wallet):
|
|
||||||
if 'will_settings' in json_wallet:
|
|
||||||
del json_wallet['will_settings']
|
|
||||||
if 'will' in json_wallet:
|
|
||||||
del json_wallet['will']
|
|
||||||
if 'heirs' in json_wallet:
|
|
||||||
del json_wallet['heirs']
|
|
||||||
return True
|
|
||||||
|
|
||||||
def save_wallet(self, json_wallet, storage):
|
|
||||||
try:
|
|
||||||
human_readable = not storage.is_encrypted()
|
|
||||||
storage.write(json.dumps(
|
|
||||||
json_wallet,
|
|
||||||
indent=4 if human_readable else None,
|
|
||||||
sort_keys=bool(human_readable),
|
|
||||||
cls=MyEncoder,
|
|
||||||
))
|
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
self.log_message(f"Save error: {str(e)}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def fix_wallet(self):
|
def fix_wallet(self):
|
||||||
self.process_wallet('fix')
|
self.process_wallet("fix")
|
||||||
|
|
||||||
def uninstall_wallet(self):
|
def uninstall_wallet(self):
|
||||||
self.log_message("WARNING: This will remove all BAL settings. This operation cannot be undone.")
|
self.log_message(
|
||||||
self.process_wallet('uninstall')
|
"WARNING: This will remove all BAL settings. This operation cannot be undone."
|
||||||
|
)
|
||||||
|
self.process_wallet("uninstall")
|
||||||
|
|
||||||
def process_wallet(self, command):
|
def process_wallet(self, command):
|
||||||
wallet_path = self.wallet_path_edit.text().strip()
|
wallet_path = self.wallet_path_edit.text().strip()
|
||||||
@@ -168,7 +140,9 @@ class WalletUtilityGUI(QMainWindow):
|
|||||||
# Decrypt if necessary
|
# Decrypt if necessary
|
||||||
if storage.is_encrypted():
|
if storage.is_encrypted():
|
||||||
if not password:
|
if not password:
|
||||||
self.log_message("ERROR: Wallet is encrypted, please enter password")
|
self.log_message(
|
||||||
|
"ERROR: Wallet is encrypted, please enter password"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -180,24 +154,31 @@ class WalletUtilityGUI(QMainWindow):
|
|||||||
|
|
||||||
# Read wallet
|
# Read wallet
|
||||||
data = storage.read()
|
data = storage.read()
|
||||||
json_wallet = json.loads(data)
|
json_wallet = json.loads("[" + data + "]")[0]
|
||||||
|
|
||||||
have_to_save = False
|
have_to_save = False
|
||||||
message = ""
|
message = ""
|
||||||
|
|
||||||
if command == 'fix':
|
if command == "fix":
|
||||||
have_to_save = self.fix_will_settings_tx_fees(json_wallet)
|
have_to_save = fix_will_settings_tx_fees(json_wallet)
|
||||||
message = "Fix applied successfully" if have_to_save else "No fix needed"
|
message = (
|
||||||
|
"Fix applied successfully" if have_to_save else "No fix needed"
|
||||||
|
)
|
||||||
|
|
||||||
elif command == 'uninstall':
|
elif command == "uninstall":
|
||||||
have_to_save = self.uninstall_bal(json_wallet)
|
have_to_save = uninstall_bal(json_wallet)
|
||||||
message = "BAL uninstalled successfully" if have_to_save else "No BAL settings found to uninstall"
|
message = (
|
||||||
|
"BAL uninstalled successfully"
|
||||||
|
if have_to_save
|
||||||
|
else "No BAL settings found to uninstall"
|
||||||
|
)
|
||||||
|
|
||||||
if have_to_save:
|
if have_to_save:
|
||||||
if self.save_wallet(json_wallet, storage):
|
try:
|
||||||
|
save(json_wallet, storage)
|
||||||
self.log_message(f"SUCCESS: {message}")
|
self.log_message(f"SUCCESS: {message}")
|
||||||
else:
|
except Exception as e:
|
||||||
self.log_message("ERROR: Failed to save wallet")
|
self.log_message(f"Save error: {str(e)}")
|
||||||
else:
|
else:
|
||||||
self.log_message(f"INFO: {message}")
|
self.log_message(f"INFO: {message}")
|
||||||
|
|
||||||
@@ -205,6 +186,7 @@ class WalletUtilityGUI(QMainWindow):
|
|||||||
error_msg = f"ERROR: Processing failed: {str(e)}"
|
error_msg = f"ERROR: Processing failed: {str(e)}"
|
||||||
self.log_message(error_msg)
|
self.log_message(error_msg)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
@@ -221,5 +203,6 @@ def main():
|
|||||||
|
|
||||||
return app.exec()
|
return app.exec()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
50
will.py
50
will.py
@@ -19,7 +19,7 @@ from electrum.util import (
|
|||||||
write_json_file,
|
write_json_file,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .util import *
|
from .util import Util
|
||||||
from .willexecutors import Willexecutors
|
from .willexecutors import Willexecutors
|
||||||
|
|
||||||
MIN_LOCKTIME = 1
|
MIN_LOCKTIME = 1
|
||||||
@@ -60,7 +60,7 @@ class Will:
|
|||||||
for w in will:
|
for w in will:
|
||||||
if w != wid and not tx.to_json() != will[w]["tx"].to_json():
|
if w != wid and not tx.to_json() != will[w]["tx"].to_json():
|
||||||
if will[w]["tx"].txid() != tx.txid():
|
if will[w]["tx"].txid() != tx.txid():
|
||||||
if cmp_txs(will[w]["tx"], tx):
|
if Util.cmp_txs(will[w]["tx"], tx):
|
||||||
return will[w]["tx"]
|
return will[w]["tx"]
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -107,6 +107,7 @@ class Will:
|
|||||||
will = willitems
|
will = willitems
|
||||||
errors = {}
|
errors = {}
|
||||||
for wid in will:
|
for wid in will:
|
||||||
|
|
||||||
txid = will[wid].tx.txid()
|
txid = will[wid].tx.txid()
|
||||||
|
|
||||||
if txid is None:
|
if txid is None:
|
||||||
@@ -155,9 +156,9 @@ class Will:
|
|||||||
return inp
|
return inp
|
||||||
|
|
||||||
def check_anticipate(ow: "WillItem", nw: "WillItem"):
|
def check_anticipate(ow: "WillItem", nw: "WillItem"):
|
||||||
anticipate = anticipate_locktime(ow.tx.locktime, days=1)
|
anticipate = Util.anticipate_locktime(ow.tx.locktime, days=1)
|
||||||
if int(nw.tx.locktime) >= int(anticipate):
|
if int(nw.tx.locktime) >= int(anticipate):
|
||||||
if cmp_heirs_by_values(
|
if Util.cmp_heirs_by_values(
|
||||||
ow.heirs, nw.heirs, [0, 1], exclude_willexecutors=True
|
ow.heirs, nw.heirs, [0, 1], exclude_willexecutors=True
|
||||||
):
|
):
|
||||||
if nw.we and ow.we:
|
if nw.we and ow.we:
|
||||||
@@ -173,7 +174,7 @@ class Will:
|
|||||||
ow.tx.locktime
|
ow.tx.locktime
|
||||||
else:
|
else:
|
||||||
if nw.we == ow.we:
|
if nw.we == ow.we:
|
||||||
if not cmp_heirs_by_values(ow.heirs, nw.heirs, [0, 3]):
|
if not Util.cmp_heirs_by_values(ow.heirs, nw.heirs, [0, 3]):
|
||||||
return anticipate
|
return anticipate
|
||||||
else:
|
else:
|
||||||
return ow.tx.locktime
|
return ow.tx.locktime
|
||||||
@@ -337,12 +338,11 @@ class Will:
|
|||||||
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()
|
||||||
utxo_to_spend.append(utxo)
|
utxo_to_spend.append(utxo)
|
||||||
|
|
||||||
if len(utxo_to_spend) > 0:
|
if len(utxo_to_spend) > 0:
|
||||||
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 = get_current_height(wallet.network)
|
locktime = Util.get_current_height(wallet.network)
|
||||||
tx = PartialTransaction.from_io(
|
tx = PartialTransaction.from_io(
|
||||||
utxo_to_spend, [out], locktime=locktime, version=2
|
utxo_to_spend, [out], locktime=locktime, version=2
|
||||||
)
|
)
|
||||||
@@ -375,7 +375,7 @@ class Will:
|
|||||||
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 = in_utxo(inp, all_utxos)
|
inutxo = Util.in_utxo(inp, all_utxos)
|
||||||
for w in ws:
|
for w in ws:
|
||||||
wi = w[1]
|
wi = w[1]
|
||||||
if (
|
if (
|
||||||
@@ -406,7 +406,7 @@ class Will:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def utxos_strs(utxos):
|
def utxos_strs(utxos):
|
||||||
return [utxo_to_str(u) for u in utxos]
|
return [Util.utxo_to_str(u) for u in utxos]
|
||||||
|
|
||||||
def set_invalidate(wid, will=[]):
|
def set_invalidate(wid, will=[]):
|
||||||
will[wid].set_status("INVALIDATED", True)
|
will[wid].set_status("INVALIDATED", True)
|
||||||
@@ -416,18 +416,17 @@ class Will:
|
|||||||
|
|
||||||
def check_tx_height(tx, wallet):
|
def check_tx_height(tx, wallet):
|
||||||
info = wallet.get_tx_info(tx)
|
info = wallet.get_tx_info(tx)
|
||||||
return info.tx_mined_status.height
|
return info.tx_mined_status.height()
|
||||||
|
|
||||||
# check if transactions are stil valid tecnically valid
|
# check if transactions are stil valid tecnically valid
|
||||||
def check_invalidated(willtree, utxos_list, wallet):
|
def check_invalidated(willtree, utxos_list, wallet):
|
||||||
for wid, w in willtree.items():
|
for wid, w in willtree.items():
|
||||||
if not w.father:
|
if not w.father:
|
||||||
for inp in w.tx.inputs():
|
for inp in w.tx.inputs():
|
||||||
inp_str = utxo_to_str(inp)
|
inp_str = Util.utxo_to_str(inp)
|
||||||
if not inp_str in utxos_list:
|
if not inp_str 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:
|
||||||
Will.set_invalidate(wid, willtree)
|
Will.set_invalidate(wid, willtree)
|
||||||
elif height == 0:
|
elif height == 0:
|
||||||
@@ -478,9 +477,7 @@ class Will:
|
|||||||
Will.check_invalidated(will, utxos_list, wallet)
|
Will.check_invalidated(will, utxos_list, wallet)
|
||||||
|
|
||||||
all_inputs = Will.get_all_inputs(will, only_valid=True)
|
all_inputs = Will.get_all_inputs(will, only_valid=True)
|
||||||
|
|
||||||
all_inputs_min_locktime = Will.get_all_inputs_min_locktime(all_inputs)
|
all_inputs_min_locktime = Will.get_all_inputs_min_locktime(all_inputs)
|
||||||
|
|
||||||
Will.check_will_expired(
|
Will.check_will_expired(
|
||||||
all_inputs_min_locktime, block_to_check, timestamp_to_check
|
all_inputs_min_locktime, block_to_check, timestamp_to_check
|
||||||
)
|
)
|
||||||
@@ -502,7 +499,6 @@ class Will:
|
|||||||
callback_not_valid_tx=None,
|
callback_not_valid_tx=None,
|
||||||
):
|
):
|
||||||
Will.check_will(will, all_utxos, wallet, block_to_check, timestamp_to_check)
|
Will.check_will(will, all_utxos, wallet, block_to_check, timestamp_to_check)
|
||||||
|
|
||||||
if heirs:
|
if heirs:
|
||||||
if not Will.check_willexecutors_and_heirs(
|
if not Will.check_willexecutors_and_heirs(
|
||||||
will,
|
will,
|
||||||
@@ -520,7 +516,7 @@ class Will:
|
|||||||
if all_inputs:
|
if all_inputs:
|
||||||
for utxo in all_utxos:
|
for utxo in all_utxos:
|
||||||
if utxo.value_sats() > 68 * tx_fees:
|
if utxo.value_sats() > 68 * tx_fees:
|
||||||
if not in_utxo(utxo, all_inputs.keys()):
|
if not Util.in_utxo(utxo, all_inputs.keys()):
|
||||||
_logger.info("utxo is not spent", utxo.to_json())
|
_logger.info("utxo is not spent", utxo.to_json())
|
||||||
_logger.debug(all_inputs.keys())
|
_logger.debug(all_inputs.keys())
|
||||||
raise NotCompleteWillException(
|
raise NotCompleteWillException(
|
||||||
@@ -550,7 +546,7 @@ class Will:
|
|||||||
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 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()
|
||||||
@@ -591,11 +587,12 @@ class Will:
|
|||||||
if not 'w!ll3x3c"' == wheir[:9]:
|
if not 'w!ll3x3c"' == wheir[:9]:
|
||||||
their = will[wid].heirs[wheir]
|
their = will[wid].heirs[wheir]
|
||||||
if heir := heirs.get(wheir, None):
|
if heir := heirs.get(wheir, None):
|
||||||
|
|
||||||
if (
|
if (
|
||||||
heir[0] == their[0]
|
heir[0] == their[0]
|
||||||
and heir[1] == their[1]
|
and heir[1] == their[1]
|
||||||
and parse_locktime_string(heir[2])
|
and Util.parse_locktime_string(heir[2])
|
||||||
>= parse_locktime_string(their[2])
|
>= Util.parse_locktime_string(their[2])
|
||||||
):
|
):
|
||||||
count = heirs_found.get(wheir, 0)
|
count = heirs_found.get(wheir, 0)
|
||||||
heirs_found[wheir] = count + 1
|
heirs_found[wheir] = count + 1
|
||||||
@@ -606,7 +603,7 @@ class Will:
|
|||||||
continue
|
continue
|
||||||
if willexecutor := w.we:
|
if willexecutor := w.we:
|
||||||
count = willexecutors_found.get(willexecutor["url"], 0)
|
count = willexecutors_found.get(willexecutor["url"], 0)
|
||||||
if cmp_willexecutor(
|
if Util.cmp_willexecutor(
|
||||||
willexecutor, willexecutors.get(willexecutor["url"], None)
|
willexecutor, willexecutors.get(willexecutor["url"], None)
|
||||||
):
|
):
|
||||||
willexecutors_found[willexecutor["url"]] = count + 1
|
willexecutors_found[willexecutor["url"]] = count + 1
|
||||||
@@ -615,7 +612,7 @@ class Will:
|
|||||||
no_willexecutor += 1
|
no_willexecutor += 1
|
||||||
count_heirs = 0
|
count_heirs = 0
|
||||||
for h in heirs:
|
for h in heirs:
|
||||||
if 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 not h in heirs_found:
|
||||||
_logger.debug(f"heir: {h} not found")
|
_logger.debug(f"heir: {h} not found")
|
||||||
@@ -635,6 +632,7 @@ class Will:
|
|||||||
|
|
||||||
|
|
||||||
class WillItem(Logger):
|
class WillItem(Logger):
|
||||||
|
|
||||||
STATUS_DEFAULT = {
|
STATUS_DEFAULT = {
|
||||||
"ANTICIPATED": ["Anticipated", False],
|
"ANTICIPATED": ["Anticipated", False],
|
||||||
"BROADCASTED": ["Broadcasted", False],
|
"BROADCASTED": ["Broadcasted", False],
|
||||||
@@ -656,11 +654,11 @@ class WillItem(Logger):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def set_status(self, status, value=True):
|
def set_status(self, status, value=True):
|
||||||
_logger.debug(
|
#_logger.trace(
|
||||||
"set status {} - {} {} -> {}".format(
|
# "set status {} - {} {} -> {}".format(
|
||||||
self._id, status, self.STATUS[status][1], value
|
# self._id, status, self.STATUS[status][1], value
|
||||||
)
|
# )
|
||||||
)
|
#)
|
||||||
if self.STATUS[status][1] == bool(value):
|
if self.STATUS[status][1] == bool(value):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ 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
|
||||||
# from .util import *
|
|
||||||
|
|
||||||
DEFAULT_TIMEOUT = 5
|
DEFAULT_TIMEOUT = 5
|
||||||
_logger = get_logger(__name__)
|
_logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Willexecutors:
|
class Willexecutors:
|
||||||
|
|
||||||
def save(bal_plugin, willexecutors):
|
def save(bal_plugin, willexecutors):
|
||||||
aw = bal_plugin.WILLEXECUTORS.get()
|
aw = bal_plugin.WILLEXECUTORS.get()
|
||||||
aw[constants.net.NET_NAME] = willexecutors
|
aw[constants.net.NET_NAME] = willexecutors
|
||||||
@@ -35,34 +35,34 @@ class Willexecutors:
|
|||||||
continue
|
continue
|
||||||
Willexecutors.initialize_willexecutor(willexecutors[w], w)
|
Willexecutors.initialize_willexecutor(willexecutors[w], w)
|
||||||
for w in to_del:
|
for w in to_del:
|
||||||
print("ERROR: WILLEXECUTOR TO DELETE:", w)
|
_logger.error("error Willexecutor to delete type:{} ", type(willexecutor[w]),w)
|
||||||
del willexecutors[w]
|
del willexecutors[w]
|
||||||
bal = bal_plugin.WILLEXECUTORS.default.get(constants.net.NET_NAME, {})
|
bal = bal_plugin.WILLEXECUTORS.default.get(constants.net.NET_NAME, {})
|
||||||
for bal_url, bal_executor in bal.items():
|
for bal_url, bal_executor in bal.items():
|
||||||
if not bal_url in willexecutors:
|
if not bal_url 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:
|
||||||
found = False
|
# found = False
|
||||||
for url, we in willexecutors.items():
|
# for url, we in willexecutors.items():
|
||||||
if Willexecutors.is_selected(we):
|
# if Willexecutors.is_selected(we):
|
||||||
found = True
|
# found = True
|
||||||
if found or force:
|
# if found or force:
|
||||||
if bal_plugin.PING_WILLEXECUTORS.get() or force:
|
# if bal_plugin.PING_WILLEXECUTORS.get() or force:
|
||||||
ping_willexecutors = True
|
# ping_willexecutors = True
|
||||||
if bal_plugin.ASK_PING_WILLEXECUTORS.get() and not force:
|
# if bal_plugin.ASK_PING_WILLEXECUTORS.get() and not force:
|
||||||
if bal_window:
|
# if bal_window:
|
||||||
ping_willexecutors = bal_window.window.question(
|
# ping_willexecutors = bal_window.window.question(
|
||||||
_(
|
# _(
|
||||||
"Contact willexecutors servers to update payment informations?"
|
# "Contact willexecutors servers to update payment informations?"
|
||||||
)
|
# )
|
||||||
)
|
# )
|
||||||
|
|
||||||
if ping_willexecutors:
|
# if ping_willexecutors:
|
||||||
if task:
|
# if task:
|
||||||
bal_window.ping_willexecutors(willexecutors, task)
|
# bal_window.ping_willexecutors(willexecutors, task)
|
||||||
else:
|
# else:
|
||||||
bal_window.ping_willexecutors_task(willexecutors)
|
# bal_window.ping_willexecutors_task(willexecutors)
|
||||||
w_sorted = dict(
|
w_sorted = dict(
|
||||||
sorted(
|
sorted(
|
||||||
willexecutors.items(), key=lambda w: w[1].get("sort", 0), reverse=True
|
willexecutors.items(), key=lambda w: w[1].get("sort", 0), reverse=True
|
||||||
@@ -170,6 +170,7 @@ class Willexecutors:
|
|||||||
def push_transactions_to_willexecutor(willexecutor):
|
def push_transactions_to_willexecutor(willexecutor):
|
||||||
out = True
|
out = True
|
||||||
try:
|
try:
|
||||||
|
|
||||||
_logger.debug(f"willexecutor['txs']")
|
_logger.debug(f"willexecutor['txs']")
|
||||||
if w := Willexecutors.send_request(
|
if w := Willexecutors.send_request(
|
||||||
"post",
|
"post",
|
||||||
|
|||||||
Reference in New Issue
Block a user