Browse Source

Fixed keva_delete.

cn
Jianping Wu 6 years ago
parent
commit
f6b074a81c
  1. 8
      src/keva/main.cpp
  2. 13
      src/wallet/rpckeva.cpp

8
src/keva/main.cpp

@ -359,11 +359,6 @@ CheckKevaTransaction (const CTransaction& tx, unsigned nHeight,
if (!nameOpIn.isAnyUpdate() && !nameOpIn.isNamespaceRegistration()) { if (!nameOpIn.isAnyUpdate() && !nameOpIn.isNamespaceRegistration()) {
return state.Invalid(error("CheckKevaTransaction: KEVA_DELETE with prev input that is no update")); 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; return true;
} }
@ -410,7 +405,10 @@ void ApplyKevaTransaction(const CTransaction& tx, unsigned nHeight,
CKevaData data; CKevaData data;
if (op.isDelete()) { if (op.isDelete()) {
CKevaData oldData;
if (view.GetName(nameSpace, key, oldData)) {
view.DeleteName(nameSpace, key); view.DeleteName(nameSpace, key);
}
} else { } else {
data.fromScript(nHeight, COutPoint(tx.GetHash(), i), op); data.fromScript(nHeight, COutPoint(tx.GetHash(), i), op);
view.SetName(nameSpace, key, data, false); view.SetName(nameSpace, key, data, false);

13
src/wallet/rpckeva.cpp

@ -327,18 +327,25 @@ UniValue keva_delete(const JSONRPCRequest& request)
throw JSONRPCError (RPC_INVALID_PARAMETER, "the key is too long"); throw JSONRPCError (RPC_INVALID_PARAMETER, "the key is too long");
} }
bool hasKey = false;
CKevaData data; CKevaData data;
{ {
LOCK2(cs_main, mempool.cs); LOCK2(cs_main, mempool.cs);
if (!pcoinsTip->GetName(nameSpace, key, data)) {
std::vector<std::tuple<valtype, valtype, valtype, uint256>> unconfirmedKeyValueList; std::vector<std::tuple<valtype, valtype, valtype, uint256>> unconfirmedKeyValueList;
valtype val; valtype val;
if (!mempool.getUnconfirmedKeyValue(nameSpace, key, val) || val.size() == 0) { if (mempool.getUnconfirmedKeyValue(nameSpace, key, val)) {
throw JSONRPCError (RPC_TRANSACTION_ERROR, "key not found"); 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); EnsureWalletIsUnlocked(pwallet);
COutput output; COutput output;

Loading…
Cancel
Save