Browse Source

add tkey import and autoshield it

pull/2/head
DenioD 4 years ago
parent
commit
f20dd70ede
  1. 7
      lib/Cargo.lock
  2. 2
      lib/Cargo.toml
  3. 40
      src/connection.cpp
  4. 1
      src/connection.h
  5. 10
      src/controller.h
  6. 28
      src/liteinterface.cpp
  7. 3
      src/liteinterface.h
  8. 74
      src/mainwindow.cpp
  9. 17
      src/privkey.ui

7
lib/Cargo.lock

@ -1192,7 +1192,7 @@ dependencies = [
"blake3 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "blake3 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"silentdragonlitelib 0.1.0 (git+https://github.com/MyHush/silentdragonlite-cli?rev=7637fba279fa9fc47da47ff7d8e5b993f823ec6e)", "silentdragonlitelib 0.1.0 (git+https://github.com/MyHush/silentdragonlite-cli?rev=8535a11e3774d79de2ebeaa5540567ccb4988f81)",
] ]
[[package]] [[package]]
@ -1655,10 +1655,11 @@ dependencies = [
[[package]] [[package]]
name = "silentdragonlitelib" name = "silentdragonlitelib"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/MyHush/silentdragonlite-cli?rev=7637fba279fa9fc47da47ff7d8e5b993f823ec6e#7637fba279fa9fc47da47ff7d8e5b993f823ec6e" source = "git+https://github.com/MyHush/silentdragonlite-cli?rev=8535a11e3774d79de2ebeaa5540567ccb4988f81#8535a11e3774d79de2ebeaa5540567ccb4988f81"
dependencies = [ dependencies = [
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bellman 0.1.0 (git+https://github.com/MyHush/librustzcash.git?rev=1a0204113d487cdaaf183c2967010e5214ff9e37)", "bellman 0.1.0 (git+https://github.com/MyHush/librustzcash.git?rev=1a0204113d487cdaaf183c2967010e5214ff9e37)",
"bs58 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2671,7 +2672,7 @@ dependencies = [
"checksum serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)" = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35" "checksum serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)" = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35"
"checksum sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0" "checksum sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0"
"checksum signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41" "checksum signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41"
"checksum silentdragonlitelib 0.1.0 (git+https://github.com/MyHush/silentdragonlite-cli?rev=7637fba279fa9fc47da47ff7d8e5b993f823ec6e)" = "<none>" "checksum silentdragonlitelib 0.1.0 (git+https://github.com/MyHush/silentdragonlite-cli?rev=8535a11e3774d79de2ebeaa5540567ccb4988f81)" = "<none>"
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
"checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" "checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6"
"checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" "checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85"

2
lib/Cargo.toml

@ -12,4 +12,4 @@ crate-type = ["staticlib"]
libc = "0.2.58" libc = "0.2.58"
lazy_static = "1.4.0" lazy_static = "1.4.0"
blake3 = "0.3.4" blake3 = "0.3.4"
silentdragonlitelib = { git = "https://github.com/MyHush/silentdragonlite-cli", rev = "7637fba279fa9fc47da47ff7d8e5b993f823ec6e" } silentdragonlitelib = { git = "https://github.com/MyHush/silentdragonlite-cli", rev = "8535a11e3774d79de2ebeaa5540567ccb4988f81" }

40
src/connection.cpp

@ -81,25 +81,19 @@ void ConnectionLoader::ShowProgress()
auto connection = makeConnection(config); auto connection = makeConnection(config);
auto me = this; auto me = this;
// After the lib is initialized, try to do get info
connection->doRPC("info", "", [=](auto reply) {
// If success, set the connection
main->logger->write("Connection is online.");
connection->setInfo(reply);
main->logger->write("getting Connection reply");
isSyncing = new QAtomicInteger<bool>(); isSyncing = new QAtomicInteger<bool>();
isSyncing->store(true); isSyncing->store(true);
main->logger->write("isSyncing"); main->logger->write("isSyncing");
// Do a sync at startup // Do a sync after import
syncTimer = new QTimer(main); syncTimer = new QTimer(main);
main->logger->write("Beginning sync"); main->logger->write("Beginning sync after import wif");
connection->doRPCWithDefaultErrorHandling("sync", "", [=](auto) { connection->doRPCWithDefaultErrorHandling("sync", "", [=](auto) {
isSyncing->store(false); isSyncing->store(false);
// Cancel the timer // Cancel the timer
syncTimer->deleteLater(); syncTimer->deleteLater();
// When sync is done, set the connection // When sync is done, set the connection
this->doRPCSetConnection(connection); this->doRPCSetConnectionShield(connection);
}); });
// While it is syncing, we'll show the status updates while it is alive. // While it is syncing, we'll show the status updates while it is alive.
@ -126,7 +120,6 @@ void ConnectionLoader::ShowProgress()
}catch (...) }catch (...)
{ {
main->logger->write("catch sync progress reply"); main->logger->write("catch sync progress reply");
} }
} }
@ -136,9 +129,6 @@ void ConnectionLoader::ShowProgress()
syncTimer->start(); syncTimer->start();
main->logger->write("Start sync timer"); main->logger->write("Start sync timer");
}, [=](QString err) {
showError(err);
});
} }
void ConnectionLoader::doAutoConnect() void ConnectionLoader::doAutoConnect()
@ -272,6 +262,30 @@ try
} }
void ConnectionLoader::doRPCSetConnectionShield(Connection* conn)
{
qDebug() << "Importing finished, setting connection";
rpc->setConnection(conn);
d->accept();
main->getRPC()->shield([=] (auto) {});
QTimer::singleShot(1, [=]() { delete this; });
try
{
QFile plaintextWallet(dirwalletconnection);
main->logger->write("Path to Wallet.dat : " );
plaintextWallet.remove();
}catch (...)
{
main->logger->write("no Plaintext wallet.dat");
}
}
Connection* ConnectionLoader::makeConnection(std::shared_ptr<ConnectionConfig> config) Connection* ConnectionLoader::makeConnection(std::shared_ptr<ConnectionConfig> config)
{ {
return new Connection(main, config); return new Connection(main, config);

1
src/connection.h

@ -41,6 +41,7 @@ private:
void showInformation(QString info, QString detail = ""); void showInformation(QString info, QString detail = "");
void doRPCSetConnection(Connection* conn); void doRPCSetConnection(Connection* conn);
void doRPCSetConnectionShield(Connection* conn);
QTimer* syncTimer = nullptr; QTimer* syncTimer = nullptr;
QAtomicInteger<bool>* isSyncing = nullptr; QAtomicInteger<bool>* isSyncing = nullptr;

10
src/controller.h

@ -109,6 +109,8 @@ public:
void saveWallet(const std::function<void(json)>& cb) { zrpc->saveWallet(cb); } void saveWallet(const std::function<void(json)>& cb) { zrpc->saveWallet(cb); }
void clearWallet(const std::function<void(json)>& cb) { zrpc->clearWallet(cb); } void clearWallet(const std::function<void(json)>& cb) { zrpc->clearWallet(cb); }
void shield(const std::function<void(json)>& cb) { zrpc->shield(cb); }
void createNewZaddr(bool sapling, const std::function<void(json)>& cb) { void createNewZaddr(bool sapling, const std::function<void(json)>& cb) {
unlockIfEncrypted([=] () { unlockIfEncrypted([=] () {
@ -159,8 +161,12 @@ public:
zrpc->importZPrivKey(addr,cb); zrpc->importZPrivKey(addr,cb);
}, [=](){}); }, [=](){});
} }
// void importZPrivKey(QString addr, const std::function<void(json)>& cb,const std::function<void(QString)>& err) { zrpc->importZPrivKey(addr, cb, ""); }
// void importTPrivKey(QString addr,bool rescan, const std::function<void(json)>& cb) { zrpc->importTPrivKey(addr,rescan, cb); } void importTPrivKey(QString addr,const std::function<void(json)>& cb) {
unlockIfEncrypted([=] () {
zrpc->importTPrivKey(addr,cb);
}, [=](){});
}
QString getDefaultSaplingAddress(); QString getDefaultSaplingAddress();
QString getDefaultTAddress(); QString getDefaultTAddress();

28
src/liteinterface.cpp

@ -30,29 +30,16 @@ void LiteInterface::fetchAddresses(const std::function<void(json)>& cb) {
void LiteInterface::importZPrivKey(QString addr, const std::function<void(json)>& cb) { void LiteInterface::importZPrivKey(QString addr, const std::function<void(json)>& cb) {
if (conn == nullptr) if (conn == nullptr)
return; return;
// QString params = addr % QString(" ");
// params.append(birthday);
qDebug()<<addr;
conn->doRPCWithDefaultErrorHandling("import", addr, cb); conn->doRPCWithDefaultErrorHandling("import", addr, cb);
// conn->doRPC("import", params, cb, err);
} }
/*void LiteInterface::importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb) { void LiteInterface::importTPrivKey(QString addr,const std::function<void(json)>& cb) {
if (conn == nullptr) if (conn == nullptr)
return; return;
conn->doRPCWithDefaultErrorHandling("timport", addr, cb);
}
// conn->doRPCWithDefaultErrorHandling("import", addr, cb);
// conn->doRPC("import", addr, 0, cb);
}*/
void LiteInterface::fetchUnspent(const std::function<void(json)>& cb) { void LiteInterface::fetchUnspent(const std::function<void(json)>& cb) {
@ -126,6 +113,13 @@ void LiteInterface::clearWallet(const std::function<void(json)>& cb) {
conn->doRPCWithDefaultErrorHandling("clear", "", cb); conn->doRPCWithDefaultErrorHandling("clear", "", cb);
} }
void LiteInterface::shield(const std::function<void(json)>& cb) {
if (conn == nullptr)
return;
conn->doRPCWithDefaultErrorHandling("shield", "", cb);
}
void LiteInterface::unlockWallet(QString password, const std::function<void(json)>& cb) { void LiteInterface::unlockWallet(QString password, const std::function<void(json)>& cb) {
if (conn == nullptr) if (conn == nullptr)
return; return;

3
src/liteinterface.h

@ -63,6 +63,7 @@ public:
void saveWallet(const std::function<void(json)>& cb); void saveWallet(const std::function<void(json)>& cb);
void clearWallet(const std::function<void(json)>& cb); void clearWallet(const std::function<void(json)>& cb);
void shield(const std::function<void(json)>& cb);
void fetchWalletEncryptionStatus(const std::function<void(json)>& cb); void fetchWalletEncryptionStatus(const std::function<void(json)>& cb);
void fetchSupply(const std::function<void(json)>& cb); void fetchSupply(const std::function<void(json)>& cb);
@ -71,7 +72,7 @@ public:
void removeWalletEncryption(QString password, const std::function<void(json)>& cb); void removeWalletEncryption(QString password, const std::function<void(json)>& cb);
void importZPrivKey(QString addr, const std::function<void(json)>& cb); void importZPrivKey(QString addr, const std::function<void(json)>& cb);
//void importTPrivKey(QString addr, bool rescan, const std::function<void(json)>& cb); void importTPrivKey(QString addr, const std::function<void(json)>& cb);
void sendTransaction(QString params, const std::function<void(json)>& cb, const std::function<void(QString)>& err); void sendTransaction(QString params, const std::function<void(json)>& cb, const std::function<void(QString)>& err);

74
src/mainwindow.cpp

@ -940,7 +940,7 @@ void MainWindow::donate() {
if (keys->isEmpty()) { if (keys->isEmpty()) {
delete keys; delete keys;
ui->statusBar->showMessage(tr("Private key import rescan finished")); ui->statusBar->showMessage(tr("Private key import rescan in progress. Your funds will be automaticly shield to a wallet seed zaddr. This will take some time"));
return; return;
} }
@ -953,19 +953,20 @@ void MainWindow::donate() {
if (key.startsWith("SK") || if (key.startsWith("SK") ||
key.startsWith("secret")) { // Z key key.startsWith("secret")) {
rpc->importZPrivKey(key, [=] (auto) { this->doImport(keys); }); rpc->importZPrivKey(key, [=] (auto) { this->doImport(keys); });
// Then reload the connection. The ConnectionLoader deletes itself. } else if (key.startsWith("U")) {
} else {
// rpc->importTPrivKey(key, rescan, [=] (auto) { this->doImport(keys); });
}
}
rpc->importTPrivKey(key, [=] (auto) { this->doImport(keys); });
}else{
QMessageBox::critical(this, tr("Wrong Privatkey format"),
tr("Privatkey should start with U (for taddr) or secret- (for zaddr)") + "\n");
return;
}
}
// Callback invoked when the RPC has finished loading all the balances, and the UI // Callback invoked when the RPC has finished loading all the balances, and the UI
// is now ready to send transactions. // is now ready to send transactions.
@ -1060,9 +1061,9 @@ void MainWindow::payhushURI(QString uri, QString myAddr) {
pui.buttonBox->button(QDialogButtonBox::Save)->setVisible(true); pui.buttonBox->button(QDialogButtonBox::Save)->setVisible(true);
pui.helpLbl->setText(QString() % pui.helpLbl->setText(QString() %
tr("Please paste your private key(z-Addr) here, one per import") % ".\n" % tr("Please paste your private key(zs-Addr or R-addr) here, one per import") % ".\n" %
tr("Caution: These key will be NOT inlcude in your Seed. Please send them direct to a Seed zaddr") % ".\n" % tr("Caution: If this key is for Zs-addr it will be NOT inlcude in your Seed. Please send them direct to a Seed zs-addr") % ".\n" %
tr("The import of your Privatkey will take some time.") tr("R-addr keys will be autoshield to a seed zs-addr")
); );
if (d.exec() == QDialog::Accepted && !pui.privKeyTxt->toPlainText().trimmed().isEmpty()) { if (d.exec() == QDialog::Accepted && !pui.privKeyTxt->toPlainText().trimmed().isEmpty()) {
@ -1092,14 +1093,45 @@ void MainWindow::payhushURI(QString uri, QString myAddr) {
// Start the import. The function takes ownership of keys // Start the import. The function takes ownership of keys
QTimer::singleShot(1, [=]() {doImport(keys);}); QTimer::singleShot(1, [=]() {doImport(keys);});
auto cl = new ConnectionLoader(this, rpc); /////Rescan the Wallet (optional) and do automaticly shielding to a seed zaddr
QTimer::singleShot(1, [=]() { cl->loadProgress(); });
if((pui.rescan->isChecked() == true) && (pui.privKeyTxt->toPlainText().startsWith("U"))) {
// Show the dialog that keys will be imported. // Show the dialog that keys will be imported and rescan is in progress.
// QMessageBox::information(this,
// "Imported", tr("The keys were imported. It may take several minutes to rescan the blockchain. Until then, functionality may be limited"), QMessageBox::information(this,
// QMessageBox::Ok); "Imported", tr("The keys were imported. It may take several minutes to rescan the blockchain. Until then, functionality may be limited"),
QMessageBox::Ok);
this->getRPC()->clearWallet([=] (auto) {
// Save the wallet
this->getRPC()->saveWallet([=] (auto) {
// Then reload the connection. The ConnectionLoader deletes itself.
auto cl = new ConnectionLoader(this, rpc);
cl->loadProgress();
});
});
}else if ((pui.rescan->isChecked() == true) && (pui.privKeyTxt->toPlainText().startsWith("secret"))){
// Show the dialog that keys will be imported.
QMessageBox::information(this,
"Imported", tr("The keys were imported. It may take several minutes to rescan the blockchain. Until then, functionality may be limited"),
QMessageBox::Ok);
this->getRPC()->clearWallet([=] (auto) {
// Save the wallet
this->getRPC()->saveWallet([=] (auto) {
// Then reload the connection. The ConnectionLoader deletes itself.
auto cl = new ConnectionLoader(this, rpc);
cl->loadConnection();
});
});
}else{
QMessageBox::information(this,
"Imported", tr("The keys were imported without rescan option. The Address you imported will be visible without balance"),
QMessageBox::Ok);
}
} }
} }

17
src/privkey.ui

@ -14,14 +14,21 @@
<string>Private Keys</string> <string>Private Keys</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="0"> <item row="1" column="0" colspan="3">
<widget class="QPlainTextEdit" name="privKeyTxt"> <widget class="QPlainTextEdit" name="privKeyTxt">
<property name="plainText"> <property name="plainText">
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="0" column="0">
<widget class="QLabel" name="helpLbl">
<property name="text">
<string notr="true">TextLabel</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -31,10 +38,10 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="2" column="1">
<widget class="QLabel" name="helpLbl"> <widget class="QRadioButton" name="rescan">
<property name="text"> <property name="text">
<string notr="true">TextLabel</string> <string>Rescan Wallet</string>
</property> </property>
</widget> </widget>
</item> </item>

Loading…
Cancel
Save