#!env/bin/python3 #same as qt but for command line, useful if you are going to fix various wallet #also easier to read the code from electrum.storage import WalletStorage from electrum.util import MyEncoder import json import sys import getpass import os default_fees= 100 def fix_will_settings_tx_fees(json_wallet): tx_fees = json_wallet.get('will_settings',{}).get('tx_fees',False) if tx_fees: json_wallet['will_settings']['baltx_fees']=json_wallet.get('will_settings',{}).get('tx_fees',default_fees) del json_wallet['will_settings']['tx_fees'] return True return False def uninstall_bal(json_wallet): 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( json_wallet, indent=4 if human_readable else None, sort_keys=bool(human_readable), cls=MyEncoder, )) if __name__ == '__main__': if len(sys.argv) <3: print("usage: ./bal_wallet_utils ") print("available commands: uninstall, fix") exit(1) if not os.path.exists(sys.argv[2]): print("Error: wallet not found") exit(1) command = sys.argv[1] path = sys.argv[2] storage=WalletStorage(path) if storage.is_encrypted(): password = getpass.getpass("Enter wallet password: ", stream = None) storage.decrypt(password) data=storage.read() json_wallet=json.loads(data) have_to_save=False if command == 'fix': have_to_save = fix_will_settings_tx_fees(json_wallet) if command == 'uninstall': have_to_save = uninstall_bal(json_wallet) if have_to_save: save(json_wallet,storage) else: print("nothing to do")