-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.rb
135 lines (105 loc) · 3.75 KB
/
gui.rb
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
require "fox16"
class MainWindow < Fox::FXMainWindow
include Fox
attr_reader :key
def initialize app, cheapeth
super app, "CheapEth - EthRegistry", :width=>450, :height=>200
@cheapeth = cheapeth
@reg = EthRegistry.new @cheapeth.rpc_client, $contract_addr, nil
@key = nil
@main_frame = FXVerticalFrame.new self, :opts => LAYOUT_FILL
@chain_frame = FXVerticalFrame.new @main_frame, :opts => LAYOUT_FILL
@account_frame = FXVerticalFrame.new @main_frame, :opts => LAYOUT_FILL_X
@reg_frame = FXHorizontalFrame.new @main_frame, :opts => LAYOUT_FILL_X
@block_label = FXLabel.new @chain_frame, "Current block: #{cheapeth.get_current_block}", :padBottom => 0
@gas_label = FXLabel.new @chain_frame, "Gas price: #{cheapeth.gas_price}", :padTop => 0
@account_button = FXButton.new @account_frame, "Load account"
@address_label = FXLabel.new @account_frame, "Address: 0x", :padBottom => 0
@balance_label = FXLabel.new @account_frame, "Balance: 0.0", :padTop => 0, :padBottom => 0
@nonce_label = FXLabel.new @account_frame, "Nonce: 0.0", :padTop => 0
@account_button.connect(SEL_COMMAND) {
load_key
}
@reg_button = FXButton.new @reg_frame, "Register"
@get_button = FXButton.new @reg_frame, "Get entry"
@get_own_button = FXButton.new @reg_frame, "Get own entry"
@reg_button.connect(SEL_COMMAND) {
register
}
@get_button.connect(SEL_COMMAND) {
get
}
@get_own_button.connect(SEL_COMMAND) {
get_own
}
end
def create
super
show(Fox::PLACEMENT_SCREEN)
end
protected
def output_entry entry
if entry != ""
FXMessageBox.information self, MBOX_OK, "Result", entry
else
FXMessageBox.error self, MBOX_OK, "Not found", "Entry not found or empty"
end
end
def get
addr_dialog = FXInputDialog.new self, "Input address", "Address:"
res = addr_dialog.execute
if res == 0
FXMessageBox.warning self, MBOX_OK, "Error", "Error: No input"
return false
end
key_dialog = FXInputDialog.new self, "Input key", "Key:"
res = key_dialog.execute
if res == 0
FXMessageBox.warning self, MBOX_OK, "Error", "Error: No input"
return false
end
output_entry @reg.get(addr_dialog.text, key_dialog.text)
end
def get_own
if ! @key
FXMessageBox.warning self, MBOX_OK, "Error", "Error: Load account first"
else
key_dialog = FXInputDialog.new self, "Input key", "Key:"
res = key_dialog.execute
if res == 0
FXMessageBox.warning self, MBOX_OK, "Error", "Error: No input"
return false
end
output_entry @reg.get(@key.address, key_dialog.text)
end
end
def register
if ! @key
FXMessageBox.warning self, MBOX_OK, "Error", "Error: Load account first"
else
key_dialog = FXInputDialog.new self, "Input key", "Key:"
key_dialog.execute
value_dialog = FXInputDialog.new self, "Input value", "Value:"
value_dialog.execute
tx = @reg.register key_dialog.text, value_dialog.text
puts "txid: #{tx.id}"
end
end
def load_key
dialog = FXInputDialog.new self, "Private key", "Private key:"
dialog.execute
priv_key = dialog.text
if priv_key != ""
Thread.new {
@account_button.disable
@key = Eth::Key.new priv: priv_key
puts "load account #{@key.address}"
@reg = EthRegistry.new @cheapeth.rpc_client, $contract_addr, @key
@address_label.text = "Address: #{@key.address}"
@balance_label.text = "Balance: #{@cheapeth.get_balance_of @key.address}"
@nonce_label.text = "Nonce: #{@cheapeth.get_nonce_of @key.address}"
@account_button.enable
}
end
end
end