Skip to content
module

neo3.network.payloads.block

Block payload and related classes.

Classes
  • Block The famous Block. I transfer chain state.
  • GetBlockByIndexPayload Used to request full Block or Header objects via a message with the message.MessageType.GETBLOCKBYINDEX or message.MessageType.GETHEADERS type respectively.
  • GetBlocksPayload Used to request an array of block hashes that can be retrieved via a message with themessage.MessageType.GETDATA type.
  • Header A Block header only object.
  • HeadersPayload Payload for sending or receiving Block headers.
  • MerkleBlockPayload Payload for transfering merkletree hashes of a block.
  • TrimmedBlock A size reduced Block instance.
class

neo3.network.payloads.block.Block(header, transactions=None, *args, **kwargs)

Bases
neo3.network.payloads.inventory.IInventory neo3.network.payloads.verification.IVerifiable neo3.core.serialization.ISerializable

The famous Block. I transfer chain state.

Attributes
  • index (int) The height of the block.
  • inventory_type (InventoryType) Inventory type identifier.
  • merkle_root (UInt256) The merkle root of the transactions in the block.
  • next_consensus (UInt160) The hash of the consensus node that will generate the next block.
  • nonce (int) Random number.
  • prev_hash (UInt256) The hash of the previous block.
  • primary_index (int) The index into the consensus node list that was used to generate this block.
  • timestamp (int) UTC timestamp in milliseconds.
  • version (int) Block data structure version - for internal use.
  • witness (Witness) The witness of this block.
Methods
  • __len__() Return the length of the object in number of bytes.
  • deserialize(reader) Deserialize the object from a binary stream.
  • deserialize_unsigned(reader) Not supported.
  • get_hash_data(protocol_magic) (bytes) Get the unsigned data.
  • get_script_hashes_for_verifying(snapshot) (list) Helper method to get the data used in verifying the object.
  • hash() (UInt256) A unique identifier based on the unsigned data portion of the object.
  • rebuild_merkle_root() Recalculates the Merkle root.
  • serialize(writer) Serialize the object into a binary stream.
  • serialize_unsigned(writer) Serialize the unsigned part of the object into a binary stream.
  • to_array() (bytes) Serialize the object into a bytearray.
  • trim() (TrimmedBlock) Reduce a block in size by replacing the transaction objects with their identifying hashes.
  • deserialize_from_bytes(data) (ISerializable_T) Parse data into an object instance.
classmethod

deserialize_from_bytes(data)

Parse data into an object instance.

Parameters
  • data (bytes | bytearray) hex escaped bytes.
Returns (ISerializable_T)

a deserialized instance of the class.

method

to_array() → bytes

Serialize the object into a bytearray.

method

__len__()

Return the length of the object in number of bytes.

method

deserialize(reader)

Deserialize the object from a binary stream.

Parameters
  • reader (BinaryReader) instance.
Raises
  • ValueError if the content count of the block is zero, or if there is a duplicate transaction in the list,or if the merkle root does not include the calculated root.
method

deserialize_unsigned(reader)

Not supported.

method

get_script_hashes_for_verifying(snapshot) → list

Helper method to get the data used in verifying the object.

method

hash() → UInt256

A unique identifier based on the unsigned data portion of the object.

Recalculates the Merkle root.

method

serialize(writer)

Serialize the object into a binary stream.

Parameters
  • writer (BinaryWriter) instance.
method

serialize_unsigned(writer)

Serialize the unsigned part of the object into a binary stream.

Parameters
  • writer (BinaryWriter) instance.
method

trim() → TrimmedBlock

Reduce a block in size by replacing the transaction objects with their identifying hashes.

method

get_hash_data(protocol_magic) → bytes

Get the unsigned data.

Parameters
  • protocol_magic (int) network protocol number (NEO MainNet = 860833102, Testnet (T5) = 894710606, private net = ?)
class

neo3.network.payloads.block.GetBlockByIndexPayload(index_start, count=2000)

Bases
neo3.core.serialization.ISerializable

Used to request full Block or Header objects via a message with the message.MessageType.GETBLOCKBYINDEX or message.MessageType.GETHEADERS type respectively.

