CatapultServer  v0.5.0.1 (Elephant)
ServerHooks.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "BasicServerHooks.h"
23 #include "TransactionEvent.h"
32 
33 namespace catapult { namespace extensions {
34 
35  // region function aliases
36 
39 
42 
45 
48 
51 
54 
58 
61 
64 
66  using RemoteChainHeightsRetriever = std::function<thread::future<std::vector<Height>> (size_t)>;
67 
70 
73 
74  // endregion
75 
77  class ServerHooks {
78  public:
80  void addNewBlockSink(const NewBlockSink& sink) {
81  m_newBlockSinks.push_back(sink);
82  }
83 
86  m_newTransactionsSinks.push_back(sink);
87  }
88 
91  m_packetPayloadSinks.push_back(sink);
92  }
93 
96  m_transactionsChangeHandlers.push_back(handler);
97  }
98 
101  m_transactionEventHandlers.push_back(handler);
102  }
103 
107  }
108 
112  }
113 
117  }
118 
122  }
123 
127  }
128 
131  m_knownHashPredicates.push_back(predicate);
132  }
133 
134  public:
136  auto newBlockSink() const {
138  }
139 
141  auto newTransactionsSink() const {
143  }
144 
146  auto packetPayloadSink() const {
148  }
149 
153  }
154 
156  auto transactionEventHandler() const {
158  }
159 
161  const auto& blockRangeConsumerFactory() const {
163  }
164 
168  }
169 
171  const auto& transactionRangeConsumerFactory() const {
173  }
174 
176  const auto& remoteChainHeightsRetriever() const {
178  }
179 
181  auto chainSyncedPredicate() const {
182  return m_chainSyncedPredicate ? m_chainSyncedPredicate : []() { return true; };
183  }
184 
187  return [&utCache, knownHashPredicates = m_knownHashPredicates](auto timestamp, const auto& hash) {
188  if (utCache.view().contains(hash))
189  return true;
190 
191  for (const auto& knownHashPredicate : knownHashPredicates) {
192  if (knownHashPredicate(timestamp, hash))
193  return true;
194  }
195 
196  return false;
197  };
198  }
199 
200  private:
201  std::vector<NewBlockSink> m_newBlockSinks;
202  std::vector<SharedNewTransactionsSink> m_newTransactionsSinks;
203  std::vector<PacketPayloadSink> m_packetPayloadSinks;
204  std::vector<TransactionsChangeHandler> m_transactionsChangeHandlers;
205  std::vector<TransactionEventHandler> m_transactionEventHandlers;
206 
210 
213  std::vector<KnownHashPredicate> m_knownHashPredicates;
214  };
215 }}
catapult::extensions::ServerHooks::blockRangeConsumerFactory
const auto & blockRangeConsumerFactory() const
Gets the factory for creating a BlockRangeConsumerFunc bound to an input source.
Definition: ServerHooks.h:161
catapult::extensions::NewBlockSink
consumers::NewBlockSink NewBlockSink
A new block sink prototype.
Definition: ServerHooks.h:38
catapult::extensions::ServerHooks::m_packetPayloadSinks
std::vector< PacketPayloadSink > m_packetPayloadSinks
Definition: ServerHooks.h:203
InputUtils.h
catapult::extensions::ServerHooks::completionAwareBlockRangeConsumerFactory
const auto & completionAwareBlockRangeConsumerFactory() const
Gets the factory for creating a CompletionAwareBlockRangeConsumerFunc bound to an input source.
Definition: ServerHooks.h:166
catapult::extensions::ServerHooks::m_remoteChainHeightsRetriever
RemoteChainHeightsRetriever m_remoteChainHeightsRetriever
Definition: ServerHooks.h:211
ChainSynchronizer.h
BasicServerHooks.h
catapult::extensions::ServerHooks::setCompletionAwareBlockRangeConsumerFactory
void setCompletionAwareBlockRangeConsumerFactory(const CompletionAwareBlockRangeConsumerFactoryFunc &factory)
Sets the factory for creating a CompletionAwareBlockRangeConsumerFunc bound to an input source.
Definition: ServerHooks.h:110
catapult::predicate
std::function< bool(TArgs...)> predicate
A predicate function.
Definition: functions.h:31
catapult::extensions::RemoteChainHeightsRetriever
std::function< thread::future< std::vector< Height > >(size_t)> RemoteChainHeightsRetriever
A retriever that returns the network chain heights for a number of peers.
Definition: ServerHooks.h:66
catapult::disruptor::InputSource
InputSource
Possible consumer input sources.
Definition: InputSource.h:42
catapult::extensions::TransactionEventHandler
consumer< const TransactionEventData & > TransactionEventHandler
Handler that is called when a transaction event is raised.
Definition: TransactionEvent.h:54
catapult::extensions::Require
const TFunc & Require(const TFunc &func)
Returns func if and only if it is set.
Definition: BasicServerHooks.h:38
catapult::extensions::TransactionRangeConsumerFactoryFunc
std::function< TransactionRangeConsumerFunc(disruptor::InputSource)> TransactionRangeConsumerFactoryFunc
Factory for creating a TransactionRangeConsumerFunc bound to an input source.
Definition: ServerHooks.h:63
BlockConsumers.h
catapult::extensions::SetOnce
void SetOnce(TFunc &dest, const TFunc &source)
Sets dest to source if and only if dest is unset.
Definition: BasicServerHooks.h:29
catapult::chain::KnownHashPredicate
predicate< Timestamp, const Hash256 & > KnownHashPredicate
Predicate for determining if a hash is known.
Definition: ChainFunctions.h:36
catapult::extensions::ServerHooks::chainSyncedPredicate
auto chainSyncedPredicate() const
Gets the chain synced predicate.
Definition: ServerHooks.h:181
catapult::extensions::ServerHooks::m_completionAwareBlockRangeConsumerFactory
CompletionAwareBlockRangeConsumerFactoryFunc m_completionAwareBlockRangeConsumerFactory
Definition: ServerHooks.h:208
catapult::extensions::CompletionAwareBlockRangeConsumerFactoryFunc
std::function< chain::CompletionAwareBlockRangeConsumerFunc(disruptor::InputSource)> CompletionAwareBlockRangeConsumerFactoryFunc
Factory for creating a CompletionAwareBlockRangeConsumerFunc bound to an input source.
Definition: ServerHooks.h:57
catapult::extensions::ServerHooks::addTransactionEventHandler
void addTransactionEventHandler(const TransactionEventHandler &handler)
Adds a transaction event handler.
Definition: ServerHooks.h:100
catapult::extensions::ChainSyncedPredicate
predicate<> ChainSyncedPredicate
Predicate for determining if a chain is synced.
Definition: ServerHooks.h:69
catapult::extensions::TransactionRangeConsumerFunc
handlers::TransactionRangeHandler TransactionRangeConsumerFunc
Function signature for delivering a transaction range to a consumer.
Definition: ServerHooks.h:60
catapult::extensions::TransactionsChangeHandler
consumers::BlockChainSyncHandlers::TransactionsChangeFunc TransactionsChangeHandler
Handler that is called when the confirmed state of transactions changes.
Definition: ServerHooks.h:47
catapult::chain::CompletionAwareBlockRangeConsumerFunc
std::function< disruptor::DisruptorElementId(model::AnnotatedBlockRange &&, const disruptor::ProcessingCompleteFunc &)> CompletionAwareBlockRangeConsumerFunc
Function signature for delivering a block range to a consumer with an additional completion handler.
Definition: ChainSynchronizer.h:43
catapult::extensions::ServerHooks::transactionsChangeHandler
auto transactionsChangeHandler() const
Gets the transactions change handler.
Definition: ServerHooks.h:151
catapult::extensions::KnownHashPredicate
chain::KnownHashPredicate KnownHashPredicate
Predicate for determining if a hash is known.
Definition: ServerHooks.h:72
catapult::extensions::ServerHooks::newTransactionsSink
auto newTransactionsSink() const
Gets the new transactions sink.
Definition: ServerHooks.h:141
catapult::extensions::PacketPayloadSink
consumer< const ionet::PacketPayload & > PacketPayloadSink
A packet payload sink.
Definition: ServerHooks.h:44
catapult::extensions::ServerHooks::m_newBlockSinks
std::vector< NewBlockSink > m_newBlockSinks
Definition: ServerHooks.h:201
catapult::extensions::BlockRangeConsumerFactoryFunc
std::function< BlockRangeConsumerFunc(disruptor::InputSource)> BlockRangeConsumerFactoryFunc
Factory for creating a BlockRangeConsumerFunc bound to an input source.
Definition: ServerHooks.h:53
MemoryUtCache.h
catapult::extensions::ServerHooks::knownHashPredicate
KnownHashPredicate knownHashPredicate(const cache::MemoryUtCache &utCache) const
Gets the known hash predicate augmented with a check in utCache.
Definition: ServerHooks.h:186
catapult::extensions::ServerHooks::transactionEventHandler
auto transactionEventHandler() const
Gets the transaction event handler.
Definition: ServerHooks.h:156
catapult::extensions::ServerHooks::m_newTransactionsSinks
std::vector< SharedNewTransactionsSink > m_newTransactionsSinks
Definition: ServerHooks.h:202
catapult::cache::MemoryUtCacheView::contains
bool contains(const Hash256 &hash) const
Returns true if the cache contains an unconfirmed transaction with associated hash,...
Definition: MemoryUtCache.cpp:67
catapult::extensions::ServerHooks::setTransactionRangeConsumerFactory
void setTransactionRangeConsumerFactory(const TransactionRangeConsumerFactoryFunc &factory)
Sets the factory for creating a TransactionRangeConsumerFunc bound to an input source.
Definition: ServerHooks.h:115
catapult::extensions::ServerHooks::addNewBlockSink
void addNewBlockSink(const NewBlockSink &sink)
Adds a new block sink.
Definition: ServerHooks.h:80
TransactionEvent.h
catapult::handlers::BlockRangeHandler
RangeHandler< model::Block > BlockRangeHandler
Prototype for a function that processes a range of blocks.
Definition: HandlerTypes.h:32
PacketPayload.h
catapult::extensions::ServerHooks::m_transactionsChangeHandlers
std::vector< TransactionsChangeHandler > m_transactionsChangeHandlers
Definition: ServerHooks.h:204
catapult::handlers::TransactionRangeHandler
RangeHandler< model::Transaction > TransactionRangeHandler
Prototype for a function that processes a range of transactions.
Definition: HandlerTypes.h:35
catapult::extensions::ServerHooks::addNewTransactionsSink
void addNewTransactionsSink(const SharedNewTransactionsSink &sink)
Adds a new transactions sink.
Definition: ServerHooks.h:85
catapult::extensions::ServerHooks::m_transactionEventHandlers
std::vector< TransactionEventHandler > m_transactionEventHandlers
Definition: ServerHooks.h:205
catapult::extensions::ServerHooks::addKnownHashPredicate
void addKnownHashPredicate(const KnownHashPredicate &predicate)
Adds a known hash predicate.
Definition: ServerHooks.h:130
catapult::extensions::BlockRangeConsumerFunc
handlers::BlockRangeHandler BlockRangeConsumerFunc
Function signature for delivering a block range to a consumer.
Definition: ServerHooks.h:50
catapult::extensions::ServerHooks
Hooks that can be used to configure server behavior.
Definition: ServerHooks.h:77
catapult::cache::MemoryUtCache
Cache for all unconfirmed transactions.
Definition: MemoryUtCache.h:81
ChainFunctions.h
catapult::extensions::ServerHooks::m_transactionRangeConsumerFactory
TransactionRangeConsumerFactoryFunc m_transactionRangeConsumerFactory
Definition: ServerHooks.h:209
catapult::extensions::ServerHooks::remoteChainHeightsRetriever
const auto & remoteChainHeightsRetriever() const
Gets the remote chain heights retriever.
Definition: ServerHooks.h:176
catapult::extensions::ServerHooks::transactionRangeConsumerFactory
const auto & transactionRangeConsumerFactory() const
Gets the factory for creating a TransactionRangeConsumerFunc bound to an input source.
Definition: ServerHooks.h:171
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::extensions::ServerHooks::m_knownHashPredicates
std::vector< KnownHashPredicate > m_knownHashPredicates
Definition: ServerHooks.h:213
catapult::consumers::NewBlockSink
consumer< const std::shared_ptr< const model::Block > & > NewBlockSink
Prototype for a function that is called with a new block.
Definition: BlockConsumers.h:84
HandlerTypes.h
catapult::extensions::ServerHooks::setRemoteChainHeightsRetriever
void setRemoteChainHeightsRetriever(const RemoteChainHeightsRetriever &retriever)
Sets the remote heights chain retriever.
Definition: ServerHooks.h:120
catapult::extensions::ServerHooks::m_blockRangeConsumerFactory
BlockRangeConsumerFactoryFunc m_blockRangeConsumerFactory
Definition: ServerHooks.h:207
catapult::extensions::ServerHooks::setChainSyncedPredicate
void setChainSyncedPredicate(const ChainSyncedPredicate &predicate)
Sets the chain synced predicate.
Definition: ServerHooks.h:125
catapult::cache::MemoryUtCache::view
MemoryUtCacheView view() const
Gets a read only view based on this cache.
Definition: MemoryUtCache.cpp:223
catapult::consumers::BlockChainSyncHandlers::TransactionsChangeFunc
consumer< const TransactionsChangeInfo & > TransactionsChangeFunc
Prototype for transaction change notification.
Definition: BlockChainSyncHandlers.h:90
catapult::extensions::ServerHooks::addPacketPayloadSink
void addPacketPayloadSink(const PacketPayloadSink &sink)
Adds a packet payload sink.
Definition: ServerHooks.h:90
catapult::extensions::ServerHooks::newBlockSink
auto newBlockSink() const
Gets the new block sink.
Definition: ServerHooks.h:136
catapult::extensions::ServerHooks::addTransactionsChangeHandler
void addTransactionsChangeHandler(const TransactionsChangeHandler &handler)
Adds a transactions change handler.
Definition: ServerHooks.h:95
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
catapult::extensions::ServerHooks::setBlockRangeConsumerFactory
void setBlockRangeConsumerFactory(const BlockRangeConsumerFactoryFunc &factory)
Sets the factory for creating a BlockRangeConsumerFunc bound to an input source.
Definition: ServerHooks.h:105
catapult::extensions::SharedNewTransactionsSink
consumer< const consumers::TransactionInfos & > SharedNewTransactionsSink
A new transactions sink prototype that does not take ownership of new infos.
Definition: ServerHooks.h:41
catapult::extensions::ServerHooks::m_chainSyncedPredicate
ChainSyncedPredicate m_chainSyncedPredicate
Definition: ServerHooks.h:212
DisruptorElement.h
catapult::extensions::ServerHooks::packetPayloadSink
auto packetPayloadSink() const
Gets the packet payload sink.
Definition: ServerHooks.h:146
catapult::extensions::AggregateConsumers
TConsumer AggregateConsumers(const std::vector< TConsumer > &consumers)
Aggregates multiple consumers into a single consumer.
Definition: BasicServerHooks.h:47