Skip to content

Commit

Permalink
Merge pull request #110 from LayerTwo-Labs/marc
Browse files Browse the repository at this point in the history
wallet starter files moved to respective sidechain base data dir. display name updates
  • Loading branch information
psztorc authored Aug 13, 2024
2 parents c3966a5 + feee0ae commit 5c4736f
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 15 deletions.
12 changes: 4 additions & 8 deletions chain_providers.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@ slot=0

id="bitnames"
version="0.4.0"
display_name="Bitnames"
display_name="BitNames"
description="Own one username that you use everywhere — replaces DNS, logging in, and email"
repo_url="https://github.com/LayerTwo-Labs/plain-bitnames"
base_download_url="https://releases.drivechain.info/"
download_file_linux="L2-S2-BitNames-latest-x86_64-unknown-linux-gnu.zip"
download_file_mac="L2-S2-BitNames-latest-x86_64-apple-darwin.zip"
download_file_win="L2-S2-BitNames-latest-x86_64-pc-windows-gnu.zip"
download_size_linux=11811153
download_size_linux=7255344
download_size_mac=14265257
download_size_win=10901471
Expand Down Expand Up @@ -100,7 +99,6 @@ base_download_url="https://releases.drivechain.info/"
download_file_linux="L2-S4-BitAssets-latest-x86_64-unknown-linux-gnu.zip"
download_file_mac="L2-S4-BitAssets-latest-x86_64-apple-darwin.zip"
download_file_win="L2-S4-BitAssets-latest-x86_64-pc-windows-gnu.zip"
download_size_linux=11087000
download_size_linux=7049013
download_size_mac=13924786
download_size_win=10693353
Expand All @@ -124,7 +122,7 @@ slot=4

id="zsail"
version="0.4.0"
display_name="zSide"
display_name="Bit-zCash"
description="A zCash clone, for privacy."
repo_url="https://github.com/LayerTwo-Labs/zcash-sidechain"
base_download_url="https://releases.drivechain.info/"
Expand All @@ -141,7 +139,7 @@ base_dir_linux="drivechain_launcher_sidechains/zsail"
base_dir_win="drivechain_launcher_sidechains/ZSail"
base_dir_mac="drivechain_launcher_sidechains/ZSail"
wallet_dir_linux=".zcash-drivechain/regtest/wallet.dat"
wallet_dir_mac="ZcashDrivechain/regtest/wallet.dat"
wallet_dir_mac="ZcashDrivechain/regtest/wallet.dat"
wallet_dir_win=""
binary_zip_path_linux="zsail"
binary_zip_path_mac="ZSail.app/Contents/MacOS/ZSail"
Expand Down Expand Up @@ -171,7 +169,7 @@ base_dir_linux="drivechain_launcher_sidechains/ethsail"
base_dir_mac="drivechain_launcher_sidechains/EthSail"
base_dir_win="drivechain_launcher_sidechains/EthSail"
wallet_dir_linux=".ethereum/keystore"
wallet_dir_mac="Library/Ethereum/keystore"
wallet_dir_mac="Library/Ethereum/keystore"
wallet_dir_win=""
binary_zip_path_linux="ethsail"
binary_zip_path_mac="EthSail.app/Contents/MacOS/EthSail"
Expand All @@ -191,7 +189,6 @@ base_download_url="https://releases.drivechain.info/"
download_file_linux="L2-S9-Thunder-latest-x86_64-unknown-linux-gnu.zip"
download_file_mac="L2-S9-Thunder-latest-x86_64-apple-darwin.zip"
download_file_win="L2-S9-Thunder-latest-x86_64-pc-windows-gnu.zip"
download_size_linux=7663000
download_size_linux=5504188
download_size_mac=8372222
download_size_win=8212946
Expand Down Expand Up @@ -222,7 +219,6 @@ base_download_url="https://releases.drivechain.info/"
download_file_linux="L2-S11-latestCore-linux.zip"
download_file_mac=""
download_file_win=""
download_size_linux=35821141
download_size_linux=284740129
download_size_mac=0
download_size_win=0
Expand Down
96 changes: 96 additions & 0 deletions source/application/show_wallet.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
extends MarginContainer

@onready var show_button: Button = $ShowWallet
var popup_window: Control = null
var wallet_file_path: String

func _ready():
wallet_file_path = OS.get_user_data_dir().path_join("wallet_starters/wallet_master_seed.txt")
show_button.disabled = true
show_button.connect("pressed", Callable(self, "_on_show_wallet_pressed"))

check_wallet_file()
get_tree().connect("files_dropped", Callable(self, "_on_files_dropped"))

func _process(delta):
check_wallet_file()

func check_wallet_file():
var file_exists = FileAccess.file_exists(wallet_file_path)
show_button.disabled = !file_exists

func _on_files_dropped(files, screen):
for file in files:
if file == wallet_file_path:
check_wallet_file()
break

