int main (int argc, char** argv) { if (argc != 3) { std::cerr << "Usage: test_nmc SOURCE HASH" << std::endl; return EXIT_FAILURE; } const std::string source = argv[1]; const std::string hash = argv[2]; RpcSettings settings; settings.readDefaultConfig (); JsonRpc rpc(settings); NamecoinInterface nc(rpc); NMC_Verifier verify(nc); const bool res = verify.verifyCredentialHashAtSource (hash, source); if (res) std::cout << "Credential hash is ok." << std::endl; else std::cout << "Verification failed." << std::endl; return EXIT_SUCCESS; }
int main () { RpcSettings settings; settings.readDefaultConfig (); JsonRpc rpc(settings); NameInterface nc(rpc); unsigned cnt = 0; const auto cb = [&cnt] (const std::string& str) { /* FIXME: Adapt to change in call-back interface. */ std::cout << str << std::endl; ++cnt; }; nc.forAllNames (cb); std::cout << "Total: " << cnt << " names" << std::endl; return EXIT_SUCCESS; }
int main () { RpcSettings settings; settings.readDefaultConfig (); JsonRpc rpc(settings); JsonRpc::JsonData res = rpc.executeRpc ("getinfo"); assert (res.isObject ()); std::cout << "Running version: " << res["version"].asInt () << std::endl; res = rpc.executeRpc ("name_show", "id/domob"); assert (res.isObject ()); assert (res["name"].asString () == "id/domob"); assert (res["value"].isString ()); assert (res["expires_in"].isInt ()); try { rpc.executeRpc ("method-does-not-exist", 5, ""); assert (false); } catch (const JsonRpc::RpcError& err) { assert (err.getErrorCode () == -32601); } try { rpc.executeRpc ("name_history", "name-does-not-exist"); assert (false); } catch (const JsonRpc::RpcError& err) { assert (err.getErrorCode () == -4); } return EXIT_SUCCESS; }
/** * Main routine with the usual interface. */ int main (int argc, char** argv) { try { if (argc < 2) { displayHelp (); return EXIT_FAILURE; } const std::string command = argv[1]; if (command == "help") { displayHelp (); return EXIT_SUCCESS; } RpcSettings settings; settings.readDefaultConfig (); JsonRpc rpc(settings); NamecoinInterface nc(rpc); if (command == "check") { if (argc != 3) throw std::runtime_error ("Expected: nmreg check FILE"); doCheck (nc, argv[2]); return EXIT_SUCCESS; } if (argc < 3) throw std::runtime_error ("Need FILE argument."); const std::string stateFile = argv[2]; RegistrationManager reg(rpc, nc); std::ifstream fileIn (stateFile.c_str ()); if (fileIn) { std::cout << "Reading old state." << std::endl; fileIn >> reg; fileIn.close (); } else std::cout << "No old state to read, intialising empty." << std::endl; if (command == "info") doInfo (reg); else if (command == "clear") { const unsigned cleaned = reg.cleanUp (); std::cout << "Removed " << cleaned << " finished names." << std::endl; } else { std::string passphrase; if (nc.needWalletPassphrase ()) { std::cout << "Enter wallet passphrase: "; std::getline (std::cin, passphrase); } NamecoinInterface::WalletUnlocker unlock(nc); unlock.unlock (passphrase); if (command == "update") { reg.update (); std::cout << "Updated all processes." << std::endl; } else if (command == "register") { if (argc != 5) throw std::runtime_error ("Expected: nmreg register" " FILE NAME VALUE"); const std::string name = argv[3]; const std::string val = argv[4]; doRegister (reg, nc, name, val); } else if (command == "multi") { if (argc != 5) throw std::runtime_error ("Expected: nmreg multi" " FILE LIST-FILE VALUE"); const std::string listFile = argv[3]; const std::string val = argv[4]; std::ifstream listIn (listFile.c_str ()); if (!listIn) throw std::runtime_error ("Could not read list of names."); while (listIn) { std::string line; std::getline (listIn, line); if (!line.empty ()) doRegister (reg, nc, line, val); } } else throw std::runtime_error ("Unknown command '" + command + "'."); } std::ofstream fileOut (stateFile.c_str ()); fileOut << reg; fileOut.close (); std::cout << "Wrote new state." << std::endl; }