Browse Source

Implemented keva_pending.

cn
Jianping Wu 6 years ago
parent
commit
ce08f141cc
  1. 26
      src/keva/main.cpp
  2. 5
      src/keva/main.h
  3. 8
      src/txmempool.cpp
  4. 8
      src/txmempool.h
  5. 2
      src/validation.cpp
  6. 77
      src/wallet/rpckeva.cpp
  7. 4
      src/wallet/rpcwallet.cpp

26
src/keva/main.cpp

@ -74,16 +74,30 @@ CKevaMemPool::getUnconfirmedKeyValue(const valtype& nameSpace, const valtype& ke
return found; return found;
} }
bool void
CKevaMemPool::getUnconfirmedNamespaces(std::vector<std::tuple<valtype, valtype>>& nameSpaces) const { CKevaMemPool::getUnconfirmedKeyValueList(std::vector<std::tuple<valtype, valtype, valtype, uint256>>& keyValueList, const valtype& nameSpace) {
bool found = false; bool matchNamespace = nameSpace.size() > 0;
for (auto entry : listUnconfirmedKeyValues) {
auto txid = std::get<0>(entry);
auto n = std::get<1>(entry);
auto k = std::get<2>(entry);
auto v = std::get<3>(entry);
if (!matchNamespace) {
keyValueList.push_back(std::make_tuple(n, k, v, txid));
} else if (n == nameSpace) {
keyValueList.push_back(std::make_tuple(n, k, v, txid));
}
}
}
void
CKevaMemPool::getUnconfirmedNamespaceList(std::vector<std::tuple<valtype, valtype, uint256>>& nameSpaces) const {
for (auto entry : listUnconfirmedNamespaces) { for (auto entry : listUnconfirmedNamespaces) {
auto txid = std::get<0>(entry);
auto ns = std::get<1>(entry); auto ns = std::get<1>(entry);
auto displayName = std::get<2>(entry); auto displayName = std::get<2>(entry);
nameSpaces.push_back(std::make_tuple(ns, displayName)); nameSpaces.push_back(std::make_tuple(ns, displayName, txid));
found = true;
} }
return found;
} }
void CKevaMemPool::remove(const CTxMemPoolEntry& entry) void CKevaMemPool::remove(const CTxMemPoolEntry& entry)

5
src/keva/main.h

@ -177,11 +177,14 @@ public:
bool checkTx (const CTransaction& tx) const; bool checkTx (const CTransaction& tx) const;
/** Keva get unconfirmed namespaces. */ /** Keva get unconfirmed namespaces. */
bool getUnconfirmedNamespaces(std::vector<std::tuple<valtype, valtype>>& nameSpaces) const; void getUnconfirmedNamespaceList(std::vector<std::tuple<valtype, valtype, uint256>>& nameSpaces) const;
/** Keva get unconfirmed key value. */ /** Keva get unconfirmed key value. */
bool getUnconfirmedKeyValue(const valtype& nameSpace, const valtype& key, valtype& value) const; bool getUnconfirmedKeyValue(const valtype& nameSpace, const valtype& key, valtype& value) const;
/** Keva get list of unconfirmed key value list. */
void getUnconfirmedKeyValueList(std::vector<std::tuple<valtype, valtype, valtype, uint256>>& keyValueList, const valtype& nameSpace);
}; };
/* ************************************************************************** */ /* ************************************************************************** */

8
src/txmempool.cpp

@ -1087,8 +1087,12 @@ bool CTxMemPool::getUnconfirmedKeyValue(const valtype& nameSpace, const valtype&
return kevaMemPool.getUnconfirmedKeyValue(nameSpace, key, value); return kevaMemPool.getUnconfirmedKeyValue(nameSpace, key, value);
} }
bool CTxMemPool::getUnconfirmedNamespaces(std::vector<std::tuple<valtype, valtype>>& nameSpaces) const { void CTxMemPool::getUnconfirmedNamespaceList(std::vector<std::tuple<valtype, valtype, uint256>>& nameSpaces) const {
return kevaMemPool.getUnconfirmedNamespaces(nameSpaces); return kevaMemPool.getUnconfirmedNamespaceList(nameSpaces);
}
void CTxMemPool::getUnconfirmedKeyValueList(std::vector<std::tuple<valtype, valtype, valtype, uint256>>& keyValueList, const valtype& nameSpace) {
kevaMemPool.getUnconfirmedKeyValueList(keyValueList, nameSpace);
} }
SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {} SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}

