CatapultServer  v0.5.0.1 (Elephant)
TransactionBuilder.h
Go to the documentation of this file.
1 
21 #pragma once
24 #include "catapult/utils/Casting.h"
26 #include "catapult/functions.h"
27 
28 namespace catapult { namespace builders {
29 
32  public:
35  : m_networkIdentifier(networkIdentifier)
36  , m_signer(signer)
37  {}
38 
39  public:
41  const Key& signer() const {
42  return m_signer;
43  }
44 
45  public:
48  m_deadline = deadline;
49  }
50 
53  m_maxFee = fee;
54  }
55 
56  private:
58  {}
59 
60  void setAdditionalFields(model::Transaction& transaction) const {
61  transaction.Deadline = m_deadline;
62  transaction.MaxFee = m_maxFee;
63  }
64 
65  protected:
66  template<typename TTransaction>
67  std::unique_ptr<TTransaction> createTransaction(size_t size) const {
68  auto pTransaction = utils::MakeUniqueWithSize<TTransaction>(size);
69  std::memset(static_cast<void*>(pTransaction.get()), 0, sizeof(TTransaction));
70 
71  // verifiable entity data
72  pTransaction->Size = utils::checked_cast<size_t, uint32_t>(size);
73  pTransaction->Type = TTransaction::Entity_Type;
74  pTransaction->Version = MakeVersion(m_networkIdentifier, TTransaction::Current_Version);
75  pTransaction->Signer = m_signer;
76 
77  // transaction data
78  setAdditionalFields(*pTransaction);
79  return pTransaction;
80  }
81 
82  template<typename T, typename Predicate>
83  static void InsertSorted(std::vector<T>& vector, const T& element, Predicate orderPredicate) {
84  auto iter = std::upper_bound(vector.begin(), vector.end(), element, orderPredicate);
85  if (iter != vector.begin() && !orderPredicate(*(iter - 1), element) && !orderPredicate(element, *(iter - 1)))
86  CATAPULT_THROW_RUNTIME_ERROR("duplicate element in sorted set");
87 
88  vector.insert(iter, element);
89  }
90 
91  private:
93  const Key& m_signer;
94 
97  };
98 }}
catapult::builders::TransactionBuilder::signer
const Key & signer() const
Returns signer.
Definition: TransactionBuilder.h:41
catapult::builders::TransactionBuilder::setMaxFee
void setMaxFee(catapult::Amount fee)
Sets maximum transaction fee.
Definition: TransactionBuilder.h:52
Transaction.h
MemoryUtils.h
functions.h
catapult::builders::TransactionBuilder::setAdditionalFields
void setAdditionalFields(model::EmbeddedTransaction &) const
Definition: TransactionBuilder.h:57
catapult::utils::BaseValue< uint64_t, Timestamp_tag >
catapult::builders::TransactionBuilder::m_maxFee
Amount m_maxFee
Definition: TransactionBuilder.h:96
NetworkInfo.h
catapult::builders::TransactionBuilder::setDeadline
void setDeadline(catapult::Timestamp deadline)
Sets transaction deadline.
Definition: TransactionBuilder.h:47
catapult::builders::TransactionBuilder::TransactionBuilder
TransactionBuilder(model::NetworkIdentifier networkIdentifier, const Key &signer)
Creates a transaction builder with networkIdentifier and signer.
Definition: TransactionBuilder.h:34
catapult::model::Transaction::MaxFee
Amount MaxFee
Definition: Transaction.h:35
size
uint64_t size
Definition: MemoryCounters.cpp:65
catapult::builders::TransactionBuilder::m_networkIdentifier
const model::NetworkIdentifier m_networkIdentifier
Definition: TransactionBuilder.h:92
catapult::builders::TransactionBuilder::createTransaction
std::unique_ptr< TTransaction > createTransaction(size_t size) const
Definition: TransactionBuilder.h:67
catapult::model::NetworkIdentifier
NetworkIdentifier
Possible network identifiers.
Definition: NetworkInfo.h:45
catapult::builders::TransactionBuilder
Base transaction builder.
Definition: TransactionBuilder.h:31
catapult::builders::TransactionBuilder::m_signer
const Key & m_signer
Definition: TransactionBuilder.h:93
catapult::model::EmbeddedTransaction
Binary layout for an embedded transaction (non-verifiable).
Definition: EmbeddedTransaction.h:38
CATAPULT_THROW_RUNTIME_ERROR
#define CATAPULT_THROW_RUNTIME_ERROR(MESSAGE)
Macro used to throw a catapult runtime error.
Definition: exceptions.h:167
catapult::model::Transaction::Deadline
Timestamp Deadline
Transaction deadline.
Definition: Transaction.h:38
catapult::builders::TransactionBuilder::setAdditionalFields
void setAdditionalFields(model::Transaction &transaction) const
Definition: TransactionBuilder.h:60
Casting.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::builders::TransactionBuilder::m_deadline
Timestamp m_deadline
Definition: TransactionBuilder.h:95
catapult::utils::ByteArray< Key_Size, Key_tag >
catapult::model::MakeVersion
constexpr uint16_t MakeVersion(NetworkIdentifier networkIdentifier, uint8_t version) noexcept
Creates a version field out of given entity version and networkIdentifier.
Definition: EntityBody.h:58
catapult::model::Transaction
Binary layout for a transaction.
Definition: Transaction.h:32
catapult::builders::TransactionBuilder::InsertSorted
static void InsertSorted(std::vector< T > &vector, const T &element, Predicate orderPredicate)
Definition: TransactionBuilder.h:83