func _on_show_wallet_pressed():
var file = FileAccess.open(wallet_file_path, FileAccess.READ)
if file:
var json_string = file.get_as_text()
file.close()
var json = JSON.new()
var parse_result = json.parse(json_string)
if parse_result == OK:
var seed_data = json.get_data()
if seed_data.has("mnemonic"):
show_popup(seed_data["mnemonic"])
else:
print("Error: Mnemonic not found in wallet file")
else:
print("Error parsing JSON: ", json.get_error_message())
else:
print("Error opening wallet file")

func show_popup(mnemonic: String):
if popup_window != null:
popup_window.queue_free()

popup_window = Panel.new()
popup_window.set_anchors_preset(Control.PRESET_CENTER)
popup_window.custom_minimum_size = Vector2(400, 300)

var stylebox = StyleBoxFlat.new()
stylebox.set_border_width_all(2)
stylebox.border_color = Color.WHITE
stylebox.bg_color = Color(0.15, 0.15, 0.15, 0.9) # Slightly transparent
popup_window.add_theme_stylebox_override("panel", stylebox)

var main_vbox = VBoxContainer.new()
main_vbox.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT, Control.PRESET_MODE_KEEP_SIZE, 10)
popup_window.add_child(main_vbox)

var mnemonic_container = PanelContainer.new()
mnemonic_container.size_flags_vertical = Control.SIZE_EXPAND_FILL
main_vbox.add_child(mnemonic_container)

var mnemonic_label = Label.new()
mnemonic_label.text = mnemonic
mnemonic_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
mnemonic_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
mnemonic_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
mnemonic_container.add_child(mnemonic_label)

var close_button = Button.new()
close_button.text = "Close"
close_button.connect("pressed", Callable(self, "_on_popup_close_pressed"))
main_vbox.add_child(close_button)

# Create a CanvasLayer to ensure the popup is on top
var canvas_layer = CanvasLayer.new()
canvas_layer.layer = 100 # Adjust this value as needed
canvas_layer.add_child(popup_window)

# Add the CanvasLayer to the scene tree
get_tree().root.add_child(canvas_layer)

# Make the popup modal
popup_window.mouse_filter = Control.MOUSE_FILTER_STOP

popup_window.show()

func _on_popup_close_pressed():
if popup_window:
popup_window.get_parent().queue_free() # Remove the CanvasLayer
popup_window = null
12 changes: 11 additions & 1 deletion source/application/wallet_creator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,17 @@ func save_wallet_data():
return

var user_data_dir = OS.get_user_data_dir()
var file = FileAccess.open(user_data_dir.path_join("wallet_starters/wallet_master_seed.txt"), FileAccess.WRITE)
var wallet_starters_dir = user_data_dir.path_join("wallet_starters")
if not DirAccess.dir_exists_absolute(wallet_starters_dir):
var dir = DirAccess.open(user_data_dir)
if dir.make_dir("wallet_starters") != OK:
print("Error: Unable to create wallet_starters directory.")
return

var file = FileAccess.open(wallet_starters_dir.path_join("wallet_master_seed.txt"), FileAccess.WRITE)
if file == null:
print("Error: Unable to open file for writing.")
return
var json_string = JSON.stringify(seed_data)
file.store_string(json_string)
file.close()
Expand Down
117 changes: 116 additions & 1 deletion source/nodes/node_panel/node_panel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func _ready():
if not is_drivechain:
Appstate.connect("drivechain_downloaded", Callable(self, "update_overlay"))
overlay.mouse_filter = Control.MOUSE_FILTER_IGNORE
var font_variation = load("res://assets/fonts/Satoshi-Regular.otf")
var font_variation = load("res://assets/fonts/Cantarell-Regular.ttf")
heading_label.add_theme_font_override("font", font_variation)
description_label.add_theme_font_override("font", font_variation)

Expand Down Expand Up @@ -176,11 +176,126 @@ func _on_cooldown_timer_timeout():

func download():
print("\nStarting download process for: ", chain_provider.id, "\n")

ensure_directories_exist()

var user_data_dir = OS.get_user_data_dir()
var wallet_starters_dir = user_data_dir.path_join("wallet_starters")
var sidechain_base_dir = chain_provider.base_dir

print("Wallet starters directory: ", wallet_starters_dir)
print("Sidechain base directory: ", sidechain_base_dir)

if chain_provider.chain_type == ChainProvider.c_type.MAIN:
handle_mainchain_file(wallet_starters_dir, sidechain_base_dir)
else:
handle_sidechain_file(wallet_starters_dir, sidechain_base_dir)

download_button.set_state(DownloadButton.STATE.DOWNLOADING)

setup_download_requirements()
initiate_download_process()

func handle_mainchain_file(wallet_starters_dir: String, sidechain_base_dir: String):
var mainchain_filename = "mainchain_starter.txt"
var source_path = wallet_starters_dir.path_join(mainchain_filename)
var dest_path = sidechain_base_dir.path_join(mainchain_filename)

print("Checking for mainchain starter file:")
print("Source path: ", source_path)
print("Destination path: ", dest_path)