Methods
  • __len__() Return the length of the object in number of bytes.
  • deserialize(reader) Deserialize the object from a binary stream.
  • serialize(writer) Serialize the object into a binary stream.
  • to_array() (bytes) Serialize the object into a bytearray.
  • deserialize_from_bytes(data) (ISerializable_T) Parse data into an object instance.
classmethod

deserialize_from_bytes(data)

Parse data into an object instance.

Parameters
  • data (bytes | bytearray) hex escaped bytes.
Returns (ISerializable_T)

a deserialized instance of the class.

method

to_array() → bytes

Serialize the object into a bytearray.

method

__len__()

Return the length of the object in number of bytes.

method

deserialize(reader)

Deserialize the object from a binary stream.

Parameters
  • reader (BinaryReader) instance.
Raises
  • ValueError if count is zero or exceeds GetBlockByIndexPayload.MAX_BLOCKS_COUNT.
method

serialize(writer)

Serialize the object into a binary stream.

Parameters
  • writer (BinaryWriter) instance.
class

neo3.network.payloads.block.GetBlocksPayload(hash_start, count=-1)

Bases
neo3.core.serialization.ISerializable

Used to request an array of block hashes that can be retrieved via a message with themessage.MessageType.GETDATA type.

Methods
  • __len__() Return the length of the object in number of bytes.
  • deserialize(reader) Deserialize the object from a binary stream.
  • serialize(writer) Serialize the object into a binary stream.
  • to_array() (bytes) Serialize the object into a bytearray.
  • deserialize_from_bytes(data) (ISerializable_T) Parse data into an object instance.
classmethod

deserialize_from_bytes(data)

Parse data into an object instance.

Parameters
  • data (bytes | bytearray) hex escaped bytes.
Returns (ISerializable_T)

a deserialized instance of the class.

method

to_array() → bytes

Serialize the object into a bytearray.

method

__len__()

Return the length of the object in number of bytes.

method

deserialize(reader)

Deserialize the object from a binary stream.

Parameters
  • reader (BinaryReader) instance.
method

serialize(writer)

Serialize the object into a binary stream.

Parameters
  • writer (BinaryWriter) instance.
class

neo3.network.payloads.block.Header(version, prev_hash, timestamp, nonce, index, primary_index, next_consensus, witness, merkle_root=None, *args, **kwargs)

Bases
neo3.network.payloads.verification.IVerifiable neo3.core.serialization.ISerializable

A Block header only object.

Does not contain any consensus data or transactions.

See also: :class:~neo3.network.payloads.block.TrimmedBlock

Methods
  • __len__() Return the length of the object in number of bytes.
  • deserialize(reader) Deserialize the object from a binary stream.
  • deserialize_unsigned(reader) Deserialize the unsigned data part of the object from a binary stream.
  • get_hash_data(protocol_magic) (bytes) Get the unsigned data.
  • get_script_hashes_for_verifying(snapshot) (list) Helper method to get the data used in verifying the object.
  • hash() (UInt256) Get a unique identifier based on the unsigned data portion of the object.
  • serialize(writer) Serialize the object into a binary stream.
  • serialize_unsigned(writer) Serialize the unsigned data portion.
  • to_array() (bytes) Serialize the object into a bytearray.
  • deserialize_from_bytes(data) (ISerializable_T) Parse data into an object instance.
classmethod

deserialize_from_bytes(data)

Parse data into an object instance.

Parameters
  • data (bytes | bytearray) hex escaped bytes.
Returns (ISerializable_T)

a deserialized instance of the class.

method

to_array() → bytes

Serialize the object into a bytearray.

method

__len__()

Return the length of the object in number of bytes.

method

deserialize(reader)

Deserialize the object from a binary stream.

Parameters
  • reader (BinaryReader) instance.
Raises
  • ValueError if the check byte does not equal.
method

deserialize_unsigned(reader)

Deserialize the unsigned data part of the object from a binary stream.

Parameters
  • reader (BinaryReader) instance.
Raises
  • ValueError if the primary_index field is greater than the configured consensus validator count.
