forked from NowputFinance/nowp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultisigaddressentry.cpp
More file actions
114 lines (94 loc) · 2.75 KB
/
Copy pathmultisigaddressentry.cpp
File metadata and controls
114 lines (94 loc) · 2.75 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
#include <qt/multisigaddressentry.h>
#include <qt/forms/ui_multisigaddressentry.h>
#include <qt/guiutil.h>
#include <qt/addressbookpage.h>
#include <qt/walletmodel.h>
#include <qt/addresstablemodel.h>
#include <util/strencodings.h>
#include <QClipboard>
MultisigAddressEntry::MultisigAddressEntry(QWidget *parent) : QFrame(parent), ui(new Ui::MultisigAddressEntry), model(0)
{
ui->setupUi(this);
GUIUtil::setupAddressWidget(ui->address, this);
}
MultisigAddressEntry::~MultisigAddressEntry()
{
delete ui;
}
void MultisigAddressEntry::setModel(WalletModel *model)
{
this->model = model;
clear();
}
void MultisigAddressEntry::clear()
{
ui->pubkey->clear();
ui->address->clear();
ui->label->clear();
ui->pubkey->setFocus();
}
bool MultisigAddressEntry::validate()
{
return !ui->pubkey->text().isEmpty();
}
QString MultisigAddressEntry::getPubkey()
{
return ui->pubkey->text();
}
void MultisigAddressEntry::setRemoveEnabled(bool enabled)
{
ui->deleteButton->setEnabled(enabled);
}
void MultisigAddressEntry::on_pasteButton_clicked()
{
ui->address->setText(QApplication::clipboard()->text());
}
void MultisigAddressEntry::on_deleteButton_clicked()
{
Q_EMIT removeEntry(this);
}
void MultisigAddressEntry::on_addressBookButton_clicked()
{
if(!model)
return;
AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::ReceivingTab, this);
dlg.setModel(model->getAddressTableModel());
if(dlg.exec())
{
ui->address->setText(dlg.getReturnValue());
}
}
void MultisigAddressEntry::on_pubkey_textChanged(const QString &pubkey)
{
// Compute address from public key
std::vector<unsigned char> vchPubKey(ParseHex(pubkey.toStdString()));
CPubKey pkey(vchPubKey);
std::string address = EncodeDestination(pkey.GetID());
ui->address->setText(address.c_str());
if(!model)
return;
// Get label of address
QString associatedLabel = model->getAddressTableModel()->labelForAddress(address.c_str());
if(!associatedLabel.isEmpty())
ui->label->setText(associatedLabel);
}
void MultisigAddressEntry::on_address_textChanged(const QString &address)
{
if(!model)
return;
// Get public key of address
CTxDestination dest = DecodeDestination(address.toStdString());
const CKeyID *keyID = boost::get<CKeyID>(&dest);
if(!keyID)
{
CPubKey vchPubKey;
model->getPubKey(*keyID, vchPubKey);
std::string pubkey = HexStr(vchPubKey);
if(!pubkey.empty())
ui->pubkey->setText(pubkey.c_str());
}
// Get label of address
QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
if(!associatedLabel.isEmpty())
ui->label->setText(associatedLabel);
}