wallet utils
This commit is contained in:
parent
9817546064
commit
b384ac562c
@ -1,6 +1,4 @@
|
||||
#!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
|
||||
@ -12,11 +10,18 @@ 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
|
||||
if tx_fees:
|
||||
json_wallet['will_settings']['baltx_fees']=json_wallet.get('will_settings',{}).get('tx_fees',default_fees)
|
||||
json_wallet['will_settings']['baltx_fees']=tx_fees
|
||||
del json_wallet['will_settings']['tx_fees']
|
||||
return True
|
||||
return False
|
||||
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
|
||||
return have_to_update
|
||||
|
||||
def uninstall_bal(json_wallet):
|
||||
del json_wallet['will_settings']
|
||||
@ -32,6 +37,15 @@ def save(json_wallet,storage):
|
||||
sort_keys=bool(human_readable),
|
||||
cls=MyEncoder,
|
||||
))
|
||||
def read_wallet(path,password=False):
|
||||
storage=WalletStorage(path)
|
||||
if storage.is_encrypted():
|
||||
if password==False:
|
||||
password = getpass.getpass("Enter wallet password: ", stream = None)
|
||||
storage.decrypt(password)
|
||||
data=storage.read()
|
||||
json_wallet=json.loads('['+data+']')[0]
|
||||
return json_wallet
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) <3:
|
||||
@ -43,13 +57,7 @@ if __name__ == '__main__':
|
||||
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)
|
||||
json_wallet = read_wallet(path)
|
||||
have_to_save=False
|
||||
if command == 'fix':
|
||||
have_to_save = fix_will_settings_tx_fees(json_wallet)
|
||||
@ -1,10 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
#this script will help to fix tx_fees wallet bug
|
||||
#also added an uninstall button to remove any bal data from wallet
|
||||
#still very work in progress.
|
||||
#
|
||||
#have to be executed from electrum source code directory in example /home/user/projects/electrum/
|
||||
#
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
@ -14,8 +8,7 @@ from PyQt6.QtWidgets import (QApplication, QMainWindow, QVBoxLayout, QHBoxLayout
|
||||
from PyQt6.QtCore import Qt
|
||||
from electrum.storage import WalletStorage
|
||||
from electrum.util import MyEncoder
|
||||
|
||||
default_fees = 100
|
||||
from bal_wallet_utils import fix_will_settings_tx_fees,uninstall_bal,read_wallet
|
||||
|
||||
class WalletUtilityGUI(QMainWindow):
|
||||
def __init__(self):
|
||||
@ -94,8 +87,8 @@ class WalletUtilityGUI(QMainWindow):
|
||||
file_path, _ = QFileDialog.getOpenFileName(
|
||||
self,
|
||||
"Select Wallet",
|
||||
"",
|
||||
"Electrum Wallet (*.dat)"
|
||||
"*",
|
||||
"Electrum Wallet (*)"
|
||||
)
|
||||
if file_path:
|
||||
self.wallet_path_edit.setText(file_path)
|
||||
@ -110,37 +103,6 @@ class WalletUtilityGUI(QMainWindow):
|
||||
def log_message(self, message):
|
||||
self.output_text.append(message)
|
||||
|
||||
def fix_will_settings_tx_fees(self, 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(self, json_wallet):
|
||||
if 'will_settings' in json_wallet:
|
||||
del json_wallet['will_settings']
|
||||
if 'will' in json_wallet:
|
||||
del json_wallet['will']
|
||||
if 'heirs' in json_wallet:
|
||||
del json_wallet['heirs']
|
||||
return True
|
||||
|
||||
def save_wallet(self, json_wallet, storage):
|
||||
try:
|
||||
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,
|
||||
))
|
||||
return True
|
||||
except Exception as e:
|
||||
self.log_message(f"Save error: {str(e)}")
|
||||
return False
|
||||
|
||||
def fix_wallet(self):
|
||||
self.process_wallet('fix')
|
||||
|
||||
@ -180,24 +142,25 @@ class WalletUtilityGUI(QMainWindow):
|
||||
|
||||
# Read wallet
|
||||
data = storage.read()
|
||||
json_wallet = json.loads(data)
|
||||
json_wallet = json.loads('[' + data + ']')[0]
|
||||
|
||||
have_to_save = False
|
||||
message = ""
|
||||
|
||||
if command == 'fix':
|
||||
have_to_save = self.fix_will_settings_tx_fees(json_wallet)
|
||||
have_to_save = fix_will_settings_tx_fees(json_wallet)
|
||||
message = "Fix applied successfully" if have_to_save else "No fix needed"
|
||||
|
||||
elif command == 'uninstall':
|
||||
have_to_save = self.uninstall_bal(json_wallet)
|
||||
have_to_save = uninstall_bal(json_wallet)
|
||||
message = "BAL uninstalled successfully" if have_to_save else "No BAL settings found to uninstall"
|
||||
|
||||
if have_to_save:
|
||||
if self.save_wallet(json_wallet, storage):
|
||||
try:
|
||||
save_wallet(json_wallet, storage)
|
||||
self.log_message(f"SUCCESS: {message}")
|
||||
else:
|
||||
self.log_message("ERROR: Failed to save wallet")
|
||||
except Exception as e:
|
||||
self.log_message(f"Save error: {str(e)}")
|
||||
else:
|
||||
self.log_message(f"INFO: {message}")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user