download welist
This commit is contained in:
parent
e542c82ee1
commit
4d021e1d82
14
bal.py
14
bal.py
@ -1,15 +1,10 @@
|
|||||||
import random
|
import random
|
||||||
import os
|
import os
|
||||||
from hashlib import sha256
|
|
||||||
from typing import NamedTuple, Optional, Dict, Tuple
|
|
||||||
|
|
||||||
from electrum.plugin import BasePlugin
|
from electrum.plugin import BasePlugin
|
||||||
from electrum.util import to_bytes, bfh
|
|
||||||
from electrum import json_db
|
from electrum import json_db
|
||||||
from electrum.transaction import tx_from_any
|
from electrum.transaction import tx_from_any
|
||||||
|
|
||||||
from . import util as Util
|
|
||||||
from . import willexecutors as Willexecutors
|
|
||||||
import os
|
import os
|
||||||
json_db.register_dict('heirs', tuple, None)
|
json_db.register_dict('heirs', tuple, None)
|
||||||
json_db.register_dict('will', lambda x: get_will(x), None)
|
json_db.register_dict('will', lambda x: get_will(x), None)
|
||||||
@ -17,11 +12,10 @@ json_db.register_dict('will_settings', lambda x:x, None)
|
|||||||
from electrum.logging import get_logger
|
from electrum.logging import get_logger
|
||||||
def get_will(x):
|
def get_will(x):
|
||||||
try:
|
try:
|
||||||
#print("______________________________________________________________________________________________________")
|
|
||||||
#print(x)
|
|
||||||
x['tx']=tx_from_any(x['tx'])
|
x['tx']=tx_from_any(x['tx'])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
#Util.print_var(x)
|
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
return x
|
return x
|
||||||
@ -69,7 +63,7 @@ class BalPlugin(BasePlugin):
|
|||||||
HIDE_INVALIDATED:True,
|
HIDE_INVALIDATED:True,
|
||||||
ALLOW_REPUSH: False,
|
ALLOW_REPUSH: False,
|
||||||
WILLEXECUTORS: {
|
WILLEXECUTORS: {
|
||||||
'http://bitcoin-after.life:9137': {
|
'https://bitcoin-after.life:9137': {
|
||||||
"base_fee": 100000,
|
"base_fee": 100000,
|
||||||
"status": "New",
|
"status": "New",
|
||||||
"info":"Bitcoin After Life Will Executor",
|
"info":"Bitcoin After Life Will Executor",
|
||||||
@ -102,10 +96,8 @@ class BalPlugin(BasePlugin):
|
|||||||
|
|
||||||
def config_get(self,key):
|
def config_get(self,key):
|
||||||
v = self.config.get(key,None)
|
v = self.config.get(key,None)
|
||||||
print("config get",key,v)
|
|
||||||
if v is None:
|
if v is None:
|
||||||
self.config.set_key(key,self.DEFAULT_SETTINGS[key])
|
self.config.set_key(key,self.DEFAULT_SETTINGS[key])
|
||||||
print("config setkey",key)
|
|
||||||
v = self.DEFAULT_SETTINGS[key]
|
v = self.DEFAULT_SETTINGS[key]
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
7
heirs.py
7
heirs.py
@ -15,8 +15,8 @@ import datetime
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from .bal import BalPlugin
|
from .bal import BalPlugin
|
||||||
from . import util as Util
|
from .util import Util
|
||||||
from . import willexecutors as Willexecutors
|
from .willexecutors import Willexecutors
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .wallet_db import WalletDB
|
from .wallet_db import WalletDB
|
||||||
from .simple_config import SimpleConfig
|
from .simple_config import SimpleConfig
|
||||||
@ -38,6 +38,7 @@ def reduce_outputs(in_amount, out_amount, fee, outputs):
|
|||||||
for output in outputs:
|
for output in outputs:
|
||||||
output.value = math.floor((in_amount-fee)/out_amount * output.value)
|
output.value = math.floor((in_amount-fee)/out_amount * output.value)
|
||||||
|
|
||||||
|
"""
|
||||||
#TODO: put this method inside wallet.db to replace or complete get_locktime_for_new_transaction
|
#TODO: put this method inside wallet.db to replace or complete get_locktime_for_new_transaction
|
||||||
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
|
||||||
@ -57,7 +58,7 @@ def get_current_height(network:'Network'):
|
|||||||
# discourage "fee sniping"
|
# discourage "fee sniping"
|
||||||
height = min(chain_height, server_height)
|
height = min(chain_height, server_height)
|
||||||
return height
|
return height
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,5 +3,6 @@
|
|||||||
"fullname": "Bitcoin After Life",
|
"fullname": "Bitcoin After Life",
|
||||||
"description": "Provides free and decentralized inheritance support",
|
"description": "Provides free and decentralized inheritance support",
|
||||||
"author":"Svātantrya",
|
"author":"Svātantrya",
|
||||||
"available_for": ["qt"]
|
"available_for": ["qt"],
|
||||||
|
"icon":"icons/bal32x32.png"
|
||||||
}
|
}
|
||||||
|
81
util.py
81
util.py
@ -8,6 +8,7 @@ import urllib.parse
|
|||||||
from electrum.util import write_json_file,FileImportFailed,FileExportFailed
|
from electrum.util import write_json_file,FileImportFailed,FileExportFailed
|
||||||
|
|
||||||
LOCKTIME_THRESHOLD = 500000000
|
LOCKTIME_THRESHOLD = 500000000
|
||||||
|
class Util:
|
||||||
def locktime_to_str(locktime):
|
def locktime_to_str(locktime):
|
||||||
try:
|
try:
|
||||||
locktime=int(locktime)
|
locktime=int(locktime)
|
||||||
@ -16,7 +17,6 @@ def locktime_to_str(locktime):
|
|||||||
return dt
|
return dt
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
#print(e)
|
|
||||||
pass
|
pass
|
||||||
return str(locktime)
|
return str(locktime)
|
||||||
|
|
||||||
@ -27,7 +27,6 @@ def str_to_locktime(locktime):
|
|||||||
else: return int(locktime)
|
else: return int(locktime)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
#print(e)
|
|
||||||
dt_object = datetime.fromisoformat(locktime)
|
dt_object = datetime.fromisoformat(locktime)
|
||||||
timestamp = dt_object.timestamp()
|
timestamp = dt_object.timestamp()
|
||||||
return int(timestamp)
|
return int(timestamp)
|
||||||
@ -38,7 +37,6 @@ def parse_locktime_string(locktime,w=None):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
#print("parse_locktime_string",e)
|
|
||||||
try:
|
try:
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
if locktime[-1] == 'y':
|
if locktime[-1] == 'y':
|
||||||
@ -49,12 +47,11 @@ 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 as e:
|
except Exception as e:
|
||||||
print("parse_locktime_string",e)
|
pass
|
||||||
#raise e
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@ -62,7 +59,7 @@ def int_locktime(seconds=0,minutes=0,hours=0, days=0, blocks = 0):
|
|||||||
return int(seconds + minutes*60 + hours*60*60 + days*60*60*24 + blocks * 600)
|
return int(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 is_perc(amount):
|
if Util.is_perc(amount):
|
||||||
return amount
|
return amount
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
@ -71,7 +68,7 @@ def encode_amount(amount, decimal_point):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
def decode_amount(amount,decimal_point):
|
def decode_amount(amount,decimal_point):
|
||||||
if is_perc(amount):
|
if Util.is_perc(amount):
|
||||||
return amount
|
return amount
|
||||||
else:
|
else:
|
||||||
num=8-decimal_point
|
num=8-decimal_point
|
||||||
@ -111,7 +108,6 @@ def cmp_willexecutor(willexecutora,willexecutorb):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def search_heir_by_values(heirs,heir,values):
|
def search_heir_by_values(heirs,heir,values):
|
||||||
#print()
|
|
||||||
for h,v in heirs.items():
|
for h,v in heirs.items():
|
||||||
found = False
|
found = False
|
||||||
for val in values:
|
for val in values:
|
||||||
@ -133,13 +129,12 @@ def cmp_heirs_by_values(heirsa,heirsb,values,exclude_willexecutors=False,reverse
|
|||||||
if (exclude_willexecutors and not "w!ll3x3c\"" in heira) or not exclude_willexecutors:
|
if (exclude_willexecutors and not "w!ll3x3c\"" in heira) 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:
|
||||||
#print(f"not_found {heira}--{heirsa[heira]}")
|
|
||||||
return False
|
return False
|
||||||
if reverse:
|
if reverse:
|
||||||
return cmp_heirs_by_values(heirsb,heirsa,values,exclude_willexecutors=exclude_willexecutors,reverse=False)
|
return Util.cmp_heirs_by_values(heirsb,heirsa,values,exclude_willexecutors=exclude_willexecutors,reverse=False)
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -148,10 +143,10 @@ def cmp_heirs(heirsa,heirsb,cmp_function = lambda x,y: x[0]==y[0] and x[3]==y[3]
|
|||||||
for heir in heirsa:
|
for heir in heirsa:
|
||||||
if not "w!ll3x3c\"" in heir:
|
if not "w!ll3x3c\"" in heir:
|
||||||
if not heir in heirsb or not cmp_function(heirsa[heir],heirsb[heir]):
|
if not heir in heirsb or not cmp_function(heirsa[heir],heirsb[heir]):
|
||||||
if not search_heir_by_values(heirsb,heirsa[heir],[0,3]):
|
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:
|
||||||
@ -162,7 +157,7 @@ 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
|
||||||
|
|
||||||
@ -170,15 +165,15 @@ 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 cmp_inputs(txa.inputs(),txb.inputs()):
|
if not Util.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
|
||||||
|
|
||||||
@ -186,30 +181,19 @@ def get_value_amount(txa,txb):
|
|||||||
outputsa=txa.outputs()
|
outputsa=txa.outputs()
|
||||||
outputsb=txb.outputs()
|
outputsb=txb.outputs()
|
||||||
value_amount = 0
|
value_amount = 0
|
||||||
#if len(outputsa) != len(outputsb):
|
|
||||||
# print("outputlen is different")
|
|
||||||
# return False
|
|
||||||
|
|
||||||
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):
|
||||||
#print("outa notin txb", same_amount,same_address)
|
|
||||||
return False
|
return False
|
||||||
if same_amount and same_address:
|
if same_amount and same_address:
|
||||||
value_amount+=outa.value
|
value_amount+=outa.value
|
||||||
if same_amount:
|
if same_amount:
|
||||||
pass
|
pass
|
||||||
#print("same amount")
|
|
||||||
if same_address:
|
if same_address:
|
||||||
pass
|
pass
|
||||||
#print("same address")
|
|
||||||
|
|
||||||
return value_amount
|
return value_amount
|
||||||
#not needed
|
|
||||||
#for outb in outputsb:
|
|
||||||
# if not in_output(outb,txa.outputs()):
|
|
||||||
# print("outb notin txb")
|
|
||||||
# return False
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -244,8 +228,8 @@ def cmp_locktime(locktimea,locktimeb):
|
|||||||
return 0
|
return 0
|
||||||
strlocktime = 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])
|
||||||
@ -268,8 +252,7 @@ def get_lowest_locktimes(locktimes):
|
|||||||
sorted_timestamp=[]
|
sorted_timestamp=[]
|
||||||
sorted_block=[]
|
sorted_block=[]
|
||||||
for l in locktimes:
|
for l in locktimes:
|
||||||
#print("locktime:",parse_locktime_string(l))
|
l=Util.parse_locktime_string(l)
|
||||||
l=parse_locktime_string(l)
|
|
||||||
if l < LOCKTIME_THRESHOLD:
|
if l < LOCKTIME_THRESHOLD:
|
||||||
bisect.insort(sorted_block,l)
|
bisect.insort(sorted_block,l)
|
||||||
else:
|
else:
|
||||||
@ -278,11 +261,11 @@ 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):
|
def get_lowest_locktimes_from_will(will):
|
||||||
return get_lowest_locktimes(get_locktimes(will))
|
return Util.get_lowest_locktimes(Util.get_locktimes(will))
|
||||||
|
|
||||||
def search_willtx_per_io(will,tx):
|
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
|
||||||
|
|
||||||
@ -304,17 +287,16 @@ def utxo_to_str(utxo):
|
|||||||
return str(utxo)
|
return str(utxo)
|
||||||
|
|
||||||
def cmp_utxo(utxoa,utxob):
|
def cmp_utxo(utxoa,utxob):
|
||||||
utxoa=utxo_to_str(utxoa)
|
utxoa=Util.utxo_to_str(utxoa)
|
||||||
utxob=utxo_to_str(utxob)
|
utxob=Util.utxo_to_str(utxob)
|
||||||
if utxoa == utxob:
|
if utxoa == utxob:
|
||||||
#if utxoa.prevout.txid==utxob.prevout.txid and utxoa.prevout.out_idx == utxob.prevout.out_idx:
|
|
||||||
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
|
||||||
|
|
||||||
@ -329,7 +311,7 @@ def cmp_output(outputa,outputb):
|
|||||||
|
|
||||||
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
|
||||||
|
|
||||||
@ -345,11 +327,9 @@ def din_output(out,outputs):
|
|||||||
if int(out.value) == int(s_o.value):
|
if int(out.value) == int(s_o.value):
|
||||||
same_amount.append(s_o)
|
same_amount.append(s_o)
|
||||||
if out.address==s_o.address:
|
if out.address==s_o.address:
|
||||||
#print("SAME_:",out.address,s_o.address)
|
|
||||||
return True, True
|
return True, True
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
#print("NOT SAME_:",out.address,s_o.address)
|
|
||||||
|
|
||||||
if len(same_amount)>0:
|
if len(same_amount)>0:
|
||||||
return True, False
|
return True, False
|
||||||
@ -417,11 +397,10 @@ def print_var(var,name = "",veryverbose=False):
|
|||||||
|
|
||||||
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("madonnamaiala_TXInput__scriptpubkey:",utxo._TXInput__scriptpubkey)
|
|
||||||
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)
|
||||||
@ -429,8 +408,8 @@ def print_utxo(utxo, 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):
|
||||||
|
114
will.py
114
will.py
@ -1,7 +1,7 @@
|
|||||||
import copy
|
import copy
|
||||||
|
|
||||||
from . import willexecutors as Willexecutors
|
from .willexecutors import Willexecutors
|
||||||
from . import util as Util
|
from .util import Util
|
||||||
|
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
|
|
||||||
@ -16,6 +16,7 @@ MIN_BLOCK = 1
|
|||||||
_logger = get_logger(__name__)
|
_logger = get_logger(__name__)
|
||||||
|
|
||||||
#return an array with the list of children
|
#return an array with the list of children
|
||||||
|
class Will:
|
||||||
def get_children(will,willid):
|
def get_children(will,willid):
|
||||||
out = []
|
out = []
|
||||||
for _id in will:
|
for _id in will:
|
||||||
@ -29,7 +30,7 @@ def get_children(will,willid):
|
|||||||
#build a tree with parent transactions
|
#build a tree with parent transactions
|
||||||
def add_willtree(will):
|
def add_willtree(will):
|
||||||
for willid in will:
|
for willid in will:
|
||||||
will[willid].children = get_children(will,willid)
|
will[willid].children = Will.get_children(will,willid)
|
||||||
for child in will[willid].children:
|
for child in will[willid].children:
|
||||||
if not will[child[0]].father:
|
if not will[child[0]].father:
|
||||||
will[child[0]].father = willid
|
will[child[0]].father = willid
|
||||||
@ -65,7 +66,7 @@ def get_tx_from_any(x):
|
|||||||
|
|
||||||
def add_info_from_will(will,wid,wallet):
|
def add_info_from_will(will,wid,wallet):
|
||||||
if isinstance(will[wid].tx,str):
|
if isinstance(will[wid].tx,str):
|
||||||
will[wid].tx = get_tx_from_any(will[wid].tx)
|
will[wid].tx = Will.get_tx_from_any(will[wid].tx)
|
||||||
if wallet:
|
if wallet:
|
||||||
will[wid].tx.add_info_from_wallet(wallet)
|
will[wid].tx.add_info_from_wallet(wallet)
|
||||||
for txin in will[wid].tx.inputs():
|
for txin in will[wid].tx.inputs():
|
||||||
@ -88,7 +89,7 @@ def normalize_will(will,wallet = None,others_inputs = {}):
|
|||||||
to_add = {}
|
to_add = {}
|
||||||
#add info from wallet
|
#add info from wallet
|
||||||
for wid in will:
|
for wid in will:
|
||||||
add_info_from_will(will,wid,wallet)
|
Will.add_info_from_will(will,wid,wallet)
|
||||||
errors ={}
|
errors ={}
|
||||||
for wid in will:
|
for wid in will:
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ def normalize_will(will,wallet = None,others_inputs = {}):
|
|||||||
will[wid]=ow.to_dict()
|
will[wid]=ow.to_dict()
|
||||||
|
|
||||||
for i in range(0,len(outputs)):
|
for i in range(0,len(outputs)):
|
||||||
change_input(will,wid,i,outputs[i],others_inputs,to_delete,to_add)
|
Will.change_input(will,wid,i,outputs[i],others_inputs,to_delete,to_add)
|
||||||
|
|
||||||
to_delete.append(wid)
|
to_delete.append(wid)
|
||||||
to_add[ow.tx.txid()]=ow.to_dict()
|
to_add[ow.tx.txid()]=ow.to_dict()
|
||||||
@ -141,23 +142,16 @@ def check_anticipate(ow:'WillItem',nw:'WillItem'):
|
|||||||
anticipate = Util.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 Util.cmp_heirs_by_values(ow.heirs,nw.heirs,[0,1],exclude_willexecutors = True):
|
if Util.cmp_heirs_by_values(ow.heirs,nw.heirs,[0,1],exclude_willexecutors = True):
|
||||||
print("same heirs",ow._id,nw._id)
|
|
||||||
if nw.we and ow.we:
|
if nw.we and ow.we:
|
||||||
if ow.we['url'] == nw.we['url']:
|
if ow.we['url'] == nw.we['url']:
|
||||||
print("same willexecutors", ow.we['url'],nw.we['url'])
|
|
||||||
if int(ow.we['base_fee'])>int(nw.we['base_fee']):
|
if int(ow.we['base_fee'])>int(nw.we['base_fee']):
|
||||||
print("anticipate")
|
|
||||||
return anticipate
|
return anticipate
|
||||||
else:
|
else:
|
||||||
if int(ow.tx_fees) != int(nw.tx_fees):
|
if int(ow.tx_fees) != int(nw.tx_fees):
|
||||||
return anticipate
|
return anticipate
|
||||||
else:
|
else:
|
||||||
print("keep the same")
|
|
||||||
#_logger.debug("ow,base fee > nw.base_fee")
|
|
||||||
ow.tx.locktime
|
ow.tx.locktime
|
||||||
else:
|
else:
|
||||||
#_logger.debug("ow.we['url']({ow.we['url']}) == nw.we['url']({nw.we['url']})")
|
|
||||||
print("keep the same")
|
|
||||||
ow.tx.locktime
|
ow.tx.locktime
|
||||||
else:
|
else:
|
||||||
if nw.we == ow.we:
|
if nw.we == ow.we:
|
||||||
@ -188,7 +182,7 @@ def change_input(will, otxid, idx, change,others_inputs,to_delete,to_append):
|
|||||||
if isinstance(w.tx,Transaction):
|
if isinstance(w.tx,Transaction):
|
||||||
will[wid].tx = PartialTransaction.from_tx(w.tx)
|
will[wid].tx = PartialTransaction.from_tx(w.tx)
|
||||||
will[wid].tx.set_rbf(True)
|
will[wid].tx.set_rbf(True)
|
||||||
will[wid].tx._inputs[i]=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 == True:
|
||||||
pass
|
pass
|
||||||
@ -199,7 +193,7 @@ def change_input(will, otxid, idx, change,others_inputs,to_delete,to_append):
|
|||||||
to_append[new_txid]=will[wid]
|
to_append[new_txid]=will[wid]
|
||||||
outputs = will[wid].tx.outputs()
|
outputs = will[wid].tx.outputs()
|
||||||
for i in range(0,len(outputs)):
|
for i in range(0,len(outputs)):
|
||||||
change_input(will, wid, i, outputs[i],others_inputs,to_delete,to_append)
|
Will.change_input(will, wid, i, outputs[i],others_inputs,to_delete,to_append)
|
||||||
|
|
||||||
def get_all_inputs(will,only_valid = False):
|
def get_all_inputs(will,only_valid = False):
|
||||||
all_inputs = {}
|
all_inputs = {}
|
||||||
@ -234,7 +228,7 @@ def search_anticipate_rec(will,old_inputs):
|
|||||||
redo = False
|
redo = False
|
||||||
to_delete = []
|
to_delete = []
|
||||||
to_append = {}
|
to_append = {}
|
||||||
new_inputs = get_all_inputs(will,only_valid = True)
|
new_inputs = Will.get_all_inputs(will,only_valid = True)
|
||||||
for nid,nwi in will.items():
|
for nid,nwi in will.items():
|
||||||
if nwi.search_anticipate(new_inputs) or nwi.search_anticipate(old_inputs):
|
if nwi.search_anticipate(new_inputs) or nwi.search_anticipate(old_inputs):
|
||||||
if nid != nwi.tx.txid():
|
if nid != nwi.tx.txid():
|
||||||
@ -243,7 +237,7 @@ def search_anticipate_rec(will,old_inputs):
|
|||||||
to_append[nwi.tx.txid()] = nwi
|
to_append[nwi.tx.txid()] = nwi
|
||||||
outputs = nwi.tx.outputs()
|
outputs = nwi.tx.outputs()
|
||||||
for i in range(0,len(outputs)):
|
for i in range(0,len(outputs)):
|
||||||
change_input(will,nid,i,outputs[i],new_inputs,to_delete,to_append)
|
Will.change_input(will,nid,i,outputs[i],new_inputs,to_delete,to_append)
|
||||||
|
|
||||||
|
|
||||||
for w in to_delete:
|
for w in to_delete:
|
||||||
@ -254,25 +248,25 @@ def search_anticipate_rec(will,old_inputs):
|
|||||||
for k,w in to_append.items():
|
for k,w in to_append.items():
|
||||||
will[k]=w
|
will[k]=w
|
||||||
if redo:
|
if redo:
|
||||||
search_anticipate_rec(will,old_inputs)
|
Will.search_anticipate_rec(will,old_inputs)
|
||||||
|
|
||||||
|
|
||||||
def update_will(old_will,new_will):
|
def update_will(old_will,new_will):
|
||||||
all_old_inputs = get_all_inputs(old_will,only_valid=True)
|
all_old_inputs = Will.get_all_inputs(old_will,only_valid=True)
|
||||||
all_inputs_min_locktime = get_all_inputs_min_locktime(all_old_inputs)
|
all_inputs_min_locktime = Will.get_all_inputs_min_locktime(all_old_inputs)
|
||||||
all_new_inputs = 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.
|
||||||
search_anticipate_rec(new_will,all_old_inputs)
|
Will.search_anticipate_rec(new_will,all_old_inputs)
|
||||||
|
|
||||||
other_inputs = get_all_inputs(old_will,{})
|
other_inputs = Will.get_all_inputs(old_will,{})
|
||||||
try:
|
try:
|
||||||
normalize_will(new_will,others_inputs=other_inputs)
|
Will.normalize_will(new_will,others_inputs=other_inputs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
for oid in only_valid(old_will):
|
for oid in Will.only_valid(old_will):
|
||||||
if oid in new_will:
|
if oid in new_will:
|
||||||
new_heirs = new_will[oid].heirs
|
new_heirs = new_will[oid].heirs
|
||||||
new_we = new_will[oid].we
|
new_we = new_will[oid].we
|
||||||
@ -280,11 +274,9 @@ def update_will(old_will,new_will):
|
|||||||
new_will[oid]=old_will[oid]
|
new_will[oid]=old_will[oid]
|
||||||
new_will[oid].heirs = new_heirs
|
new_will[oid].heirs = new_heirs
|
||||||
new_will[oid].we = new_we
|
new_will[oid].we = new_we
|
||||||
print(f"found {oid}")
|
|
||||||
|
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
print(f"not found {oid}")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def get_higher_input_for_tx(will):
|
def get_higher_input_for_tx(will):
|
||||||
@ -301,8 +293,8 @@ def get_higher_input_for_tx(will):
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
def invalidate_will(will,wallet,fees_per_byte):
|
def invalidate_will(will,wallet,fees_per_byte):
|
||||||
will_only_valid = only_valid_list(will)
|
will_only_valid = Will.only_valid_list(will)
|
||||||
inputs = get_all_inputs(will_only_valid)
|
inputs = Will.get_all_inputs(will_only_valid)
|
||||||
utxos = wallet.get_utxos()
|
utxos = wallet.get_utxos()
|
||||||
filtered_inputs = []
|
filtered_inputs = []
|
||||||
prevout_to_spend = []
|
prevout_to_spend = []
|
||||||
@ -350,7 +342,7 @@ def is_new(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 = 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:
|
||||||
@ -370,16 +362,6 @@ def search_rai (all_inputs,all_utxos,will,wallet):
|
|||||||
wi.set_status('CONFIRMED',True)
|
wi.set_status('CONFIRMED',True)
|
||||||
else:
|
else:
|
||||||
wi.set_status('INVALIDATED',True)
|
wi.set_status('INVALIDATED',True)
|
||||||
#else:
|
|
||||||
# if prevout_id in will:
|
|
||||||
# wo = will[prevout_id]
|
|
||||||
# ttx= wallet.db.get_transaction(prevout_id)
|
|
||||||
# if ttx:
|
|
||||||
# _logger.error("transaction in wallet should be early detected")
|
|
||||||
# #wi.set_status('CONFIRMED',True)
|
|
||||||
# #else:
|
|
||||||
# # _logger.error("transaction not in will or utxo")
|
|
||||||
# # wi.set_status('INVALIDATED',True)
|
|
||||||
|
|
||||||
for child in wi.search(all_inputs):
|
for child in wi.search(all_inputs):
|
||||||
if child.tx.locktime < wi.tx.locktime:
|
if child.tx.locktime < wi.tx.locktime:
|
||||||
@ -396,7 +378,7 @@ 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 self.children.items():
|
||||||
set_invalidate(c[0],will)
|
Will.set_invalidate(c[0],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)
|
||||||
@ -408,18 +390,12 @@ def check_invalidated(willtree,utxos_list,wallet):
|
|||||||
if not w.father:
|
if not w.father:
|
||||||
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)
|
||||||
#print(utxos_list)
|
|
||||||
#print(inp_str)
|
|
||||||
#print(inp_str in utxos_list)
|
|
||||||
#print("notin: ",not inp_str in utxos_list)
|
|
||||||
if not inp_str in utxos_list:
|
if not inp_str in utxos_list:
|
||||||
#print("quindi qua non ci arrivo?")
|
|
||||||
if wallet:
|
if wallet:
|
||||||
height= check_tx_height(w.tx,wallet)
|
height= Will.check_tx_height(w.tx,wallet)
|
||||||
|
|
||||||
if height < 0:
|
if height < 0:
|
||||||
#_logger.debug(f"heigth {height}")
|
Will.set_invalidate(wid,willtree)
|
||||||
set_invalidate(wid,willtree)
|
|
||||||
elif height == 0:
|
elif height == 0:
|
||||||
w.set_status("PENDING",True)
|
w.set_status("PENDING",True)
|
||||||
else:
|
else:
|
||||||
@ -436,7 +412,7 @@ def reflect_to_children(treeitem):
|
|||||||
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:
|
||||||
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 = heirs.fixed_percent_lists_amount(timestamp_to_check,dust,reverse=True)
|
fixed_heirs,fixed_amount,perc_heirs,perc_amount = heirs.fixed_percent_lists_amount(timestamp_to_check,dust,reverse=True)
|
||||||
@ -457,35 +433,32 @@ def check_amounts(heirs,willexecutors,all_utxos,timestamp_to_check,dust):
|
|||||||
|
|
||||||
|
|
||||||
def check_will(will,all_utxos,wallet,block_to_check,timestamp_to_check):
|
def check_will(will,all_utxos,wallet,block_to_check,timestamp_to_check):
|
||||||
add_willtree(will)
|
Will.add_willtree(will)
|
||||||
utxos_list= utxos_strs(all_utxos)
|
utxos_list= Will.utxos_strs(all_utxos)
|
||||||
|
|
||||||
check_invalidated(will,utxos_list,wallet)
|
Will.check_invalidated(will,utxos_list,wallet)
|
||||||
#from pprint import pprint
|
|
||||||
#for wid,w in will.items():
|
|
||||||
# pprint(w.to_dict())
|
|
||||||
|
|
||||||
all_inputs=get_all_inputs(will,only_valid = True)
|
all_inputs=Will.get_all_inputs(will,only_valid = True)
|
||||||
|
|
||||||
all_inputs_min_locktime = get_all_inputs_min_locktime(all_inputs)
|
all_inputs_min_locktime = Will.get_all_inputs_min_locktime(all_inputs)
|
||||||
|
|
||||||
check_will_expired(all_inputs_min_locktime,block_to_check,timestamp_to_check)
|
Will.check_will_expired(all_inputs_min_locktime,block_to_check,timestamp_to_check)
|
||||||
|
|
||||||
all_inputs=get_all_inputs(will,only_valid = True)
|
all_inputs=Will.get_all_inputs(will,only_valid = True)
|
||||||
|
|
||||||
search_rai(all_inputs,all_utxos,will,wallet)
|
Will.search_rai(all_inputs,all_utxos,will,wallet)
|
||||||
|
|
||||||
def is_will_valid(will, block_to_check, timestamp_to_check, tx_fees, all_utxos,heirs={},willexecutors={},self_willexecutor=False, wallet=False, callback_not_valid_tx=None):
|
def is_will_valid(will, block_to_check, timestamp_to_check, tx_fees, all_utxos,heirs={},willexecutors={},self_willexecutor=False, wallet=False, callback_not_valid_tx=None):
|
||||||
|
|
||||||
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 check_willexecutors_and_heirs(will,heirs,willexecutors,self_willexecutor,timestamp_to_check,tx_fees):
|
if not Will.check_willexecutors_and_heirs(will,heirs,willexecutors,self_willexecutor,timestamp_to_check,tx_fees):
|
||||||
raise NotCompleteWillException()
|
raise NotCompleteWillException()
|
||||||
|
|
||||||
|
|
||||||
all_inputs=get_all_inputs(will,only_valid = True)
|
all_inputs=Will.get_all_inputs(will,only_valid = True)
|
||||||
|
|
||||||
_logger.info('check all utxo in wallet are spent')
|
_logger.info('check all utxo in wallet are spent')
|
||||||
if all_inputs:
|
if all_inputs:
|
||||||
@ -544,13 +517,12 @@ def check_willexecutors_and_heirs(will,heirs,willexecutors,self_willexecutor,che
|
|||||||
no_willexecutor = 0
|
no_willexecutor = 0
|
||||||
willexecutors_found = {}
|
willexecutors_found = {}
|
||||||
heirs_found = {}
|
heirs_found = {}
|
||||||
will_only_valid = only_valid_list(will)
|
will_only_valid = Will.only_valid_list(will)
|
||||||
if len(will_only_valid)<1:
|
if len(will_only_valid)<1:
|
||||||
return False
|
return False
|
||||||
for wid in only_valid_list(will):
|
for wid in Will.only_valid_list(will):
|
||||||
w = will[wid]
|
w = will[wid]
|
||||||
if w.tx_fees != tx_fees:
|
if w.tx_fees != tx_fees:
|
||||||
#w.set_status('VALID',False)
|
|
||||||
raise TxFeesChangedException(f"{tx_fees}:",w.tx_fees)
|
raise TxFeesChangedException(f"{tx_fees}:",w.tx_fees)
|
||||||
for wheir in w.heirs:
|
for wheir in w.heirs:
|
||||||
if not 'w!ll3x3c"' == wheir[:9]:
|
if not 'w!ll3x3c"' == wheir[:9]:
|
||||||
@ -630,8 +602,6 @@ class WillItem(Logger):
|
|||||||
self.STATUS['PUSH_FAIL'][1] = False
|
self.STATUS['PUSH_FAIL'][1] = False
|
||||||
self.STATUS['CHECK_FAIL'][1] = False
|
self.STATUS['CHECK_FAIL'][1] = False
|
||||||
|
|
||||||
#if status in ['CHECK_FAIL']:
|
|
||||||
# self.STATUS['PUSHED'][1] = False
|
|
||||||
|
|
||||||
if status in ['CHECKED']:
|
if status in ['CHECKED']:
|
||||||
self.STATUS['PUSHED'][1] = True
|
self.STATUS['PUSHED'][1] = True
|
||||||
@ -646,7 +616,7 @@ class WillItem(Logger):
|
|||||||
if isinstance(w,WillItem,):
|
if isinstance(w,WillItem,):
|
||||||
self.__dict__ = w.__dict__.copy()
|
self.__dict__ = w.__dict__.copy()
|
||||||
else:
|
else:
|
||||||
self.tx = get_tx_from_any(w['tx'])
|
self.tx = Will.get_tx_from_any(w['tx'])
|
||||||
self.heirs = w.get('heirs',None)
|
self.heirs = w.get('heirs',None)
|
||||||
self.we = w.get('willexecutor',None)
|
self.we = w.get('willexecutor',None)
|
||||||
self.status = w.get('status',None)
|
self.status = w.get('status',None)
|
||||||
@ -700,13 +670,11 @@ class WillItem(Logger):
|
|||||||
return str(self.to_dict())
|
return str(self.to_dict())
|
||||||
|
|
||||||
def set_anticipate(self, ow:'WillItem'):
|
def set_anticipate(self, ow:'WillItem'):
|
||||||
nl = min(ow.tx.locktime,check_anticipate(ow,self))
|
nl = min(ow.tx.locktime,Will.check_anticipate(ow,self))
|
||||||
if int(nl) < self.tx.locktime:
|
if int(nl) < self.tx.locktime:
|
||||||
#_logger.debug("actually anticipating")
|
|
||||||
self.tx.locktime = int(nl)
|
self.tx.locktime = int(nl)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
#_logger.debug("keeping the same locktime")
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,16 +9,15 @@ from electrum.logging import get_logger
|
|||||||
from electrum.gui.qt.util import WaitingDialog
|
from electrum.gui.qt.util import WaitingDialog
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
|
|
||||||
from .balqt.baldialog import BalWaitingDialog
|
from .util import Util
|
||||||
from . import util as Util
|
|
||||||
|
|
||||||
DEFAULT_TIMEOUT = 5
|
DEFAULT_TIMEOUT = 5
|
||||||
_logger = get_logger(__name__)
|
_logger = get_logger(__name__)
|
||||||
|
class Willexecutors:
|
||||||
def get_willexecutors(bal_plugin, update = False,bal_window=False,force=False,task=True):
|
def get_willexecutors(bal_plugin, update = False,bal_window=False,force=False,task=True):
|
||||||
willexecutors = bal_plugin.config_get(bal_plugin.WILLEXECUTORS)
|
willexecutors = bal_plugin.config_get(bal_plugin.WILLEXECUTORS)
|
||||||
for w in willexecutors:
|
for w in willexecutors:
|
||||||
initialize_willexecutor(willexecutors[w],w)
|
Willexecutors.initialize_willexecutor(willexecutors[w],w)
|
||||||
|
|
||||||
bal=bal_plugin.DEFAULT_SETTINGS[bal_plugin.WILLEXECUTORS]
|
bal=bal_plugin.DEFAULT_SETTINGS[bal_plugin.WILLEXECUTORS]
|
||||||
for bal_url,bal_executor in bal.items():
|
for bal_url,bal_executor in bal.items():
|
||||||
@ -28,7 +27,7 @@ def get_willexecutors(bal_plugin, update = False,bal_window=False,force=False,ta
|
|||||||
if update:
|
if update:
|
||||||
found = False
|
found = False
|
||||||
for url,we in willexecutors.items():
|
for url,we in willexecutors.items():
|
||||||
if is_selected(we):
|
if Willexecutors.is_selected(we):
|
||||||
found = True
|
found = True
|
||||||
if found or force:
|
if found or force:
|
||||||
if bal_plugin.config_get(bal_plugin.PING_WILLEXECUTORS) or force:
|
if bal_plugin.config_get(bal_plugin.PING_WILLEXECUTORS) or force:
|
||||||
@ -61,7 +60,7 @@ def get_willexecutor_transactions(will, force=False):
|
|||||||
if not willitem.get_status('PUSHED') or force:
|
if not willitem.get_status('PUSHED') or force:
|
||||||
if willexecutor := willitem.we:
|
if willexecutor := willitem.we:
|
||||||
url=willexecutor['url']
|
url=willexecutor['url']
|
||||||
if willexecutor and is_selected(willexecutor):
|
if willexecutor and Willexecutors.is_selected(willexecutor):
|
||||||
if not url in willexecutors:
|
if not url in willexecutors:
|
||||||
willexecutor['txs']=""
|
willexecutor['txs']=""
|
||||||
willexecutor['txsids']=[]
|
willexecutor['txsids']=[]
|
||||||
@ -74,16 +73,16 @@ def get_willexecutor_transactions(will, force=False):
|
|||||||
|
|
||||||
def only_selected_list(willexecutors):
|
def only_selected_list(willexecutors):
|
||||||
out = {}
|
out = {}
|
||||||
for url,v in willexectors.items():
|
for url,v in willexecutors.items():
|
||||||
if is_selected(willexecutor):
|
if Willexecutors.is_selected(willexecutor):
|
||||||
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 = get_transactions_to_be_pushed()
|
||||||
for url in willexecutors:
|
for url in willexecutors:
|
||||||
willexecutor = willexecutors[url]
|
willexecutor = willexecutors[url]
|
||||||
if is_selected(willexecutor):
|
if Willexecutors.is_selected(willexecutor):
|
||||||
if 'txs' in willexecutor:
|
if 'txs' in willexecutor:
|
||||||
push_transactions_to_willexecutor(willexecutors[url]['txs'],url)
|
Willexecutors.push_transactions_to_willexecutor(willexecutors[url]['txs'],url)
|
||||||
|
|
||||||
def send_request(method, url, data=None, *, timeout=10):
|
def send_request(method, url, data=None, *, timeout=10):
|
||||||
network = Network.get_instance()
|
network = Network.get_instance()
|
||||||
@ -99,13 +98,13 @@ def send_request(method, url, data=None, *, timeout=10):
|
|||||||
response = Network.send_http_on_proxy(method, url,
|
response = Network.send_http_on_proxy(method, url,
|
||||||
params=data,
|
params=data,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
on_finish=handle_response,
|
on_finish=Willexecutors.handle_response,
|
||||||
timeout=timeout)
|
timeout=timeout)
|
||||||
elif method == 'post':
|
elif method == 'post':
|
||||||
response = Network.send_http_on_proxy(method, url,
|
response = Network.send_http_on_proxy(method, url,
|
||||||
body=data,
|
body=data,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
on_finish=handle_response,
|
on_finish=Willexecutors.handle_response,
|
||||||
timeout=timeout)
|
timeout=timeout)
|
||||||
else:
|
else:
|
||||||
raise Exception(f"unexpected {method=!r}")
|
raise Exception(f"unexpected {method=!r}")
|
||||||
@ -120,7 +119,7 @@ async def handle_response(resp:ClientResponse):
|
|||||||
try:
|
try:
|
||||||
r=json.loads(r)
|
r=json.loads(r)
|
||||||
r['status'] = resp.status
|
r['status'] = resp.status
|
||||||
r['selected']=is_selected(willexecutor)
|
r['selected']=Willexecutors.is_selected(willexecutor)
|
||||||
r['url']=url
|
r['url']=url
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@ -131,8 +130,9 @@ class AlreadyPresentException(Exception):
|
|||||||
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:=send_request('post', willexecutor['url']+"/"+constants.net.NET_NAME+"/pushtxs", data=willexecutor['txs'].encode('ascii')):
|
if w:=Willexecutors.send_request('post', willexecutor['url']+"/"+constants.net.NET_NAME+"/pushtxs", data=willexecutor['txs'].encode('ascii')):
|
||||||
willexecutor['broadcast_status'] = _("Success")
|
willexecutor['broadcast_status'] = _("Success")
|
||||||
_logger.debug(f"pushed: {w}")
|
_logger.debug(f"pushed: {w}")
|
||||||
if w !='thx':
|
if w !='thx':
|
||||||
@ -143,7 +143,7 @@ def push_transactions_to_willexecutor(willexecutor):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.debug(f"error:{e}")
|
_logger.debug(f"error:{e}")
|
||||||
if str(e) == "already present":
|
if str(e) == "already present":
|
||||||
raise AlreadyPresentException()
|
raise Willexecutors.AlreadyPresentException()
|
||||||
out=False
|
out=False
|
||||||
willexecutor['broadcast_status'] = _("Failed")
|
willexecutor['broadcast_status'] = _("Failed")
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ def push_transactions_to_willexecutor(willexecutor):
|
|||||||
|
|
||||||
def ping_servers(willexecutors):
|
def ping_servers(willexecutors):
|
||||||
for url,we in willexecutors.items():
|
for url,we in willexecutors.items():
|
||||||
get_info_task(url,we)
|
Willexecutors.get_info_task(url,we)
|
||||||
|
|
||||||
|
|
||||||
def get_info_task(url,willexecutor):
|
def get_info_task(url,willexecutor):
|
||||||
@ -159,7 +159,10 @@ def get_info_task(url,willexecutor):
|
|||||||
try:
|
try:
|
||||||
_logger.info("GETINFO_WILLEXECUTOR")
|
_logger.info("GETINFO_WILLEXECUTOR")
|
||||||
_logger.debug(url)
|
_logger.debug(url)
|
||||||
w = send_request('get',url+"/"+constants.net.NET_NAME+"/info")
|
netname="bitcoin"
|
||||||
|
if constants.net.NET_NAME!="mainnet":
|
||||||
|
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'] = w['status']
|
||||||
willexecutor['base_fee'] = w['base_fee']
|
willexecutor['base_fee'] = w['base_fee']
|
||||||
@ -175,18 +178,34 @@ def get_info_task(url,willexecutor):
|
|||||||
return willexecutor
|
return willexecutor
|
||||||
|
|
||||||
def initialize_willexecutor(willexecutor,url,status=None,selected=None):
|
def initialize_willexecutor(willexecutor,url,status=None,selected=None):
|
||||||
|
print("1",willexecutor)
|
||||||
willexecutor['url']=url
|
willexecutor['url']=url
|
||||||
|
print("2",status)
|
||||||
if not status is None:
|
if not status is None:
|
||||||
willexecutor['status'] = status
|
willexecutor['status'] = status
|
||||||
willexecutor['selected'] = is_selected(willexecutor,selected)
|
willexecutor['selected'] = Willexecutors.is_selected(willexecutor,selected)
|
||||||
|
def download_list(bal_plugin):
|
||||||
|
try:
|
||||||
|
l = Willexecutors.send_request('get',"https://welist.bitcoin-after.life/data/bitcoin?page=0&limit=100")
|
||||||
|
del l['status']
|
||||||
|
from pprint import pprint
|
||||||
|
pprint(l)
|
||||||
|
for w in l:
|
||||||
|
print("----")
|
||||||
|
willexecutor=l[w]
|
||||||
|
Willexecutors.initialize_willexecutor(willexecutor,w,'New',False)
|
||||||
|
bal_plugin.config.set_key(bal_plugin.WILLEXECUTORS,l,save=True)
|
||||||
|
return l
|
||||||
|
except Exception as e:
|
||||||
|
_logger.error(f"error downloading willexecutors list:{e}")
|
||||||
|
return {}
|
||||||
def get_willexecutors_list_from_json(bal_plugin):
|
def get_willexecutors_list_from_json(bal_plugin):
|
||||||
try:
|
try:
|
||||||
with open("willexecutors.json") as f:
|
with open("willexecutors.json") as f:
|
||||||
willexecutors = json.load(f)
|
willexecutors = json.load(f)
|
||||||
for w in willexecutors:
|
for w in willexecutors:
|
||||||
willexecutor=willexecutors[w]
|
willexecutor=willexecutors[w]
|
||||||
willexecutors.initialize_willexecutor(willexecutor,w,'New',False)
|
Willexecutors.initialize_willexecutor(willexecutor,w,'New',False)
|
||||||
bal_plugin.config.set_key(bal_plugin.WILLEXECUTORS,willexecutors,save=True)
|
bal_plugin.config.set_key(bal_plugin.WILLEXECUTORS,willexecutors,save=True)
|
||||||
return h
|
return h
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -196,7 +215,7 @@ def get_willexecutors_list_from_json(bal_plugin):
|
|||||||
def check_transaction(txid,url):
|
def check_transaction(txid,url):
|
||||||
_logger.debug(f"{url}:{txid}")
|
_logger.debug(f"{url}:{txid}")
|
||||||
try:
|
try:
|
||||||
w = send_request('post',url+"/searchtx",data=txid.encode('ascii'))
|
w = Willexecutors.send_request('post',url+"/searchtx",data=txid.encode('ascii'))
|
||||||
return w
|
return w
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_logger.error(f"error contacting {url} for checking txs {e}")
|
_logger.error(f"error contacting {url} for checking txs {e}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user