CatapultServer  v0.5.0.1 (Elephant)
BlockUtils.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "Block.h"
23 #include "Elements.h"
24 #include "EntityInfo.h"
25 
26 namespace catapult { namespace crypto { class KeyPair; } }
27 
28 namespace catapult { namespace model {
29 
30  // region hashes
31 
33  void CalculateBlockTransactionsHash(const std::vector<const TransactionInfo*>& transactionInfos, Hash256& blockTransactionsHash);
34 
37  GenerationHash CalculateGenerationHash(const GenerationHash& previousGenerationHash, const Key& publicKey);
38 
39  // endregion
40 
41  // region sign / verify
42 
45  void SignBlockHeader(const crypto::KeyPair& signer, Block& block);
46 
48  bool VerifyBlockHeaderSignature(const Block& block);
49 
50  // endregion
51 
52  // region fees
53 
57  uint32_t Count = 0;
58 
61  };
62 
65 
66  // endregion
67 
68  // region create block
69 
71  using Transactions = std::vector<std::shared_ptr<const Transaction>>;
72 
77  : BlockHash()
78  , GenerationHash()
79  , BlockHeight(0)
80  , Timestamp(0)
81  {}
82 
84  explicit PreviousBlockContext(const BlockElement& blockElement)
85  : BlockHash(blockElement.EntityHash)
86  , GenerationHash(blockElement.GenerationHash)
87  , BlockHeight(blockElement.Block.Height)
88  , Timestamp(blockElement.Block.Timestamp)
89  {}
90 
93 
96 
99 
102  };
103 
106  std::unique_ptr<Block> CreateBlock(
107  const PreviousBlockContext& context,
108  NetworkIdentifier networkIdentifier,
109  const Key& signerPublicKey,
110  const Transactions& transactions);
111 
113  std::unique_ptr<Block> StitchBlock(const BlockHeader& blockHeader, const Transactions& transactions);
114 
115  // endregion
116 }}
catapult::model::TransactionContainer::Transactions
auto Transactions(EntityContainerErrorPolicy errorPolicy=EntityContainerErrorPolicy::Throw)
Definition: TransactionContainer.h:37
Block.h
catapult::model::CalculateBlockTransactionsHash
void CalculateBlockTransactionsHash(const std::vector< const TransactionInfo * > &transactionInfos, Hash256 &blockTransactionsHash)
Calculates the block transactions hash of transactionInfos into blockTransactionsHash.
Definition: BlockUtils.cpp:42
catapult::model::CreateBlock
std::unique_ptr< Block > CreateBlock(const PreviousBlockContext &context, NetworkIdentifier networkIdentifier, const Key &signerPublicKey, const Transactions &transactions)
Definition: BlockUtils.cpp:138
MemoryUtils.h
catapult::Hash256
utils::ByteArray< Hash256_Size, Hash256_tag > Hash256
Definition: src/catapult/types.h:47
catapult::model::SignBlockHeader
void SignBlockHeader(const crypto::KeyPair &signer, Block &block)
Definition: BlockUtils.cpp:63
catapult::model::PreviousBlockContext
Context passed when creating new block.
Definition: BlockUtils.h:74
MerkleHashBuilder.h
catapult::Height
utils::BaseValue< uint64_t, Height_tag > Height
Definition: src/catapult/types.h:85
catapult::crypto::KeccakBuilder
Builder for building a hash.
Definition: Hashes.h:61
catapult::model::BlockHeader
Binary layout for a block header.
Definition: Block.h:34
catapult::model::VerifiableEntityHeader::Header_Size
static constexpr size_t Header_Size
Size of the VerifiableEntity part that can be skipped when signing/verifying.
Definition: VerifiableEntity.h:38
catapult::model::CalculateGenerationHash
GenerationHash CalculateGenerationHash(const GenerationHash &previousGenerationHash, const Key &publicKey)
Definition: BlockUtils.cpp:50
catapult::model::Transactions
std::vector< std::shared_ptr< const Transaction > > Transactions
Container of transactions.
Definition: BlockUtils.h:71
catapult::model::StitchBlock
std::unique_ptr< Block > StitchBlock(const BlockHeader &blockHeader, const Transactions &transactions)
Creates a new block by stitching together blockHeader and transactions.
Definition: BlockUtils.cpp:146
catapult::model::BlockTransactionsInfo
Information about transactions stored in a block.
Definition: BlockUtils.h:55
catapult::model::PreviousBlockContext::GenerationHash
catapult::GenerationHash GenerationHash
Generation hash of previous block.
Definition: BlockUtils.h:95
catapult::model::BlockTransactionsInfo::Count
uint32_t Count
Number of transactions.
Definition: BlockUtils.h:57
Elements.h
catapult::utils::BaseValue< uint64_t, Amount_tag >
catapult::model::PreviousBlockContext::BlockHash
Hash256 BlockHash
Hash of previous block.
Definition: BlockUtils.h:92
catapult::model::PreviousBlockContext::PreviousBlockContext
PreviousBlockContext()
Creates an empty context.
Definition: BlockUtils.h:76
catapult::crypto::MerkleHashBuilder
Builder for creating a merkle hash.
Definition: MerkleHashBuilder.h:28
catapult::crypto::KeccakBuilder::final
void final(OutputType &output) noexcept
Finalize hash calculation. Returns result in output.
Definition: Hashes.cpp:145
Hashes.h
catapult::crypto::KeyPair
Represents a pair of private key with associated public key.
Definition: KeyPair.h:33
Signer.h
catapult::model::EntityBody::Signer
Key Signer
Entity signer's public key.
Definition: EntityBody.h:36
catapult::model::BlockTransactionsInfo::TotalFee
Amount TotalFee
Total fee of all transactions.
Definition: BlockUtils.h:60
catapult::crypto::KeccakBuilder::update
void update(const RawBuffer &dataBuffer) noexcept
Updates the state of hash with data inside dataBuffer.
Definition: Hashes.cpp:134
catapult::crypto::MerkleHashBuilder::update
void update(const Hash256 &hash)
Adds hash to the merkle hash.
Definition: MerkleHashBuilder.cpp:72
catapult::model::VerifiableEntityHeader::Signature
catapult::Signature Signature
Entity signature.
Definition: VerifiableEntity.h:41
size
uint64_t size
Definition: MemoryCounters.cpp:65
EntityInfo.h
catapult::model::PreviousBlockContext::Timestamp
catapult::Timestamp Timestamp
Timestamp of previous block.
Definition: BlockUtils.h:101
catapult::model::NetworkIdentifier
NetworkIdentifier
Possible network identifiers.
Definition: NetworkInfo.h:45
catapult::model::BlockHeader::FeeMultiplier
BlockFeeMultiplier FeeMultiplier
Fee multiplier applied to transactions contained in block.
Definition: Block.h:50
catapult::model::BlockElement
Processing element for a block composed of a block and metadata.
Definition: Elements.h:55
catapult::model::Block
Binary layout for a block.
Definition: Block.h:69
FeeUtils.h
catapult::Difficulty
utils::ClampedBaseValue< uint64_t, Difficulty_tag > Difficulty
Definition: src/catapult/types.h:99
catapult::model::PreviousBlockContext::PreviousBlockContext
PreviousBlockContext(const BlockElement &blockElement)
Creates a context with blockElement as the previous block.
Definition: BlockUtils.h:84
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::GenerationHash
utils::ByteArray< Hash256_Size, GenerationHash_tag > GenerationHash
Definition: src/catapult/types.h:53
catapult::crypto::Verify
bool Verify(const Key &publicKey, const RawBuffer &dataBuffer, const Signature &signature)
Definition: Signer.cpp:136
catapult::model::CalculateBlockTransactionsInfo
BlockTransactionsInfo CalculateBlockTransactionsInfo(const Block &block)
Calculates information about transactions stored in block.
Definition: BlockUtils.cpp:75
catapult::model::PreviousBlockContext::BlockHeight
Height BlockHeight
Height of previous block.
Definition: BlockUtils.h:98
catapult::model::CalculateTransactionFee
Amount CalculateTransactionFee(BlockFeeMultiplier feeMultiplier, const Transaction &transaction)
Calculates the fee for transaction contained in block with feeMultiplier.
Definition: FeeUtils.cpp:26
catapult::utils::ByteArray< Hash256_Size, Hash256_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::VerifyBlockHeaderSignature
bool VerifyBlockHeaderSignature(const Block &block)
Validates signature of block header.
Definition: BlockUtils.cpp:67
catapult::crypto::MerkleHashBuilder::final
void final(Hash256 &hash)
Finalizes the merkle hash into hash.
Definition: MerkleHashBuilder.cpp:76
catapult::crypto::Sign
void Sign(const KeyPair &keyPair, const RawBuffer &dataBuffer, Signature &computedSignature)
Definition: Signer.cpp:82
catapult::Key
utils::ByteArray< Key_Size, Key_tag > Key
Definition: src/catapult/types.h:41
BlockUtils.h
catapult::utils::RawBuffer
BasicRawBuffer< const uint8_t > RawBuffer
A const binary buffer.
Definition: RawBuffer.h:62