text: // Copyright (c) 2010 Satoshi Nakamoto
  // Copyright (c) 2009-2018 The Bitcoin Core developers
  // Distributed under the MIT software license, see the accompanying
  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  
  #include <chain.h>
  #include <clientversion.h>
  #include <core_io.h>
  #include <crypto/ripemd160.h>
  #include <key_io.h>
  #include <validation.h>
  #include <httpserver.h>
  #include <net.h>
  #include <netbase.h>
  #include <outputtype.h>
  #include <rpc/blockchain.h>
  #include <rpc/server.h>
  #include <rpc/util.h>
  #include <timedata.h>
  #include <util.h>
  #include <utilstrencodings.h>
  #ifdef ENABLE_WALLET
  #include <wallet/rpcwallet.h>
  #include <wallet/wallet.h>
  #include <wallet/walletdb.h>
  #endif
  #include <warnings.h>
  
  #include <stdint.h>
  #ifdef HAVE_MALLOC_INFO
  #include <malloc.h>
  #endif
  
  #include <univalue.h>
  
  /// FORKGEN ONLY {
  
  /**
   * @note Do not add or change anything in the information returned by this
   * method. `getinfo` exists for backwards-compatibility only. It combines
   * information from wildly different sources in the program, which is a mess,
   * and is thus planned to be deprecated eventually.
   *
   * Based on the source of the information, new information should be added to:
   * - `getblockchaininfo`,
   * - `getnetworkinfo` or
   * - `getwalletinfo`
   *
   * Or alternatively, create a specific query method for the information.
   **/
  UniValue getinfo(const JSONRPCRequest& request)
  {
      if (request.fHelp || request.params.size() != 0)
          throw std::runtime_error(
              "getinfo\n"
              "\nDEPRECATED. Returns an object containing various state info.\n"
              "\nResult:\n"
              "{\n"
              "  \"deprecation-warning\": \"...\" (string) warning that the getinfo command is deprecated and will be removed in 0.16\n"
              "  \"version\": xxxxx,           (numeric) the server version\n"
              "  \"protocolversion\": xxxxx,   (numeric) the protocol version\n"
              "  \"walletversion\": xxxxx,     (numeric) the wallet version\n"
              "  \"balance\": xxxxxxx,         (numeric) the total paycheckcash balance of the wallet\n"
              "  \"blocks\": xxxxxx,           (numeric) the current number of blocks processed in the server\n"
              "  \"timeoffset\": xxxxx,        (numeric) the time offset\n"
              "  \"connections\": xxxxx,       (numeric) the number of connections\n"
              "  \"proxy\": \"host:port\",       (string, optional) the proxy used by the server\n"
              "  \"difficulty\": xxxxxx,       (numeric) the current difficulty\n"
              "  \"testnet\": true|false,      (boolean) if the server is using testnet or not\n"
              "  \"keypoololdest\": xxxxxx,    (numeric) the timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool\n"
              "  \"keypoolsize\": xxxx,        (numeric) how many new keys are pre-generated\n"
              "  \"unlocked_until\": ttt,      (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
              "  \"paytxfee\": x.xxxx,         (numeric) the transaction fee set in " +
              CURRENCY_UNIT + "/kB\n"
                              "  \"relayfee\": x.xxxx,         (numeric) minimum relay fee for transactions in " +
              CURRENCY_UNIT + "/kB\n"
                              "  \"errors\": \"...\"             (string) any error messages\n"
                              "}\n"
                              "\nExamples:\n" +
              HelpExampleCli("getinfo", "") + HelpExampleRpc("getinfo", ""));
  
  #ifdef ENABLE_WALLET
      std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
      CWallet* const pwallet = wallet.get();
  
      LOCK2(cs_main, pwallet ? &pwallet->cs_wallet : nullptr);
  #else
      LOCK(cs_main);
  #endif
  
      proxyType proxy;
      GetProxy(NET_IPV4, proxy);
  
      UniValue obj(UniValue::VOBJ);
      obj.push_back(Pair("deprecation-warning", "WARNING: getinfo is deprecated and will be fully removed SOON."
                                                " Projects should transition to using getblockchaininfo, getnetworkinfo, and getwalletinfo ASAP"));
      obj.push_back(Pair("version", CLIENT_VERSION));
      obj.push_back(Pair("protocolversion", PROTOCOL_VERSION));
  #ifdef ENABLE_WALLET
      if (pwallet) {
          obj.push_back(Pair("walletversion", pwallet->GetVersion()));
          obj.push_back(Pair("balance", ValueFromAmount(pwallet->GetBalance())));
      }
  #endif
      obj.push_back(Pair("blocks", (int)chainActive.Height()));
      obj.push_back(Pair("timeoffset", GetTimeOffset()));
      if (g_connman)
          obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));
      obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : std::string())));
      obj.push_back(Pair("difficulty", (double)GetDifficulty(chainActive.Tip())));
      obj.push_back(Pair("testnet", Params().NetworkIDString() == CBaseChainParams::TESTNET));
  #ifdef ENABLE_WALLET
      if (pwallet) {
          obj.push_back(Pair("keypoololdest", pwallet->GetOldestKeyPoolTime()));
          obj.push_back(Pair("keypoolsize", (int)pwallet->GetKeyPoolSize()));
      }
      if (pwallet && pwallet->IsCrypted()) {
          obj.push_back(Pair("unlocked_until", pwallet->nRelockTime));
      }
      obj.push_back(Pair("paytxfee", ValueFromAmount(pwallet->m_pay_tx_fee.GetFeePerK())));
  #endif
      obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
      obj.push_back(Pair("errors", GetWarnings("statusbar")));
      return obj;
  }
  
  /// } FORKGEN ONLY
  
  // Needed even with !ENABLE_WALLET, to pass (ignored) pointers around
  class CWallet;
  
  static UniValue createmultisig(const JSONRPCRequest& request)
  {
      if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) {
          std::string msg = "createmultisig nrequired [\"key\",...] ( \"address_type\" )\n"
                            "\nCreates a multi-signature address with n signature of m keys required.\n"
                            "It returns a json object with the address and redeemScript.\n"
                            "\nArguments:\n"
                            "1. nrequired                    (numeric, required) The number of required signatures out of the n keys.\n"
                            "2. \"keys\"                       (string, required) A json array of hex-encoded public keys\n"
                            "     [\n"
                            "       \"key\"                    (string) The hex-encoded public key\n"
                            "       ,...\n"
                            "     ]\n"
                            "3. \"address_type\"               (string, optional) The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\". Default is legacy.\n"
  
                            "\nResult:\n"
                            "{\n"
                            "  \"address\":\"multisigaddress\",  (string) The value of the new multisig address.\n"
                            "  \"redeemScript\":\"script\"       (string) The string value of the hex-encoded redemption script.\n"
                            "}\n"
  
                            "\nExamples:\n"
                            "\nCreate a multisig address from 2 public keys\n" +
                            HelpExampleCli("createmultisig", "2 \"[\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\",\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\"]\"") +
                            "\nAs a json rpc call\n" + HelpExampleRpc("createmultisig", "2, \"[\\\"03789ed0bb717d88f7d321a368d905e7430207ebbd82bd342cf11ae157a7ace5fd\\\",\\\"03dbc6764b8884a92e871274b87583e6d5c2a58819473e17e107ef3f6aa5a61626\\\"]\"");
          throw std::runtime_error(msg);
      }
  
      int required = request.params[0].get_int();
  
      // Get the public keys
      const UniValue& keys = request.params[1].get_array();
      std::vector<CPubKey> pubkeys;
      for (unsigned int i = 0; i < keys.size(); ++i) {
          if (IsHex(keys[i].get_str()) && (keys[i].get_str().length() == 66 || keys[i].get_str().length() == 130)) {
              pubkeys.push_back(HexToPubKey(keys[i].get_str()));
          } else {
              throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Invalid public key: %s\nNote that from v0.16, createmultisig no longer accepts addresses."
                                                                       " Users must use addmultisigaddress to create multisig addresses with addresses known to the wallet.",
                                                                 keys[i].get_str()));
          }
      }
  
      // Get the output type
      OutputType output_type = OutputType::LEGACY;
      if (!request.params[2].isNull()) {
          if (!ParseOutputType(request.params[2].get_str(), output_type)) {
              throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[2].get_str()));
          }
      }
  
      // Construct using pay-to-script-hash:
      const CScript inner = CreateMultisigRedeemscript(required, pubkeys);
      CBasicKeyStore keystore;
      const CTxDestination dest = AddAndGetDestinationForScript(keystore, inner, output_type);
  
      UniValue result(UniValue::VOBJ);
      result.pushKV("address", EncodeDestination(dest));
      result.pushKV("redeemScript", HexStr(inner.begin(), inner.end()));
  
      return result;
  }
  
  static UniValue verifymessage(const JSONRPCRequest& request)
  {
      if (request.fHelp || request.params.size() != 3)
          throw std::runtime_error(
              "verifymessage \"address\" \"signature\" \"message\"\n"
              "\nVerify a signed message\n"
              "\nArguments:\n"
              "1. \"address\"         (string, required) The paycheckcash address to use for the signature.\n"
              "2. \"signature\"       (string, required) The signature provided by the signer in base 64 encoding (see signmessage).\n"
              "3. \"message\"         (string, required) The message that was signed.\n"
              "\nResult:\n"
              "true|false   (boolean) If the signature is verified or not.\n"
              "\nExamples:\n"
              "\nUnlock the wallet for 30 seconds\n" +
              HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
              "\nCreate the signature\n" + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") +
              "\nVerify the signature\n" + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
              "\nAs json rpc\n" + HelpExampleRpc("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"signature\", \"my message\""));
  
      LOCK(cs_main);
  
      std::string strAddress = request.params[0].get_str();
      std::string strSign = request.params[1].get_str();
      std::string strMessage = request.params[2].get_str();
  
      CTxDestination destination = DecodeDestination(strAddress);
      if (!IsValidDestination(destination)) {
          throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
      }
  
      const CKeyID* keyID = boost::get<CKeyID>(&destination);
      if (!keyID) {
          throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
      }
  
      bool fInvalid = false;
      std::vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid);
  
      if (fInvalid)
          throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
  
      CHashWriter ss(SER_GETHASH, 0);
      ss << strMessageMagic;
      ss << strMessage;
  
      CPubKey pubkey;
      if (!pubkey.RecoverCompact(ss.GetHash(), vchSig))
          return false;
  
      return (pubkey.GetID() == *keyID);
  }
  
  static UniValue signmessagewithprivkey(const JSONRPCRequest& request)
  {
      if (request.fHelp || request.params.size() != 2)
          throw std::runtime_error(
              "signmessagewithprivkey \"privkey\" \"message\"\n"
              "\nSign a message with the private key of an address\n"
              "\nArguments:\n"
              "1. \"privkey\"         (string, required) The private key to sign the message with.\n"
              "2. \"message\"         (string, required) The message to create a signature of.\n"
              "\nResult:\n"
              "\"signature\"          (string) The signature of the message encoded in base 64\n"
              "\nExamples:\n"
              "\nCreate the signature\n" +
              HelpExampleCli("signmessagewithprivkey", "\"privkey\" \"my message\"") +
              "\nVerify the signature\n" + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
              "\nAs json rpc\n" + HelpExampleRpc("signmessagewithprivkey", "\"privkey\", \"my message\""));
  
      std::string strPrivkey = request.params[0].get_str();
      std::string strMessage = request.params[1].get_str();
  
      CKey key = DecodeSecret(strPrivkey);
      if (!key.IsValid()) {
          throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
      }
  
      CHashWriter ss(SER_GETHASH, 0);
      ss << strMessageMagic;
      ss << strMessage;
  
      std::vector<unsigned char> vchSig;
      if (!key.SignCompact(ss.GetHash(), vchSig))
          throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
  
      return EncodeBase64(vchSig.data(), vchSig.size());
  }
  
  static UniValue setmocktime(const JSONRPCRequest& request)
  {
      if (request.fHelp || request.params.size() != 1)
          throw std::runtime_error(
              "setmocktime timestamp\n"
              "\nSet the local time to given timestamp (-regtest only)\n"
              "\nArguments:\n"
              "1. timestamp  (integer, required) Unix seconds-since-epoch timestamp\n"
              "   Pass 0 to go back to using the system time.");
  
      if (!Params().MineBlocksOnDemand())
          throw std::runtime_error("setmocktime for regression testing (-regtest mode) only");
  
      // For now, don't change mocktime if we're in the middle of validation, as
      // this could have an effect on mempool time-based eviction, as well as
      // IsCurrentForFeeEstimation() and IsInitialBlockDownload().
      // TODO: figure out the right way to synchronize around mocktime, and
      // ensure all call sites of GetTime() are accessing this safely.
      LOCK(cs_main);
  
      RPCTypeCheck(request.params, {UniValue::VNUM});
      SetMockTime(request.params[0].get_int64());
  
      return NullUniValue;
  }
  
  static UniValue RPCLockedMemoryInfo()
  {
      LockedPool::Stats stats = LockedPoolManager::Instance().stats();
      UniValue obj(UniValue::VOBJ);
      obj.pushKV("used", uint64_t(stats.used));
      obj.pushKV("free", uint64_t(stats.free));
      obj.pushKV("total", uint64_t(stats.total));
      obj.pushKV("locked", uint64_t(stats.locked));
      obj.pushKV("chunks_used", uint64_t(stats.chunks_used));
      obj.pushKV("chunks_free", uint64_t(stats.chunks_free));
      return obj;
  }
  
  #ifdef HAVE_MALLOC_INFO
  static std::string RPCMallocInfo()
  {
      char* ptr = nullptr;
      size_t size = 0;
      FILE* f = open_memstream(&ptr, &size);
      if (f) {
          malloc_info(0, f);
          fclose(f);
          if (ptr) {
              std::string rv(ptr, size);
              free(ptr);
              return rv;
          }
      }
      return "";
  }
  #endif
  
  static UniValue getmemoryinfo(const JSONRPCRequest& request)
  {
      /* Please, avoid using the word "pool" here in the RPC interface or help,
       * as users will undoubtedly confuse it with the other "memory pool"
       */
      if (request.fHelp || request.params.size() > 1)
          throw std::runtime_error(
              "getmemoryinfo (\"mode\")\n"
              "Returns an object containing information about memory usage.\n"
              "Arguments:\n"
              "1. \"mode\" determines what kind of information is returned. This argument is optional, the default mode is \"stats\".\n"
              "  - \"stats\" returns general statistics about memory usage in the daemon.\n"
              "  - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc 2.10+).\n"
              "\nResult (mode \"stats\"):\n"
              "{\n"
              "  \"locked\": {               (json object) Information about locked memory manager\n"
              "    \"used\": xxxxx,          (numeric) Number of bytes used\n"
              "    \"free\": xxxxx,          (numeric) Number of bytes available in current arenas\n"
              "    \"total\": xxxxxxx,       (numeric) Total number of bytes managed\n"
              "    \"locked\": xxxxxx,       (numeric) Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk.\n"
              "    \"chunks_used\": xxxxx,   (numeric) Number allocated chunks\n"
              "    \"chunks_free\": xxxxx,   (numeric) Number unused chunks\n"
              "  }\n"
              "}\n"
              "\nResult (mode \"mallocinfo\"):\n"
              "\"<malloc version=\"1\">...\"\n"
              "\nExamples:\n" +
              HelpExampleCli("getmemoryinfo", "") + HelpExampleRpc("getmemoryinfo", ""));
  
      std::string mode = request.params[0].isNull() ? "stats" : request.params[0].get_str();
      if (mode == "stats") {
          UniValue obj(UniValue::VOBJ);
          obj.pushKV("locked", RPCLockedMemoryInfo());
          return obj;
      } else if (mode == "mallocinfo") {
  #ifdef HAVE_MALLOC_INFO
          return RPCMallocInfo();
  #else
          throw JSONRPCError(RPC_INVALID_PARAMETER, "mallocinfo is only available when compiled with glibc 2.10+");
  #endif
      } else {
          throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown mode " + mode);
      }
  }
  
  static void EnableOrDisableLogCategories(UniValue cats, bool enable)
  {
      cats = cats.get_array();
      for (unsigned int i = 0; i < cats.size(); ++i) {
          std::string cat = cats[i].get_str();
  
          bool success;
          if (enable) {
              success = g_logger->EnableCategory(cat);
          } else {
              success = g_logger->DisableCategory(cat);
          }
  
          if (!success) {
              throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown logging category " + cat);
          }
      }
  }
  
  UniValue logging(const JSONRPCRequest& request)
  {
      if (request.fHelp || request.params.size() > 2) {
          throw std::runtime_error(
              "logging ( <include> <exclude> )\n"
              "Gets and sets the logging configuration.\n"
              "When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n"
              "When called with arguments, adds or removes categories from debug logging and return the lists above.\n"
              "The arguments are evaluated in order \"include\", \"exclude\".\n"
              "If an item is both included and excluded, it will thus end up being excluded.\n"
              "The valid logging categories are: " +
              ListLogCategories() + "\n"
                                    "In addition, the following are available as category names with special meanings:\n"
                                    "  - \"all\",  \"1\" : represent all logging categories.\n"
                                    "  - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n"
                                    "\nArguments:\n"
                                    "1. \"include\"        (array of strings, optional) A json array of categories to add debug logging\n"
                                    "     [\n"
                                    "       \"category\"   (string) the valid logging category\n"
                                    "       ,...\n"
                                    "     ]\n"
                                    "2. \"exclude\"        (array of strings, optional) A json array of categories to remove debug logging\n"
                                    "     [\n"
                                    "       \"category\"   (string) the valid logging category\n"
                                    "       ,...\n"
                                    "     ]\n"
                                    "\nResult:\n"
                                    "{                   (json object where keys are the logging categories, and values indicates its status\n"
                                    "  \"category\": 0|1,  (numeric) if being debug logged or not. 0:inactive, 1:active\n"
                                    "  ...\n"
                                    "}\n"
                                    "\nExamples:\n" +
              HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"") + HelpExampleRpc("logging", "[\"all\"], \"[libevent]\""));
      }
  
      uint32_t original_log_categories = g_logger->GetCategoryMask();
      if (request.params[0].isArray()) {
          EnableOrDisableLogCategories(request.params[0], true);
      }
      if (request.params[1].isArray()) {
          EnableOrDisableLogCategories(request.params[1], false);
      }
      uint32_t updated_log_categories = g_logger->GetCategoryMask();
      uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
  
      // Update libevent logging if BCLog::LIBEVENT has changed.
      // If the library version doesn't allow it, UpdateHTTPServerLogging() returns false,
      // in which case we should clear the BCLog::LIBEVENT flag.
      // Throw an error if the user has explicitly asked to change only the libevent
      // flag and it failed.
      if (changed_log_categories & BCLog::LIBEVENT) {
          if (!UpdateHTTPServerLogging(g_logger->WillLogCategory(BCLog::LIBEVENT))) {
              g_logger->DisableCategory(BCLog::LIBEVENT);
              if (changed_log_categories == BCLog::LIBEVENT) {
                  throw JSONRPCError(RPC_INVALID_PARAMETER, "libevent logging cannot be updated when using libevent before v2.1.1.");
              }
          }
      }
  
      UniValue result(UniValue::VOBJ);
      std::vector<CLogCategoryActive> vLogCatActive = ListActiveLogCategories();
      for (const auto& logCatActive : vLogCatActive) {
          result.pushKV(logCatActive.category, logCatActive.active);
      }
  
      return result;
  }
  
  static UniValue echo(const JSONRPCRequest& request)
  {
      if (request.fHelp)
          throw std::runtime_error(
              "echo|echojson \"message\" ...\n"
              "\nSimply echo back the input arguments. This command is for testing.\n"
              "\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in"
              "paycheckcash-cli and the GUI. There is no server-side difference.");
  
      return request.params;
  }
  
  static UniValue getinfo_deprecated(const JSONRPCRequest& request)
  {
      throw JSONRPCError(RPC_METHOD_NOT_FOUND,
          "getinfo\n"
          "\nThis call was removed in version 0.16.0. Use the appropriate fields from:\n"
          "- getblockchaininfo: blocks, difficulty, chain\n"
          "- getnetworkinfo: version, protocolversion, timeoffset, connections, proxy, relayfee, warnings\n"
          "- getwalletinfo: balance, keypoololdest, keypoolsize, paytxfee, unlocked_until, walletversion\n"
          "\npaycheckcash-cli has the option -getinfo to collect and format these in the old format.");
  }
  
  static const CRPCCommand commands[] =
      {
          //  category              name                      actor (function)         argNames
          //  --------------------- ------------------------  -----------------------  ----------
          {"control", "getmemoryinfo", &getmemoryinfo, {"mode"}},
          {"control", "logging", &logging, {"include", "exclude"}},
          {"util", "createmultisig", &createmultisig, {"nrequired", "keys"}},
          {"util", "verifymessage", &verifymessage, {"address", "signature", "message"}},
          {"util", "signmessagewithprivkey", &signmessagewithprivkey, {"privkey", "message"}},
  
          {"forkgen", "getinfo", &getinfo, {}}, /* uses wallet if enabled */
  
          /* Not shown in help */
          {"hidden", "setmocktime", &setmocktime, {"timestamp"}},
          {"hidden", "echo", &echo, {"arg0", "arg1", "arg2", "arg3", "arg4", "arg5", "arg6", "arg7", "arg8", "arg9"}},
          {"hidden", "echojson", &echo, {"arg0", "arg1", "arg2", "arg3", "arg4", "arg5", "arg6", "arg7", "arg8", "arg9"}},
          {"hidden", "getinfo", &getinfo_deprecated, {}},
  };
  
  void RegisterMiscRPCCommands(CRPCTable& t)
  {
      for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
          t.appendCommand(commands[vcidx].name, &commands[vcidx]);
  }
  