Skip to content
This repository has been archived by the owner on Nov 10, 2024. It is now read-only.

Commit

Permalink
Wallet : merge utxos
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzygarmyz committed Jul 16, 2024
1 parent 659f78e commit 8189b9f
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 45 deletions.
2 changes: 1 addition & 1 deletion nodez/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def main():
app.app_id = "com.nodez"
app.home_page = "https://www.getbtcz.com"
app.author = "BTCZCommunity"
app.version = "1.0.4"
app.version = "1.0.5"
return app


Expand Down
5 changes: 2 additions & 3 deletions nodez/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,8 @@ def z_importWallet(self, backup_file):
)


def z_mergeToaAdress(self, list_addresses, address, tx_fee, limit):
addresses_json = json.dumps(list_addresses)
def z_mergeToaAdress(self, list_addresses, address, tx_fee):
return self.make_rpc_request(
"z_mergetoaddress",
[addresses_json, address, tx_fee, limit]
[list_addresses, address, tx_fee]
)
4 changes: 2 additions & 2 deletions nodez/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ async def z_importWallet(self, backup_file):
return await self._run_command(command)


async def z_mergeToaAdress(self, list_addresses, address, tx_fee, limit):
async def z_mergeToaAdress(self, list_addresses, address, tx_fee):
addresses_json = json.dumps(list_addresses)
command = f'{self.bitcoinz_cli_file} z_mergetoaddress {addresses_json} {address} {tx_fee} {limit}'
command = f'{self.bitcoinz_cli_file} z_mergetoaddress {addresses_json} {address} {tx_fee}'
return await self._run_command(command)
33 changes: 28 additions & 5 deletions nodez/config/options/divers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ def __init__(
"exportdir :",
style=LabelStyle.exportdir_txt
)
self.zmergetoaddress_switch = Switch(
"zmergetoaddress",
style=SwitchStyle.switch,
on_change=lambda switch: self.update_config_switch(
switch, "zmergetoaddress"
)
)
self.genproclimit_input = NumberInput(
step=1,
min=-1,
Expand Down Expand Up @@ -123,6 +130,12 @@ def __init__(
style=ButtonStyle.info_button,
on_press=self.display_info
)
self.zmergetoaddress_info = Button(
"?",
id="zmergetoaddress",
style=ButtonStyle.info_button,
on_press=self.display_info
)
self.exportdir_button = Button(
"...",
style=ButtonStyle.exportdir_button,
Expand Down Expand Up @@ -150,10 +163,12 @@ def __init__(
style=BoxStyle.divers_row2_box
)
self.divers_switch_box.add(
self.gen_switch
self.gen_switch,
self.zmergetoaddress_switch
)
self.divers_button_box.add(
self.gen_info
self.gen_info,
self.zmergetoaddress_info
)
self.divers_button2_box.add(
self.genproclimit_info,
Expand Down Expand Up @@ -188,11 +203,14 @@ def __init__(


async def read_file_lines(self, widget):

gen = None
genproclimit = None
equihashsolver = None
keypool = None
exportdir = None
zmergetoaddress = None

with open(self.file_path, 'r') as file:
lines = file.readlines()
for line in lines:
Expand All @@ -208,9 +226,11 @@ async def read_file_lines(self, widget):
elif key == "keypool":
keypool = value
elif key == "exportdir":
exportdir = value
exportdir = value
elif key == "zmergetoaddress":
zmergetoaddress = value
await self.update_values(
gen, genproclimit, equihashsolver, keypool, exportdir
gen, genproclimit, equihashsolver, keypool, exportdir, zmergetoaddress
)


Expand All @@ -231,9 +251,10 @@ async def on_confirm(window, path):

async def update_values(
self,
gen, genproclimit, equihashsolver, keypool, exportdir
gen, genproclimit, equihashsolver, keypool, exportdir, zmergetoaddress
):
self.gen_switch.value = (gen == "1")
self.zmergetoaddress_switch.value = (zmergetoaddress == "1")
self.genproclimit_input.value = genproclimit
self.equihashsolver_input.value = equihashsolver
self.keypool_input.value = keypool
Expand Down Expand Up @@ -309,6 +330,8 @@ def display_info(self, button):
info_message = "Pre-generate this many public/private key pairs, so wallet backups will be valid for both prior transactions and several dozen future transactions."
elif button.id == "exportdir":
info_message = ""
elif button.id == "zmergetoaddress":
info_message = "Enable z_mergetoaddress function"
self.app.main_window.info_dialog(
"Info",
info_message
Expand Down
Binary file added nodez/icones/loading_blocks.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added nodez/icones/scan_utxos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions nodez/main_window/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StartNode(Window):
def __init__(self, app:App, local_button):
super().__init__(
title="Loading...",
size=(280, 90),
size=(250, 300),
resizable=False,
minimizable=False,
closable=False
Expand All @@ -40,6 +40,9 @@ def __init__(self, app:App, local_button):
self.local_button = local_button
self.bitcoinzd_file = os.path.join(self.app.paths.data, "bitcoinzd.exe")

self.loading_image = ImageView(
"icones/loading_blocks.gif"
)
self.starting_txt = Label(
"Starting Node...",
style=LabelStyle.starting_txt
Expand All @@ -51,13 +54,10 @@ def __init__(self, app:App, local_button):
self.main_box = Box(
style=BoxStyle.start_main_box
)
self.bitcoinz_coin = ImageView(
("resources/btcz_coin1.gif")
)
self.main_box.add(
self.starting_txt,
self.divider_top,
self.bitcoinz_coin
self.loading_image
)
self.content = self.main_box
self.app.add_background_task(
Expand Down
3 changes: 2 additions & 1 deletion nodez/main_window/styles/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class BoxStyle():

start_main_box = Pack(
direction = COLUMN,
alignment = CENTER
alignment = CENTER,
background_color = BLACK
)

download_main_box = Pack(
Expand Down
2 changes: 1 addition & 1 deletion nodez/main_window/styles/divider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class DividerStyle():

start_divider_top = Pack(
padding_bottom = 5
padding_bottom = 10
)

download_divider_top = Pack(
Expand Down
7 changes: 4 additions & 3 deletions nodez/main_window/styles/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ class LabelStyle():
)

starting_txt = Pack(
font_family = MONOSPACE,
font_weight = BOLD,
text_align = CENTER,
padding_top = 5,
padding_bottom = 5
padding_top = 20,
padding_bottom = 10,
background_color = BLACK,
color = WHITE
)

download_txt = Pack(
Expand Down
Binary file modified nodez/resources/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 96 additions & 19 deletions nodez/wallet/receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,33 @@ def __init__(self, app:App, window_button, explorer_button):
"Merge multiple UTXOs into a single UTXO or note.",
style=LabelStyle.merge_info_txt
)
self.merge_result_txt = Label(
"- Opreration Result -",
style=LabelStyle.merge_result_txt
self.operation_status_txt = Label(
"- Operation Result -",
style=LabelStyle.operation_status_txt
)
self.remaining_utxos = Label(
"remainingUTXOs :",
style=LabelStyle.status_txt
)
self.remaining_value = Label(
"remainingValue :",
style=LabelStyle.status_txt
)
self.merging_utxos = Label(
"mergingUTXOs :",
style=LabelStyle.status_txt
)
self.merging_value = Label(
"mergingValue :",
style=LabelStyle.status_txt
)
self.operation_id = Label(
"OperationID :",
style=LabelStyle.status_txt
)
self.operation_id_output = TextInput(
readonly=True,
style=InputStyle.operation_id_output
)
self.merge_select_address_txt = Label(
"Merge to :",
Expand All @@ -161,7 +185,7 @@ def __init__(self, app:App, window_button, explorer_button):
style=InputStyle.merge_fee_input
)
self.scan_button = Button(
"Scan UTXOs",
icon=Icon("icones/scan_utxos"),
enabled= True,
style=ButtonStyle.scan_button,
on_press=self.scan_utxos
Expand Down Expand Up @@ -270,7 +294,13 @@ async def display_window(self):
self.scan_button
)
self.merge_reslut_box.add(
self.merge_result_txt
self.operation_status_txt,
self.remaining_utxos,
self.remaining_value,
self.merging_utxos,
self.merging_value,
self.operation_id,
self.operation_id_output
)
self.merge_manage_box.add(
self.merge_operation_box,
Expand All @@ -292,25 +322,31 @@ async def scan_utxos(self, button):
self.scan_button.enabled = False
if os.path.exists(db_path):
scan_addresses = self.client.listAddressgroupPings()
account_addresses = self.client.getAddressesByAccount()
else:
account_addresses = await self.command.getAddressesByAccount()
account_addresses = json.loads(account_addresses)

scan_addresses = await self.command.listAddressgroupPings()
scan_addresses = json.loads(scan_addresses)

if scan_addresses:
flattened_addresses = [address_info for address_info_list in scan_addresses for address_info in address_info_list]
filtered_addresses = [address_info for address_info in flattened_addresses if address_info[1] != 0]
sorted_addresses = sorted(filtered_addresses, key=lambda x: x[1], reverse=True)
self.number_addresses = len(sorted_addresses)
if self.number_addresses == 0:
self.scan_button.enabled = True
return
self.total_amount = sum(address_info[1] for address_info in sorted_addresses)

addresses_only = [address_info[0] for address_info in sorted_addresses]
self.json_addresses = json.dumps(addresses_only)
if account_addresses:
main_addresees = [address_info for address_info in account_addresses]
addresses_only = [address for address in addresses_only if address not in main_addresees]
self.number_addresses = len(addresses_only)
if self.number_addresses == 0:
self.scan_button.enabled = True
await self.display_merge_options()
return
else:
self.scan_button.enabled = True
self.json_addresses = addresses_only
await self.display_merge_options()


async def display_merge_options(self):
Expand Down Expand Up @@ -357,20 +393,30 @@ async def start_merge_opertation(self, address, tx_fee):
operation = self.client.z_mergeToaAdress(
self.json_addresses,
address,
tx_fee,
self.number_addresses
tx_fee
)
else:
self.json_addresses = json.dumps(self.json_addresses)
operation = await self.command.z_mergeToaAdress(
self.json_addresses,
address,
tx_fee,
self.number_addresses
tx_fee
)
if operation:
operation = json.loads(operation)
if operation is not None:
print(operation)
remainingUTXOs = operation.get("remainingUTXOs")
remainingTransparentValue = operation.get("remainingTransparentValue")
mergingUTXOs = operation.get("mergingUTXOs")
mergingTransparentValue = operation.get("mergingTransparentValue")
operationID = operation.get("opid")
await self.update_operation_status(
remainingUTXOs,
remainingTransparentValue,
mergingUTXOs,
mergingTransparentValue,
operationID
)
else:
self.error_dialog(
"Error...",
Expand All @@ -379,7 +425,35 @@ async def start_merge_opertation(self, address, tx_fee):
await asyncio.sleep(1)
self.cancel_button.enabled = True
self.merge_button.enabled = True




async def update_operation_status(self, remainingUTXOs, remainingTransparentValue, mergingUTXOs, mergingTransparentValue, operationID):
self.remaining_utxos.text = f"remainingUTXOs : {remainingUTXOs}"
self.remaining_value.text = f"remainingValue : {self.system.format_balance(remainingTransparentValue)}"
self.merging_utxos.text = f"mergingUTXOs : {mergingUTXOs}"
self.merging_value.text = f"mergingValue : {self.system.format_balance(mergingTransparentValue)}"
self.operation_id_output.value = f"OperationID : {operationID}"
config_path = self.app.paths.config
db_path = os.path.join(config_path, 'config.db')
while True:
if os.path.exists(db_path):
operation_status = self.client.z_getOperationStatus(operationID)
else:
operation_status = await self.command.z_getOperationStatus(operationID)
operation_status = json.loads(operation_status)
if operation_status is not None:
status = operation_status[0].get('status')
if status == "success":
await asyncio.sleep(3)
self.remaining_utxos.text = f"remainingUTXOs :"
self.remaining_value.text = f"remainingValue :"
self.merging_utxos.text = f"mergingUTXOs :"
self.merging_value.text = f"mergingValue :"
self.operation_id_output.value = ""
await self.cancel_merge_utxos(None)
return
await asyncio.sleep(5)


async def cancel_merge_utxos(self, button):
Expand Down Expand Up @@ -658,7 +732,7 @@ async def on_confirm(window, path):
self.open_file_dialog(
title="Select file...",
file_types=["*"],
initial_directory=self.app.paths.data,
initial_directory=self.app.paths.config,
multiple_select=False,
on_result=on_confirm
)
Expand Down Expand Up @@ -726,16 +800,19 @@ async def generate_new_address(self, button):

async def update_addresses_list(self, address):
self.select_address.items.clear()
self.merge_select_address.items.clear()

if self.transaction_mode == "transparent":
transparent_address = await self.get_transparent_addresses()
self.select_address.style.color = YELLOW
self.select_address.items = transparent_address
self.merge_select_address.items = transparent_address

elif self.transaction_mode == "shielded":
shielded_address = await self.get_shielded_addresses()
self.select_address.style.color = CYAN
self.select_address.items = shielded_address
self.merge_select_address.items = shielded_address
if address is not None:
self.select_address.value = self.select_address.items.find(address)

Expand Down
Loading

0 comments on commit 8189b9f

Please sign in to comment.