Ejemplo n.º 1
0
json_spirit::Value
name_scan (const json_spirit::Array& params, bool fHelp)
{
  if (fHelp || params.size () > 2)
    throw std::runtime_error (
        "name_scan (\"start\" (\"count\"))\n"
        "\nList names in the database.\n"
        "\nArguments:\n"
        "1. \"start\"       (string, optional) skip initially to this name\n"
        "2. \"count\"       (numeric, optional, default=500) stop after this many names\n"
        "\nResult:\n"
        "[\n"
        + getNameInfoHelp ("  ", ",") +
        "  ...\n"
        "]\n"
        "\nExamples:\n"
        + HelpExampleCli ("name_scan", "")
        + HelpExampleCli ("name_scan", "\"d/abc\"")
        + HelpExampleCli ("name_scan", "\"d/abc\" 10")
        + HelpExampleRpc ("name_scan", "\"d/abc\"")
      );

  if (IsInitialBlockDownload ())
    throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD,
                       "Namecoin is downloading blocks...");

  valtype start;
  if (params.size () >= 1)
    start = ValtypeFromString (params[0].get_str ());

  int count = 500;
  if (params.size () >= 2)
    count = params[1].get_int ();

  json_spirit::Array res;
  if (count <= 0)
    return res;

  {
    LOCK (cs_main);
    pcoinsTip->Flush ();

    valtype name;
    CNameData data;
    for (std::auto_ptr<CNameIterator> iter(pcoinsTip->IterateNames (start));
         count > 0 && iter->next (name, data); --count)
      res.push_back (getNameInfo (name, data));
  }

  return res;
}
Ejemplo n.º 2
0
json_spirit::Value
name_history (const json_spirit::Array& params, bool fHelp)
{
  if (fHelp || params.size () != 1)
    throw std::runtime_error (
        "name_history \"name\"\n"
        "\nLook up the current and all past data for the given name."
        "  -namehistory must be enabled.\n"
        "\nArguments:\n"
        "1. \"name\"          (string, required) the name to query for\n"
        "\nResult:\n"
        "[\n"
        + getNameInfoHelp ("  ", ",") +
        "  ...\n"
        "]\n"
        "\nExamples:\n"
        + HelpExampleCli ("name_history", "\"myname\"")
        + HelpExampleRpc ("name_history", "\"myname\"")
      );

  if (!fNameHistory)
    throw std::runtime_error ("-namehistory is not enabled");

  if (IsInitialBlockDownload ())
    throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD,
                       "Namecoin is downloading blocks...");

  const std::string nameStr = params[0].get_str ();
  const valtype name = ValtypeFromString (nameStr);

  CNameData data;
  CNameHistory history;

  {
    LOCK (cs_main);

    if (!pcoinsTip->GetName (name, data))
      {
        std::ostringstream msg;
        msg << "name not found: '" << nameStr << "'";
        throw JSONRPCError (RPC_WALLET_ERROR, msg.str ());
      }

    if (!pcoinsTip->GetNameHistory (name, history))
      assert (history.empty ());
  }

  json_spirit::Array res;
  BOOST_FOREACH (const CNameData& entry, history.getData ())
    res.push_back (getNameInfo (name, entry));
  res.push_back (getNameInfo (name, data));

  return res;
}
Ejemplo n.º 3
0
json_spirit::Value listblackaddrs(const json_spirit::Array& params, bool fHelp)
{
    if (fHelp || params.size() != 0)
        throw runtime_error(
            "listblackaddrs\n"
            "List blacklisted addresses");

    json_spirit::Array reply;

    for(const char **p = blacklisted_addrs; *p; p++)
	reply.push_back(string(*p));

    return reply;
}
Ejemplo n.º 4
0
bool GdaJson::arrayToVec(const json_spirit::Array& js_array,
						 std::vector<int>& output)
{
	output.clear();
	try {
		for (size_t i=0, sz=js_array.size(); i<sz; ++i) {
			output.push_back(js_array[i].get_int());
		}
		return true;
	}
	catch (std::runtime_error e) {
		LOG_MSG("GdaJson::jsonArrayToVec (int): std::runtime_error");
	}
	return false;
}
Ejemplo n.º 5
0
json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp)
{
    if (fHelp || params.size() != 0)
        throw std::runtime_error(
            "getconnectioncount\n"
            "\nReturns the number of connections to other nodes.\n"
            "\nbResult:\n"
            "n          (numeric) The connection count\n"
            "\nExamples:\n"
            + HelpExampleCli("getconnectioncount", "")
            + HelpExampleRpc("getconnectioncount", "")
        );

    LOCK(cs_vNodes);
    return (int)vNodes.size();
}
Ejemplo n.º 6
0
json_spirit::Value startservicenodes(const json_spirit::Array& params, bool fHelp)
{
    if (IsControlNode(pNodeMain))
    {
        if (fHelp)
            throw std::runtime_error(
                    "startservicenodes [alias1] [alias2] .. [aliasN] \n"
                    "Start remote service node(s)");

        // check if the wallet is syncing
        if (IsInitialBlockDownload())
            return "Initial block download in progress";

        if(pwalletMain->IsLocked())
            return "Wallet needs to be unlocked";

        CControlNode* node = ((CControlNode*)pNodeMain);

        std::string message = "";

        if (params.size() == 0)
        {
            std::vector<std::string> vAliases = node->GetSlaveAliases();

            if (vAliases.size() == 0)
                message += "no registered slave service nodes";
            else
                BOOST_FOREACH(std::string alias, vAliases)
                    message += startservicenode(node, alias);
        }
        else
        {
            BOOST_FOREACH(json_spirit::Value param, params)
                message += startservicenode(node, param.get_str());
        }

        return message;
    }
    else
    {
        if (fHelp)
            throw std::runtime_error("");

        throw std::runtime_error("generatesharedkey is only available to control nodes");
    }
}
Ejemplo n.º 7
0
json_spirit::Value generatesharedkey(const json_spirit::Array& params, bool fHelp)
{
    if (IsControlNode(pNodeMain))
    {
        if ( fHelp || params.size() != 0)
            throw std::runtime_error(
                    "generatesharedkey\n"
                    "Generates a key to be shared between the control node and service node");

        return ((CControlNode*)pNodeMain)->GenerateSharedKey();
    }
    else
    {
        if (fHelp)
            throw std::runtime_error("");

        throw std::runtime_error("generatesharedkey is only available to control nodes");
    }
}
Ejemplo n.º 8
0
json_spirit::Value
name_checkdb (const json_spirit::Array& params, bool fHelp)
{
  if (fHelp || params.size () != 0)
    throw std::runtime_error (
        "name_checkdb\n"
        "\nValidate the name DB's consistency.\n"
        "\nRoughly between blocks 139,000 and 180,000, this call is expected\n"
        "to fail due to the historic 'name stealing' bug.\n"
        "\nResult:\n"
        "xxxxx                        (boolean) whether the state is valid\n"
        "\nExamples:\n"
        + HelpExampleCli ("name_checkdb", "")
        + HelpExampleRpc ("name_checkdb", "")
      );

  LOCK (cs_main);
  pcoinsTip->Flush ();
  return pcoinsTip->ValidateNameDB ();
}
Ejemplo n.º 9
0
json_spirit::Value ping(const json_spirit::Array& params, bool fHelp)
{
    if (fHelp || params.size() != 0)
        throw std::runtime_error(
            "ping\n"
            "\nRequests that a ping be sent to all other nodes, to measure ping time.\n"
            "Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n"
            "Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n"
            "\nExamples:\n"
            + HelpExampleCli("ping", "")
            + HelpExampleRpc("ping", "")
        );

    // Request that each node send a ping during next message processing pass
    LOCK(cs_vNodes);
    BOOST_FOREACH(CNode* pNode, vNodes) {
        pNode->fPingQueued = true;
    }

    return json_spirit::Value::null;
}
Ejemplo n.º 10
0
json_spirit::Value listservicenodes(const json_spirit::Array& params, bool fHelp)
{
    if (fHelp)
        throw std::runtime_error(
                "listservicenodes [extensive = 0] \n"
                "Lists known service nodes ");

    // check if the wallet is syncing
    if (IsInitialBlockDownload())
        return "Initial block download in progress";

    std::string result;

    bool extensive = false;

    if (params.size() > 0)
        extensive = params[0].get_bool();

    BOOST_FOREACH(boost::shared_ptr<CServiceNodeInfo> node, pNodeMain->GetServiceNodes())
        result += (boost::format("%1%\n") % (node->ToString(extensive))).str();

    return result;
}
Ejemplo n.º 11
0
json_spirit::Value
name_show (const json_spirit::Array& params, bool fHelp)
{
  if (fHelp || params.size () != 1)
    throw std::runtime_error (
        "name_show \"name\"\n"
        "\nLook up the current data for the given name."
        "  Fails if the name doesn't exist.\n"
        "\nArguments:\n"
        "1. \"name\"          (string, required) the name to query for\n"
        "\nResult:\n"
        + getNameInfoHelp ("", "") +
        "\nExamples:\n"
        + HelpExampleCli ("name_show", "\"myname\"")
        + HelpExampleRpc ("name_show", "\"myname\"")
      );

  if (IsInitialBlockDownload ())
    throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD,
                       "Namecoin is downloading blocks...");

  const std::string nameStr = params[0].get_str ();
  const valtype name = ValtypeFromString (nameStr);

  CNameData data;
  {
    LOCK (cs_main);
    if (!pcoinsTip->GetName (name, data))
      {
        std::ostringstream msg;
        msg << "name not found: '" << nameStr << "'";
        throw JSONRPCError (RPC_WALLET_ERROR, msg.str ());
      }
  }

  return getNameInfo (name, data);
}
Ejemplo n.º 12
0
void DecisionCreationWidget::editArray(json_spirit::Array array)
{
    if (array.size() < 6) {
        return;
    }

    // Load owner address
    json_spirit::Value ownerAddr = array.at(0);
    ui->lineEditOwnerAddr->setText(QString::fromStdString(ownerAddr.get_str()));

    // Load branchID
    json_spirit::Value branch = array.at(1);
    QString branchLabel = "Branch: ";
    QString branchID = QString::fromStdString(branch.get_str());
    branchLabel.append(branchID.left(12));
    branchLabel.append("...");
    ui->labelBranch->setText(branchLabel);
    if (branchID == "0f894a25c5e0318ee148fe54600ebbf50782f0a1df1eb2aab06321a8ccec270d") {
        ui->comboBoxBranch->setCurrentIndex(0); // Main
    } else if (branchID == "419cd87761f45c108a976ca6d93d4929c7c4d1ff4386f5089fc2f7ff7ae21ddf") {
        ui->comboBoxBranch->setCurrentIndex(1); // Sports
    } else if (branchID == "3277b5057ac9cda54e9edfbb45fd8bab38be1b5afc3cd6c587f6d17779f34f74") {
        ui->comboBoxBranch->setCurrentIndex(2); // Econ
    }

    // Load prompt
    json_spirit::Value prompt = array.at(2);
    ui->plainTextEditPrompt->setPlainText(QString::fromStdString(prompt.get_str()));

    // Load event over by
//    TODO: Replace with nLockTime
//    json_spirit::Value eventOverBy = array.at(3);
//    int overBy = eventOverBy.get_int();

    // Load voteMandatory
    json_spirit::Value voteMandatory = array.at(4);
    ui->checkBoxVoteMandatory->setChecked(voteMandatory.get_bool());

    // Load scaled
    json_spirit::Value scaled = array.at(5);
    bool isScaled = scaled.get_bool();
    ui->radioButtonScaled->setChecked(isScaled);
    if (isScaled) {
        // Load scale values
        json_spirit::Value scaledMin = array.at(6);
        ui->doubleSpinBoxScaledMin->setValue(scaledMin.get_real());
        json_spirit::Value scaledMax = array.at(7);
        ui->doubleSpinBoxScaledMax->setValue(scaledMax.get_real());
    }

    // Unhide the scaled spinboxes if the decision is scaled
    on_radioButtonScaled_clicked(isScaled);

    // Check for update index from model
    if (isScaled && array.size() == 10) {
        ui->pushButtonCreateDecision->hide();
        ui->pushButtonUpdateDecision->show();
        updateIndex = array.at(9).get_int();
    } else if (!isScaled && array.size() == 8) {
        ui->pushButtonCreateDecision->hide();
        ui->pushButtonUpdateDecision->show();
        updateIndex = array.at(7).get_int();
    }
}
Ejemplo n.º 13
0
json_spirit::Value
name_filter (const json_spirit::Array& params, bool fHelp)
{
  if (fHelp || params.size () > 5)
    throw std::runtime_error (
        "name_filter (\"regexp\" (\"maxage\" (\"from\" (\"nb\" (\"stat\")))))\n"
        "\nScan and list names matching a regular expression.\n"
        "\nArguments:\n"
        "1. \"regexp\"      (string, optional) filter names with this regexp\n"
        "2. \"maxage\"      (numeric, optional, default=36000) only consider names updated in the last \"maxage\" blocks; 0 means all names\n"
        "3. \"from\"        (numeric, optional, default=0) return from this position onward; index starts at 0\n"
        "4. \"nb\"          (numeric, optional, default=0) return only \"nb\" entries; 0 means all\n"
        "5. \"stat\"        (string, optional) if set to the string \"stat\", print statistics instead of returning the names\n"
        "\nResult:\n"
        "[\n"
        + getNameInfoHelp ("  ", ",") +
        "  ...\n"
        "]\n"
        "\nExamples:\n"
        + HelpExampleCli ("name_filter", "\"\" 5")
        + HelpExampleCli ("name_filter", "\"^id/\"")
        + HelpExampleCli ("name_filter", "\"^id/\" 36000 0 0 \"stat\"")
        + HelpExampleRpc ("name_scan", "\"^d/\"")
      );

  if (IsInitialBlockDownload ())
    throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD,
                       "Namecoin is downloading blocks...");

  /* ********************** */
  /* Interpret parameters.  */

  bool haveRegexp(false);
  boost::xpressive::sregex regexp;

  int maxage(36000), from(0), nb(0);
  bool stats(false);

  if (params.size () >= 1)
    {
      haveRegexp = true;
      regexp = boost::xpressive::sregex::compile (params[0].get_str ());
    }

  if (params.size () >= 2)
    maxage = params[1].get_int ();
  if (maxage < 0)
    throw JSONRPCError (RPC_INVALID_PARAMETER,
                        "'maxage' should be non-negative");
  if (params.size () >= 3)
    from = params[2].get_int ();
  if (from < 0)
    throw JSONRPCError (RPC_INVALID_PARAMETER, "'from' should be non-negative");

  if (params.size () >= 4)
    nb = params[3].get_int ();
  if (nb < 0)
    throw JSONRPCError (RPC_INVALID_PARAMETER, "'nb' should be non-negative");

  if (params.size () >= 5)
    {
      if (params[4].get_str () != "stat")
        throw JSONRPCError (RPC_INVALID_PARAMETER,
                            "fifth argument must be the literal string 'stat'");
      stats = true;
    }

  /* ******************************************* */
  /* Iterate over names to build up the result.  */

  json_spirit::Array names;
  unsigned count(0);

  /* The lock must be held throughout the call, since walker.getResult()
     uses chainActive for the block height in stats mode.  */
  LOCK (cs_main);
  pcoinsTip->Flush ();

  std::auto_ptr<CNameIterator> iter(pcoinsTip->IterateNames (valtype ()));
  valtype name;
  CNameData data;
  while (iter->next (name, data))
    {
      const int age = chainActive.Height () - data.getHeight ();
      assert (age >= 0);
      if (maxage != 0 && age >= maxage)
        continue;

      if (haveRegexp)
        {
          const std::string nameStr = ValtypeToString (name);
          boost::xpressive::smatch matches;
          if (!boost::xpressive::regex_search (nameStr, matches, regexp))
            continue;
        }

      if (from > 0)
        {
          --from;
          continue;
        }
      assert (from == 0);

      if (stats)
        ++count;
      else
        names.push_back (getNameInfo (name, data));

      if (nb > 0)
        {
          --nb;
          if (nb == 0)
            break;
        }
    }

  /* ********************************************************** */
  /* Return the correct result (take stats mode into account).  */

  if (stats)
    {
      json_spirit::Object res;
      res.push_back (json_spirit::Pair ("blocks", chainActive.Height ()));
      res.push_back (json_spirit::Pair ("count", static_cast<int> (count)));

      return res;
    }

  return names;
}