|
|
@ -25,6 +25,53 @@ |
|
|
|
#include <univalue.h> |
|
|
|
#include <univalue.h> |
|
|
|
#include <boost/xpressive/xpressive_dynamic.hpp> |
|
|
|
#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) |
|
|
|
UniValue keva_get(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (request.fHelp || request.params.size() != 2) { |
|
|
|
if (request.fHelp || request.params.size() != 2) { |
|
|
@ -60,25 +107,31 @@ UniValue keva_get(const JSONRPCRequest& request) |
|
|
|
if (key.size() > MAX_KEY_LENGTH) |
|
|
|
if (key.size() > MAX_KEY_LENGTH) |
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "the key is too long"); |
|
|
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "the key is too long"); |
|
|
|
|
|
|
|
|
|
|
|
CKevaData data; |
|
|
|
// If there is unconfirmed one, return its value.
|
|
|
|
{ |
|
|
|
|
|
|
|
LOCK(cs_main); |
|
|
|
|
|
|
|
pcoinsTip->GetName(nameSpace, key, data); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto value = data.getValue(); |
|
|
|
|
|
|
|
// Also get the unconfirmed ones.
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
LOCK (mempool.cs); |
|
|
|
LOCK (mempool.cs); |
|
|
|
valtype val; |
|
|
|
valtype val; |
|
|
|
if (mempool.getUnconfirmedKeyValue(nameSpace, key, 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); |
|
|
|
UniValue obj(UniValue::VOBJ); |
|
|
|
obj.pushKV("key", keyStr); |
|
|
|
obj.pushKV("key", keyStr); |
|
|
|
obj.pushKV("value", ValtypeToString(value)); |
|
|
|
obj.pushKV("value", ""); |
|
|
|
return obj; |
|
|
|
return obj; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -108,53 +161,6 @@ std::string getKevaInfoHelp (const std::string& indent, const std::string& trail |
|
|
|
return res.str (); |
|
|
|
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) |
|
|
|
UniValue keva_filter(const JSONRPCRequest& request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (request.fHelp || request.params.size() > 6 || request.params.size() == 0) |
|
|
|
if (request.fHelp || request.params.size() > 6 || request.params.size() == 0) |
|
|
|