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

Commit

Permalink
Test fast withdraw request
Browse files Browse the repository at this point in the history
  • Loading branch information
CryptAxe committed Mar 19, 2024
1 parent 9c9ef6c commit f2d0867
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 9 deletions.
36 changes: 33 additions & 3 deletions client.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,41 @@ func _ready() -> void:
var peer = ENetMultiplayerPeer.new()
peer.create_client(SERVER_1, PORT)
multiplayer.multiplayer_peer = peer

$"/root/Net".fast_withdraw_invoice.connect(_on_fast_withdraw_invoice)
$"/root/Net".fast_withdraw_complete.connect(_on_fast_withdraw_complete)

print("Client started. Connected to ID: ", peer.get_unique_id())
print("Is it a server?: ", multiplayer.is_server())
print("Client started. Peer ID: ", peer.get_unique_id())


func _on_button_test_pressed() -> void:
# Send fast withdraw request only to server
$"/root/Net".request_fast_withdraw.rpc_id(1, 21.0)
$"/root/Net".request_fast_withdraw.rpc_id(1, $SpinBoxAmount.value, $LineEditMainchainAddress.text)


func _on_button_test_complete_pressed() -> void:
# Tell the server we paid
var txid : String = $LineEditTXID.text
$"/root/Net".invoice_paid.rpc_id(1, txid, $SpinBoxAmount.value, $LineEditMainchainAddress.text)


func _on_fast_withdraw_invoice(amount : float, destination: String) -> void:
print("Received fast withdraw invoice!")
print("Amount: ", amount)
print("Destination: ", destination)

var invoice_text = "Fast withdraw request received!\n"
invoice_text += str("Send ", amount, " BTC to ", destination, "\n")
invoice_text += "Then enter the L2 txid and hit invoice paid"

$LabelInvoice.text = invoice_text


func _on_fast_withdraw_complete(txid: String, amount : float, destination: String) -> void:
print("Fast withdraw complete!")
print("TxID: ", txid)
print("Amount: ", amount)
print("Destination: ", destination)

$LabelComplete.text = str("Withdraw complete: ", txid)

65 changes: 62 additions & 3 deletions client_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,68 @@ script = ExtResource("1_4itd0")

[node name="ButtonTest" type="Button" parent="."]
layout_mode = 0
offset_right = 8.0
offset_bottom = 8.0
text = "Test
offset_left = 15.0
offset_top = 47.0
offset_right = 303.0
offset_bottom = 78.0
text = "Request fast withdrawal test invoice"

[node name="LineEditMainchainAddress" type="LineEdit" parent="."]
layout_mode = 0
offset_left = 14.0
offset_top = 10.0
offset_right = 429.0
offset_bottom = 41.0
placeholder_text = "Enter mainchain address"

[node name="LabelInvoice" type="Label" parent="."]
layout_mode = 0
offset_left = 22.0
offset_top = 90.0
offset_right = 62.0
offset_bottom = 113.0

[node name="ButtonTestComplete" type="Button" parent="."]
layout_mode = 0
offset_left = 16.0
offset_top = 221.0
offset_right = 117.0
offset_bottom = 252.0
text = "Invoice Paid"

[node name="LineEditTXID" type="LineEdit" parent="."]
layout_mode = 0
offset_left = 16.0
offset_top = 182.0
offset_right = 620.0
offset_bottom = 213.0
placeholder_text = "Enter L2 payment txid"

[node name="LabelComplete" type="Label" parent="."]
layout_mode = 0
offset_left = 19.0
offset_top = 264.0
offset_right = 550.0
offset_bottom = 287.0

[node name="SpinBoxAmount" type="SpinBox" parent="."]
layout_mode = 0
offset_left = 620.0
offset_top = 9.0
offset_right = 776.0
offset_bottom = 40.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 = 14.0
offset_right = 608.0
offset_bottom = 37.0
text = "Amount to withdraw:
"

[connection signal="pressed" from="ButtonTest" to="." method="_on_button_test_pressed"]
[connection signal="pressed" from="ButtonTestComplete" to="." method="_on_button_test_complete_pressed"]
42 changes: 39 additions & 3 deletions net.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
extends Node

# Server signals
signal fast_withdraw_requested(amount: float)
signal fast_withdraw_requested(peer : int, amount: float, destination: String)
signal fast_withdraw_invoice_paid(peer : int, 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
@rpc("any_peer", "call_remote", "reliable")
func request_fast_withdraw(amount : float) -> void:
func request_fast_withdraw(amount : float, destination : String) -> void:
print("Received fast withdrawal request")
print("Amount: ", amount)
print("Destination: ", destination)
print("Peer: ", multiplayer.get_remote_sender_id())

fast_withdraw_requested.emit(amount)
fast_withdraw_requested.emit(multiplayer.get_remote_sender_id(), amount, destination)


@rpc("authority", "call_remote", "reliable")
func receive_fast_withdraw_invoice(amount : float, destination : String) -> void:
print("Received fast withdrawal invoice")
print("Amount: ", amount)
print("Destination: ", destination)
print("Peer: ", multiplayer.get_remote_sender_id())

fast_withdraw_invoice.emit(amount, destination)


@rpc("any_peer", "call_remote", "reliable")
func invoice_paid(txid: String, amount : float, destination : String) -> void:
print("Paid fast withdrawal invoice")
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)


@rpc("authority", "call_remote", "reliable")
func withdraw_complete(txid: String, amount : float, destination : String) -> void:
print("Fast withdraw completed!")
print("Amount: ", amount)
print("Destination: ", destination)
print("Txid: ", txid)

fast_withdraw_complete.emit(txid, amount, destination)

0 comments on commit f2d0867

Please sign in to comment.