CatapultServer  v0.5.0.1 (Elephant)
StatePathHandlerFactory.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "catapult/ionet/Packet.h"
25 #include "catapult/utils/Casting.h"
26 
27 namespace catapult { namespace handlers {
28 
30  template<typename TPacket, typename TCache>
31  void RegisterStatePathHandler(ionet::ServerPacketHandlers& handlers, const TCache& cache) {
32  handlers.registerHandler(TPacket::Packet_Type, [&cache](const auto& packet, auto& context) {
33  const auto* pRequest = ionet::CoercePacket<TPacket>(&packet);
34  if (!pRequest)
35  return;
36 
37  auto view = cache.createView();
38  std::vector<tree::TreeNode> path;
39  view->tryLookup(pRequest->Key, path);
40 
41  // serialize path even if lookup failed (to provide proof that key does not exist in state)
42  std::vector<uint8_t> serializedPath;
43  for (const auto& node : path) {
44  auto serializedNode = tree::PatriciaTreeSerializer::SerializeValue(node);
45  const auto* pData = reinterpret_cast<const uint8_t*>(serializedNode.data());
46  serializedPath.insert(serializedPath.end(), pData, pData + serializedNode.size());
47  }
48 
49  auto payloadSize = utils::checked_cast<size_t, uint32_t>(serializedPath.size());
50  auto pResponsePacket = ionet::CreateSharedPacket<ionet::Packet>(payloadSize);
51  pResponsePacket->Type = TPacket::Packet_Type;
52  std::memcpy(pResponsePacket->Data(), serializedPath.data(), serializedPath.size());
53  context.response(ionet::PacketPayload(pResponsePacket));
54  });
55  }
56 }}
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
InputUtils.h
catapult::disruptor::TransactionConsumer
DisruptorConsumerT< TransactionElements > TransactionConsumer
A transaction disruptor consumer function.
Definition: DisruptorConsumer.h:44
catapult::validators::IsValidationResultSuccess
constexpr bool IsValidationResultSuccess(ValidationResult result)
Returns a value indicating whether the validation result is a success.
Definition: ValidationResult.h:90
AggregateEntityValidator.h
catapult::chain::FailedTransactionSink
consumer< const model::Transaction &, const Hash256 &, validators::ValidationResult > FailedTransactionSink
Indicates a transaction with the specified hash failed validation.
Definition: ChainFunctions.h:33
catapult::consumers::CreateBlockStatelessValidationConsumer
disruptor::ConstBlockConsumer CreateBlockStatelessValidationConsumer(const std::shared_ptr< const validators::stateless::AggregateEntityValidator > &pValidator, const std::shared_ptr< const validators::ParallelValidationPolicy > &pValidationPolicy, const RequiresValidationPredicate &requiresValidationPredicate)
Definition: StatelessValidationConsumer.cpp:65
catapult::disruptor::ConstBlockConsumer
DisruptorConsumerT< const BlockElements > ConstBlockConsumer
A const block disruptor consumer function.
Definition: DisruptorConsumer.h:41
BlockConsumers.h
catapult::consumers::ExtractEntityInfos
void ExtractEntityInfos(const TransactionElements &elements, model::WeakEntityInfos &entityInfos, std::vector< size_t > &entityInfoElementIndexes)
Definition: InputUtils.cpp:45
Packet.h
catapult::ionet::ServerPacketHandlers::registerHandler
void registerHandler(PacketType type, const PacketHandler &handler)
Registers a handler for the specified packet type.
Definition: PacketHandlers.cpp:100
ConsumerResultFactory.h
catapult::validators::AggregateValidationResult
void AggregateValidationResult(std::atomic< ValidationResult > &aggregate, ValidationResult value)
Aggregates result into aggregate.
Definition: AggregateValidationResult.cpp:62
PacketHandlers.h
Packet_Type
static constexpr auto Packet_Type
Definition: RemoteNodeApi.cpp:33
catapult::disruptor::ConsumerResultSeverity::Neutral
Neutral result.
catapult::model::ExtractMatchingEntityInfos
void ExtractMatchingEntityInfos(const std::vector< BlockElement > &elements, WeakEntityInfos &entityInfos, const MatchingEntityPredicate &predicate)
Extracts all entity infos for which predicate returns true from elements into entityInfos.
Definition: Elements.cpp:79
AggregateValidationResult.h
catapult::consumers::Abort
constexpr disruptor::ConsumerResult Abort(validators::ValidationResult validationResult)
Creates an aborted consumer result around validationResult.
Definition: ConsumerResultFactory.h:34
CATAPULT_LOG_LEVEL
#define CATAPULT_LOG_LEVEL(LEVEL)
Writes a log entry to the default logger with LEVEL severity.
Definition: Logging.h:336
catapult::validators::ValidationResult::Success
Validation succeeded.
catapult::disruptor::ConsumerResultSeverity::Failure
Failure result.
Casting.h
catapult::ionet::PacketPayload
A packet payload that can be written.
Definition: PacketPayload.h:29
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::validators::IsValidationResultFailure
constexpr bool IsValidationResultFailure(ValidationResult result)
Returns a value indicating whether the validation result is a failure.
Definition: ValidationResult.h:95
catapult::validators::MapToLogLevel
constexpr utils::LogLevel MapToLogLevel(ValidationResult result)
Maps validation result to an appropriate logging level.
Definition: ValidationResult.h:100
catapult::tree::PatriciaTreeSerializer::SerializeValue
static std::string SerializeValue(const tree::TreeNode &value)
Serializes value to string.
Definition: PatriciaTreeSerializer.cpp:119
catapult::consumers::RequiresValidationPredicate
model::MatchingEntityPredicate RequiresValidationPredicate
Predicate for checking whether or not an entity requires validation.
Definition: BlockConsumers.h:58
catapult::ionet::ServerPacketHandlers
A collection of packet handlers where there is at most one handler per packet type.
Definition: PacketHandlers.h:62
catapult::consumers::CreateTransactionStatelessValidationConsumer
disruptor::TransactionConsumer CreateTransactionStatelessValidationConsumer(const std::shared_ptr< const validators::stateless::AggregateEntityValidator > &pValidator, const std::shared_ptr< const validators::ParallelValidationPolicy > &pValidationPolicy, const chain::FailedTransactionSink &failedTransactionSink)
Definition: StatelessValidationConsumer.cpp:77
PatriciaTreeSerializer.h
catapult::model::WeakEntityInfos
std::vector< WeakEntityInfo > WeakEntityInfos
A container of weak entity infos.
Definition: WeakEntityInfo.h:144
catapult::consumers::Continue
constexpr disruptor::ConsumerResult Continue()
Creates a continuation consumer result.
Definition: ConsumerResultFactory.h:29
TransactionConsumers.h
catapult::handlers::RegisterStatePathHandler
void RegisterStatePathHandler(ionet::ServerPacketHandlers &handlers, const TCache &cache)
Registers a handler in handlers that responds with serialized state path produced by querying cache.
Definition: StatePathHandlerFactory.h:31