CatapultServer  v0.5.0.1 (Elephant)
EntityInfo.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "Block.h"
23 #include "ContainerTypes.h"
24 #include "Transaction.h"
25 #include "catapult/utils/Hashers.h"
27 #include <memory>
28 
29 namespace catapult { namespace model {
30 
32  template<typename TEntity>
33  struct EntityInfo : public utils::MoveOnly {
34  public:
36  EntityInfo() = default;
37 
39  explicit EntityInfo(const std::shared_ptr<TEntity>& pEntityParam, const Hash256& hash)
40  : pEntity(pEntityParam)
41  , EntityHash(hash)
42  {}
43 
45  std::shared_ptr<TEntity> pEntity;
46 
49 
50  public:
52  explicit operator bool() const noexcept {
53  return !!pEntity;
54  }
55  };
56 
58  template<typename TEntity>
59  struct EntityInfoHasher {
61  size_t operator()(const EntityInfo<TEntity>& info) const {
62  return utils::ArrayHasher<Hash256>()(info.EntityHash);
63  }
64  };
65 
67  template<typename TEntity>
68  struct EntityInfoComparer {
70  bool operator()(const EntityInfo<TEntity>& lhs, const EntityInfo<TEntity>& rhs) const {
71  return lhs.EntityHash == rhs.EntityHash;
72  }
73  };
74 
77  struct DetachedTransactionInfo : EntityInfo<const Transaction> {
78  public:
80 
81  public:
83  DetachedTransactionInfo() = default;
84 
86  explicit DetachedTransactionInfo(const std::shared_ptr<const Transaction>& pTransaction)
87  : DetachedTransactionInfo(pTransaction, Hash256())
88  {}
89 
90  public:
93  auto transactionInfo = DetachedTransactionInfo(pEntity, EntityHash);
94  transactionInfo.OptionalExtractedAddresses = OptionalExtractedAddresses;
95  return transactionInfo;
96  }
97 
98  public:
100  std::shared_ptr<const UnresolvedAddressSet> OptionalExtractedAddresses;
101  };
102 
105  public:
107  TransactionInfo() = default;
108 
110  explicit TransactionInfo(const std::shared_ptr<const Transaction>& pTransaction)
111  : TransactionInfo(pTransaction, Hash256())
112  {}
113 
115  explicit TransactionInfo(const std::shared_ptr<const Transaction>& pTransaction, const Hash256& hash)
116  : DetachedTransactionInfo(pTransaction, hash)
118  {}
119 
120  public:
123  auto transactionInfo = TransactionInfo(pEntity, EntityHash);
124  transactionInfo.OptionalExtractedAddresses = OptionalExtractedAddresses;
125  transactionInfo.MerkleComponentHash = MerkleComponentHash;
126  return transactionInfo;
127  }
128 
129  public:
132  };
133 }}
catapult::model::TransactionInfo::TransactionInfo
TransactionInfo()=default
Creates a transaction info.
Block.h
catapult::model::DetachedTransactionInfo::DetachedTransactionInfo
DetachedTransactionInfo()=default
Creates a transaction info.
catapult::model::TransactionInfo::TransactionInfo
TransactionInfo(const std::shared_ptr< const Transaction > &pTransaction)
Creates a transaction info around pTransaction without any metadata.
Definition: EntityInfo.h:110
Transaction.h
catapult::model::DetachedTransactionInfo::copy
DetachedTransactionInfo copy() const
Creates a (shallow) copy of this info.
Definition: EntityInfo.h:92
catapult::model::TransactionInfo::MerkleComponentHash
Hash256 MerkleComponentHash
Modified hash that should be used as a hash in the merkle tree.
Definition: EntityInfo.h:131
catapult::model::TransactionInfo
A transaction and its associated metadata.
Definition: EntityInfo.h:104
catapult::model::EntityInfoComparer::operator()
bool operator()(const EntityInfo< TEntity > &lhs, const EntityInfo< TEntity > &rhs) const
Returns true if lhs and rhs are equal.
Definition: EntityInfo.h:70
catapult::model::DetachedTransactionInfo::OptionalExtractedAddresses
std::shared_ptr< const UnresolvedAddressSet > OptionalExtractedAddresses
Extracted addresses (optional).
Definition: EntityInfo.h:100
forwardsValidation.info
def info(*args)
Definition: forwardsValidation.py:12
catapult::model::EntityInfo::EntityInfo
EntityInfo(const std::shared_ptr< TEntity > &pEntityParam, const Hash256 &hash)
Creates an entity info around pEntityParam and its associated metadata (hash).
Definition: EntityInfo.h:39
catapult::model::EntityInfo::EntityInfo
EntityInfo()=default
Creates an entity info.
catapult::utils::MoveOnly
A class that can be moved but not copied.
Definition: NonCopyable.h:43
ContainerTypes.h
catapult::model::TransactionInfo::TransactionInfo
TransactionInfo(const std::shared_ptr< const Transaction > &pTransaction, const Hash256 &hash)
Creates a transaction info around pTransaction and its associated metadata (hash).
Definition: EntityInfo.h:115
catapult::model::EntityInfo::pEntity
std::shared_ptr< TEntity > pEntity
Entity pointer.
Definition: EntityInfo.h:45
catapult
Definition: AddressExtractionExtension.cpp:28
Hashers.h
catapult::model::EntityInfoHasher::operator()
size_t operator()(const EntityInfo< TEntity > &info) const
Hashes info.
Definition: EntityInfo.h:61
catapult::utils::ByteArray< Hash256_Size, Hash256_tag >
catapult::model::EntityInfo::EntityHash
Hash256 EntityHash
Entity hash.
Definition: EntityInfo.h:48
catapult::model::EntityInfo
Tuple composed of an entity and its associated metadata.
Definition: EntityInfo.h:33
catapult::utils::ArrayHasher
Definition: Hashers.h:32
catapult::model::DetachedTransactionInfo
Definition: EntityInfo.h:77
catapult::model::TransactionInfo::copy
TransactionInfo copy() const
Creates a (shallow) copy of this info.
Definition: EntityInfo.h:122
NonCopyable.h
catapult::model::DetachedTransactionInfo::DetachedTransactionInfo
DetachedTransactionInfo(const std::shared_ptr< const Transaction > &pTransaction)
Creates a transaction info around pTransaction without any metadata.
Definition: EntityInfo.h:86