method

get_script_hashes_for_verifying(snapshot) → list

Helper method to get the data used in verifying the object.

method

hash() → UInt256

Get a unique identifier based on the unsigned data portion of the object.

method

serialize(writer)

Serialize the object into a binary stream.

Parameters
  • writer (BinaryWriter) instance.
method

serialize_unsigned(writer)

Serialize the unsigned data portion.

Parameters
  • writer (BinaryWriter) instance.
method

get_hash_data(protocol_magic) → bytes

Get the unsigned data.

Parameters
  • protocol_magic (int) network protocol number (NEO MainNet = 860833102, Testnet (T5) = 894710606, private net = ?)
class

neo3.network.payloads.block.HeadersPayload(headers=None)

Bases
neo3.core.serialization.ISerializable

Payload for sending or receiving Block headers.

Methods
  • __len__() Return the length of the object in number of bytes.
  • deserialize(reader) Deserialize the object from a binary stream.
  • serialize(writer) Serialize the object into a binary stream.
  • to_array() (bytes) Serialize the object into a bytearray.
  • deserialize_from_bytes(data) (ISerializable_T) Parse data into an object instance.
classmethod

deserialize_from_bytes(data)

Parse data into an object instance.

Parameters
  • data (bytes | bytearray) hex escaped bytes.
Returns (ISerializable_T)

a deserialized instance of the class.

method

to_array() → bytes

Serialize the object into a bytearray.

method

__len__()

Return the length of the object in number of bytes.

method

deserialize(reader)

Deserialize the object from a binary stream.

Parameters
  • reader (BinaryReader) instance.
method

serialize(writer)

Serialize the object into a binary stream.

Parameters
  • writer (BinaryWriter) instance.
class

neo3.network.payloads.block.MerkleBlockPayload(block, flags)

Bases
neo3.core.serialization.ISerializable

Payload for transfering merkletree hashes of a block.

Methods
  • __len__() Return the length of the object in number of bytes.
  • deserialize(reader) Deserialize the object from a binary stream.
  • serialize(writer) Serialize the object into a binary stream.
  • to_array() (bytes) Serialize the object into a bytearray.
  • deserialize_from_bytes(data) (ISerializable_T) Parse data into an object instance.
classmethod

deserialize_from_bytes(data)

Parse data into an object instance.

Parameters
  • data (bytes | bytearray) hex escaped bytes.
Returns (ISerializable_T)

a deserialized instance of the class.

method

to_array() → bytes

Serialize the object into a bytearray.

method

__len__()

Return the length of the object in number of bytes.

method

deserialize(reader)

Deserialize the object from a binary stream.

Parameters
  • reader (BinaryReader) instance.
method

serialize(writer)

Serialize the object into a binary stream.

Parameters
  • writer (BinaryWriter) instance.
class

neo3.network.payloads.block.TrimmedBlock(header, hashes)

Bases
neo3.core.serialization.ISerializable

A size reduced Block instance.

Contains consensus data and transactions hashes instead of their full objects.

Attributes
  • index The height of the block.
Methods
  • __len__() Return the length of the object in number of bytes.
  • deserialize(reader) Deserialize the object from a binary stream.
  • hash() A unique identifier based on the unsigned data portion of the object.
  • serialize(writer) Serialize the object into a binary stream.
  • to_array() (bytes) Serialize the object into a bytearray.
  • deserialize_from_bytes(data) (ISerializable_T) Parse data into an object instance.
classmethod

deserialize_from_bytes(data)

Parse data into an object instance.

Parameters
  • data (bytes | bytearray) hex escaped bytes.
Returns (ISerializable_T)

a deserialized instance of the class.

method

to_array() → bytes

Serialize the object into a bytearray.

method

__len__()

Return the length of the object in number of bytes.

method

deserialize(reader)

Deserialize the object from a binary stream.

Parameters
  • reader (BinaryReader) instance.
method

hash()

A unique identifier based on the unsigned data portion of the object.

method

serialize(writer)

Serialize the object into a binary stream.

Parameters
  • writer (BinaryWriter) instance.