Class BlockLocator
A class that contains BlockHashes for a series of blocks.
Inherited Members
Namespace: Libplanet.Blockchain
Assembly: Libplanet.dll
Syntax
public class BlockLocator : IEnumerable<BlockHash>, IEnumerable
Constructors
| Improve this Doc View SourceBlockLocator(IEnumerable<BlockHash>)
Initializes a new instance of BlockLocator from hashes
.
Declaration
public BlockLocator(IEnumerable<BlockHash> hashes)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<BlockHash> | hashes | Enumerable of BlockHashes to convert from. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown when |
Methods
| Improve this Doc View SourceCreate(Int64, Func<Int64, Nullable<BlockHash>>, Int64)
Creates a new instance of BlockLocator with an indexer
function, sampling after sampleAfter
number of
Blocks.
This collects all BlockHashes corresponding to indices inductively defined by:
-
i_0 = startIndex
-
i_k = max(i_(k - 1) - 1, 0)
for0 < k
andk <= s
-
i_k = max(i_(k - 1) - 2^(k - 1 - s), 0)
for0 < k
ands < k
s = max(sampleAfter, 0)
and the sequence terminates after index i_k
reaches zero or the BlockHash returned by
indexToBlockHash
for i_k
is null,
in which case the BlockHash corresponding to index 0
(presumably a BlockHash of the genesis Block)
is added at the end.
Declaration
public static BlockLocator Create(long startIndex, Func<long, BlockHash?> indexToBlockHash, long sampleAfter = 10L)
Parameters
Type | Name | Description |
---|---|---|
Int64 | startIndex | The starting index. |
Func<Int64, Nullable<BlockHash>> | indexToBlockHash | The function that converts an index to a
BlockHash. This can be null which indicates
a missing Block at the index. Any value from |
Int64 | sampleAfter | The number of consecutive blocks to include before sampling. |
Returns
Type | Description |
---|---|
BlockLocator | An instance of BlockLocator created with given arguments. |
Remarks
Returned BlockLocator created by this factory method is guaranteed
to have the BlockHash corresponding to index 0
.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown when |
ArgumentException | Thrown when either BlockHash returned
by |
GetEnumerator()
Gets the enumerator.
Declaration
public IEnumerator<BlockHash> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<BlockHash> | The enumerator. |
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable.GetEnumerator()
A class that contains BlockHashes for a series of blocks.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator |