Skip to content

Commit

Permalink
Remove CNameMemPool::getTxForName.
Browse files Browse the repository at this point in the history
The function getTxForName is only used for name_pending filtered by
name.  There, we can instead just go through the full mempool anyway
and then filter the name scripts.

With #304 coming up,
there will no longer be a single transaction per name.  Thus by removing
the unnecessary function now, we avoid having to complicate it with
returning multiple names.
  • Loading branch information
domob1812 committed Jun 28, 2019
1 parent 53f5859 commit 0bb0946
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 66 deletions.
22 changes: 0 additions & 22 deletions src/names/mempool.cpp
Expand Up @@ -14,28 +14,6 @@

/* ************************************************************************** */

uint256
CNameMemPool::getTxForName (const valtype& name) const
{
NameTxMap::const_iterator mi;

mi = mapNameRegs.find (name);
if (mi != mapNameRegs.end ())
{
assert (mapNameUpdates.count (name) == 0);
return mi->second;
}

mi = mapNameUpdates.find (name);
if (mi != mapNameUpdates.end ())
{
assert (mapNameRegs.count (name) == 0);
return mi->second;
}

return uint256 ();
}

void
CNameMemPool::addUnchecked (const CTxMemPoolEntry& entry)
{
Expand Down
8 changes: 0 additions & 8 deletions src/names/mempool.h
Expand Up @@ -85,14 +85,6 @@ class CNameMemPool
return mapNameUpdates.count (name) > 0;
}

/**
* Return txid of transaction registering or updating a name. The returned
* txid is null if no such tx exists.
* @param name The name to check for.
* @return The txid that registers/updates it. Null if none.
*/
uint256 getTxForName (const valtype& name) const;

/**
* Clear all data.
*/
Expand Down
18 changes: 8 additions & 10 deletions src/rpc/names.cpp
Expand Up @@ -727,16 +727,12 @@ name_pending (const JSONRPCRequest& request)
options = request.params[1].get_obj ();

std::vector<uint256> txHashes;
if (request.params.size () == 0 || request.params[0].isNull ())
mempool.queryHashes (txHashes);
else
{
const valtype name
= DecodeNameFromRPCOrThrow (request.params[0], options);
const uint256 txid = mempool.getTxForName (name);
if (!txid.IsNull ())
txHashes.push_back (txid);
}
mempool.queryHashes (txHashes);

const bool hasNameFilter = !request.params[0].isNull ();
valtype nameFilter;
if (hasNameFilter)
nameFilter = DecodeNameFromRPCOrThrow (request.params[0], options);

UniValue arr(UniValue::VARR);
for (const auto& txHash : txHashes)
Expand All @@ -751,6 +747,8 @@ name_pending (const JSONRPCRequest& request)
const CNameScript op(txOut.scriptPubKey);
if (!op.isNameOp () || !op.isAnyUpdate ())
continue;
if (hasNameFilter && op.getOpName () != nameFilter)
continue;

UniValue obj = getNameInfo (options,
op.getOpName (), op.getOpValue (),
Expand Down
18 changes: 0 additions & 18 deletions src/test/name_mempool_tests.cpp
Expand Up @@ -240,24 +240,6 @@ BOOST_FIXTURE_TEST_CASE (name_update, NameMempoolTestSetup)
BOOST_CHECK (mempool.checkNameOps (tx2));
}

BOOST_FIXTURE_TEST_CASE (getTxForName, NameMempoolTestSetup)
{
BOOST_CHECK (mempool.getTxForName (Name ("new")).IsNull ());
BOOST_CHECK (mempool.getTxForName (Name ("reg")).IsNull ());
BOOST_CHECK (mempool.getTxForName (Name ("upd")).IsNull ());

const auto txReg = Tx (FirstScript (ADDR, "reg", 'a'));
const auto txUpd = Tx (UpdateScript (ADDR, "upd", "x"));

mempool.addUnchecked (Entry (Tx (NewScript (ADDR, "new", 'a'))));
mempool.addUnchecked (Entry (txReg));
mempool.addUnchecked (Entry (txUpd));

BOOST_CHECK (mempool.getTxForName (Name ("new")).IsNull ());
BOOST_CHECK (mempool.getTxForName (Name ("reg")) == txReg.GetHash ());
BOOST_CHECK (mempool.getTxForName (Name ("upd")) == txUpd.GetHash ());
}

BOOST_FIXTURE_TEST_CASE (mempool_sanity_check, NameMempoolTestSetup)
{
mempool.addUnchecked (Entry (Tx (NewScript (ADDR, "new", 'a'))));
Expand Down
11 changes: 3 additions & 8 deletions src/txmempool.h
Expand Up @@ -749,24 +749,19 @@ class CTxMemPool
return (mapTx.count(hash) != 0);
}

inline bool
bool
registersName(const valtype& name) const
{
AssertLockHeld(cs);
return names.registersName(name);
}
inline bool

bool
updatesName(const valtype& name) const
{
AssertLockHeld(cs);
return names.updatesName(name);
}
inline uint256
getTxForName (const valtype& name) const
{
AssertLockHeld(cs);
return names.getTxForName(name);
}

/**
* Check if a tx can be added to it according to name criteria.
Expand Down

0 comments on commit 0bb0946

Please sign in to comment.