/** * Construct with NMC_Interface to take the connections from. It also * queries the database to fill in the pending registrations. * @param nmc NMC_Interface instance to use. */ NMC_NameManager::NMC_NameManager (NMC_Interface& nmc) : rpc(nmc.getJsonRpc ()), nc(nmc.getNamecoin ()), pendingRegs() { if (instance != nullptr) qDebug () << "Error: Already have a NMC_NameManager instance!"; else instance = this; const QString query = "SELECT `regData` FROM `nmc_names`" " WHERE (`regData` IS NOT NULL) AND (NOT `active`)"; /* FIXME: Replace by lambda expression if we use C++11-only. */ AddPendingRegFunctor addPendingReg(*this); qDebug () << "Loading pending name registrations:"; DBHandler::getInstance ()->queryMultiple (query, addPendingReg); }
/** * For a given Nym ID and credential ID, find the Namecoin status text * to display for it. * @param nym Nym ID. * @param cred Master credential hash. * @return The string to display as status text. */ QString MTCredentials::getNamecoinStatus (const std::string& nym, const std::string& cred) { QString res; bool found = false; NMC_Interface nmc; nmcrpc::NamecoinInterface& nc = nmc.getNamecoin (); NameStatusFunctor nameHandler (nc, res, found, nym, cred); DBHandler& db = *DBHandler::getInstance (); const QString queryStr = "SELECT `name`, `active`, `updateTx`" " FROM `nmc_names`" " WHERE `nym` = :nym AND `cred` = :cred"; #ifdef CXX_11 std::unique_ptr<DBHandler::PreparedQuery> qu; #else /* CXX_11? */ std::auto_ptr<DBHandler::PreparedQuery> qu; #endif /* CXX_11? */ qu.reset (db.prepareQuery (queryStr)); qu->bind (":nym", nym.c_str ()); qu->bind (":cred", cred.c_str ()); try { db.queryMultiple (qu.release (), nameHandler); } catch (const nmcrpc::JsonRpc::RpcError& exc) { qDebug () << "NMC RPC Error: " << exc.getErrorMessage ().c_str (); res = tr("error"); } catch (const std::exception& exc) { qDebug () << "Error: " << exc.what (); res = tr("error"); } return res; }