message: Port address index functions
diff: @@ -246,6 +246,7 @@ uint256 g_best_block;
  int nScriptCheckThreads = 0;
  std::atomic_bool fImporting(false);
  std::atomic_bool fReindex(false);
  +bool fAddressIndex = false; // qtum
  bool fLogEvents = false;
  bool fHavePruned = false;
  bool fPruneMode = false;
  @@ -6234,22 +6235,51 @@ public:
  }
  } instance_of_cmaincleanup;
  +////////////////////////////////////////////////////////////////////////////////// // qtum
  bool GetAddressIndex(uint160 addressHash, int type, std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex, int start, int end)
  {
  - return false;
  + if (!fAddressIndex)
  + return error("address index not enabled");
  +
  + if (!pblocktree->ReadAddressIndex(addressHash, type, addressIndex, start, end))
  + return error("unable to get txids for address");
  +
  + return true;
  }
  bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
  {
  + if (!fAddressIndex)
  return false;
  +
  + if (mempool.getSpentIndex(key, value))
  + return true;
  +
  + if (!pblocktree->ReadSpentIndex(key, value))
  + return false;
  +
  + return true;
  }
  bool GetAddressUnspent(uint160 addressHash, int type, std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs)
  {
  - return false;
  + if (!fAddressIndex)
  + return error("address index not enabled");
  +
  + if (!pblocktree->ReadAddressUnspentIndex(addressHash, type, unspentOutputs))
  + return error("unable to get txids for address");
  +
  + return true;
  }
  bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, const bool fActiveOnly, std::vector<std::pair<uint256, unsigned int> > &hashes)
  {
  - return false;
  + if (!fAddressIndex)
  + return error("Timestamp index not enabled");
  +
  + if (!pblocktree->ReadTimestampIndex(high, low, fActiveOnly, hashes))
  + return error("Unable to get hashes for timestamps");
  +
  + return true;
  }
  +//////////////////////////////////////////////////////////////////////////////////
  