From d94a8e52caa9d4d8782010ba20182a9c6a340084 Mon Sep 17 00:00:00 2001 From: Jianping Wu Date: Tue, 11 Dec 2018 23:04:51 -0800 Subject: [PATCH] Fixed keva_delete. --- src/keva/main.cpp | 10 ++++------ src/wallet/rpckeva.cpp | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/keva/main.cpp b/src/keva/main.cpp index ae44e35ff..3e6821d7d 100644 --- a/src/keva/main.cpp +++ b/src/keva/main.cpp @@ -359,11 +359,6 @@ CheckKevaTransaction (const CTransaction& tx, unsigned nHeight, if (!nameOpIn.isAnyUpdate() && !nameOpIn.isNamespaceRegistration()) { return state.Invalid(error("CheckKevaTransaction: KEVA_DELETE with prev input that is no update")); } - CKevaData data; - const bool hasKey = view.GetName(nameSpace, nameOpOut.getOpKey(), data); - if (!hasKey) { - return state.Invalid(error("CheckKevaTransaction: no key to delete")); - } } return true; } @@ -410,7 +405,10 @@ void ApplyKevaTransaction(const CTransaction& tx, unsigned nHeight, CKevaData data; if (op.isDelete()) { - view.DeleteName(nameSpace, key); + CKevaData oldData; + if (view.GetName(nameSpace, key, oldData)) { + view.DeleteName(nameSpace, key); + } } else { data.fromScript(nHeight, COutPoint(tx.GetHash(), i), op); view.SetName(nameSpace, key, data, false); diff --git a/src/wallet/rpckeva.cpp b/src/wallet/rpckeva.cpp index cee089858..535ea1d7b 100644 --- a/src/wallet/rpckeva.cpp +++ b/src/wallet/rpckeva.cpp @@ -327,18 +327,25 @@ UniValue keva_delete(const JSONRPCRequest& request) throw JSONRPCError (RPC_INVALID_PARAMETER, "the key is too long"); } + bool hasKey = false; CKevaData data; { LOCK2(cs_main, mempool.cs); - if (!pcoinsTip->GetName(nameSpace, key, data)) { - std::vector> unconfirmedKeyValueList; - valtype val; - if (!mempool.getUnconfirmedKeyValue(nameSpace, key, val) || val.size() == 0) { - throw JSONRPCError (RPC_TRANSACTION_ERROR, "key not found"); + std::vector> unconfirmedKeyValueList; + valtype val; + if (mempool.getUnconfirmedKeyValue(nameSpace, key, val)) { + if (val.size() > 0) { + hasKey = true; } + } else if (pcoinsTip->GetName(nameSpace, key, data)) { + hasKey = true; } } + if (!hasKey) { + throw JSONRPCError (RPC_TRANSACTION_ERROR, "key not found"); + } + EnsureWalletIsUnlocked(pwallet); COutput output;