MsgGetHeaders class

MsgGetHeaders implements the Message interface and represents a bitcoin getheaders message. It is used to request a list of block headers for blocks starting after the last known hash in the slice of block locator hashes. The list is returned via a headers message (MsgHeaders) and is limited by a specific hash to stop at or the maximum number of block headers per message, which is currently 2000.

Set the hashStop field to the hash at which to stop and use addBlockLocatorHash to build up the list of block locator hashes.

The algorithm for building the block locator hashes should be to add the hashes in reverse order until you reach the genesis block. In order to keep the list of locator hashes to a reasonable number of entries, first add the most recent 10 block hashes, then double the step each loop iteration to exponentially decrease the number of hashes the further away from head and closer to the genesis block you get.

Inheritance

Constructors

MsgGetHeaders({required int protocolVersion, required List<Hash> blockLocatorHashes, required Hash hashStop})
Creates a new MsgGetHeaders message.
MsgGetHeaders.deserialize(Uint8List data)
Deserializes a MsgGetHeaders from byte data.
factory
MsgGetHeaders.empty({int protocolVersion = 70015, Hash? hashStop})
Creates an empty MsgGetHeaders message with default values.

Properties

blockLocatorHashes List<Hash>
List of block locator hashes starting from the most recent.
final
command String
Get the command string for this message type
no setteroverride
hashCode int
The hash code for this object.
no setteroverride
hashStop Hash
Hash at which to stop returning headers (can be zero hash for no limit).
final
isEmpty bool
Checks if this message has no block locator hashes.
no setter
isNotEmpty bool
Checks if this message has block locator hashes.
no setter
locatorCount int
Returns the number of block locator hashes.
no setter
maxPayloadLength int
Get maximum payload length for this message type
no setteroverride
protocolVersion int
Protocol version for this message.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addBlockLocatorHash(Hash hash) → void
Adds a new block locator hash to the message.
decode(Uint8List data, int protocolVersion, MessageEncoding encoding) → void
Decode message from bytes
override
encode(int protocolVersion, MessageEncoding encoding) Uint8List
Encode message to bytes
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
serialize(int protocolVersion, BitcoinNetwork network) Uint8List
Serialize complete message with header
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override

Static Methods

registerWithFactory() → void
Register this message type with the factory.