Browse Source

Updated keva related function names.

issue_19
Just Wonder 4 years ago
parent
commit
c8875d60fa
  1. 4
      src/coins.cpp
  2. 4
      src/coins.h
  3. 10
      src/keva/main.cpp
  4. 6
      src/rpc/rpckeva_nonwallet.cpp
  5. 32
      src/test/keva_tests.cpp
  6. 6
      src/validation.cpp

4
src/coins.cpp

@ -208,7 +208,7 @@ CKevaIterator* CCoinsViewCache::IterateAssociatedNamespaces(const valtype& nameS
time. The ordinary case (!undo) means that we update the name normally, time. The ordinary case (!undo) means that we update the name normally,
going forward in time. This is important for keeping track of the going forward in time. This is important for keeping track of the
name history. */ name history. */
void CCoinsViewCache::SetName(const valtype &nameSpace, const valtype &key, const CKevaData& data, bool undo) void CCoinsViewCache::SetKeyValue(const valtype &nameSpace, const valtype &key, const CKevaData& data, bool undo)
{ {
cacheNames.set(nameSpace, key, data); cacheNames.set(nameSpace, key, data);
@ -225,7 +225,7 @@ void CCoinsViewCache::SetName(const valtype &nameSpace, const valtype &key, cons
cacheNames.associateNamespaces(nameSpace, associdateNamespace, data); cacheNames.associateNamespaces(nameSpace, associdateNamespace, data);
} }
void CCoinsViewCache::DeleteName(const valtype &nameSpace, const valtype &key) { void CCoinsViewCache::DeleteKey(const valtype &nameSpace, const valtype &key) {
CKevaData oldData; CKevaData oldData;
if (!GetName(nameSpace, key, oldData)) { if (!GetName(nameSpace, key, oldData)) {
assert(false); assert(false);

4
src/coins.h

@ -263,8 +263,8 @@ public:
} }
/* Changes to the name database. */ /* Changes to the name database. */
void SetName(const valtype &nameSpace, const valtype &key, const CKevaData &data, bool undo); void SetKeyValue(const valtype &nameSpace, const valtype &key, const CKevaData &data, bool undo);
void DeleteName(const valtype &nameSpace, const valtype &key); void DeleteKey(const valtype &nameSpace, const valtype &key);
/** /**
* Check if we have the given utxo already loaded in this cache. * Check if we have the given utxo already loaded in this cache.

10
src/keva/main.cpp

@ -39,10 +39,10 @@ void
CKevaTxUndo::apply(CCoinsViewCache& view) const CKevaTxUndo::apply(CCoinsViewCache& view) const
{ {
if (isNew) { if (isNew) {
view.DeleteName(nameSpace, key); view.DeleteKey(nameSpace, key);
} }
else { else {
view.SetName(nameSpace, key, oldData, true); view.SetKeyValue(nameSpace, key, oldData, true);
} }
} }
@ -403,7 +403,7 @@ void ApplyKevaTransaction(const CTransaction& tx, const CBlockIndex& pindex,
CKevaData data; CKevaData data;
data.fromScript(nHeight, COutPoint(tx.GetHash(), i), op); data.fromScript(nHeight, COutPoint(tx.GetHash(), i), op);
view.SetName(nameSpace, key, data, false); view.SetKeyValue(nameSpace, key, data, false);
notifier.KevaNamespaceCreated(tx, pindex, EncodeBase58Check(nameSpace)); notifier.KevaNamespaceCreated(tx, pindex, EncodeBase58Check(nameSpace));
} else if (op.isAnyUpdate()) { } else if (op.isAnyUpdate()) {
const valtype& nameSpace = op.getOpNamespace(); const valtype& nameSpace = op.getOpNamespace();
@ -419,12 +419,12 @@ void ApplyKevaTransaction(const CTransaction& tx, const CBlockIndex& pindex,
if (op.isDelete()) { if (op.isDelete()) {
CKevaData oldData; CKevaData oldData;
if (view.GetName(nameSpace, key, oldData)) { if (view.GetName(nameSpace, key, oldData)) {
view.DeleteName(nameSpace, key); view.DeleteKey(nameSpace, key);
notifier.KevaDeleted(tx, pindex, EncodeBase58Check(nameSpace), ValtypeToString(key)); notifier.KevaDeleted(tx, pindex, EncodeBase58Check(nameSpace), ValtypeToString(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.SetKeyValue(nameSpace, key, data, false);
notifier.KevaUpdated(tx, pindex, EncodeBase58Check(nameSpace), ValtypeToString(key), ValtypeToString(data.getValue())); notifier.KevaUpdated(tx, pindex, EncodeBase58Check(nameSpace), ValtypeToString(key), ValtypeToString(data.getValue()));
} }
} }

6
src/rpc/rpckeva_nonwallet.cpp

@ -362,9 +362,9 @@ UniValue keva_group_filter(const JSONRPCRequest& request)
" ...\n" " ...\n"
"]\n" "]\n"
"\nExamples:\n" "\nExamples:\n"
+ HelpExampleCli ("keva_filter", "\"namespaceId\" \"all\"") + HelpExampleCli ("keva_group_filter", "\"namespaceId\" \"all\"")
+ HelpExampleCli ("keva_filter", "\"namespaceId\" \"self\" 96000 0 0 \"stat\"") + HelpExampleCli ("keva_group_filter", "\"namespaceId\" \"self\" 96000 0 0 \"stat\"")
+ HelpExampleRpc ("keva_filter", "\"namespaceId\"") + HelpExampleRpc ("keva_group_filter", "\"namespaceId\"")
); );
RPCTypeCheck(request.params, { RPCTypeCheck(request.params, {

32
src/test/keva_tests.cpp

@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE (name_database)
BOOST_CHECK (setRet == setExpected); BOOST_CHECK (setRet == setExpected);
BOOST_CHECK (!view.GetName (name1, data2)); BOOST_CHECK (!view.GetName (name1, data2));
view.SetName (name1, dataHeight2, false); view.SetKeyValue (name1, dataHeight2, false);
BOOST_CHECK (view.GetName (name1, data2)); BOOST_CHECK (view.GetName (name1, data2));
BOOST_CHECK (dataHeight2 == data2); BOOST_CHECK (dataHeight2 == data2);
@ -138,12 +138,12 @@ BOOST_AUTO_TEST_CASE (name_database)
BOOST_CHECK (view.GetName (name1, data2)); BOOST_CHECK (view.GetName (name1, data2));
BOOST_CHECK (dataHeight2 == data2); BOOST_CHECK (dataHeight2 == data2);
view.SetName (name2, dataHeight2, false); view.SetKeyValue (name2, dataHeight2, false);
BOOST_CHECK (view.GetNamesForHeight (height2, setRet)); BOOST_CHECK (view.GetNamesForHeight (height2, setRet));
setExpected.insert (name2); setExpected.insert (name2);
BOOST_CHECK (setRet == setExpected); BOOST_CHECK (setRet == setExpected);
view.DeleteName (name1); view.DeleteKey (name1);
BOOST_CHECK (!view.GetName (name1, data2)); BOOST_CHECK (!view.GetName (name1, data2));
BOOST_CHECK (view.Flush()); BOOST_CHECK (view.Flush());
BOOST_CHECK (!view.GetName (name1, data2)); BOOST_CHECK (!view.GetName (name1, data2));
@ -152,9 +152,9 @@ BOOST_AUTO_TEST_CASE (name_database)
setExpected.erase (name1); setExpected.erase (name1);
BOOST_CHECK (setRet == setExpected); BOOST_CHECK (setRet == setExpected);
view.SetName (name2, dataHeight1, false); view.SetKeyValue (name2, dataHeight1, false);
BOOST_CHECK (view.Flush()); BOOST_CHECK (view.Flush());
view.SetName (name1, dataHeight1, false); view.SetKeyValue (name1, dataHeight1, false);
BOOST_CHECK (view.GetNamesForHeight (height2, setRet)); BOOST_CHECK (view.GetNamesForHeight (height2, setRet));
setExpected.clear(); setExpected.clear();
@ -420,8 +420,8 @@ NameIterationTester::add (const std::string& n)
assert (data.count (name) == 0); assert (data.count (name) == 0);
data[name] = testData; data[name] = testData;
hybrid.SetName (name, testData, false); hybrid.SetKeyValue (name, testData, false);
cache.SetName (name, testData, false); cache.SetKeyValue (name, testData, false);
verify(); verify();
} }
@ -433,8 +433,8 @@ NameIterationTester::update (const std::string& n)
assert (data.count (name) == 1); assert (data.count (name) == 1);
data[name] = testData; data[name] = testData;
hybrid.SetName (name, testData, false); hybrid.SetKeyValue (name, testData, false);
cache.SetName (name, testData, false); cache.SetKeyValue (name, testData, false);
verify(); verify();
} }
@ -445,8 +445,8 @@ NameIterationTester::remove (const std::string& n)
assert (data.count (name) == 1); assert (data.count (name) == 1);
data.erase (name); data.erase (name);
hybrid.DeleteName (name); hybrid.DeleteKey (name);
cache.DeleteName (name); cache.DeleteKey (name);
verify(); verify();
} }
@ -538,7 +538,7 @@ BOOST_AUTO_TEST_CASE (name_tx_verification)
CNameData data1; CNameData data1;
data1.fromScript (100000, inFirst, CNameScript (scrFirst)); data1.fromScript (100000, inFirst, CNameScript (scrFirst));
view.SetName (name1, data1, false); view.SetKeyValue (name1, data1, false);
/* ****************************************************** */ /* ****************************************************** */
/* Try out the Namecoin / non-Namecoin tx version check. */ /* Try out the Namecoin / non-Namecoin tx version check. */
@ -604,7 +604,7 @@ BOOST_AUTO_TEST_CASE (name_tx_verification)
CCoinsViewCache viewFirst(&view); CCoinsViewCache viewFirst(&view);
CCoinsViewCache viewUpd(&view); CCoinsViewCache viewUpd(&view);
data1.fromScript (100000, inUpdate, CNameScript (scrUpdate)); data1.fromScript (100000, inUpdate, CNameScript (scrUpdate));
viewUpd.SetName (name1, data1, false); viewUpd.SetKeyValue (name1, data1, false);
/* Check update of UPDATE output, plus expiry. */ /* Check update of UPDATE output, plus expiry. */
mtx = CMutableTransaction (baseTx); mtx = CMutableTransaction (baseTx);
@ -647,14 +647,14 @@ BOOST_AUTO_TEST_CASE (name_tx_verification)
mtx.vout.push_back (CTxOut (COIN, scrUpdate)); mtx.vout.push_back (CTxOut (COIN, scrUpdate));
mtx.vin.push_back (CTxIn (inNew)); mtx.vin.push_back (CTxIn (inNew));
CCoinsViewCache viewNew(&view); CCoinsViewCache viewNew(&view);
viewNew.DeleteName (name1); viewNew.DeleteKey (name1);
BOOST_CHECK (!CheckNameTransaction (mtx, 110000, viewNew, state, 0)); BOOST_CHECK (!CheckNameTransaction (mtx, 110000, viewNew, state, 0));
/* ********************************** */ /* ********************************** */
/* Test NAME_FIRSTUPDATE validation. */ /* Test NAME_FIRSTUPDATE validation. */
CCoinsViewCache viewClean(&view); CCoinsViewCache viewClean(&view);
viewClean.DeleteName (name1); viewClean.DeleteKey (name1);
/* Basic valid transaction. */ /* Basic valid transaction. */
mtx = CMutableTransaction (baseTx); mtx = CMutableTransaction (baseTx);
@ -869,7 +869,7 @@ BOOST_AUTO_TEST_CASE(keva_mempool)
const CKevaScript nameOp(upd1); const CKevaScript nameOp(upd1);
CKevaData data; CKevaData data;
data.fromScript(100, COutPoint (uint256(), 0), nameOp); data.fromScript(100, COutPoint (uint256(), 0), nameOp);
view.SetName(nameUpd, data, false); view.SetKeyValue(nameUpd, data, false);
mempool.checkNames(&view); mempool.checkNames(&view);
#endif #endif

6
src/validation.cpp

@ -690,17 +690,17 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
CKevaData data; CKevaData data;
// Make sure namespace info is in cache. // Make sure namespace info is in cache.
if (view.GetNamespace(nameSpace, data)) { if (view.GetNamespace(nameSpace, data)) {
view.SetName(nameSpace, ValtypeFromString(CKevaScript::KEVA_DISPLAY_NAME_KEY), data, false); view.SetKeyValue(nameSpace, ValtypeFromString(CKevaScript::KEVA_DISPLAY_NAME_KEY), data, false);
} }
if (view.GetName(nameSpace, key, data)) { if (view.GetName(nameSpace, key, data)) {
view.SetName(nameSpace, key, data, false); view.SetKeyValue(nameSpace, key, data, false);
} }
} else if (kevaOp.isNamespaceRegistration()) { } else if (kevaOp.isNamespaceRegistration()) {
const valtype& nameSpace = kevaOp.getOpNamespace(); const valtype& nameSpace = kevaOp.getOpNamespace();
const valtype& key = ValtypeFromString(CKevaScript::KEVA_DISPLAY_NAME_KEY); const valtype& key = ValtypeFromString(CKevaScript::KEVA_DISPLAY_NAME_KEY);
CKevaData data; CKevaData data;
if (view.GetName(nameSpace, key, data)) { if (view.GetName(nameSpace, key, data)) {
view.SetName(nameSpace, key, data, false); view.SetKeyValue(nameSpace, key, data, false);
} }
} else { } else {
assert(false); assert(false);

Loading…
Cancel
Save