src/connection.cpp
/**
 * Try to automatically detect a HUSH3/HUSH3.conf file in the correct location and load parameters
 */
Try to automatically detect a HUSH3/HUSH3.conf file in the correct location and load parameters
Try to automatically detect a HUSH3 / HUSH3 . conf file in the correct location and load parameters
std::shared_ptr<ConnectionConfig> ConnectionLoader::autoDetectZcashConf() {    
    auto confLocation = locateZcashConfFile();
    if (confLocation.isNull()) {
        return nullptr;
    }
    QFile file(confLocation);
    if (!file.open(QIODevice::ReadOnly)) {
        qDebug() << file.errorString();
        return nullptr;
    }
    QTextStream in(&file);
    auto zcashconf = new ConnectionConfig();
    zcashconf->host     = "127.0.0.1";
    zcashconf->connType = ConnectionType::DetectedConfExternalZcashD;
    zcashconf->usingZcashConf = true;
    zcashconf->zcashDir = QFileInfo(confLocation).absoluteDir().absolutePath();
    zcashconf->zcashDaemon = false;
    Settings::getInstance()->setUsingZcashConf(confLocation);
    while (!in.atEnd()) {
        QString line = in.readLine();
        auto s = line.indexOf("=");
        QString name  = line.left(s).trimmed().toLower();
        QString value = line.right(line.length() - s - 1).trimmed();
        if (name == "rpcuser") {
            zcashconf->rpcuser = value;
        }
        if (name == "rpcpassword") {
            zcashconf->rpcpassword = value;
        }
        if (name == "rpcport") {
            zcashconf->port = value;
        }
        if (name == "daemon" && value == "1") {
            zcashconf->zcashDaemon = true;
        }
        if (name == "proxy") {
            zcashconf->proxy = value;
        }
        if (name == "testnet" &&
            value == "1"  &&
            zcashconf->port.isEmpty()) {
                zcashconf->port = "18232";
        }
    }
    if (zcashconf->port.isEmpty()) zcashconf->port = "23136";
    file.close();
    return std::shared_ptr<ConnectionConfig>(zcashconf);
}
std :: shared_ptr < ConnectionConfig > ConnectionLoader :: autoDetectZcashConf ( ) { auto confLocation = locateZcashConfFile ( ) ; if ( confLocation . isNull ( ) ) { return nullptr ; } QFile file ( confLocation ) ; if ( ! file . open ( QIODevice :: ReadOnly ) ) { qDebug ( ) << file . errorString ( ) ; return nullptr ; } QTextStream in ( & file ) ; auto zcashconf = new ConnectionConfig ( ) ; zcashconf -> host = " " ; zcashconf -> connType = ConnectionType :: DetectedConfExternalZcashD ; zcashconf -> usingZcashConf = true ; zcashconf -> zcashDir = QFileInfo ( confLocation ) . absoluteDir ( ) . absolutePath ( ) ; zcashconf -> zcashDaemon = false ; Settings :: getInstance ( ) -> setUsingZcashConf ( confLocation ) ; while ( ! in . atEnd ( ) ) { QString line = in . readLine ( ) ; auto s = line . indexOf ( " " ) ; QString name = line . left ( s ) . trimmed ( ) . toLower ( ) ; QString value = line . right ( line . length ( ) - s - 1 ) . trimmed ( ) ; if ( name == " " ) { zcashconf -> rpcuser = value ; } if ( name == " " ) { zcashconf -> rpcpassword = value ; } if ( name == " " ) { zcashconf -> port = value ; } if ( name == " " && value == " " ) { zcashconf -> zcashDaemon = true ; } if ( name == " " ) { zcashconf -> proxy = value ; } if ( name == " " && value == " " && zcashconf -> port . isEmpty ( ) ) { zcashconf -> port = " " ; } } if ( zcashconf -> port . isEmpty ( ) ) zcashconf -> port = " " ; file . close ( ) ; return std :: shared_ptr < ConnectionConfig > ( zcashconf ) ; }
Try to automatically detect a HUSH3/HUSH3.conf file in the correct location and load parameters
Try to automatically detect a HUSH3 / HUSH3 . conf file in the correct location and load parameters
// No Zcash file, just return with nothing // If rpcport is not in the file, and it was not set by the testnet=1 flag, then go to default // In addition to the HUSH3/HUSH3.conf file, also double check the params. 