From debf61b66fd0a4b2c5f61088f2b3a876b0736116 Mon Sep 17 00:00:00 2001 From: CryptAxe Date: Sat, 20 Jul 2024 15:45:22 -0700 Subject: [PATCH 1/3] Fast withdraw: Auto connect server & show status --- ui/components/fast_withdraw/fast_withdraw.gd | 38 ++++---- .../fast_withdraw/fast_withdraw.tscn | 86 ++++++++----------- 2 files changed, 60 insertions(+), 64 deletions(-) diff --git a/ui/components/fast_withdraw/fast_withdraw.gd b/ui/components/fast_withdraw/fast_withdraw.gd index c4d379b..0237316 100644 --- a/ui/components/fast_withdraw/fast_withdraw.gd +++ b/ui/components/fast_withdraw/fast_withdraw.gd @@ -1,14 +1,17 @@ extends Control -const SERVER_LOCALHOST = "127.0.0.1" -const SERVER_L2L_GA = "172.105.148.135" - -const PORT = 8382 +const SERVER_LOCALHOST : String = "127.0.0.1" +const SERVER_L2L_GA : String = "172.105.148.135" +const PORT : int = 8382 var invoice_address : String = "" +var connected_to_server : bool = false +signal fast_withdraw_server_connection_status_changed func _ready() -> void: + $LabelConnectionStatus.visible = false + multiplayer.connected_to_server.connect(_on_connected_to_withdrawal_server) multiplayer.connection_failed.connect(_on_failed_connect_to_withdrawal_server) multiplayer.server_disconnected.connect(_on_disconnected_from_withdrawal_server) @@ -23,16 +26,18 @@ func _on_connected_to_withdrawal_server() -> void: $LabelConnectionStatus.text = "Connected" - $ButtonConnect.disabled = true + connected_to_server = true + fast_withdraw_server_connection_status_changed.emit() func _on_disconnected_from_withdrawal_server() -> void: if $"/root/Net".print_debug_net: print("Disonnected to fast withdraw server") - $LabelConnectionStatus.text = "Not Connected" - - $ButtonConnect.disabled = false + $LabelConnectionStatus.text = "Disconnected" + $LabelInvoice.text = "" + connected_to_server = false + fast_withdraw_server_connection_status_changed.emit() func _on_failed_connect_to_withdrawal_server() -> void: @@ -40,8 +45,9 @@ func _on_failed_connect_to_withdrawal_server() -> void: print("Failed to connect to fast withdraw server") $LabelConnectionStatus.text = "Not Connected" - - $ButtonConnect.disabled = false + + connected_to_server = false + fast_withdraw_server_connection_status_changed.emit() func connect_to_withdrawal_server() -> void: @@ -63,8 +69,6 @@ func connect_to_withdrawal_server() -> void: $LabelConnectionStatus.text = "Connecting..." - $ButtonConnect.disabled = true - multiplayer.multiplayer_peer = peer @@ -111,9 +115,11 @@ func _on_button_invoice_paid_pressed() -> void: func _on_button_request_invoice_pressed() -> void: + # Establish connection with fast withdraw server + connect_to_withdrawal_server() + $LabelConnectionStatus.visible = true + + await fast_withdraw_server_connection_status_changed + # Send fast withdraw request only to server $"/root/Net".request_fast_withdraw.rpc_id(1, $SpinBoxAmount.value, $LineEditMainchainAddress.text) - - -func _on_button_connect_pressed() -> void: - connect_to_withdrawal_server() diff --git a/ui/components/fast_withdraw/fast_withdraw.tscn b/ui/components/fast_withdraw/fast_withdraw.tscn index 8ba350d..578c62e 100644 --- a/ui/components/fast_withdraw/fast_withdraw.tscn +++ b/ui/components/fast_withdraw/fast_withdraw.tscn @@ -13,41 +13,41 @@ script = ExtResource("1_4itd0") [node name="ButtonRequestInvoice" type="Button" parent="."] layout_mode = 0 -offset_left = 15.0 -offset_top = 104.0 -offset_right = 303.0 -offset_bottom = 135.0 +offset_left = 11.0 +offset_top = 54.0 +offset_right = 299.0 +offset_bottom = 85.0 text = "Request fast withdrawal test invoice" [node name="LineEditMainchainAddress" type="LineEdit" parent="."] layout_mode = 0 -offset_left = 14.0 -offset_top = 67.0 -offset_right = 429.0 -offset_bottom = 98.0 +offset_left = 10.0 +offset_top = 12.0 +offset_right = 425.0 +offset_bottom = 43.0 placeholder_text = "Enter mainchain address" [node name="LabelInvoice" type="Label" parent="."] layout_mode = 0 -offset_left = 22.0 -offset_top = 147.0 -offset_right = 62.0 -offset_bottom = 170.0 +offset_left = 17.0 +offset_top = 100.0 +offset_right = 57.0 +offset_bottom = 123.0 [node name="ButtonInvoicePaid" type="Button" parent="."] layout_mode = 0 offset_left = 16.0 -offset_top = 278.0 +offset_top = 228.0 offset_right = 117.0 -offset_bottom = 309.0 +offset_bottom = 259.0 text = "Invoice Paid" [node name="LineEditTXID" type="LineEdit" parent="."] layout_mode = 0 offset_left = 16.0 -offset_top = 239.0 +offset_top = 190.0 offset_right = 620.0 -offset_bottom = 270.0 +offset_bottom = 221.0 placeholder_text = "Enter L2 payment txid" [node name="LabelComplete" type="Label" parent="."] @@ -59,60 +59,50 @@ offset_bottom = 344.0 [node name="SpinBoxAmount" type="SpinBox" parent="."] layout_mode = 0 -offset_left = 620.0 -offset_top = 66.0 -offset_right = 776.0 -offset_bottom = 97.0 +offset_left = 614.0 +offset_top = 14.0 +offset_right = 770.0 +offset_bottom = 45.0 min_value = 1.0 value = 1.0 suffix = "BTC" [node name="Label" type="Label" parent="."] layout_mode = 0 -offset_left = 443.0 -offset_top = 71.0 -offset_right = 608.0 -offset_bottom = 94.0 +offset_left = 441.0 +offset_top = 17.0 +offset_right = 606.0 +offset_bottom = 40.0 text = "Amount to withdraw: " [node name="ButtonCopyAddress" type="Button" parent="."] layout_mode = 0 -offset_left = 499.0 -offset_top = 176.0 -offset_right = 612.0 -offset_bottom = 207.0 +offset_left = 441.0 +offset_top = 111.0 +offset_right = 554.0 +offset_bottom = 142.0 text = "Copy Address " [node name="CheckButtonLocalhost" type="CheckButton" parent="."] layout_mode = 0 -offset_left = 268.0 -offset_top = 24.0 -offset_right = 535.0 -offset_bottom = 55.0 -text = "Use localhost (debug) server" - -[node name="ButtonConnect" type="Button" parent="."] -layout_mode = 0 -offset_left = 15.0 -offset_top = 21.0 -offset_right = 85.0 -offset_bottom = 52.0 -text = "connect -" +offset_left = 865.0 +offset_top = 4.0 +offset_right = 1016.0 +offset_bottom = 35.0 +text = "Debug server" [node name="LabelConnectionStatus" type="Label" parent="."] layout_mode = 0 -offset_left = 100.0 -offset_top = 27.0 -offset_right = 216.0 -offset_bottom = 50.0 +offset_left = 337.0 +offset_top = 61.0 +offset_right = 453.0 +offset_bottom = 84.0 text = "Not Connected" -[connection signal="pressed" from="ButtonRequestInvoice" to="." method="_on_button_request_invoice_pressed"] [connection signal="pressed" from="ButtonRequestInvoice" to="." method="_on_button_test_pressed"] +[connection signal="pressed" from="ButtonRequestInvoice" to="." method="_on_button_request_invoice_pressed"] [connection signal="pressed" from="ButtonInvoicePaid" to="." method="_on_button_invoice_paid_pressed"] [connection signal="pressed" from="ButtonInvoicePaid" to="." method="_on_button_test_complete_pressed"] [connection signal="pressed" from="ButtonCopyAddress" to="." method="_on_button_copy_address_pressed"] -[connection signal="pressed" from="ButtonConnect" to="." method="_on_button_connect_pressed"] From 100960d30ff4797aaf8f36852c3c1d69167ee5f6 Mon Sep 17 00:00:00 2001 From: CryptAxe Date: Sat, 20 Jul 2024 17:28:02 -0700 Subject: [PATCH 2/3] Fast Withdraw: multi chain support --- net.gd | 20 +++-- ui/components/fast_withdraw/fast_withdraw.gd | 14 +++- .../fast_withdraw/fast_withdraw.tscn | 75 ++++++++++++------- 3 files changed, 73 insertions(+), 36 deletions(-) diff --git a/net.gd b/net.gd index 54be3dd..b2400fa 100644 --- a/net.gd +++ b/net.gd @@ -3,26 +3,29 @@ extends Node # Enable this for debug printing in net.gd and fast_withdraw.gd var print_debug_net : bool = false -# TODO rename this and move it on the server as well? +const FAST_WITHDRAW_CHAIN_TESTCHAIN : String = "Testchain" +const FAST_WITHDRAW_CHAIN_THUNDER : String = "Thunder" +const FAST_WITHDRAW_CHAIN_ZSIDE : String = "ZSide" # Server signals -signal fast_withdraw_requested(peer : int, amount: float, destination: String) -signal fast_withdraw_invoice_paid(peer : int, txid: String, amount: float, destination: String) +signal fast_withdraw_requested(peer : int, chain_name : String, amount: float, destination: String) +signal fast_withdraw_invoice_paid(peer : int, chain_name : String, txid: String, amount: float, destination: String) # Client signals signal fast_withdraw_invoice(amount: float, destination: String) signal fast_withdraw_complete(txid: String, amount: float, destination: String) -# TODO add params: SC #, MC fee, MC destination +# TODO add params: MC fee @rpc("any_peer", "call_remote", "reliable") -func request_fast_withdraw(amount : float, destination : String) -> void: +func request_fast_withdraw(amount : float, chain_name: String, destination : String) -> void: if print_debug_net: print("Received fast withdrawal request") + print("Chain: ", chain_name) print("Amount: ", amount) print("Destination: ", destination) print("Peer: ", multiplayer.get_remote_sender_id()) - fast_withdraw_requested.emit(multiplayer.get_remote_sender_id(), amount, destination) + fast_withdraw_requested.emit(multiplayer.get_remote_sender_id(), chain_name, amount, destination) @rpc("authority", "call_remote", "reliable") @@ -37,15 +40,16 @@ func receive_fast_withdraw_invoice(amount : float, destination : String) -> void @rpc("any_peer", "call_remote", "reliable") -func invoice_paid(txid: String, amount : float, destination : String) -> void: +func invoice_paid(chain_name : String, txid: String, amount : float, destination : String) -> void: if print_debug_net: print("Paid fast withdrawal invoice") + print("Chain: ", chain_name) print("Amount: ", amount) print("Destination: ", destination) print("Txid: ", txid) print("Peer: ", multiplayer.get_remote_sender_id()) - fast_withdraw_invoice_paid.emit(multiplayer.get_remote_sender_id(), txid, amount, destination) + fast_withdraw_invoice_paid.emit(multiplayer.get_remote_sender_id(), chain_name, txid, amount, destination) @rpc("authority", "call_remote", "reliable") diff --git a/ui/components/fast_withdraw/fast_withdraw.gd b/ui/components/fast_withdraw/fast_withdraw.gd index 0237316..e22540f 100644 --- a/ui/components/fast_withdraw/fast_withdraw.gd +++ b/ui/components/fast_withdraw/fast_withdraw.gd @@ -6,12 +6,15 @@ const PORT : int = 8382 var invoice_address : String = "" var connected_to_server : bool = false +var selected_chain : String = "" signal fast_withdraw_server_connection_status_changed func _ready() -> void: $LabelConnectionStatus.visible = false + selected_chain = $"/root/Net".FAST_WITHDRAW_CHAIN_TESTCHAIN + multiplayer.connected_to_server.connect(_on_connected_to_withdrawal_server) multiplayer.connection_failed.connect(_on_failed_connect_to_withdrawal_server) multiplayer.server_disconnected.connect(_on_disconnected_from_withdrawal_server) @@ -32,7 +35,7 @@ func _on_connected_to_withdrawal_server() -> void: func _on_disconnected_from_withdrawal_server() -> void: if $"/root/Net".print_debug_net: - print("Disonnected to fast withdraw server") + print("Disonnected from fast withdraw server") $LabelConnectionStatus.text = "Disconnected" $LabelInvoice.text = "" @@ -111,7 +114,7 @@ func _on_button_copy_address_pressed() -> void: func _on_button_invoice_paid_pressed() -> void: # Tell the server we paid var txid : String = $LineEditTXID.text - $"/root/Net".invoice_paid.rpc_id(1, txid, $SpinBoxAmount.value, $LineEditMainchainAddress.text) + $"/root/Net".invoice_paid.rpc_id(1, selected_chain, txid, $SpinBoxAmount.value, $LineEditMainchainAddress.text) func _on_button_request_invoice_pressed() -> void: @@ -122,4 +125,9 @@ func _on_button_request_invoice_pressed() -> void: await fast_withdraw_server_connection_status_changed # Send fast withdraw request only to server - $"/root/Net".request_fast_withdraw.rpc_id(1, $SpinBoxAmount.value, $LineEditMainchainAddress.text) + $"/root/Net".request_fast_withdraw.rpc_id(1, $SpinBoxAmount.value, selected_chain, $LineEditMainchainAddress.text) + + +func _on_chain_selection_button_item_selected(index): + var selection_index = $ChainSelectionButton.get_selected() + selected_chain = $ChainSelectionButton.get_item_text(selection_index) diff --git a/ui/components/fast_withdraw/fast_withdraw.tscn b/ui/components/fast_withdraw/fast_withdraw.tscn index 578c62e..2541479 100644 --- a/ui/components/fast_withdraw/fast_withdraw.tscn +++ b/ui/components/fast_withdraw/fast_withdraw.tscn @@ -13,10 +13,10 @@ script = ExtResource("1_4itd0") [node name="ButtonRequestInvoice" type="Button" parent="."] layout_mode = 0 -offset_left = 11.0 -offset_top = 54.0 -offset_right = 299.0 -offset_bottom = 85.0 +offset_left = 156.0 +offset_top = 79.0 +offset_right = 470.0 +offset_bottom = 114.0 text = "Request fast withdrawal test invoice" [node name="LineEditMainchainAddress" type="LineEdit" parent="."] @@ -29,33 +29,33 @@ placeholder_text = "Enter mainchain address" [node name="LabelInvoice" type="Label" parent="."] layout_mode = 0 -offset_left = 17.0 -offset_top = 100.0 -offset_right = 57.0 -offset_bottom = 123.0 +offset_left = 18.0 +offset_top = 135.0 +offset_right = 58.0 +offset_bottom = 158.0 [node name="ButtonInvoicePaid" type="Button" parent="."] layout_mode = 0 offset_left = 16.0 -offset_top = 228.0 -offset_right = 117.0 -offset_bottom = 259.0 +offset_top = 298.0 +offset_right = 126.0 +offset_bottom = 333.0 text = "Invoice Paid" [node name="LineEditTXID" type="LineEdit" parent="."] layout_mode = 0 offset_left = 16.0 -offset_top = 190.0 +offset_top = 259.0 offset_right = 620.0 -offset_bottom = 221.0 +offset_bottom = 290.0 placeholder_text = "Enter L2 payment txid" [node name="LabelComplete" type="Label" parent="."] layout_mode = 0 -offset_left = 19.0 -offset_top = 321.0 -offset_right = 550.0 -offset_bottom = 344.0 +offset_left = 17.0 +offset_top = 341.0 +offset_right = 548.0 +offset_bottom = 364.0 [node name="SpinBoxAmount" type="SpinBox" parent="."] layout_mode = 0 @@ -78,10 +78,10 @@ text = "Amount to withdraw: [node name="ButtonCopyAddress" type="Button" parent="."] layout_mode = 0 -offset_left = 441.0 -offset_top = 111.0 -offset_right = 554.0 -offset_bottom = 142.0 +offset_left = 247.0 +offset_top = 164.0 +offset_right = 372.0 +offset_bottom = 199.0 text = "Copy Address " @@ -95,14 +95,39 @@ text = "Debug server" [node name="LabelConnectionStatus" type="Label" parent="."] layout_mode = 0 -offset_left = 337.0 -offset_top = 61.0 -offset_right = 453.0 -offset_bottom = 84.0 +offset_left = 488.0 +offset_top = 88.0 +offset_right = 604.0 +offset_bottom = 111.0 text = "Not Connected" +[node name="Label2" type="Label" parent="."] +layout_mode = 0 +offset_left = 14.0 +offset_top = 51.0 +offset_right = 198.0 +offset_bottom = 72.0 +text = "Sidechain to withdraw from: +" + +[node name="ChainSelectionButton" type="OptionButton" parent="."] +layout_mode = 0 +offset_left = 16.0 +offset_top = 79.0 +offset_right = 40.0 +offset_bottom = 99.0 +item_count = 3 +selected = 0 +popup/item_0/text = "Testchain" +popup/item_0/id = 0 +popup/item_1/text = "Thunder" +popup/item_1/id = 1 +popup/item_2/text = "ZSide" +popup/item_2/id = 2 + [connection signal="pressed" from="ButtonRequestInvoice" to="." method="_on_button_test_pressed"] [connection signal="pressed" from="ButtonRequestInvoice" to="." method="_on_button_request_invoice_pressed"] [connection signal="pressed" from="ButtonInvoicePaid" to="." method="_on_button_invoice_paid_pressed"] [connection signal="pressed" from="ButtonInvoicePaid" to="." method="_on_button_test_complete_pressed"] [connection signal="pressed" from="ButtonCopyAddress" to="." method="_on_button_copy_address_pressed"] +[connection signal="item_selected" from="ChainSelectionButton" to="." method="_on_chain_selection_button_item_selected"] From 887e10a745ca142ec29f3dd20ac7ace684cc112f Mon Sep 17 00:00:00 2001 From: CryptAxe Date: Sun, 21 Jul 2024 16:02:50 -0700 Subject: [PATCH 3/3] Fast withdraw: move buttons --- ui/components/fast_withdraw/fast_withdraw.tscn | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/components/fast_withdraw/fast_withdraw.tscn b/ui/components/fast_withdraw/fast_withdraw.tscn index 2541479..46c2641 100644 --- a/ui/components/fast_withdraw/fast_withdraw.tscn +++ b/ui/components/fast_withdraw/fast_withdraw.tscn @@ -78,10 +78,10 @@ text = "Amount to withdraw: [node name="ButtonCopyAddress" type="Button" parent="."] layout_mode = 0 -offset_left = 247.0 -offset_top = 164.0 -offset_right = 372.0 -offset_bottom = 199.0 +offset_left = 390.0 +offset_top = 181.0 +offset_right = 515.0 +offset_bottom = 216.0 text = "Copy Address " @@ -125,8 +125,8 @@ popup/item_1/id = 1 popup/item_2/text = "ZSide" popup/item_2/id = 2 -[connection signal="pressed" from="ButtonRequestInvoice" to="." method="_on_button_test_pressed"] [connection signal="pressed" from="ButtonRequestInvoice" to="." method="_on_button_request_invoice_pressed"] +[connection signal="pressed" from="ButtonRequestInvoice" to="." method="_on_button_test_pressed"] [connection signal="pressed" from="ButtonInvoicePaid" to="." method="_on_button_invoice_paid_pressed"] [connection signal="pressed" from="ButtonInvoicePaid" to="." method="_on_button_test_complete_pressed"] [connection signal="pressed" from="ButtonCopyAddress" to="." method="_on_button_copy_address_pressed"]