8
src/txmempool.h

@ -682,8 +682,7 @@ public:
* @param tx The tx that should be added. * @param tx The tx that should be added.
* @return True if it doesn't conflict. * @return True if it doesn't conflict.
*/ */
inline bool inline bool checkKevaOps(const CTransaction& tx) const
checkNameOps (const CTransaction& tx) const
{ {
AssertLockHeld(cs); AssertLockHeld(cs);
return kevaMemPool.checkTx(tx); return kevaMemPool.checkTx(tx);
@ -693,7 +692,10 @@ public:
bool getUnconfirmedKeyValue(const valtype& nameSpace, const valtype& key, valtype& value) const; bool getUnconfirmedKeyValue(const valtype& nameSpace, const valtype& key, valtype& value) const;
/** Keva get unconfirmed namespaces. */ /** Keva get unconfirmed namespaces. */
bool getUnconfirmedNamespaces(std::vector<std::tuple<valtype, valtype>>& nameSpaces) const; void getUnconfirmedNamespaceList(std::vector<std::tuple<valtype, valtype, uint256>>& nameSpaces) const;
/** Keva get list of unconfirmed key value list. */
void getUnconfirmedKeyValueList(std::vector<std::tuple<valtype, valtype, valtype, uint256>>& keyValueList, const valtype& nameSpace);
CTransactionRef get(const uint256& hash) const; CTransactionRef get(const uint256& hash) const;
TxMempoolInfo info(const uint256& hash) const; TxMempoolInfo info(const uint256& hash) const;

2
src/validation.cpp

@ -637,7 +637,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
} }
} }
if (!pool.checkNameOps(tx)) { if (!pool.checkKevaOps(tx)) {
return false; return false;
} }

77
src/wallet/rpckeva.cpp

