@ -14,6 +14,7 @@ ConnectionLoader::ConnectionLoader(MainWindow* main, RPC* rpc) {
this - > rpc = rpc ;
d = new QDialog ( main ) ;
d - > setWindowFlags ( d - > windowFlags ( ) & ~ ( Qt : : WindowCloseButtonHint | Qt : : WindowContextHelpButtonHint ) ) ;
connD = new Ui_ConnectionDialog ( ) ;
connD - > setupUi ( d ) ;
QPixmap logo ( " :/img/res/logobig.gif " ) ;
@ -51,29 +52,29 @@ void ConnectionLoader::doAutoConnect(bool tryEzcashdStart) {
// Refused connection. So try and start embedded zcashd
if ( Settings : : getInstance ( ) - > useEmbedded ( ) ) {
if ( tryEzcashdStart ) {
this - > showInformation ( QObject : : tr ( " Starting embedded zca shd " ) ) ;
this - > showInformation ( QObject : : tr ( " Starting embedded hu shd " ) ) ;
if ( this - > startEmbeddedZcashd ( ) ) {
// Embedded zcashd started up. Wait a second and then refresh the connection
main - > logger - > write ( " Embedded zca shd started up, trying autoconnect in 1 sec " ) ;
main - > logger - > write ( " Embedded hu shd started up, trying autoconnect in 1 sec " ) ;
QTimer : : singleShot ( 1000 , [ = ] ( ) { doAutoConnect ( ) ; } ) ;
} else {
if ( config - > zcashDaemon ) {
// zca shd is configured to run as a daemon, so we must wait for a few seconds
// hu shd is configured to run as a daemon, so we must wait for a few seconds
// to let it start up.
main - > logger - > write ( " zca shd is daemon=1. Waiting for it to start up" ) ;
this - > showInformation ( QObject : : tr ( " zca shd is set to run as daemon" ) , QObject : : tr ( " Waiting for zca shd " ) ) ;
QTimer : : singleShot ( 5000 , [ = ] ( ) { doAutoConnect ( /* don't attempt to start ezca shd */ false ) ; } ) ;
main - > logger - > write ( " hu shd is daemon=1. Waiting for it to start up" ) ;
this - > showInformation ( QObject : : tr ( " hu shd is set to run as daemon" ) , QObject : : tr ( " Waiting for hu shd " ) ) ;
QTimer : : singleShot ( 5000 , [ = ] ( ) { doAutoConnect ( /* don't attempt to start ehu shd */ false ) ; } ) ;
} else {
// Something is wrong.
// We're going to attempt to connect to the one in the background one last time
// and see if that works, else throw an error
main - > logger - > write ( " Unknown problem while trying to start zcashd " ) ;
main - > logger - > write ( " Unknown problem while trying to start hushd! " ) ;
QTimer : : singleShot ( 2000 , [ = ] ( ) { doAutoConnect ( /* don't attempt to start ezcashd */ false ) ; } ) ;
}
}
} else {
// We tried to start ezcashd previously, and it didn't work. So, show the error.
main - > logger - > write ( " Couldn't start embedded zca shd for unknown reason " ) ;
main - > logger - > write ( " Couldn't start embedded hu shd for unknown reason " ) ;
QString explanation ;
if ( config - > zcashDaemon ) {
explanation = QString ( ) % QObject : : tr ( " You have komodod set to start as a daemon, which can cause problems "
@ -81,9 +82,9 @@ void ConnectionLoader::doAutoConnect(bool tryEzcashdStart) {
" Please remove the following line from your HUSH3.conf and restart SilentDragon \n "
" daemon=1 " ) ;
} else {
explanation = QString ( ) % QObject : : tr ( " Couldn't start the embedded komodo d. \n \n "
explanation = QString ( ) % QObject : : tr ( " Couldn't start the embedded hush d. \n \n "
" Please try restarting. \n \n If you previously started komodod with custom arguments, you might need to reset HUSH3.conf. \n \n "
" If all else fails, please run zca shd manually. " ) %
" If all else fails, please run hu shd manually. " ) %
( ezcashd ? QObject : : tr ( " The process returned " ) + " : \n \n " % ezcashd - > errorString ( ) : QString ( " " ) ) ;
}
@ -178,15 +179,23 @@ void ConnectionLoader::createZcashConf() {
QFile file ( confLocation ) ;
if ( ! file . open ( QIODevice : : ReadWrite | QIODevice : : Truncate ) ) {
main - > logger - > write ( " Could not create HUSH3.conf, returning " ) ;
QString explanation = QString ( ) % QObject : : tr ( " Could not create HUSH3.conf. " ) ;
this - > showError ( explanation ) ;
return ;
}
QTextStream out ( & file ) ;
out < < " # Autogenerated by Silent Dragon \n " ;
out < < " server=1 \n " ;
out < < " rpcuser=hush \n " ;
out < < " rpcpassword= " % randomPassword ( ) < < " \n " ;
out < < " rpcport=18031 \n " ;
out < < " txindex=1 \n " ;
out < < " addressindex=1 \n " ;
out < < " spentindex=1 \n " ;
out < < " timestampindex=1 \n " ;
out < < " rpcworkqueue=256 \n " ;
out < < " rpcallowip=127.0.0.1 \n " ;
@ -209,11 +218,9 @@ void ConnectionLoader::downloadParams(std::function<void(void)> cb) {
// Add all the files to the download queue
downloadQueue = new QQueue < QUrl > ( ) ;
client = new QNetworkAccessManager ( main ) ;
downloadQueue - > enqueue ( QUrl ( " https://z.cash/downloads/sapling-output.params " ) ) ;
downloadQueue - > enqueue ( QUrl ( " https://z.cash/downloads/sapling-spend.params " ) ) ;
downloadQueue - > enqueue ( QUrl ( " https://z.cash/downloads/sprout-proving.key " ) ) ;
downloadQueue - > enqueue ( QUrl ( " https://z.cash/downloads/sprout-verifying.key " ) ) ;
downloadQueue - > enqueue ( QUrl ( " https://z.cash/downloads/sapling-spend.params " ) ) ;
downloadQueue - > enqueue ( QUrl ( " https://z.cash/downloads/sprout-groth16.params " ) ) ;
doNextDownload ( cb ) ;
@ -333,39 +340,44 @@ bool ConnectionLoader::startEmbeddedZcashd() {
// Finally, start zcashd
QDir appPath ( QCoreApplication : : applicationDirPath ( ) ) ;
# ifdef Q_OS_LINUX
auto zcashdProgram = appPath . absoluteFilePath ( " komodo d" ) ;
auto zcashdProgram = appPath . absoluteFilePath ( " hush d" ) ;
if ( ! QFile ( zcashdProgram ) . exists ( ) ) {
zcashdProgram = appPath . absoluteFilePath ( " komodo d" ) ;
zcashdProgram = appPath . absoluteFilePath ( " hush d" ) ;
}
# elif defined(Q_OS_DARWIN)
auto zcashdProgram = appPath . absoluteFilePath ( " komodod " ) ;
auto zcashdProgram = appPath . absoluteFilePath ( " hushd " ) ;
# elif defined(Q_OS_WIN64)
auto zcashdProgram = appPath . absoluteFilePath ( " hushd.bat " ) ;
# else
auto zcashdProgram = appPath . absoluteFilePath ( " komodod.exe " ) ;
//TODO: Not Linux + not darwin DOES NOT EQUAL windows!!!
auto zcashdProgram = appPath . absoluteFilePath ( " hushd " ) ;
# endif
if ( ! QFile ( zcashdProgram ) . exists ( ) ) {
qDebug ( ) < < " Can't find zca shd at " < < zcashdProgram ;
main - > logger - > write ( " Can't find zca shd at " + zcashdProgram ) ;
qDebug ( ) < < " Can't find hu shd at " < < zcashdProgram ;
main - > logger - > write ( " Can't find hu shd at " + zcashdProgram ) ;
return false ;
}
ezcashd = new QProcess ( main ) ;
QObject : : connect ( ezcashd , & QProcess : : started , [ = ] ( ) {
//qDebug() << "zcashd started";
ezcashd = std : : shared_ptr < QProcess > ( new QProcess ( main ) ) ;
QObject : : connect ( ezcashd . get ( ) , & QProcess : : started , [ = ] ( ) {
qDebug ( ) < < " Embedded hushd started " ;
} ) ;
QObject : : connect ( ezcashd , QOverload < int , QProcess : : ExitStatus > : : of ( & QProcess : : finished ) ,
[ = ] ( int , QProcess : : ExitStatus ) {
//qDebug() << "zcashd finished with code " << exitCode << "," << exitStatus;
QObject : : connect ( ezcashd . get ( ) , QOverload < int , QProcess : : ExitStatus > : : of ( & QProcess : : finished ) ,
[ = ] ( int exitCode , QProcess : : ExitStatus e xitStatus ) {
qDebug ( ) < < " hushd finished with code " < < exitCode < < " , " < < exitStatus ;
} ) ;
QObject : : connect ( ezcashd , & QProcess : : errorOccurred , [ & ] ( auto ) {
//qDebug() << "Couldn't start zcashd: " << error;
QObject : : connect ( ezcashd . get ( ) , & QProcess : : errorOccurred , [ & ] ( QProcess : : ProcessError error ) {
qDebug ( ) < < " Couldn't start hushd: " < < error ;
} ) ;
QObject : : connect ( ezcashd , & QProcess : : readyReadStandardError , [ = ] ( ) {
auto output = ezcashd - > readAllStandardError ( ) ;
main - > logger - > write ( " hushd stderr: " + output ) ;
std : : weak_ptr < QProcess > weak_obj ( ezcashd ) ;
auto ptr_main ( main ) ;
QObject : : connect ( ezcashd . get ( ) , & QProcess : : readyReadStandardError , [ weak_obj , ptr_main ] ( ) {
auto output = weak_obj . lock ( ) - > readAllStandardError ( ) ;
ptr_main - > logger - > write ( " hushd stderr: " + output ) ;
processStdErrOutput . append ( output ) ;
} ) ;
@ -375,7 +387,7 @@ bool ConnectionLoader::startEmbeddedZcashd() {
ezcashd - > start ( zcashdProgram ) ;
# else
ezcashd - > setWorkingDirectory ( appPath . absolutePath ( ) ) ;
ezcashd - > start ( " komodo.exe " ) ;
ezcashd - > start ( zcashdProgram ) ;
# endif // Q_OS_LINUX
@ -448,10 +460,10 @@ void ConnectionLoader::refreshZcashdState(Connection* connection, std::function<
} ;
connection - > doRPC ( payload ,
[ = ] ( auto ) {
// Success, hide the dialog if it was shown.
d - > hide ( ) ;
// Success
main - > logger - > write ( " hushd is online. " ) ;
this - > doRPCSetConnection ( connection ) ;
// Delay 1 second to ensure loading (splash) is seen at least 1 second.
QTimer : : singleShot ( 1000 , [ = ] ( ) { this - > doRPCSetConnection ( connection ) ; } ) ;
} ,
[ = ] ( auto reply , auto res ) {
// Failed, see what it is.
@ -563,13 +575,14 @@ QString ConnectionLoader::zcashParamsDir() {
bool ConnectionLoader : : verifyParams ( ) {
QDir paramsDir ( zcashParamsDir ( ) ) ;
qDebug ( ) < < " Verifying param files exist " ;
if ( ! QFile ( paramsDir . filePath ( " sapling-output.params " ) ) . exists ( ) ) return false ;
if ( ! QFile ( paramsDir . filePath ( " sapling-spend.params " ) ) . exists ( ) ) return false ;
//TODO: sprout probably not needed
if ( ! QFile ( paramsDir . filePath ( " sprout-proving.key " ) ) . exists ( ) ) return false ;
if ( ! QFile ( paramsDir . filePath ( " sprout-verifying.key " ) ) . exists ( ) ) return false ;
if ( ! QFile ( paramsDir . filePath ( " sprout-groth16.params " ) ) . exists ( ) ) return false ;
qDebug ( ) < < " All param files found! " ;
return true ;
}