black refactor + bugfix

This commit is contained in:
2026-01-04 23:52:53 -04:00
parent 936d4ef467
commit 6cf12eec80
19 changed files with 2907 additions and 4170 deletions

View File

@@ -1,4 +1,4 @@
#!env/bin/python3
#!env/bin/python3
from electrum.storage import WalletStorage
from electrum.util import MyEncoder
import json
@@ -6,49 +6,57 @@ import sys
import getpass
import os
default_fees= 100
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
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)
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
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']
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(
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)
)
)
def read_wallet(path, password=False):
storage = WalletStorage(path)
if storage.is_encrypted():
if password==False:
password = getpass.getpass("Enter wallet password: ", stream = None)
if password == False:
password = getpass.getpass("Enter wallet password: ", stream=None)
storage.decrypt(password)
data=storage.read()
json_wallet=json.loads('['+data+']')[0]
data = storage.read()
json_wallet = json.loads("[" + data + "]")[0]
return json_wallet
if __name__ == '__main__':
if len(sys.argv) <3:
if __name__ == "__main__":
if len(sys.argv) < 3:
print("usage: ./bal_wallet_utils <command> <wallet path>")
print("available commands: uninstall, fix")
exit(1)
@@ -58,12 +66,12 @@ if __name__ == '__main__':
command = sys.argv[1]
path = sys.argv[2]
json_wallet = read_wallet(path)
have_to_save=False
if command == 'fix':
have_to_save = False
if command == "fix":
have_to_save = fix_will_settings_tx_fees(json_wallet)
if command == 'uninstall':
if command == "uninstall":
have_to_save = uninstall_bal(json_wallet)
if have_to_save:
save(json_wallet,storage)
save(json_wallet, storage)
else:
print("nothing to do")