@ -185,11 +185,10 @@ UniValue keva_list_namespaces(const JSONRPCRequest& request)
{ {
LOCK (mempool.cs); LOCK (mempool.cs);
// Also get the unconfirmed ones from mempool. // Also get the unconfirmed ones from mempool.
std::vector<std::tuple<valtype, valtype>> unconfirmedNamespaces; std::vector<std::tuple<valtype, valtype, uint256>> unconfirmedNamespaces;
if (mempool.getUnconfirmedNamespaces(unconfirmedNamespaces)) { mempool.getUnconfirmedNamespaceList(unconfirmedNamespaces);
for (auto entry : unconfirmedNamespaces) { for (auto entry : unconfirmedNamespaces) {
res.push_back(EncodeBase58(std::get<0>(entry)) + " : " + ValtypeToString(std::get<1>(entry))); res.push_back(EncodeBase58(std::get<0>(entry)) + " : " + ValtypeToString(std::get<1>(entry)));
}
} }
} }
@ -340,3 +339,71 @@ UniValue keva_get(const JSONRPCRequest& request)
return ValtypeToString(value); return ValtypeToString(value);
} }
UniValue keva_pending(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size () > 1)
throw std::runtime_error (
"keva_pending (\"namespace\")\n"
"\nList unconfirmed keva operations in the mempool.\n"
"\nIf a namespace is given, only check for operations on this namespace.\n"
"\nArguments:\n"
"1. \"namespace\" (string, optional) only look for this namespace\n"
"\nResult:\n"
"[\n"
" {\n"
" \"op\": xxxx (string) the operation being performed\n"
" \"name\": xxxx (string) the namespace operated on\n"
" \"value\": xxxx (string) the namespace's new value\n"
" \"txid\": xxxx (string) the txid corresponding to the operation\n"
" \"ismine\": xxxx (boolean) whether the name is owned by the wallet\n"
" },\n"
" ...\n"
"]\n"
+ HelpExampleCli ("keva_pending", "")
+ HelpExampleCli ("keva_pending", "\"NJdZVkeerpgxqFM2oAzitVU8xsdj7\"")
+ HelpExampleRpc ("keva_pending", "")
);
ObserveSafeMode ();
std::string namespaceStr;
valtype nameSpace;
if (request.params.size() == 1) {
RPCTypeCheckArgument(request.params[0], UniValue::VSTR);
namespaceStr = request.params[0].get_str();
if (!DecodeBase58(namespaceStr, nameSpace)) {
throw JSONRPCError (RPC_INVALID_PARAMETER, "failed to decode namespace");
}
}
LOCK (mempool.cs);
std::vector<std::tuple<valtype, valtype, uint256>> unconfirmedNamespaces;
mempool.getUnconfirmedNamespaceList(unconfirmedNamespaces);
std::vector<std::tuple<valtype, valtype, valtype, uint256>> unconfirmedKeyValueList;
mempool.getUnconfirmedKeyValueList(unconfirmedKeyValueList, nameSpace);
UniValue arr(UniValue::VARR);
for (auto entry: unconfirmedNamespaces) {
UniValue obj(UniValue::VOBJ);
obj.pushKV("namespace", EncodeBase58(std::get<0>(entry)));
obj.pushKV("display name", ValtypeToString(std::get<1>(entry)));
obj.pushKV("txid", std::get<2>(entry).ToString());
arr.push_back(obj);
}
for (auto entry: unconfirmedKeyValueList) {
UniValue obj(UniValue::VOBJ);
obj.pushKV("namespace", EncodeBase58(std::get<0>(entry)));
obj.pushKV("key", ValtypeToString(std::get<1>(entry)));
obj.pushKV("value", ValtypeToString(std::get<2>(entry)));
obj.pushKV("txid", std::get<3>(entry).ToString());
arr.push_back(obj);
}
return arr;
}

4
src/wallet/rpcwallet.cpp

@ -3595,6 +3595,7 @@ extern UniValue keva_namespace(const JSONRPCRequest& request);
extern UniValue keva_put(const JSONRPCRequest& request); extern UniValue keva_put(const JSONRPCRequest& request);
extern UniValue keva_get(const JSONRPCRequest& request); extern UniValue keva_get(const JSONRPCRequest& request);
extern UniValue keva_list_namespaces(const JSONRPCRequest& request); extern UniValue keva_list_namespaces(const JSONRPCRequest& request);
extern UniValue keva_pending(const JSONRPCRequest& request);
static const CRPCCommand commands[] = static const CRPCCommand commands[] =
{ // category name actor (function) argNames { // category name actor (function) argNames
@ -3657,7 +3658,8 @@ static const CRPCCommand commands[] =
{ "kevacoin", "keva_namespace", &keva_namespace, {"display_name"} }, { "kevacoin", "keva_namespace", &keva_namespace, {"display_name"} },
{ "kevacoin", "keva_list_namespaces", &keva_list_namespaces, {} }, { "kevacoin", "keva_list_namespaces", &keva_list_namespaces, {} },
{ "kevacoin", "keva_put", &keva_put, {"namespace", "key", "value"} }, { "kevacoin", "keva_put", &keva_put, {"namespace", "key", "value"} },
{ "kevacoin", "keva_get", &keva_get, {"namespace", "key"} } { "kevacoin", "keva_get", &keva_get, {"namespace", "key"} },
{ "kevacoin", "keva_pending", &keva_pending, {"namespace"} }
}; };
void RegisterWalletRPCCommands(CRPCTable &t) void RegisterWalletRPCCommands(CRPCTable &t)

Loading…
Cancel
Save