veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
altintegration::adaptors::BlockIteratorImpl< BlockT > Struct Template Reference

Detailed Description

template<typename BlockT>
struct altintegration::adaptors::BlockIteratorImpl< BlockT >

Definition at line 88 of file block_provider_impl.hpp.

+ Inheritance diagram for altintegration::adaptors::BlockIteratorImpl< BlockT >:
+ Collaboration diagram for altintegration::adaptors::BlockIteratorImpl< BlockT >:

Public Member Functions

 BlockIteratorImpl (std::shared_ptr< StorageIterator > it, const AltChainParams &params)
 
void next () override
 Iterate to the next block. More...
 
bool value (StoredBlockIndex< BlockT > &out) const override
 Return the current block value. More...
 
bool key (typename BlockT::hash_t &out) const override
 Return the current block hash key. More...
 
bool valid () const override
 Return if valid iterator or not. More...
 
void seek_start () override
 Set iterator to the start of the collection. More...
 
virtual void next ()=0
 Iterate to the next block. More...
 
virtual bool value (StoredBlockIndex< BlockT > &out) const =0
 Return the current block value. More...
 
virtual bool key (prev_hash_t &out) const =0
 Return the current block hash key. More...
 
virtual bool valid () const =0
 Return if valid iterator or not. More...
 
virtual void seek_start ()=0
 Set iterator to the start of the collection. More...
 

Additional Inherited Members

- Public Types inherited from altintegration::BlockIterator< BlockT >
using prev_hash_t = typename BlockT::hash_t
 

Constructor & Destructor Documentation

◆ BlockIteratorImpl()

template<typename BlockT >
altintegration::adaptors::BlockIteratorImpl< BlockT >::BlockIteratorImpl ( std::shared_ptr< StorageIterator it,
const AltChainParams params 
)
inline

Definition at line 91 of file block_provider_impl.hpp.

93 : it_(std::move(it)), params_(params) {}

Member Function Documentation

◆ key()

template<typename BlockT >
bool altintegration::adaptors::BlockIteratorImpl< BlockT >::key ( typename BlockT::hash_t &  out) const
inlineoverridevirtual
Parameters
[out]outblock hash
Returns
true if we can successfully return key, false otherwise

Implements altintegration::BlockIterator< BlockT >.

Definition at line 115 of file block_provider_impl.hpp.

115 {
116 std::vector<uint8_t> bytes;
117 if (!it_->key(bytes)) {
118 return false;
119 }
120 // remove prefix
121 out = {bytes.begin() + 1, bytes.end()};
122 return true;
123 }

◆ next()

template<typename BlockT >
void altintegration::adaptors::BlockIteratorImpl< BlockT >::next ( )
inlineoverridevirtual

Implements altintegration::BlockIterator< BlockT >.

Definition at line 95 of file block_provider_impl.hpp.

95{ it_->next(); }

◆ seek_start()

template<typename BlockT >
void altintegration::adaptors::BlockIteratorImpl< BlockT >::seek_start ( )
inlineoverridevirtual

Implements altintegration::BlockIterator< BlockT >.

Definition at line 132 of file block_provider_impl.hpp.

132 {
133 static const uint8_t prefix = block_key<BlockT>({})[0];
134
135 it_->seek({prefix});
136 }

◆ valid()

template<typename BlockT >
bool altintegration::adaptors::BlockIteratorImpl< BlockT >::valid ( ) const
inlineoverridevirtual
Returns
true if the iterator is valid, false otherwise

Implements altintegration::BlockIterator< BlockT >.

Definition at line 125 of file block_provider_impl.hpp.

125 {
126 static const uint8_t prefix = block_key<BlockT>({})[0];
127
128 std::vector<uint8_t> key;
129 return it_->valid() && it_->key(key) && !key.empty() && key[0] == prefix;
130 }
bool key(typename BlockT::hash_t &out) const override
Return the current block hash key.

◆ value()

template<typename BlockT >
bool altintegration::adaptors::BlockIteratorImpl< BlockT >::value ( StoredBlockIndex< BlockT > &  out) const
inlineoverridevirtual
Parameters
[out]outblock, altintegration::StoredBlockIndex
Returns
true if we can successfully return value, false otherwise

Implements altintegration::BlockIterator< BlockT >.

Definition at line 97 of file block_provider_impl.hpp.

97 {
98 std::vector<uint8_t> bytes;
99 if (!it_->value(bytes)) {
100 return false;
101 }
102
103 ValidationState dummy;
104 if (!DeserializeFromVbkEncoding<StoredBlockIndex<BlockT>>(
105 bytes, out, dummy)) {
106 VBK_LOG_ERROR("Can not deserialize StoredBlockIndex<%s>: %s",
107 BlockT::name(),
108 dummy.toString());
109 return false;
110 }
111
112 return true;
113 }
bool DeserializeFromVbkEncoding(ReadStream &stream, AltBlockAddon &out, ValidationState &state)
This is an overloaded member function, provided for convenience. It differs from the above function o...

The documentation for this struct was generated from the following file: