Port mutex to locked_chain

Signed-off-by: Anthony Fieroni <bvbfan@abv.bg>
This commit is contained in:
Anthony Fieroni 2020-01-14 19:12:37 +02:00
parent 6b9c1b995d
commit 3b7892b276
2 changed files with 11 additions and 7 deletions

View file

@ -613,13 +613,15 @@ void ListNameClaims(interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx,
auto trieCache = ::ClaimtrieCache();
if (auto pindex = LookupBlockIndex(wtx.m_confirm.hashBlock))
if (auto blockHeight = locked_chain.getBlockHeight(wtx.m_confirm.hashBlock))
{
entry.pushKV("height", pindex->nHeight);
entry.pushKV("expiration height", pindex->nHeight + trieCache.expirationTime());
if (pindex->nHeight + trieCache.expirationTime() > ::ChainActive().Height()) {
entry.pushKV("height", *blockHeight);
auto chainHeight = locked_chain.getHeight();
auto expirationHeight = *blockHeight + trieCache.expirationTime();
entry.pushKV("expiration height", expirationHeight);
if (chainHeight && expirationHeight > *chainHeight) {
entry.pushKV("expired", false);
entry.pushKV("blocks to expiration", pindex->nHeight + trieCache.expirationTime() - ::ChainActive().Height());
entry.pushKV("blocks to expiration", expirationHeight - *chainHeight);
}
else {
entry.pushKV("expired", true);
@ -692,7 +694,7 @@ UniValue listnameclaims(const JSONRPCRequest& request)
UniValue ret(UniValue::VARR);
pwallet->BlockUntilSyncedToCurrentChain();
auto locked_chain = pwallet->chain().lock();
LOCK2(cs_main, pwallet->cs_wallet);
LOCK(pwallet->cs_wallet);
const auto& txOrdered = pwallet->wtxOrdered;
for (auto it = txOrdered.rbegin(); it != txOrdered.rend(); ++it)
@ -754,7 +756,7 @@ UniValue supportclaim(const JSONRPCRequest& request)
pwallet->BlockUntilSyncedToCurrentChain();
auto locked_chain = pwallet->chain().lock();
LOCK2(cs_main, pwallet->cs_wallet);
LOCK(pwallet->cs_wallet);
EnsureWalletIsUnlocked(pwallet);
auto trieCache = ::ClaimtrieCache();

View file

@ -197,6 +197,7 @@ void AddClaimSupportThenRemove() {
auto txid = ClaimAName("tester", "deadbeef", "1.0");
auto g1 = generateBlock();
auto looked = LookupAllNames().get_array();
BOOST_CHECK_EQUAL(looked.size(), 1);
BOOST_CHECK_EQUAL(looked[0]["value"].get_str(), "deadbeef");
BOOST_CHECK_EQUAL(looked[0]["txid"].get_str(), txid.GetHex());
@ -211,6 +212,7 @@ void AddClaimSupportThenRemove() {
auto spid = SupportAName("tester", clid, "0.5");
auto g3 = generateBlock();
looked = LookupAllNames().get_array();
BOOST_CHECK_EQUAL(looked.size(), 2);
BOOST_CHECK_EQUAL(looked[0]["value"].get_str(), "deadbeef02");
BOOST_CHECK_EQUAL(looked[0]["amount"].get_real(), 1.0);
BOOST_CHECK_EQUAL(looked[1]["claimtype"].get_str(), "SUPPORT");