CatapultServer  v0.5.0.1 (Elephant)
HandlerUtils.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "HandlerTypes.h"
25 #include "catapult/utils/Logging.h"
26 #include <functional>
27 
28 namespace catapult { namespace handlers {
29 
32  template<typename TEntity>
33  auto CreatePushEntityHandler(const model::TransactionRegistry& registry, const RangeHandler<TEntity>& rangeHandler) {
34  return [rangeHandler, &registry](const ionet::Packet& packet, const auto& context) {
35  auto range = ionet::ExtractEntitiesFromPacket<TEntity>(packet, [&registry](const auto& entity) {
36  return IsSizeValid(entity, registry);
37  });
38  if (range.empty()) {
39  CATAPULT_LOG(warning) << "rejecting empty range: " << packet;
40  return;
41  }
42 
43  CATAPULT_LOG(trace) << "received valid " << packet;
44  rangeHandler({ std::move(range), context.key() });
45  };
46  }
47 }}
catapult::handlers::RangeHandler
consumer< model::AnnotatedEntityRange< TEntity > && > RangeHandler
A handler for processing an annotated entity range.
Definition: HandlerTypes.h:29
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
catapult::handlers::CreatePushEntityHandler
auto CreatePushEntityHandler(const model::TransactionRegistry &registry, const RangeHandler< TEntity > &rangeHandler)
Definition: HandlerUtils.h:33
PacketEntityUtils.h
catapult::ionet::Packet
A packet header with a data payload.
Definition: Packet.h:32
colorPrint.warning
def warning(*args)
Definition: colorPrint.py:10
TransactionPlugin.h
catapult::model::IsSizeValid
bool IsSizeValid(const AggregateTransaction &aggregate, const TransactionRegistry &registry)
Definition: AggregateTransaction.cpp:38
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::model::TransactionRegistry
A registry of transaction plugins.
Definition: TransactionPlugin.h:98
HandlerTypes.h
Logging.h