willexecutor manager improved
This commit is contained in:
73
heirs.py
73
heirs.py
@@ -1,23 +1,37 @@
|
||||
import datetime
|
||||
import json
|
||||
# import datetime
|
||||
# import json
|
||||
import math
|
||||
import random
|
||||
import re
|
||||
import threading
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple
|
||||
|
||||
# import urllib.parse
|
||||
# import urllib.request
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Dict,
|
||||
# List,
|
||||
Optional,
|
||||
# Sequence,
|
||||
Tuple,
|
||||
)
|
||||
|
||||
import dns
|
||||
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.transaction import (
|
||||
PartialTransaction,
|
||||
PartialTxInput,
|
||||
PartialTxOutput,
|
||||
TxOutpoint,
|
||||
TxOutput,
|
||||
# TxOutput,
|
||||
)
|
||||
from electrum.util import (
|
||||
bfh,
|
||||
@@ -30,11 +44,11 @@ from electrum.util import (
|
||||
from .util import Util
|
||||
from .willexecutors import Willexecutors
|
||||
from electrum.util import BitcoinException
|
||||
from electrum import constants
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .simple_config import SimpleConfig
|
||||
from .wallet_db import WalletDB
|
||||
|
||||
# from .wallet_db import WalletDB
|
||||
|
||||
|
||||
_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
|
||||
),
|
||||
)
|
||||
total_used_utxos = []
|
||||
# total_used_utxos = []
|
||||
txsout = {}
|
||||
locktime, _ = Util.get_lowest_locktimes(locktimes)
|
||||
if not locktime:
|
||||
@@ -105,7 +119,7 @@ def prepare_transactions(locktimes, available_utxos, fees, wallet):
|
||||
outputs = []
|
||||
paid_heirs = {}
|
||||
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]
|
||||
):
|
||||
try:
|
||||
@@ -200,7 +214,7 @@ def get_utxos_from_inputs(tx_inputs, tx, utxos):
|
||||
|
||||
# TODO calculate de minimum inputs to be invalidated
|
||||
def invalidate_inheritance_transactions(wallet):
|
||||
listids = []
|
||||
# listids = []
|
||||
utxos = {}
|
||||
dtxs = {}
|
||||
for k, v in wallet.get_all_labels().items():
|
||||
@@ -229,7 +243,7 @@ def invalidate_inheritance_transactions(wallet):
|
||||
for key, value in utxos:
|
||||
for tx in value["txs"]:
|
||||
txid = tx.txid()
|
||||
if not txid in invalidated:
|
||||
if txid not in invalidated:
|
||||
invalidated.append(tx.txid())
|
||||
remaining[key] = value
|
||||
|
||||
@@ -237,10 +251,10 @@ def invalidate_inheritance_transactions(wallet):
|
||||
def print_transaction(heirs, tx, locktimes, tx_fees):
|
||||
jtx = tx.to_json()
|
||||
print(f"TX: {tx.txid()}\t-\tLocktime: {jtx['locktime']}")
|
||||
print(f"---")
|
||||
print("---")
|
||||
for inp in jtx["inputs"]:
|
||||
print(f"{inp['address']}: {inp['value_sats']}")
|
||||
print(f"---")
|
||||
print("---")
|
||||
for out in jtx["outputs"]:
|
||||
heirname = ""
|
||||
for key in heirs.keys():
|
||||
@@ -262,7 +276,7 @@ def print_transaction(heirs, tx, locktimes, tx_fees):
|
||||
print()
|
||||
try:
|
||||
print(tx.serialize_to_network())
|
||||
except:
|
||||
except Exception:
|
||||
print("impossible to serialize")
|
||||
print()
|
||||
|
||||
@@ -285,7 +299,7 @@ class Heirs(dict, Logger):
|
||||
d = self.db.get("heirs", {})
|
||||
try:
|
||||
self.update(d)
|
||||
except e as Exception:
|
||||
except Exception:
|
||||
return
|
||||
|
||||
def invalidate_transactions(self, wallet):
|
||||
@@ -357,10 +371,10 @@ class Heirs(dict, Logger):
|
||||
def amount_to_float(self, amount):
|
||||
try:
|
||||
return float(amount)
|
||||
except:
|
||||
except Exception:
|
||||
try:
|
||||
return float(amount[:-1])
|
||||
except:
|
||||
except Exception:
|
||||
return 0.0
|
||||
|
||||
def fixed_percent_lists_amount(self, from_locktime, dust_threshold, reverse=False):
|
||||
@@ -376,7 +390,7 @@ class Heirs(dict, Logger):
|
||||
)
|
||||
if cmp <= 0:
|
||||
_logger.debug(
|
||||
"cmp < 0 {} {} {} ".format(
|
||||
"cmp < 0 {} {} {} {}".format(
|
||||
cmp, key, self[key][HEIR_LOCKTIME], from_locktime
|
||||
)
|
||||
)
|
||||
@@ -430,7 +444,7 @@ class Heirs(dict, Logger):
|
||||
willexecutors[
|
||||
'w!ll3x3c"' + willexecutor["url"] + '"' + str(locktime)
|
||||
] = h
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
return [], False
|
||||
else:
|
||||
_logger.error(
|
||||
@@ -440,9 +454,6 @@ class Heirs(dict, Logger):
|
||||
newbalance -= willexecutors_amount
|
||||
if newbalance < 0:
|
||||
raise WillExecutorFeeException(willexecutor)
|
||||
a = list(
|
||||
self.fixed_percent_lists_amount(from_locktime, wallet.dust_threshold())
|
||||
)
|
||||
(
|
||||
fixed_heirs,
|
||||
fixed_amount,
|
||||
@@ -484,7 +495,7 @@ class Heirs(dict, Logger):
|
||||
locktimes = {}
|
||||
for key, value in heir_list:
|
||||
locktime = Util.parse_locktime_string(value[HEIR_LOCKTIME])
|
||||
if not locktime in locktimes:
|
||||
if locktime not in locktimes:
|
||||
locktimes[locktime] = {key: value}
|
||||
else:
|
||||
locktimes[locktime][key] = value
|
||||
@@ -545,12 +556,12 @@ class Heirs(dict, Logger):
|
||||
total_fees = 0
|
||||
for fee in fees:
|
||||
total_fees += int(fees[fee])
|
||||
newbalance = balance
|
||||
# newbalance = balance
|
||||
try:
|
||||
locktimes, onlyfixed = self.prepare_lists(
|
||||
balance, total_fees, wallet, willexecutor, from_locktime
|
||||
)
|
||||
except WillExecutorFeeException as e:
|
||||
except WillExecutorFeeException:
|
||||
i = 10
|
||||
continue
|
||||
if locktimes:
|
||||
@@ -566,9 +577,11 @@ class Heirs(dict, Logger):
|
||||
)
|
||||
try:
|
||||
if "w!ll3x3c" in e.heirname:
|
||||
Willexecutors.is_selected(willexecutors[w], False)
|
||||
Willexecutors.is_selected(
|
||||
e.heirname[len("w!ll3x3c") :], False
|
||||
)
|
||||
break
|
||||
except:
|
||||
except Exception:
|
||||
raise e
|
||||
total_fees = 0
|
||||
total_fees_real = 0
|
||||
@@ -583,7 +596,7 @@ class Heirs(dict, Logger):
|
||||
rfee = tx.input_value() - tx.output_value()
|
||||
if rfee < fee or rfee > fee + wallet.dust_threshold():
|
||||
redo = True
|
||||
oldfees = fees.get(tx.my_locktime, 0)
|
||||
# oldfees = fees.get(tx.my_locktime, 0)
|
||||
fees[tx.my_locktime] = fee
|
||||
|
||||
if balance - total_in > wallet.dust_threshold():
|
||||
|
||||
Reference in New Issue
Block a user