if not FileAccess.file_exists(dest_path):
if FileAccess.file_exists(source_path):
print("Mainchain starter file found in wallet_starters directory. Moving to sidechain base directory.")
var err = DirAccess.copy_absolute(source_path, dest_path)
if err == OK:
print("Successfully moved mainchain starter file to sidechain base directory.")
else:
print("Failed to move mainchain starter file. Error code: ", err)
else:
print("Mainchain starter file not found in wallet_starters directory.")
print("This may indicate that the wallet has not been set up properly.")
print("Please ensure you have created a wallet and generated the mainchain starter file.")
print("If you have already created a wallet, try regenerating the mainchain starter file.")
list_directory_contents(wallet_starters_dir)
else:
print("Mainchain starter file already exists in sidechain base directory.")

func handle_sidechain_file(wallet_starters_dir: String, sidechain_base_dir: String):
var slot_number = get_sidechain_slot_number()
var sidechain_filename = "sidechain_%s_starter.txt" % slot_number
var source_path = wallet_starters_dir.path_join(sidechain_filename)
var dest_path = sidechain_base_dir.path_join(sidechain_filename)

print("Checking for sidechain starter file:")
print("Source path: ", source_path)
print("Destination path: ", dest_path)

if not FileAccess.file_exists(dest_path):
if FileAccess.file_exists(source_path):
print("Sidechain starter file found in wallet_starters directory. Moving to sidechain base directory.")
var err = DirAccess.copy_absolute(source_path, dest_path)
if err == OK:
print("Successfully moved sidechain starter file to sidechain base directory.")
else:
print("Failed to move sidechain starter file. Error code: ", err)
else:
print("Sidechain starter file not found in wallet_starters directory.")
print("This may indicate that the wallet has not been set up properly.")
print("Please ensure you have created a wallet and generated sidechain starter files.")
print("If you have already created a wallet, try regenerating the sidechain starter files.")
list_directory_contents(wallet_starters_dir)
else:
print("Sidechain starter file already exists in sidechain base directory.")

func get_sidechain_slot_number() -> String:
if chain_provider and "slot" in chain_provider:
var slot = chain_provider.slot
if slot != -1:
return str(slot)

print("Warning: Slot number not found for chain ID: ", chain_provider.id)
return "unknown"

func ensure_directories_exist():
var user_data_dir = OS.get_user_data_dir()
var wallet_starters_dir = user_data_dir.path_join("wallet_starters")

var dir = DirAccess.open(user_data_dir)
if dir:
if not dir.dir_exists("wallet_starters"):
var err = dir.make_dir("wallet_starters")
if err != OK:
print("Failed to create wallet_starters directory. Error code: ", err)
else:
print("Failed to access user data directory")

# Ensure the sidechain base directory exists
if chain_provider:
var err = DirAccess.make_dir_recursive_absolute(chain_provider.base_dir)
if err != OK:
print("Failed to create sidechain base directory. Error code: ", err)

func list_directory_contents(path: String):
var dir = DirAccess.open(path)
if dir:
print("Contents of ", path, ":")
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
if dir.current_is_dir():
print(" [Dir] " + file_name)
else:
print(" [File] " + file_name)
file_name = dir.get_next()
dir.list_dir_end()
else:
print("An error occurred when trying to access the path: ", path)
print("This could be due to permission issues or the directory not existing.")
print("Please check that the following directory exists and is accessible:")
print(path)

func setup_download_requirements():
if download_req != null:
remove_child(download_req)
Expand Down
8 changes: 3 additions & 5 deletions source/nodes/node_panel/node_panel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[ext_resource type="Script" path="res://source/nodes/node_panel/node_panel.gd" id="1_ijj0w"]
[ext_resource type="PackedScene" uid="uid://cjfcxi77d8pjt" path="res://source/nodes/node_panel/download.tscn" id="2_ubul7"]
[ext_resource type="Texture2D" uid="uid://drrrqh5w6tl8t" path="res://assets/images/icons8-settings.svg" id="4_15yd3"]
[ext_resource type="FontFile" uid="uid://b1w37357tl3er" path="res://assets/fonts/Cantarell-Bold.ttf" id="4_h86ci"]

[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_bl3lx"]
Expand All @@ -23,9 +24,6 @@ expand_margin_top = 8.0
expand_margin_right = 8.0
expand_margin_bottom = 8.0

[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_orksi"]
load_path = "res://.godot/imported/icons8-settings.svg-3abab0a1cc1e22f71f96e60e0862595e.ctex"

[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_aqe83"]
load_path = "res://.godot/imported/trash-svgrepo-com(1).svg-0f38edd909f1c2b1144dc0fc23313836.ctex"

Expand Down Expand Up @@ -94,12 +92,12 @@ theme_override_font_sizes/font_size = 28
text = "NodePanel"

[node name="Settings" type="Button" parent="MarginContainer/Container/Header"]
texture_filter = 4
texture_filter = 3
custom_minimum_size = Vector2(0, 32)
layout_mode = 2
size_flags_vertical = 4
focus_mode = 0
icon = SubResource("CompressedTexture2D_orksi")
icon = ExtResource("4_15yd3")

[node name="Delete" type="Button" parent="MarginContainer/Container/Header"]
texture_filter = 4
Expand Down

0 comments on commit 5c4736f

Please sign in to comment.