@ -280,6 +280,8 @@ MainWindow::MainWindow(QWidget *parent) :
dialog . exec ( ) ;
} ) ;
// Import Privkey
QObject : : connect ( ui - > actionImport_Privatkey , & QAction : : triggered , this , & MainWindow : : importPrivKey ) ;
// Address Book
QObject : : connect ( ui - > action_Address_Book , & QAction : : triggered , this , & MainWindow : : addressBook ) ;
@ -930,31 +932,41 @@ void MainWindow::donate() {
ui - > tabWidget - > setCurrentIndex ( 1 ) ;
}
// void MainWindow::doImport(QList<QString>* keys) {
// if (rpc->getConnection() == nullptr) {
// // No connection, just return
// return;
// }
void MainWindow : : doImport ( QList < QString > * keys ) {
if ( rpc - > getConnection ( ) = = nullptr ) {
// No connection, just return
return ;
}
// if (keys->isEmpty()) {
// delete keys;
// ui->statusBar->showMessage(tr("Private key import rescan finished"));
// return;
// }
if ( keys - > isEmpty ( ) ) {
delete keys ;
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 ;
}
// Pop the first key
QString key = keys - > first ( ) ;
QString key1 = key + QString ( " " ) + QString ( " 0 " ) ;
keys - > pop_front ( ) ;
bool rescan = keys - > isEmpty ( ) ;
// // Pop the first key
// QString key = keys->first();
// keys->pop_front();
// bool rescan = keys->isEmpty();
if ( key . startsWith ( " SK " ) | |
key . startsWith ( " secret " ) ) {
rpc - > importZPrivKey ( key , [ = ] ( auto ) { this - > doImport ( keys ) ; } ) ;
} else if ( key . startsWith ( " U " ) ) {
// if (key.startsWith("SK") ||
// key.startsWith("secret")) { // Z key
// rpc->importZPrivKey(key, rescan, [=] (auto) { this->doImport(keys); });
// } 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
// is now ready to send transactions.
@ -1041,51 +1053,87 @@ void MainWindow::payhushURI(QString uri, QString myAddr) {
}
}
void MainWindow : : importPrivKey ( ) {
QDialog d ( this ) ;
Ui_PrivKey pui ;
pui . setupUi ( & d ) ;
Settings : : saveRestore ( & d ) ;
pui . buttonBox - > button ( QDialogButtonBox : : Save ) - > setVisible ( true ) ;
pui . helpLbl - > setText ( QString ( ) %
tr ( " Please paste your private key(zs-Addr or R-addr) here, one per import " ) % " . \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 ( " R-addr keys will be autoshield to a seed zs-addr " )
) ;
if ( d . exec ( ) = = QDialog : : Accepted & & ! pui . privKeyTxt - > toPlainText ( ) . trimmed ( ) . isEmpty ( ) ) {
auto rawkeys = pui . privKeyTxt - > toPlainText ( ) . trimmed ( ) . split ( " \n " ) ;
QList < QString > keysTmp ;
// Filter out all the empty keys.
std : : copy_if ( rawkeys . begin ( ) , rawkeys . end ( ) , std : : back_inserter ( keysTmp ) , [ = ] ( auto key ) {
return ! key . startsWith ( " # " ) & & ! key . trimmed ( ) . isEmpty ( ) ;
} ) ;
auto keys = new QList < QString > ( ) ;
std : : transform ( keysTmp . begin ( ) , keysTmp . end ( ) , std : : back_inserter ( * keys ) , [ = ] ( auto key ) {
return key . trimmed ( ) . split ( " " ) [ 0 ] ;
} ) ;
// Special case.
// Sometimes, when importing from a paperwallet or such, the key is split by newlines, and might have
// been pasted like that. So check to see if the whole thing is one big private key
if ( Settings : : getInstance ( ) - > isValidSaplingPrivateKey ( keys - > join ( " " ) ) ) {
auto multiline = keys ;
keys = new QList < QString > ( ) ;
keys - > append ( multiline - > join ( " " ) ) ;
delete multiline ;
}
// Start the import. The function takes ownership of keys
QTimer : : singleShot ( 1 , [ = ] ( ) { doImport ( keys ) ; } ) ;
/////Rescan the Wallet (optional) and do automaticly shielding to a seed zaddr
if ( ( pui . rescan - > isChecked ( ) = = true ) & & ( pui . privKeyTxt - > toPlainText ( ) . startsWith ( " U " ) ) ) {
// 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 : : 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 ( ) ;
} ) ;
} ) ;
// void MainWindow::importPrivKey() {
// QDialog d(this);
// Ui_PrivKey pui;
// pui.setupUi(&d);
// Settings::saveRestore(&d);
// pui.buttonBox->button(QDialogButtonBox::Save)->setVisible(false);
// pui.helpLbl->setText(QString() %
// tr("Please paste your private keys (z-Addr or t-Addr) here, one per line") % ".\n" %
// tr("The keys will be imported into your connected hushd node"));
// if (d.exec() == QDialog::Accepted && !pui.privKeyTxt->toPlainText().trimmed().isEmpty()) {
// auto rawkeys = pui.privKeyTxt->toPlainText().trimmed().split("\n");
// QList<QString> keysTmp;
// // Filter out all the empty keys.
// std::copy_if(rawkeys.begin(), rawkeys.end(), std::back_inserter(keysTmp), [=] (auto key) {
// return !key.startsWith("#") && !key.trimmed().isEmpty();
// });
// auto keys = new QList<QString>();
// std::transform(keysTmp.begin(), keysTmp.end(), std::back_inserter(*keys), [=](auto key) {
// return key.trimmed().split(" ")[0];
// });
// // Special case.
// // Sometimes, when importing from a paperwallet or such, the key is split by newlines, and might have
// // been pasted like that. So check to see if the whole thing is one big private key
// if (Settings::getInstance()->isValidSaplingPrivateKey(keys->join(""))) {
// auto multiline = keys;
// keys = new QList<QString>();
// keys->append(multiline->join(""));
// delete multiline;
// }
// // Start the import. The function takes ownership of keys
// QTimer::singleShot(1, [=]() {doImport(keys);});
// // 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);
// }
// }
} else {
QMessageBox : : information ( this ,
" Imported " , tr ( " The keys were imported without rescan option. The Address you imported will be visible without balance " ) ,
QMessageBox : : Ok ) ;
}
}
}
/**
* Export transaction history into a CSV file