Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.cpp
Show All 30 Lines | |||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
#include <memory> | #include <memory> | ||||
#include <utility> | #include <utility> | ||||
namespace interfaces { | namespace interfaces { | ||||
namespace { | namespace { | ||||
class LockImpl : public Chain::Lock { | class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex> { | ||||
Optional<int> getHeight() override { | Optional<int> getHeight() override { | ||||
int height = ::ChainActive().Height(); | int height = ::ChainActive().Height(); | ||||
if (height >= 0) { | if (height >= 0) { | ||||
return height; | return height; | ||||
} | } | ||||
return nullopt; | return nullopt; | ||||
} | } | ||||
Optional<int> getBlockHeight(const BlockHash &hash) override { | Optional<int> getBlockHeight(const BlockHash &hash) override { | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex> { | ||||
bool submitToMemoryPool(const Config &config, CTransactionRef tx, | bool submitToMemoryPool(const Config &config, CTransactionRef tx, | ||||
Amount absurd_fee, | Amount absurd_fee, | ||||
CValidationState &state) override { | CValidationState &state) override { | ||||
LockAnnotation lock(::cs_main); | LockAnnotation lock(::cs_main); | ||||
return AcceptToMemoryPool(config, ::g_mempool, state, tx, | return AcceptToMemoryPool(config, ::g_mempool, state, tx, | ||||
nullptr /* missing inputs */, | nullptr /* missing inputs */, | ||||
false /* bypass limits */, absurd_fee); | false /* bypass limits */, absurd_fee); | ||||
} | } | ||||
}; | |||||
class LockingStateImpl : public LockImpl, | |||||
public UniqueLock<RecursiveMutex> { | |||||
using UniqueLock::UniqueLock; | using UniqueLock::UniqueLock; | ||||
}; | }; | ||||
class NotificationsHandlerImpl : public Handler, CValidationInterface { | class NotificationsHandlerImpl : public Handler, CValidationInterface { | ||||
public: | public: | ||||
explicit NotificationsHandlerImpl(Chain &chain, | explicit NotificationsHandlerImpl(Chain &chain, | ||||
Chain::Notifications ¬ifications) | Chain::Notifications ¬ifications) | ||||
: m_chain(chain), m_notifications(¬ifications) { | : m_chain(chain), m_notifications(¬ifications) { | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | public: | ||||
CRPCCommand m_command; | CRPCCommand m_command; | ||||
const CRPCCommand *m_wrapped_command; | const CRPCCommand *m_wrapped_command; | ||||
}; | }; | ||||
class ChainImpl : public Chain { | class ChainImpl : public Chain { | ||||
public: | public: | ||||
std::unique_ptr<Chain::Lock> lock(bool try_lock) override { | std::unique_ptr<Chain::Lock> lock(bool try_lock) override { | ||||
auto result = std::make_unique<LockingStateImpl>( | auto result = std::make_unique<LockImpl>( | ||||
::cs_main, "cs_main", __FILE__, __LINE__, try_lock); | ::cs_main, "cs_main", __FILE__, __LINE__, try_lock); | ||||
if (try_lock && result && !*result) { | if (try_lock && result && !*result) { | ||||
return {}; | return {}; | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
std::unique_ptr<Chain::Lock> assumeLocked() override { | |||||
return std::make_unique<LockImpl>(); | |||||
} | |||||
bool findBlock(const BlockHash &hash, CBlock *block, int64_t *time, | bool findBlock(const BlockHash &hash, CBlock *block, int64_t *time, | ||||
int64_t *time_max) override { | int64_t *time_max) override { | ||||
CBlockIndex *index; | CBlockIndex *index; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
index = LookupBlockIndex(hash); | index = LookupBlockIndex(hash); | ||||
if (!index) { | if (!index) { | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 112 Lines • Show Last 20 Lines |