CatapultServer  v0.5.0.1 (Elephant)
MemoryBlockStorage.h
Go to the documentation of this file.
1 
21 #pragma once
24 #include <map>
25 
26 namespace catapult { namespace extensions {
27 
30  private:
31  using Blocks = std::map<Height, std::shared_ptr<model::Block>>;
32  using BlockElements = std::map<Height, std::shared_ptr<model::BlockElement>>;
33  using BlockStatements = std::map<Height, std::shared_ptr<const model::BlockStatement>>;
34 
35  public:
37  explicit MemoryBlockStorage(const model::BlockElement& nemesisBlockElement);
38 
39  public:
40  // LightBlockStorage
41  Height chainHeight() const override;
42  model::HashRange loadHashesFrom(Height height, size_t maxHashes) const override;
43  void saveBlock(const model::BlockElement& blockElement) override;
44  void dropBlocksAfter(Height height) override;
45 
46  // BlockStorage
47  std::shared_ptr<const model::Block> loadBlock(Height height) const override;
48  std::shared_ptr<const model::BlockElement> loadBlockElement(Height height) const override;
49  std::pair<std::vector<uint8_t>, bool> loadBlockStatementData(Height height) const override;
50 
51  // PrunableBlockStorage
52  void purge() override;
53 
54  private:
55  void requireHeight(Height height, const char* description) const;
56 
57  private:
62  };
63 }}
catapult::extensions::MemoryBlockStorage::dropBlocksAfter
void dropBlocksAfter(Height height) override
Drops all blocks after height.
Definition: MemoryBlockStorage.cpp:111
m_buffer
std::vector< uint8_t > & m_buffer
Definition: MemoryBlockStorage.cpp:161
catapult::validators::FunctionalNotificationValidatorT
Notification validator that wraps a function.
Definition: FunctionalNotificationValidator.h:29
catapult::UnresolvedAddress
utils::ByteArray< Address_Decoded_Size, UnresolvedAddress_tag > UnresolvedAddress
Definition: src/catapult/types.h:66
NumAdds
size_t NumAdds
Definition: MaxAccountRestrictionValuesValidator.cpp:30
MemoryUtils.h
catapult::extensions::MemoryBlockStorage::loadBlockElement
std::shared_ptr< const model::BlockElement > loadBlockElement(Height height) const override
Returns the block element (owning a block) at height.
Definition: MemoryBlockStorage.cpp:137
AccountRestrictionCache.h
catapult::extensions::MemoryBlockStorage::m_blocks
Blocks m_blocks
Definition: MemoryBlockStorage.h:58
catapult::Amount
utils::BaseValue< uint64_t, Amount_tag > Amount
Definition: src/catapult/types.h:76
catapult::extensions::MemoryBlockStorage::requireHeight
void requireHeight(Height height, const char *description) const
Definition: MemoryBlockStorage.cpp:192
ValidatorContext.h
catapult::Height
utils::BaseValue< uint64_t, Height_tag > Height
Definition: src/catapult/types.h:85
BlockStorage.h
catapult::validators::DEFINE_ACCOUNT_RESTRICTION_MAX_VALUES_VALIDATOR
DEFINE_ACCOUNT_RESTRICTION_MAX_VALUES_VALIDATOR(MaxAccountAddressRestrictionValues, model::ModifyAccountAddressRestrictionNotification, UnresolvedAddress) DEFINE_ACCOUNT_RESTRICTION_MAX_VALUES_VALIDATOR(MaxAccountMosaicRestrictionValues
catapult::validators::ValidationResult
ValidationResult
Enumeration of all possible validation results.
Definition: ValidationResult.h:51
catapult::validators::Notification
model::AccountAddressNotification Notification
Definition: AddressValidator.cpp:27
catapult::model::EntityType
EntityType
Enumeration of entity types.
Definition: EntityType.h:43
CATAPULT_THROW_FILE_IO_ERROR
#define CATAPULT_THROW_FILE_IO_ERROR(MESSAGE)
Macro used to throw a catapult file io error.
Definition: exceptions.h:195
catapult::model::BlockElement::Block
const model::Block & Block
Block entity.
Definition: Elements.h:63
catapult::extensions::MemoryBlockStorage::m_blockStatements
BlockStatements m_blockStatements
Definition: MemoryBlockStorage.h:60
catapult::extensions::MemoryBlockStorage::m_blockElements
BlockElements m_blockElements
Definition: MemoryBlockStorage.h:59
catapult::model::ModifyAccountOperationRestrictionNotification
ModifyAccountRestrictionNotification< EntityType, RestrictionAccount_Operation_Modifications_Notification > ModifyAccountOperationRestrictionNotification
Definition: AccountRestrictionNotifications.h:168
catapult::model::MosaicSupplyChangeDirection::Decrease
Decreases the supply.
catapult::io::PrunableBlockStorage
Interface that allows saving, loading and pruning blocks.
Definition: BlockStorage.h:63
catapult::extensions::MemoryBlockStorage::loadBlockStatementData
std::pair< std::vector< uint8_t >, bool > loadBlockStatementData(Height height) const override
Returns the optional block statement data at height.
Definition: MemoryBlockStorage.cpp:165
catapult::model::EntityRange
Represents a range of entities.
Definition: EntityRange.h:31
catapult::extensions::MemoryBlockStorage
A memory-based block storage that loads and saves blocks in memory.
Definition: MemoryBlockStorage.h:29
catapult::model::BalanceTransferNotification
Notifies a balance transfer from sender to recipient.
Definition: Notifications.h:120
catapult::validators::DECLARE_STATEFUL_VALIDATOR
DECLARE_STATEFUL_VALIDATOR(Address, Notification)(model
Definition: AddressValidator.cpp:29
Elements.h
catapult::model::MosaicSupplyChangeNotification
Notification of a mosaic supply change.
Definition: MosaicNotifications.h:143
catapult::utils::BaseValue< uint64_t, Height_tag >
catapult::io::WriteBlockStatement
void WriteBlockStatement(const model::BlockStatement &blockStatement, OutputStream &outputStream)
Writes blockStatement into outputStream.
Definition: BlockStatementSerializer.cpp:65
catapult::model::ModifyAccountMosaicRestrictionNotification
ModifyAccountRestrictionNotification< UnresolvedMosaicId, RestrictionAccount_Mosaic_Modifications_Notification > ModifyAccountMosaicRestrictionNotification
Definition: AccountRestrictionNotifications.h:165
Validators.h
catapult::extensions::MemoryBlockStorage::saveBlock
void saveBlock(const model::BlockElement &blockElement) override
Saves blockElement.
Definition: MemoryBlockStorage.cpp:93
catapult::validators::MAKE_STATELESS_VALIDATOR
for(const auto &name :reservedRootNamespaceNames) reservedRootIds.emplace(model return MAKE_STATELESS_VALIDATOR(NamespaceName,([maxNameSize, reservedRootIds](const auto &notification) { if(maxNameSize< notification.NameSize||!model::IsValidName(notification.NamePtr, notification.NameSize)) return Failure_Namespace_Invalid_Name;auto name=utils::RawString(reinterpret_cast< const char * >(notification.NamePtr), notification.NameSize);if(notification.NamespaceId !=model::GenerateNamespaceId(notification.ParentId, name)) return Failure_Namespace_Name_Id_Mismatch;auto namespaceId=Namespace_Base_Id==notification.ParentId ? notification.NamespaceId :notification.ParentId;if(reservedRootIds.cend() !=reservedRootIds.find(namespaceId)) return Failure_Namespace_Root_Name_Reserved;return ValidationResult::Success;}))
Definition: NamespaceNameValidator.cpp:36
catapult::model::EntityRange::PrepareFixed
static EntityRange PrepareFixed(size_t numElements, uint8_t **ppRangeData=nullptr)
Definition: EntityRange.h:265
catapult::model::TransactionElement::EntityHash
Hash256 EntityHash
Entity hash.
Definition: Elements.h:44
catapult::extensions::MemoryBlockStorage::BlockStatements
std::map< Height, std::shared_ptr< const model::BlockStatement > > BlockStatements
Definition: MemoryBlockStorage.h:33
catapult::model::BlockHeader::Height
catapult::Height Height
Height of a block.
Definition: Block.h:41
catapult::extensions::MemoryBlockStorage::MemoryBlockStorage
MemoryBlockStorage(const model::BlockElement &nemesisBlockElement)
Creates a memory-based block storage around nemesisBlockElement.
Definition: MemoryBlockStorage.cpp:30
Address.h
catapult::model::TransactionElement::MerkleComponentHash
Hash256 MerkleComponentHash
Modified hash that should be used as a hash in the merkle tree.
Definition: Elements.h:47
catapult::model::ModifyAccountAddressRestrictionNotification
ModifyAccountRestrictionNotification< UnresolvedAddress, RestrictionAccount_Address_Modifications_Notification > ModifyAccountAddressRestrictionNotification
Definition: AccountRestrictionNotifications.h:162
NumDeletes
size_t NumDeletes
Definition: MaxAccountRestrictionValuesValidator.cpp:31
catapult::model::PublicKeyToAddress
Address PublicKeyToAddress(const Key &publicKey, NetworkIdentifier networkIdentifier)
Creates an address from a public key (publicKey) for the network identified by networkIdentifier.
Definition: Address.cpp:50
Validators.h
catapult::model::HashRange
EntityRange< Hash256 > HashRange
An entity range composed of hashes.
Definition: RangeTypes.h:35
AccountStateCache.h
catapult::model::TransactionElement
Processing element for a transaction composed of a transaction and metadata.
Definition: Elements.h:33
MemoryBlockStorage.h
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
catapult::validators::ValidationResult::Success
Validation succeeded.
BlockStatementSerializer.h
catapult::validators::DECLARE_STATELESS_VALIDATOR
DECLARE_STATELESS_VALIDATOR(MaxTransactions, Notification)(uint32_t maxTransactions)
Definition: MaxTransactionsValidator.cpp:27
CATAPULT_THROW_INVALID_ARGUMENT
#define CATAPULT_THROW_INVALID_ARGUMENT(MESSAGE)
Macro used to throw a catapult invalid argument.
Definition: exceptions.h:179
catapult::extensions::MemoryBlockStorage::chainHeight
Height chainHeight() const override
Gets the number of blocks.
Definition: MemoryBlockStorage.cpp:38
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::model::AccountAddressNotification
Notification of use of an account address.
Definition: Notifications.h:57
catapult::extensions::MemoryBlockStorage::m_height
Height m_height
Definition: MemoryBlockStorage.h:61
AccountBalances.h
Stream.h
catapult::extensions::MemoryBlockStorage::BlockElements
std::map< Height, std::shared_ptr< model::BlockElement > > BlockElements
Definition: MemoryBlockStorage.h:32
catapult::model::DeepCopyTo
void DeepCopyTo(BlockStatement &destination, const BlockStatement &source)
Creates a deep copy of source into destination.
Definition: BlockStatement.cpp:101
catapult::extensions::MemoryBlockStorage::loadBlock
std::shared_ptr< const model::Block > loadBlock(Height height) const override
Returns the block at height.
Definition: MemoryBlockStorage.cpp:128
catapult::extensions::MemoryBlockStorage::loadHashesFrom
model::HashRange loadHashesFrom(Height height, size_t maxHashes) const override
Returns a range of at most maxHashes hashes starting at height.
Definition: MemoryBlockStorage.cpp:42
catapult::io::OutputStream
Writer interface.
Definition: Stream.h:41
catapult::extensions::MemoryBlockStorage::Blocks
std::map< Height, std::shared_ptr< model::Block > > Blocks
Definition: MemoryBlockStorage.h:31
Validators.h
catapult::model::CosignatoryModificationType::Add
Add cosignatory.
catapult::extensions::MemoryBlockStorage::purge
void purge() override
Purges all blocks from storage.
Definition: MemoryBlockStorage.cpp:181
catapult::model::SizePrefixedEntity::Size
uint32_t Size
Entity size.
Definition: SizePrefixedEntity.h:33
catapult::utils::RawBuffer
BasicRawBuffer< const uint8_t > RawBuffer
A const binary buffer.
Definition: RawBuffer.h:62
catapult::validators::UnresolvedMosaicId
UnresolvedMosaicId
Definition: AccountRestrictionRedundantModificationValidator.cpp:78