forked from bitshares/gwallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.cpp
185 lines (160 loc) · 6.75 KB
/
commands.cpp
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "../include/panels/commands.hpp"
#include "../include/panels/wallet.hpp"
#include "../include/panels/cli.hpp"
Commands::Commands(GWallet* gwallet) : wxPanel()
{
p_GWallet = gwallet;
InitWidgetsFromXRC((wxWindow *)p_GWallet);
}
void Commands::DoSignedTranactionResponse(wxTreeCtrl* response_tree, signed_transaction result)
{
response_tree->ShowScrollbars(wxSHOW_SB_DEFAULT,wxSHOW_SB_NEVER);
const auto root = response_tree->AddRoot(_("Signed Transaction"));
const auto ref_block_num = response_tree->AppendItem(root, _("Reference block number"));
response_tree->AppendItem(ref_block_num, to_string(result.ref_block_num));
const auto ref_block_prefix = response_tree->AppendItem(root, _("Reference block prefix"));
response_tree->AppendItem(ref_block_prefix, to_string(result.ref_block_prefix));
const auto expiration = response_tree->AppendItem(root, _("Expiration"));
response_tree->AppendItem(expiration, result.expiration.to_iso_string());
const auto operations = response_tree->AppendItem(root, _("Operations"));
response_tree->AppendItem(operations, fc::json::to_string(result.operations));
const auto extensions = response_tree->AppendItem(root, _("Extensions"));
response_tree->AppendItem(extensions, fc::json::to_string(result.extensions));
const auto signatures = response_tree->AppendItem(root, _("Signatures"));
response_tree->AppendItem(signatures, fc::json::to_string(result.signatures));
response_tree->ExpandAll();
}
void Commands::Wait()
{
wxBusyCursor wait;
wxTheApp->Yield(true);
}
void Commands::DoGridProperties(wxGrid* grid)
{
grid->EnableDragCell();
grid->EnableDragColMove();
grid->EnableDragColSize();
grid->EnableDragGridSize();
grid->EnableDragRowSize();
}
uint32_t Commands::DoDateToSeconds(wxDatePickerCtrl* date, wxTimePickerCtrl* time)
{
const auto date_value = date->GetValue().ToUTC().GetValue().ToLong()/1000;
const auto time_second = time->GetValue().ToUTC().GetSecond();
const auto time_minute = time->GetValue().ToUTC().GetMinute();
const auto time_hour = time->GetValue().ToUTC().GetHour();
const auto time_value = (time_hour*3600) + (time_minute*60) + time_second;
auto now = wxDateTime::Now().ToUTC().GetValue().ToLong()/1000;
uint32_t seconds = date_value + time_value - now;
return seconds;
}
optional<wxAny> Commands::ValidateAccount(wxSearchCtrl* control)
{
try
{
return p_GWallet->bitshares.wallet_api_ptr->get_account(control->GetValue().ToStdString());
}
catch(const fc::exception& e)
{
p_GWallet->OnError(this, _("Account is invalid"));
control->SetFocus();
return {};
}
}
optional<wxAny> Commands::ValidateAsset(wxSearchCtrl* control)
{
try
{
return p_GWallet->bitshares.wallet_api_ptr->get_asset(control->GetValue().ToStdString());
}
catch(const fc::exception& e)
{
p_GWallet->OnError(this, _("Asset is invalid"));
control->SetFocus();
return {};
}
}
wxAny Commands::ExecuteWalletCommand(string command_string, string account, wxString confirm, bool cli, bool broadcast)
{
wxAny response;
p_GWallet->panels.p_commands->Wait();
const fc::variants line_variants = fc::json::variants_from_string(command_string);
const auto command_name = line_variants[0].get_string();
auto arguments_variants = fc::variants(line_variants.begin()+1,line_variants.end());
if(cli)
{
p_GWallet->panels.p_cli->DoCommand(command_string);
p_GWallet->DoAssets(account);
return {};
}
else
{
// broadcast is always false in the first one
arguments_variants[arguments_variants.size()-1] = false;
try {
auto result_obj = p_GWallet->bitshares.wallet_cli->receive_call(p_GWallet->bitshares.api_id, command_name, arguments_variants);
auto st = result_obj.as<signed_transaction>(GRAPHENE_MAX_NESTED_OBJECTS);
response = st;
if(broadcast) {
wxRichMessageDialog _confirm(this, _("Please double check and confirm operation below"),
confirm, wxNO_DEFAULT | wxYES_NO | wxICON_QUESTION);
_confirm.ShowDetailedText(fc::json::to_pretty_string(st.operations[0]));
if (wxID_YES == _confirm.ShowModal()) {
wxTheApp->Yield(true);
arguments_variants[arguments_variants.size()-1] = true;
result_obj = p_GWallet->bitshares.wallet_cli->receive_call(p_GWallet->bitshares.api_id, command_name, arguments_variants);
p_GWallet->DoAssets(account);
}
else {
return {};
}
st = result_obj.as<signed_transaction>(GRAPHENE_MAX_NESTED_OBJECTS);
response = st;
}
return response;
}
catch (const fc::exception &e) {
p_GWallet->OnError(this, e.to_detail_string());
return {};
}
}
}
template<typename T>
wxAny Commands::ExecuteGetterCommand(string command_string, bool cli, wxString error_message)
{
wxAny response;
p_GWallet->panels.p_commands->Wait();
const fc::variants line_variants = fc::json::variants_from_string(command_string);
const auto command_name = line_variants[0].get_string();
auto arguments_variants = fc::variants( line_variants.begin()+1,line_variants.end());
if(cli)
{
p_GWallet->panels.p_cli->DoCommand(command_string);
return {};
}
else
{
try {
auto result_obj = p_GWallet->bitshares.wallet_cli->receive_call(p_GWallet->bitshares.api_id, command_name,
arguments_variants);
auto casted = result_obj.as<T>(GRAPHENE_MAX_NESTED_OBJECTS);
response = casted;
return response;
}
catch (const fc::exception &e) {
p_GWallet->OnError(this, error_message);
return {};
}
}
}
// needed for linker purposes
template wxAny Commands::ExecuteGetterCommand<asset_object>(string command_string, bool cli, wxString error_message);
template wxAny Commands::ExecuteGetterCommand<account_object>(string command_string, bool cli, wxString error_message);
template wxAny Commands::ExecuteGetterCommand<witness_object>(string command_string, bool cli, wxString error_message);
template wxAny Commands::ExecuteGetterCommand<committee_member_object>(string command_string, bool cli, wxString error_message);
template wxAny Commands::ExecuteGetterCommand<order_book>(string command_string, bool cli, wxString error_message);
template wxAny Commands::ExecuteGetterCommand<fc::variant>(string command_string, bool cli, wxString error_message);
template wxAny Commands::ExecuteGetterCommand<vector<graphene::wallet::operation_detail>>(string command_string, bool cli,
wxString error_message);
template wxAny Commands::ExecuteGetterCommand<map<string, public_key_type>>(string command_string, bool cli,
wxString error_message);