Show / Hide Table of Contents

Class BlockLocator

A class that contains BlockHashes for a series of blocks.

Inheritance
Object
BlockLocator
Implements
IEnumerable<BlockHash>
IEnumerable
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Libplanet.Blockchain
Assembly: Libplanet.dll
Syntax
public class BlockLocator : IEnumerable<BlockHash>, IEnumerable

Constructors

| Improve this Doc View Source

BlockLocator(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 hashes is empty.

Methods

| Improve this Doc View Source

Create(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) for 0 < k and k <= s
  • i_k = max(i_(k - 1) - 2^(k - 1 - s), 0) for 0 < k and s < k
where 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 0 to startIndex may be used as an argument to call this function.

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 startIndex is negative.

ArgumentException

Thrown when either BlockHash returned by indexToBlockHash for index 0 is null.

| Improve this Doc View Source

GetEnumerator()

Gets the enumerator.

Declaration
public IEnumerator<BlockHash> GetEnumerator()
Returns
Type Description
IEnumerator<BlockHash>

The enumerator.

Explicit Interface Implementations

| Improve this Doc View Source

IEnumerable.GetEnumerator()

A class that contains BlockHashes for a series of blocks.

Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
IEnumerator

Implements

System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable

Extension Methods

EnumerableMeasurement.OnBeforeAndAfter<T>(IEnumerable<T>, Action, Action)
EnumerableMeasurement.WithMeasuringTime<T>(IEnumerable<T>, Action<Stopwatch>)
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2023 Planetarium