This repository has been archived by the owner on Apr 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
client.gd
112 lines (71 loc) · 3.1 KB
/
client.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
extends Control
const SERVER_LOCALHOST = "127.0.0.1"
const SERVER_L2L_GA = "172.105.148.135"
const PORT = 8382
var invoice_address : String = ""
func _ready() -> void:
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)
$"/root/Net".fast_withdraw_invoice.connect(_on_fast_withdraw_invoice)
$"/root/Net".fast_withdraw_complete.connect(_on_fast_withdraw_complete)
func _on_connected_to_withdrawal_server() -> void:
print("CONNECTED")
$LabelConnectionStatus.text = "Connected"
$ButtonConnect.disabled = true
func _on_disconnected_from_withdrawal_server() -> void:
print("DIS CONNECTED")
$LabelConnectionStatus.text = "Not Connected"
$ButtonConnect.disabled = false
func _on_failed_connect_to_withdrawal_server() -> void:
print("FAILED TO CONNECT")
$LabelConnectionStatus.text = "Not Connected"
$ButtonConnect.disabled = false
func connect_to_withdrawal_server() -> void:
# Create fast withdraw client
var peer = ENetMultiplayerPeer.new()
if $CheckButtonLocalhost.is_pressed():
print("will connect to localhost")
var error = peer.create_client(SERVER_LOCALHOST, PORT)
if error:
print("Error: ", error)
else:
print("will connect to ga")
var error = peer.create_client(SERVER_L2L_GA, PORT)
if error:
print("Error: ", error)
$LabelConnectionStatus.text = "Connecting..."
$ButtonConnect.disabled = true
multiplayer.multiplayer_peer = peer
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! Invoice created:\n"
invoice_text += str("Send ", amount, " L2 coins to ", destination, "\n")
invoice_text += "Once you have paid enter the L2 txid and hit invoice paid"
invoice_address = destination
$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)
var output : String = "Withdraw complete!\n"
output += "Mainchain payout txid:\n" + txid + "\n"
output += "Amount: " + str(amount) + "\n"
output += "Destination: " + destination + "\n"
$LabelComplete.text = output
if multiplayer.multiplayer_peer:
multiplayer.multiplayer_peer.close()
func _on_button_copy_address_pressed() -> void:
DisplayServer.clipboard_set(invoice_address)
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)
func _on_button_request_invoice_pressed() -> void:
# 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()