Browse Source

Added additional information in keva_get result.

views
Just Wonder 4 years ago
parent
commit
4bbf37c2dc
  1. 120
      src/rpc/rpckeva_nonwallet.cpp

120
src/rpc/rpckeva_nonwallet.cpp

@ -25,6 +25,53 @@ @@ -25,6 +25,53 @@
#include <univalue.h>
#include <boost/xpressive/xpressive_dynamic.hpp>
/**
* Utility routine to construct a "keva info" object to return. This is used
* for keva_filter.
* @param key The key.
* @param value The key's value.
* @param outp The last update's outpoint.
* @param addr The key's address script.
* @param height The key's last update height.
* @return A JSON object to return.
*/
UniValue
getKevaInfo(const valtype& key, const valtype& value, const COutPoint& outp,
const CScript& addr, int height)
{
UniValue obj(UniValue::VOBJ);
obj.pushKV("key", ValtypeToString(key));
obj.pushKV("value", ValtypeToString(value));
obj.pushKV("txid", outp.hash.GetHex());
obj.pushKV("vout", static_cast<int>(outp.n));
/* Try to extract the address. May fail if we can't parse the script
as a "standard" script. */
CTxDestination dest;
std::string addrStr;
if (ExtractDestination(addr, dest))
addrStr = EncodeDestination(dest);
else
addrStr = "<nonstandard>";
obj.pushKV("address", addrStr);
obj.pushKV("height", height);
return obj;
}
/**
* Return keva info object for a CKevaData object.
* @param key The key.
* @param data The key's data.
* @return A JSON object to return.
*/
UniValue
getKevaInfo(const valtype& key, const CKevaData& data)
{
return getKevaInfo(key, data.getValue(), data.getUpdateOutpoint(),
data.getAddress(), data.getHeight());
}
UniValue keva_get(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 2) {
@ -60,25 +107,31 @@ UniValue keva_get(const JSONRPCRequest& request) @@ -60,25 +107,31 @@ UniValue keva_get(const JSONRPCRequest& request)
if (key.size() > MAX_KEY_LENGTH)
throw JSONRPCError(RPC_INVALID_PARAMETER, "the key is too long");
CKevaData data;
{
LOCK(cs_main);
pcoinsTip->GetName(nameSpace, key, data);
}
auto value = data.getValue();
// Also get the unconfirmed ones.
// If there is unconfirmed one, return its value.
{
LOCK (mempool.cs);
valtype val;
if (mempool.getUnconfirmedKeyValue(nameSpace, key, val)) {
value = val;
UniValue obj(UniValue::VOBJ);
obj.pushKV("key", keyStr);
obj.pushKV("value", ValtypeToString(val));
return obj;
}
}
// Otherwise, return the confirmed value.
{
LOCK(cs_main);
CKevaData data;
if (pcoinsTip->GetName(nameSpace, key, data)) {
return getKevaInfo(key, data);
}
}
// Empty value
UniValue obj(UniValue::VOBJ);
obj.pushKV("key", keyStr);
obj.pushKV("value", ValtypeToString(value));
obj.pushKV("value", "");
return obj;
}
@ -108,53 +161,6 @@ std::string getKevaInfoHelp (const std::string& indent, const std::string& trail @@ -108,53 +161,6 @@ std::string getKevaInfoHelp (const std::string& indent, const std::string& trail
return res.str ();
}
/**
* Utility routine to construct a "keva info" object to return. This is used
* for keva_filter.
* @param key The key.
* @param value The key's value.
* @param outp The last update's outpoint.
* @param addr The key's address script.
* @param height The key's last update height.
* @return A JSON object to return.
*/
UniValue
getKevaInfo(const valtype& key, const valtype& value, const COutPoint& outp,
const CScript& addr, int height)
{
UniValue obj(UniValue::VOBJ);
obj.pushKV("key", ValtypeToString(key));
obj.pushKV("value", ValtypeToString(value));
obj.pushKV("txid", outp.hash.GetHex());
obj.pushKV("vout", static_cast<int>(outp.n));
/* Try to extract the address. May fail if we can't parse the script
as a "standard" script. */
CTxDestination dest;
std::string addrStr;
if (ExtractDestination(addr, dest))
addrStr = EncodeDestination(dest);
else
addrStr = "<nonstandard>";
obj.pushKV("address", addrStr);
obj.pushKV("height", height);
return obj;
}
/**
* Return keva info object for a CKevaData object.
* @param key The key.
* @param data The key's data.
* @return A JSON object to return.
*/
UniValue
getKevaInfo(const valtype& key, const CKevaData& data)
{
return getKevaInfo(key, data.getValue(), data.getUpdateOutpoint(),
data.getAddress(), data.getHeight());
}
UniValue keva_filter(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() > 6 || request.params.size() == 0)

Loading…
Cancel
Save