black refactor + bugfix
This commit is contained in:
183
bal.py
183
bal.py
@@ -1,124 +1,139 @@
|
||||
import random
|
||||
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.logging import get_logger
|
||||
from electrum.plugin import BasePlugin
|
||||
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):
|
||||
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)
|
||||
|
||||
|
||||
|
||||
def get_will(x):
|
||||
try:
|
||||
x['tx']=tx_from_any(x['tx'])
|
||||
x["tx"] = tx_from_any(x["tx"])
|
||||
except Exception as e:
|
||||
raise e
|
||||
return x
|
||||
|
||||
class BalConfig():
|
||||
|
||||
class BalConfig:
|
||||
def __init__(self, config, name, default):
|
||||
self.config = config
|
||||
self.name = name
|
||||
self.default = default
|
||||
|
||||
def get(self,default=None):
|
||||
def get(self, default=None):
|
||||
v = self.config.get(self.name, default)
|
||||
if v is None:
|
||||
if not default is None:
|
||||
if default is not None:
|
||||
v = default
|
||||
else:
|
||||
v = self.default
|
||||
return v
|
||||
|
||||
def set(self,value,save=True):
|
||||
self.config.set_key(self.name,value,save=save)
|
||||
|
||||
def set(self, value, save=True):
|
||||
self.config.set_key(self.name, value, save=save)
|
||||
|
||||
|
||||
class BalPlugin(BasePlugin):
|
||||
LATEST_VERSION = '1'
|
||||
KNOWN_VERSIONS = ('0', '1')
|
||||
LATEST_VERSION = "1"
|
||||
KNOWN_VERSIONS = ("0", "1")
|
||||
assert LATEST_VERSION in KNOWN_VERSIONS
|
||||
|
||||
def version():
|
||||
try:
|
||||
f=""
|
||||
with open("VERSION","r") as f:
|
||||
f = str(f.readline())
|
||||
f = ""
|
||||
with open("VERSION", "r") as fi:
|
||||
f = str(fi.readline())
|
||||
return f
|
||||
except:
|
||||
return "unknown"
|
||||
|
||||
SIZE = (159, 97)
|
||||
|
||||
def __init__(self, parent, config, name):
|
||||
print("init bal_plugin")
|
||||
self.logger = get_logger(__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]
|
||||
zipfile="/".join(self.plugin_dir.split("/")[:-1])
|
||||
#print("real path",os.path.realpath(__file__))
|
||||
#self.logger.info(self.base_dir)
|
||||
#print("base_dir:", self.base_dir)
|
||||
#print("suca:",zipfile)
|
||||
#print("plugin_dir:", self.plugin_dir)
|
||||
zipfile = "/".join(self.plugin_dir.split("/")[:-1])
|
||||
# print("real path",os.path.realpath(__file__))
|
||||
# self.logger.info(self.base_dir)
|
||||
# print("base_dir:", self.base_dir)
|
||||
# print("suca:",zipfile)
|
||||
# print("plugin_dir:", self.plugin_dir)
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, zipfile)
|
||||
#print("sono state listate?")
|
||||
# print("sono state listate?")
|
||||
self.parent = parent
|
||||
self.config = config
|
||||
self.name = name
|
||||
|
||||
self.ASK_BROADCAST = BalConfig(config, "bal_ask_broadcast", True)
|
||||
self.BROADCAST = BalConfig(config, "bal_broadcast", True)
|
||||
self.LOCKTIME_TIME = BalConfig(config, "bal_locktime_time", 90)
|
||||
self.LOCKTIME_BLOCKS = BalConfig(config, "bal_locktime_blocks", 144*90)
|
||||
self.LOCKTIMEDELTA_TIME = BalConfig(config, "bal_locktimedelta_time", 7)
|
||||
self.LOCKTIMEDELTA_BLOCKS = BalConfig(config, "bal_locktimedelta_blocks", 144*7)
|
||||
self.ENABLE_MULTIVERSE = BalConfig(config, "bal_enable_multiverse", False)
|
||||
self.TX_FEES = BalConfig(config, "bal_tx_fees", 100)
|
||||
self.INVALIDATE = BalConfig(config, "bal_invalidate", True)
|
||||
self.ASK_INVALIDATE = BalConfig(config, "bal_ask_invalidate", True)
|
||||
self.PREVIEW = BalConfig(config, "bal_preview", True)
|
||||
self.SAVE_TXS = BalConfig(config, "bal_save_txs", True)
|
||||
self.WILLEXECUTORS = BalConfig(config, "bal_willexecutors", True)
|
||||
self.PING_WILLEXECUTORS = BalConfig(config, "bal_ping_willexecutors", True)
|
||||
self.ASK_PING_WILLEXECUTORS = BalConfig(config, "bal_ask_ping_willexecutors", True)
|
||||
self.NO_WILLEXECUTOR = BalConfig(config, "bal_no_willexecutor", True)
|
||||
self.HIDE_REPLACED = BalConfig(config, "bal_hide_replaced", True)
|
||||
self.HIDE_INVALIDATED = BalConfig(config, "bal_hide_invalidated", True)
|
||||
self.ALLOW_REPUSH = BalConfig(config, "bal_allow_repush", True)
|
||||
self.FIRST_EXECUTION = BalConfig(config, "bal_first_execution", True)
|
||||
self.WILLEXECUTORS = BalConfig(config, "bal_willexecutors", {
|
||||
"mainnet": {
|
||||
'https://we.bitcoin-after.life': {
|
||||
"base_fee": 100000,
|
||||
"status": "New",
|
||||
"info":"Bitcoin After Life Will Executor",
|
||||
"address":"bcrt1qa5cntu4hgadw8zd3n6sq2nzjy34sxdtd9u0gp7",
|
||||
"selected":True
|
||||
}
|
||||
}
|
||||
})
|
||||
self.WILL_SETTINGS = BalConfig(config, "bal_will_settings", {
|
||||
'baltx_fees':100,
|
||||
'threshold':'180d',
|
||||
'locktime':'1y',
|
||||
})
|
||||
self.ASK_BROADCAST = BalConfig(config, "bal_ask_broadcast", True)
|
||||
self.BROADCAST = BalConfig(config, "bal_broadcast", True)
|
||||
self.LOCKTIME_TIME = BalConfig(config, "bal_locktime_time", 90)
|
||||
self.LOCKTIME_BLOCKS = BalConfig(config, "bal_locktime_blocks", 144 * 90)
|
||||
self.LOCKTIMEDELTA_TIME = BalConfig(config, "bal_locktimedelta_time", 7)
|
||||
self.LOCKTIMEDELTA_BLOCKS = BalConfig(
|
||||
config, "bal_locktimedelta_blocks", 144 * 7
|
||||
)
|
||||
self.ENABLE_MULTIVERSE = BalConfig(config, "bal_enable_multiverse", False)
|
||||
self.TX_FEES = BalConfig(config, "bal_tx_fees", 100)
|
||||
self.INVALIDATE = BalConfig(config, "bal_invalidate", True)
|
||||
self.ASK_INVALIDATE = BalConfig(config, "bal_ask_invalidate", True)
|
||||
self.PREVIEW = BalConfig(config, "bal_preview", True)
|
||||
self.SAVE_TXS = BalConfig(config, "bal_save_txs", True)
|
||||
self.WILLEXECUTORS = BalConfig(config, "bal_willexecutors", True)
|
||||
self.PING_WILLEXECUTORS = BalConfig(config, "bal_ping_willexecutors", True)
|
||||
self.ASK_PING_WILLEXECUTORS = BalConfig(
|
||||
config, "bal_ask_ping_willexecutors", True
|
||||
)
|
||||
self.NO_WILLEXECUTOR = BalConfig(config, "bal_no_willexecutor", True)
|
||||
self.HIDE_REPLACED = BalConfig(config, "bal_hide_replaced", True)
|
||||
self.HIDE_INVALIDATED = BalConfig(config, "bal_hide_invalidated", True)
|
||||
self.ALLOW_REPUSH = BalConfig(config, "bal_allow_repush", True)
|
||||
self.FIRST_EXECUTION = BalConfig(config, "bal_first_execution", True)
|
||||
self.WILLEXECUTORS = BalConfig(
|
||||
config,
|
||||
"bal_willexecutors",
|
||||
{
|
||||
"mainnet": {
|
||||
"https://we.bitcoin-after.life": {
|
||||
"base_fee": 100000,
|
||||
"status": "New",
|
||||
"info": "Bitcoin After Life Will Executor",
|
||||
"address": "bcrt1qa5cntu4hgadw8zd3n6sq2nzjy34sxdtd9u0gp7",
|
||||
"selected": True,
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
self.WILL_SETTINGS = BalConfig(
|
||||
config,
|
||||
"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()
|
||||
self._hide_replaced= self.HIDE_REPLACED.get()
|
||||
|
||||
|
||||
def resource_path(self,*parts):
|
||||
def resource_path(self, *parts):
|
||||
return os.path.join(self.plugin_dir, *parts)
|
||||
|
||||
def hide_invalidated(self):
|
||||
@@ -129,20 +144,16 @@ class BalPlugin(BasePlugin):
|
||||
self._hide_replaced = not self._hide_replaced
|
||||
self.HIDE_REPLACED.set(self._hide_replaced)
|
||||
|
||||
def validate_will_settings(self,will_settings):
|
||||
#print(type(will_settings))
|
||||
#print(will_settings.get('baltx_fees',1),1)
|
||||
if int(will_settings.get('baltx_fees',1))<1:
|
||||
will_settings['baltx_fees']=1
|
||||
if not will_settings.get('threshold'):
|
||||
will_settings['threshold']='180d'
|
||||
if not will_settings.get('locktime')=='':
|
||||
will_settings['locktime']='1y'
|
||||
def validate_will_settings(self, will_settings):
|
||||
# print(type(will_settings))
|
||||
# print(will_settings.get('baltx_fees',1),1)
|
||||
if int(will_settings.get("baltx_fees", 1)) < 1:
|
||||
will_settings["baltx_fees"] = 1
|
||||
if not will_settings.get("threshold"):
|
||||
will_settings["threshold"] = "180d"
|
||||
if not will_settings.get("locktime") == "":
|
||||
will_settings["locktime"] = "1y"
|
||||
return will_settings
|
||||
|
||||
def default_will_settings(self):
|
||||
return {
|
||||
'baltx_fees':100,
|
||||
'threshold':'180d',
|
||||
'locktime':'1y'
|
||||
}
|
||||
return {"baltx_fees": 100, "threshold": "180d", "locktime": "1y"}
|
||||
|
||||
Reference in New Issue
Block a user