This repository was archived by the owner on Dec 5, 2020. It is now read-only.
forked from jonasschnelli/dbb-app
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathdbb_gui.h
More file actions
428 lines (383 loc) · 17 KB
/
dbb_gui.h
File metadata and controls
428 lines (383 loc) · 17 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
// Copyright (c) 2015 Jonas Schnelli
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DBBDAEMON_QT_DAEMONGUI_H
#define DBBDAEMON_QT_DAEMONGUI_H
#include <QMainWindow>
#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include <QPropertyAnimation>
#include <QStandardItemModel>
#include <QUuid>
#include <functional>
#include <thread>
#include <mutex>
#ifdef WIN32
#include <windows.h>
#include "mingw/mingw.mutex.h"
#include "mingw/mingw.condition_variable.h"
#include "mingw/mingw.thread.h"
#endif
#include "config/_dbb-config.h"
#include "dbb_app.h"
#include "dbb_configdata.h"
#include "update.h"
#include "dbb_wallet.h"
#include "dbb_comserver.h"
#ifdef DBB_USE_MULTIMEDIA
#include "qrcodescanner.h"
#endif
#include "backupdialog.h"
#include "getaddressdialog.h"
#include "paymentproposal.h"
#include "signconfirmationdialog.h"
#include "verificationdialog.h"
#include "settingsdialog.h"
#define WALLET_POLL_TIME 25000
namespace Ui
{
class MainWindow;
}
static bool DBB_USE_TESTNET = false;
//DBB USB response types
typedef enum DBB_RESPONSE_TYPE {
DBB_RESPONSE_TYPE_UNKNOWN,
DBB_RESPONSE_TYPE_PASSWORD,
DBB_RESPONSE_TYPE_XPUB_MS_MASTER,
DBB_RESPONSE_TYPE_XPUB_MS_REQUEST,
DBB_RESPONSE_TYPE_XPUB_SW_MASTER,
DBB_RESPONSE_TYPE_XPUB_SW_REQUEST,
DBB_RESPONSE_TYPE_CREATE_WALLET,
DBB_RESPONSE_TYPE_INFO,
DBB_RESPONSE_TYPE_ERASE,
DBB_RESPONSE_TYPE_LED_BLINK,
DBB_RESPONSE_TYPE_ADD_BACKUP,
DBB_RESPONSE_TYPE_LIST_BACKUP,
DBB_RESPONSE_TYPE_ERASE_BACKUP,
DBB_RESPONSE_TYPE_VERIFY_BACKUP,
DBB_RESPONSE_TYPE_RANDOM_NUM,
DBB_RESPONSE_TYPE_DEVICE_LOCK,
DBB_RESPONSE_TYPE_VERIFYPASS_ECDH,
DBB_RESPONSE_TYPE_XPUB_VERIFY,
DBB_RESPONSE_TYPE_XPUB_GET_ADDRESS,
DBB_RESPONSE_TYPE_BOOTLOADER_UNLOCK,
DBB_RESPONSE_TYPE_BOOTLOADER_LOCK,
DBB_RESPONSE_TYPE_SET_DEVICE_NAME,
DBB_RESPONSE_TYPE_SET_DEVICE_NAME_CREATE,
DBB_RESPONSE_TYPE_SET_DEVICE_NAME_RECREATE,
DBB_RESPONSE_TYPE_RESET_PASSWORD,
DBB_RESPONSE_TYPE_RESET_U2F,
} dbb_response_type_t;
typedef enum DBB_ADDRESS_STYLE {
DBB_ADDRESS_STYLE_MULTISIG_1OF1,
DBB_ADDRESS_STYLE_P2PKH
} dbb_address_style_t;
typedef enum DBB_PROCESS_INFOLAYER_STYLE {
DBB_PROCESS_INFOLAYER_STYLE_NO_INFO,
DBB_PROCESS_INFOLAYER_STYLE_TOUCHBUTTON,
DBB_PROCESS_INFOLAYER_STYLE_REPLUG,
DBB_PROCESS_INFOLAYER_CONFIRM_WITH_BUTTON,
DBB_PROCESS_INFOLAYER_CONFIRM_WITH_BUTTON_WARNING,
DBB_PROCESS_INFOLAYER_UPGRADE_FIRMWARE
} dbb_process_infolayer_style_t;
typedef enum DBB_LED_BLINK_MODE {
DBB_LED_BLINK_MODE_BLINK,
DBB_LED_BLINK_MODE_ABORT
} dbb_led_blink_mode_t;
class DBBDaemonGui : public QMainWindow
{
Q_OBJECT
public:
explicit DBBDaemonGui(const QString& uri, QWidget* parent = 0);
~DBBDaemonGui();
public slots:
signals:
//emitted when the device state has chaned (connected / disconnected)
void deviceStateHasChanged(bool state, int deviceType);
//emitted when the network activity has changed
void changeNetLoading(bool state);
//emitted when the DBB could generate a xpub
void XPubForCopayWalletIsAvailable(int walletIndex);
//emitted when the request xpub key is available
void RequestXPubKeyForCopayWalletIsAvailable(int walletIndex);
//emitted when a response from the DBB is available
void gotResponse(const UniValue& response, dbb_cmd_execution_status_t status, dbb_response_type_t tag, int subtag = 0);
//emitted when a copay getwallet response is available
void getWalletsResponseAvailable(DBBWallet* wallet, bool walletsAvailable, const std::string& walletsResponse, bool initialJoin = false);
//emitted when a copay wallet history response is available
void getTransactionHistoryAvailable(DBBWallet* wallet, bool historyAvailable, const UniValue& historyResponse);
//emitted when a payment proposal and a given signatures should be verified
void shouldVerifySigning(DBBWallet*, const UniValue& paymentProposal, int actionType, const std::string& signature);
//emitted when the verification dialog shoud hide
void shouldHideVerificationInfo();
//emitted when signatures for a payment proposal are available
void signedProposalAvailable(DBBWallet*, const UniValue& proposal, const std::vector<std::string>& vSigs);
//emitted when a wallet needs update
void shouldUpdateWallet(DBBWallet*);
//emitted when a new receiving address is available
void walletAddressIsAvailable(DBBWallet *, const std::string &newAddress, const std::string &keypath);
//emitted when a new receiving address is available
void paymentProposalUpdated(DBBWallet *, const UniValue &proposal);
//emitted when the firmeware upgrade thread is done
void firmwareThreadDone(bool);
//emitted when the firmeware upgrade thread is done
void shouldUpdateModalInfo(const QString& info);
//emitted when the modal view should be hidden from another thread
void shouldHideModalInfo();
void shouldShowAlert(const QString& title, const QString& text);
//emitted when a tx proposal was successfully created
void createTxProposalDone(DBBWallet *, const QString &tfaCode, const UniValue &proposal);
//emitted when a wallet join process was done
void joinCopayWalletDone(DBBWallet *);
void comServerIncommingMessage(const QString& msg);
void reloadGetinfo();
private:
QString *openedWithBitcoinURI;
Ui::MainWindow* ui;
DBBUpdateManager *updateManager;
BackupDialog* backupDialog;
GetAddressDialog* getAddressDialog;
VerificationDialog* verificationDialog;
SettingsDialog* settingsDialog;
QTimer *walletUpdateTimer;
QStandardItemModel *transactionTableModel;
QLabel* statusBarLabelLeft;
QLabel* statusBarLabelRight;
QPushButton* statusBarButton;
QPushButton* statusBarVDeviceIcon;
QPushButton* statusBarNetIcon;
QPushButton* statusBarUSBIcon;
bool upgradeFirmwareState; //set to true if we expect a firmware upgrade
bool shouldKeepBootloaderState; //set to true if we expect a firmware upgrade
QString firmwareFileToUse;
bool sdcardWarned;
bool processCommand;
bool deviceConnected;
bool cachedWalletAvailableState;
bool initialWalletSeeding; //state if initial wallet is in seed
bool cachedDeviceLock;
bool deviceReadyToInteract;
bool touchButtonInfo;
QPropertyAnimation* loginScreenIndicatorOpacityAnimation;
QPropertyAnimation* netActivityAnimation;
QPropertyAnimation* usbActivityAnimation;
QPropertyAnimation* verificationActivityAnimation;
QString deviceName;
QString tempNewDeviceName;
std::string sessionPassword; //TODO: needs secure space / mem locking
std::string sessionPasswordDuringChangeProcess; //TODO: needs secure space / mem locking
std::vector<DBBWallet*> vMultisigWallets; //!<immutable pointers to the multisig wallet objects (currently only 1)
DBBWallet* singleWallet; //!<immutable pointer to the single wallet object
PaymentProposal* currentPaymentProposalWidget; //!< UI element for showing a payment proposal
SignConfirmationDialog* signConfirmationDialog; //!< UI element for showing a payment proposal
DBB::DBBConfigdata *configData; //!< configuration data model
DBBComServer *comServer;
std::time_t lastPing;
std::atomic<bool> netLoaded;
std::atomic<int> netErrCount;
#ifdef DBB_USE_MULTIMEDIA
DBBQRCodeScanner *qrCodeScanner; //!< QRCode scanner object
#endif
void createMenuBar();
//== Plug / Unplug ==
//! gets called when the device was sucessfully unlocked (password accepted)
void deviceIsReadyToInteract();
//!enabled or disabled the tabbar
void setTabbarEnabled(bool status);
//!enable or disable dbb/usb/loading indication in the UI
void setLoading(bool status);
//!resets device infos (in case of a disconnect)
void resetInfos();
//! updates the ui after the current device state
void uiUpdateDeviceState(int deviceType=-1);
//== UI ==
void setActiveArrow(int pos);
//!gets called when the password was accepted by the DBB hardware
void passwordAccepted();
//!hides the enter password form
void hideSessionPasswordView();
//!update overview flags (wallet / lock, etc)
void updateOverviewFlags(bool walletAvailable, bool lockAvailable, bool loading);
//== USB ==
//wrapper for the DBB USB command action
bool executeCommandWrapper(const std::string& cmd, const dbb_process_infolayer_style_t layerstyle, std::function<void(const std::string&, dbb_cmd_execution_status_t status)> cmdFinished, const QString& modaltext = "");
// get a new backup filename
std::string getBackupString();
//== Copay Wallet ==
void hidePaymentProposalsWidget();
void executeNetUpdateWallet(DBBWallet* wallet, bool showLoading, std::function<void(bool, std::string&)> cmdFinished);
bool multisigWalletIsUpdating;
bool singleWalletIsUpdating;
std::vector<std::pair<std::time_t, std::thread*> > netThreads;
std::recursive_mutex cs_walletObjects;
std::thread *fwUpgradeThread;
private slots:
//!main callback when the device gets connected/disconnected
void changeConnectedState(bool state, int deviceType);
//!enable or disable net/loading indication in the UI
void setNetLoading(bool status);
//!slot for a periodical update timer
void updateTimerFired();
void pingComServer();
//== UI ==
//general proxy function to show an alert;
void showAlert(const QString& title, const QString& errorOut, bool critical = false);
void mainOverviewButtonClicked();
void mainMultisigButtonClicked();
void mainReceiveButtonClicked();
void mainSendButtonClicked();
void mainSettingsButtonClicked();
void gotoOverviewPage();
void gotoReceivePage();
void gotoSendCoinsPage();
void gotoMultisigPage();
void gotoSettingsPage();
//!shows info about the smartphone verification
void showEchoVerification(DBBWallet*, const UniValue& response, int actionType, const std::string& echoStr);
//!proceed with the signing (2nd step)
void proceedVerification(const QString& twoFACode, void *ptr, const UniValue& data, int actionType);
//!hides verification info
void hideVerificationInfo();
//!gets called when the user hits enter in the "enter password form"
void passwordProvided();
//!slot to ask for the current session password
void askForSessionPassword();
//!show general modal info
void showModalInfo(const QString &info, int helpType = 0);
void updateModalInfo(const QString &info);
//!show QRCode in modal view
void updateModalWithQRCode(const QString& string);
//!show a new Icon in the modal info
void updateModalWithIconName(const QString& filename);
void hideModalInfo();
void modalStateChanged(bool state);
//!show set passworf form
void showSetPasswordInfo();
//!gets called when the user presses button in the "set password form"
void setPasswordProvided(const QString& newPassword, const QString& repeatPassword);
//!gets called on device reset
void setDeviceNamePasswordProvided(const QString& newPassword, const QString& newName);
void cleanseLoginAndSetPassword();
//!gets called when checking for an update
void updateButtonSetAvailable(bool);
//== DBB USB ==
//!function is user whishes to erase the DBB
void eraseClicked();
//!reset the U2F seed
void resetU2F();
void ledClicked(dbb_led_blink_mode_t mode = DBB_LED_BLINK_MODE_BLINK);
//!get basic informations about the connected DBB
void getInfo();
//!seed the wallet, flush everything and create a new bip32 entropy
void seedHardware();
//!update device name before continuing to seed the wallet
void seedHardwareWithName();
//== DBB USB / UTILS ==
//!get the current local IPv4 address
QString getIpAddress();
//!get a random number from the dbb
void getRandomNumber();
//!lock the device, disabled "backup", "verifypass" and "seed" command
void lockDevice();
//!lock the bootloader to protect from unecpected firmware upgrades
void lockBootloader();
//!open a file chooser and unlock the bootloader
void upgradeFirmwareButton();
void upgradeFirmware(bool unlockBootload);
void noDeviceConnectedLabelLink(const QString& link);
//!start upgrading the firmware with a file at given location
void upgradeFirmwareWithFile(const QString& fileName);
void upgradeFirmwareDone(bool state);
//!change device name via modal display
void setDeviceNameProvided(const QString &name);
//!change device name via popup window
void setDeviceNameClicked();
void setDeviceName(const QString& newDeviceName, dbb_response_type_t response_type);
void parseBitcoinURI(const QString& bitcoinurl, QString& addressOut, QString& amountOut);
//== ADDRESS EXPORTING ==
void showGetAddressDialog();
void getAddressGetXPub(const QString& keypath);
void getAddressVerify(const QString& keypath);
//== DBB USB / BACKUP ==
void showBackupDialog();
void addBackup();
void listBackup();
void eraseAllBackups();
void eraseBackup(const QString& backupFilename);
void verifyBackup(const QString& backupFilename);
void restoreBackup(const QString& backupFilename);
//== DBB USB Commands (Response Parsing) ==
//!main function to parse a response from the DBB
void parseResponse(const UniValue& response, dbb_cmd_execution_status_t status, dbb_response_type_t tag, int subtag);
//== Copay Wallet ==
//!create a single wallet
void createSingleWallet();
//!get a new address
void getNewAddress();
//!verify a address over the smartphone
void verifyAddress();
//!get a xpubkey (generic function)
void getXPub(const std::string& keypath, dbb_response_type_t response_type = DBB_RESPONSE_TYPE_XPUB_VERIFY, dbb_address_style_t address_type = DBB_ADDRESS_STYLE_P2PKH);
//!gets called when a new address is available
void updateReceivingAddress(DBBWallet *wallet, const std::string &newAddress, const std::string &keypath);
//!display fee calculated based on a payment proposal based on the UI values.
void displayFee();
//!check the UI values and create a payment proposal from them, sign and post them
void createTxProposalPressed();
//!Report about a submitted payment proposal
void reportPaymentProposalPost(DBBWallet* wallet, const UniValue& proposal);
void joinCopayWalletClicked();
//!initiates a copay multisig wallet join
void joinMultisigWalletInitiate(DBBWallet*);
//!gets a xpub key for the copay wallet
void getXPubKeyForCopay(int walletIndex);
//!gets a xpub key at the keypath that is used for the request private key
void getRequestXPubKeyForCopay(int walletIndex);
//!joins a copay wallet with given xpub key
void joinCopayWallet(int walletIndex);
//!joins a copay wallet with given xpub key
void joinCopayWalletComplete(DBBWallet* wallet);
//!update a given wallet object
void updateWallet(DBBWallet* wallet);
//!update multisig wallets
void MultisigUpdateWallets(bool initialJoin=false);
//!update single wallet
void SingleWalletUpdateWallets(bool showLoading=true);
//!update the mutisig ui from a getWallets response
void updateUIMultisigWallets(const UniValue& walletResponse);
//!update the mutisig ui state (joined or not)
void updateUIStateMultisigWallets(bool joined);
//!update the singlewallet ui from a getWallets response
void updateUISingleWallet(const UniValue& walletResponse);
//!update the single wallet transaction table
void updateTransactionTable(DBBWallet *wallet, bool historyAvailable, const UniValue& history);
//!show tx in a block explorer
void historyShowTx(QModelIndex index);
//!parse single wallet wallet response
void parseWalletsResponse(DBBWallet* wallet, bool walletsAvailable, const std::string& walletsResponse, bool initialJoin=false);
//!update payment proposals
bool MultisigUpdatePaymentProposals(const UniValue& response);
//!show a single payment proposals with given id
bool MultisigShowPaymentProposal(const UniValue& pendingTxps, const std::string& targetID);
//!execute payment proposal action
void PaymentProposalAction(DBBWallet* wallet, const QString &tfaCode, const UniValue& paymentProposal, int actionType = ProposalActionTypeAccept);
//!post
void postSignaturesForPaymentProposal(DBBWallet* wallet, const UniValue& proposal, const std::vector<std::string>& vSigs);
//== Smart Verification Pairing ==
//!send a ecdh pairing request with pubkey to the DBB
void sendECDHPairingRequest(const std::string &ecdhRequest);
void pairSmartphone();
void comServerMessageParse(const QString& msg);
//== settings ==
//!show settings dialog
void showSettings();
void updateSettings();
void updateHiddenPassword(const QString& hiddenPassword);
//== QRCode Scanner==
void showQrCodeScanner();
void qrCodeFound(const QString& payload);
//== linux udev rule check
void checkUDevRule();
};
#endif