Add sapling support while generating addresses
This commit is contained in:
@@ -262,6 +262,48 @@ void MainWindow::setupTransactionsTab() {
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::addNewZaddr(bool sapling) {
|
||||
rpc->newZaddr(sapling, [=] (json reply) {
|
||||
QString addr = QString::fromStdString(reply.get<json::string_t>());
|
||||
// Make sure the RPC class reloads the Z-addrs for future use
|
||||
rpc->refreshAddresses();
|
||||
|
||||
// Just double make sure the Z-address is still checked
|
||||
if (( sapling && ui->rdioZSAddr->isChecked()) ||
|
||||
(!sapling && ui->rdioZAddr->isChecked())) {
|
||||
ui->listRecieveAddresses->insertItem(0, addr);
|
||||
ui->listRecieveAddresses->setCurrentIndex(0);
|
||||
|
||||
ui->statusBar->showMessage(QString::fromStdString("Created new zAddr") %
|
||||
(sapling ? "(Sapling)" : "(Sprout)"),
|
||||
10 * 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Adds sapling or sprout z-addresses to the combo box. Technically, returns a
|
||||
// lambda, which can be connected to the appropriate signal
|
||||
std::function<void(bool)> MainWindow::addZAddrsToComboList(bool sapling) {
|
||||
return [=] (bool checked) {
|
||||
if (checked && this->rpc->getAllZAddresses() != nullptr) {
|
||||
auto addrs = this->rpc->getAllZAddresses();
|
||||
ui->listRecieveAddresses->clear();
|
||||
|
||||
std::for_each(addrs->begin(), addrs->end(), [=] (auto addr) {
|
||||
if ( (sapling && settings->isSaplingAddress(addr)) ||
|
||||
(!sapling && !settings->isSaplingAddress(addr)))
|
||||
ui->listRecieveAddresses->addItem(addr);
|
||||
});
|
||||
|
||||
// If z-addrs are empty, then create a new one.
|
||||
if (addrs->isEmpty()) {
|
||||
addNewZaddr(sapling);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void MainWindow::setupRecieveTab() {
|
||||
auto addNewTAddr = [=] () {
|
||||
rpc->newTaddr([=] (json reply) {
|
||||
@@ -296,45 +338,17 @@ void MainWindow::setupRecieveTab() {
|
||||
}
|
||||
});
|
||||
|
||||
auto addNewZaddr = [=] () {
|
||||
rpc->newZaddr([=] (json reply) {
|
||||
QString addr = QString::fromStdString(reply.get<json::string_t>());
|
||||
// Make sure the RPC class reloads the Z-addrs for future use
|
||||
rpc->refreshAddresses();
|
||||
|
||||
// Just double make sure the Z-address is still checked
|
||||
if (ui->rdioZAddr->isChecked()) {
|
||||
ui->listRecieveAddresses->insertItem(0, addr);
|
||||
ui->listRecieveAddresses->setCurrentIndex(0);
|
||||
|
||||
ui->statusBar->showMessage("Created new zAddr", 10 * 1000);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
auto addZAddrsToComboList = [=] (bool checked) {
|
||||
if (checked && this->rpc->getAllZAddresses() != nullptr) {
|
||||
auto addrs = this->rpc->getAllZAddresses();
|
||||
ui->listRecieveAddresses->clear();
|
||||
|
||||
std::for_each(addrs->begin(), addrs->end(), [=] (auto addr) {
|
||||
ui->listRecieveAddresses->addItem(addr);
|
||||
});
|
||||
|
||||
// If z-addrs are empty, then create a new one.
|
||||
if (addrs->isEmpty()) {
|
||||
addNewZaddr();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// zAddr toggle button
|
||||
QObject::connect(ui->rdioZAddr, &QRadioButton::toggled, addZAddrsToComboList);
|
||||
// zAddr toggle button, one for sprout and one for sapling
|
||||
QObject::connect(ui->rdioZAddr, &QRadioButton::toggled, addZAddrsToComboList(false));
|
||||
QObject::connect(ui->rdioZSAddr, &QRadioButton::toggled, addZAddrsToComboList(true));
|
||||
|
||||
// Explicitly get new address button.
|
||||
QObject::connect(ui->btnRecieveNewAddr, &QPushButton::clicked, [=] () {
|
||||
if (ui->rdioZAddr->isChecked()) {
|
||||
addNewZaddr();
|
||||
addNewZaddr(false);
|
||||
} else if (ui->rdioZSAddr->isChecked()) {
|
||||
addNewZaddr(true);
|
||||
} else if (ui->rdioTAddr->isChecked()) {
|
||||
addNewTAddr();
|
||||
}
|
||||
@@ -344,15 +358,23 @@ void MainWindow::setupRecieveTab() {
|
||||
QObject::connect(ui->tabWidget, &QTabWidget::currentChanged, [=] (int tab) {
|
||||
if (tab == 2) {
|
||||
// Switched to recieve tab, so update everything.
|
||||
|
||||
// Set the radio button to "Z-Addr", which should update the Address combo
|
||||
ui->rdioZAddr->setChecked(true);
|
||||
|
||||
// Hide Sapling radio button if sapling is not active
|
||||
if (Settings::getInstance()->isSaplingActive()) {
|
||||
ui->rdioZSAddr->setVisible(true);
|
||||
ui->rdioZSAddr->setChecked(true);
|
||||
} else {
|
||||
ui->rdioZSAddr->setVisible(false);
|
||||
ui->rdioZAddr->setChecked(true);
|
||||
ui->rdioZAddr->setText("z-Addr"); // Don't use the "Sprout" label
|
||||
}
|
||||
|
||||
// And then select the first one
|
||||
ui->listRecieveAddresses->setCurrentIndex(0);
|
||||
}
|
||||
});
|
||||
|
||||
// Select item in address list
|
||||
QObject::connect(ui->listRecieveAddresses,
|
||||
QOverload<const QString &>::of(&QComboBox::currentIndexChanged), [=] (const QString& addr) {
|
||||
if (addr.isEmpty()) {
|
||||
|
||||
@@ -54,6 +54,9 @@ private:
|
||||
void addressChanged(int number, const QString& text);
|
||||
void amountChanged (int numer, const QString& text);
|
||||
|
||||
void addNewZaddr(bool sapling);
|
||||
std::function<void(bool)> addZAddrsToComboList(bool sapling);
|
||||
|
||||
void memoButtonClicked(int number);
|
||||
void setMemoEnabled(int number, bool enabled);
|
||||
|
||||
|
||||
@@ -562,10 +562,17 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_9">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rdioZSAddr">
|
||||
<property name="text">
|
||||
<string>z-Addr(Sapling)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rdioZAddr">
|
||||
<property name="text">
|
||||
<string>z-Addr</string>
|
||||
<string>z-Addr(Sprout)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
19
src/rpc.cpp
19
src/rpc.cpp
@@ -136,13 +136,14 @@ void RPC::getZUnspent(const std::function<void(json)>& cb) {
|
||||
doRPC(payload, cb);
|
||||
}
|
||||
|
||||
void RPC::newZaddr(const std::function<void(json)>& cb) {
|
||||
void RPC::newZaddr(bool sapling, const std::function<void(json)>& cb) {
|
||||
json payload = {
|
||||
{"jsonrpc", "1.0"},
|
||||
{"id", "someid"},
|
||||
{"method", "z_getnewaddress"},
|
||||
{"params", { sapling ? "sapling" : "sprout" }},
|
||||
};
|
||||
|
||||
|
||||
doRPC(payload, cb);
|
||||
}
|
||||
|
||||
@@ -321,13 +322,19 @@ void RPC::getInfoThenRefresh() {
|
||||
};
|
||||
|
||||
doRPC(payload, [=](const json& reply) {
|
||||
auto progress = reply["verificationprogress"].get<double>();
|
||||
auto progress = reply["verificationprogress"].get<double>();
|
||||
bool isSyncing = progress < 0.999; // 99.9%
|
||||
int blockNumber = reply["blocks"].get<json::number_unsigned_t>();
|
||||
|
||||
Settings::getInstance()->setSyncing(isSyncing);
|
||||
Settings::getInstance()->setBlockNumber(blockNumber);
|
||||
|
||||
QString statusText = QString() %
|
||||
(progress < 0.99 ? "Syncing" : "Connected") %
|
||||
(isSyncing ? "Syncing" : "Connected") %
|
||||
" (" %
|
||||
(Settings::getInstance()->isTestnet() ? "testnet:" : "") %
|
||||
QString::number(reply["blocks"].get<json::number_unsigned_t>()) %
|
||||
(progress < 0.99 ? ("/" % QString::number(progress*100, 'f', 0) % "%") : QString()) %
|
||||
QString::number(blockNumber) %
|
||||
(isSyncing ? ("/" % QString::number(progress*100, 'f', 0) % "%") : QString()) %
|
||||
")";
|
||||
main->statusLabel->setText(statusText);
|
||||
auto zecPrice = Settings::getInstance()->getUSDFormat(1);
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
|
||||
void reloadConnectionInfo();
|
||||
|
||||
void newZaddr (const std::function<void(json)>& cb);
|
||||
void newZaddr (bool sapling, const std::function<void(json)>& cb);
|
||||
void newTaddr (const std::function<void(json)>& cb);
|
||||
|
||||
private:
|
||||
|
||||
@@ -152,6 +152,11 @@ void Settings::setTestnet(bool isTestnet) {
|
||||
this->_isTestnet = isTestnet;
|
||||
}
|
||||
|
||||
bool Settings::isSaplingAddress(QString addr) {
|
||||
return ( isTestnet() && addr.startsWith("ztestsapling")) ||
|
||||
(!isTestnet() && addr.startsWith("zs"));
|
||||
}
|
||||
|
||||
bool Settings::isSyncing() {
|
||||
return _isSyncing;
|
||||
}
|
||||
@@ -160,6 +165,19 @@ void Settings::setSyncing(bool syncing) {
|
||||
this->_isSyncing = syncing;
|
||||
}
|
||||
|
||||
int Settings::getBlockNumber() {
|
||||
return this->_blockNumber;
|
||||
}
|
||||
|
||||
void Settings::setBlockNumber(int number) {
|
||||
this->_blockNumber = number;
|
||||
}
|
||||
|
||||
bool Settings::isSaplingActive() {
|
||||
return (isTestnet() && getBlockNumber() > 280000) ||
|
||||
(!isTestnet() && getBlockNumber() > 419200);
|
||||
}
|
||||
|
||||
double Settings::getZECPrice() {
|
||||
return zecPrice;
|
||||
}
|
||||
|
||||
@@ -28,9 +28,16 @@ public:
|
||||
bool isTestnet();
|
||||
void setTestnet(bool isTestnet);
|
||||
|
||||
bool isSaplingAddress(QString addr);
|
||||
|
||||
bool isSyncing();
|
||||
void setSyncing(bool syncing);
|
||||
|
||||
int getBlockNumber();
|
||||
void setBlockNumber(int number);
|
||||
|
||||
bool isSaplingActive();
|
||||
|
||||
const QString& getZcashdConfLocation() { return confLocation; }
|
||||
|
||||
void setZECPrice(double p) { zecPrice = p; }
|
||||
@@ -55,8 +62,9 @@ private:
|
||||
|
||||
QString confLocation;
|
||||
|
||||
bool _isTestnet = false;
|
||||
bool _isSyncing = false;
|
||||
bool _isTestnet = false;
|
||||
bool _isSyncing = false;
|
||||
int _blockNumber = 0;
|
||||
|
||||
double zecPrice = 0.0;
|
||||
};
|
||||
|
||||
@@ -118,6 +118,7 @@ public:
|
||||
QGroupBox *groupBox_6;
|
||||
QVBoxLayout *verticalLayout_9;
|
||||
QHBoxLayout *horizontalLayout_9;
|
||||
QRadioButton *rdioZSAddr;
|
||||
QRadioButton *rdioZAddr;
|
||||
QRadioButton *rdioTAddr;
|
||||
QHBoxLayout *horizontalLayout_10;
|
||||
@@ -525,6 +526,11 @@ public:
|
||||
horizontalLayout_9 = new QHBoxLayout();
|
||||
horizontalLayout_9->setSpacing(6);
|
||||
horizontalLayout_9->setObjectName(QStringLiteral("horizontalLayout_9"));
|
||||
rdioZSAddr = new QRadioButton(groupBox_6);
|
||||
rdioZSAddr->setObjectName(QStringLiteral("rdioZSAddr"));
|
||||
|
||||
horizontalLayout_9->addWidget(rdioZSAddr);
|
||||
|
||||
rdioZAddr = new QRadioButton(groupBox_6);
|
||||
rdioZAddr->setObjectName(QStringLiteral("rdioZAddr"));
|
||||
|
||||
@@ -650,7 +656,7 @@ public:
|
||||
|
||||
retranslateUi(MainWindow);
|
||||
|
||||
tabWidget->setCurrentIndex(1);
|
||||
tabWidget->setCurrentIndex(2);
|
||||
|
||||
|
||||
QMetaObject::connectSlotsByName(MainWindow);
|
||||
@@ -699,7 +705,8 @@ public:
|
||||
cancelSendButton->setText(QApplication::translate("MainWindow", "Cancel", nullptr));
|
||||
tabWidget->setTabText(tabWidget->indexOf(tab_2), QApplication::translate("MainWindow", "Send", nullptr));
|
||||
groupBox_6->setTitle(QApplication::translate("MainWindow", "Address Type", nullptr));
|
||||
rdioZAddr->setText(QApplication::translate("MainWindow", "z-Addr", nullptr));
|
||||
rdioZSAddr->setText(QApplication::translate("MainWindow", "z-Addr(Sapling)", nullptr));
|
||||
rdioZAddr->setText(QApplication::translate("MainWindow", "z-Addr(Sprout)", nullptr));
|
||||
rdioTAddr->setText(QApplication::translate("MainWindow", "t-Addr", nullptr));
|
||||
btnRecieveNewAddr->setText(QApplication::translate("MainWindow", "New Address", nullptr));
|
||||
qrcodeDisplay->setText(QString());
|
||||
|
||||
Reference in New Issue
Block a user