import random import os from electrum.plugin import BasePlugin from electrum import json_db from electrum.transaction import tx_from_any import os json_db.register_dict('heirs', tuple, None) json_db.register_dict('will', lambda x: get_will(x), None) json_db.register_dict('will_settings', lambda x:x, None) from electrum.logging import get_logger def get_will(x): try: x['tx']=tx_from_any(x['tx']) except Exception as e: raise e return x class BalConfig(): def __init__(self, config, name, default): self.config = config self.name = name self.default = default def get(self,default=None): v = self.config.get(self.name, default) if v is None: if not default is None: v = default else: v = v.default return v 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') assert LATEST_VERSION in KNOWN_VERSIONS def version(): try: f="" with open("VERSION","r") as f: f = str(f.readline()) return f except: return "unknown" SIZE = (159, 97) def __init__(self, parent, config, name): self.logger = get_logger(__name__) BasePlugin.__init__(self, parent, config, name) self.base_dir = os.path.join(config.electrum_path(), 'bal') self.plugin_dir = os.path.split(os.path.realpath(__file__))[0] self.logger.info(self.base_dir) 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.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", { 'tx_fees':100, 'threshold':'180d', 'locktime':'1y', }) self._hide_invalidated= self.HIDE_INVALIDATED.get() self._hide_replaced= self.HIDE_REPLACED.get() def resource_path(self,*parts): return os.path.join(self.plugin_dir, *parts) def hide_invalidated(self): self._hide_invalidated = not self._hide_invalidated self.HIDE_INVALIDATED.set(self._hide_invalidated) def hide_replaced(self): self._hide_replaced = not self._hide_replaced self.HIDE_REPLACED.set(self._hide_replaced) def validate_will_settings(self,will_settings): if int(will_settings.get('tx_fees',1))<1: will_settings['tx_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