Show / Hide Table of Contents

Struct BlockHash

A value type to represent SHA-256 digest of Block data.

Implements
System.Runtime.Serialization.ISerializable
IEquatable<BlockHash>
Bencodex.IBencodable
Inherited Members
Object.Equals(Object, Object)
System.Object.GetType()
Object.ReferenceEquals(Object, Object)
Namespace: Libplanet.Types.Blocks
Assembly: Libplanet.Types.dll
Syntax
[JsonConverter(typeof(BlockHashJsonConverter))]
[Serializable]
public readonly struct BlockHash : ISerializable, IEquatable<BlockHash>, IBencodable

Constructors

| Improve this Doc View Source

BlockHash(IValue)

A value type to represent SHA-256 digest of Block data.

Declaration
public BlockHash(IValue bencoded)
Parameters
Type Name Description
Bencodex.Types.IValue bencoded
See Also
Hash
| Improve this Doc View Source

BlockHash(Byte[])

Converts a System.Byte array into a BlockHash.

Declaration
public BlockHash(byte[] blockHash)
Parameters
Type Name Description
System.Byte[] blockHash

A System.Byte array that encodes a BlockHash.

Exceptions
Type Condition
System.ArgumentNullException

Thrown when the given blockHash is null.

ArgumentOutOfRangeException

Thrown when the given blockHash's Length is not 32.

See Also
Hash
| Improve this Doc View Source

BlockHash(in ImmutableArray<Byte>)

Converts an immutable System.Byte array into a BlockHash.

Declaration
public BlockHash(in ImmutableArray<byte> blockHash)
Parameters
Type Name Description
System.Collections.Immutable.ImmutableArray<System.Byte> blockHash

An immutable System.Byte array that encodes a SHA-256 digest of a Block.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the given blockHash's Length is not 32.

See Also
Hash

Fields

| Improve this Doc View Source

Size

The size of bytes that each BlockHash consists of.

Declaration
public const int Size = 32
Field Value
Type Description
Int32
See Also
Hash

Properties

| Improve this Doc View Source

Bencoded

A value type to represent SHA-256 digest of Block data.

Declaration
public readonly IValue Bencoded { get; }
Property Value
Type Description
Bencodex.Types.IValue
See Also
Hash
| Improve this Doc View Source

ByteArray

A bare immutable System.Byte array of the block hash.

Declaration
public readonly ImmutableArray<byte> ByteArray { get; }
Property Value
Type Description
System.Collections.Immutable.ImmutableArray<System.Byte>
Remarks

It is immutable. For a mutable array, use ToByteArray() method instead.

See Also
ToByteArray()

Methods

| Improve this Doc View Source

DeriveFrom(IReadOnlyList<Byte>)

Computes a SHA-256 digest from the given blockBytes.

Declaration
[Pure]
public static BlockHash DeriveFrom(IReadOnlyList<byte> blockBytes)
Parameters
Type Name Description
IReadOnlyList<System.Byte> blockBytes

The bytes serializing a block to compute its hash.

Returns
Type Description
BlockHash

The SHA-256 hash digest derived from blockBytes.

See Also
Hash
| Improve this Doc View Source

Equals(BlockHash)

A value type to represent SHA-256 digest of Block data.

Declaration
[Pure]
public readonly bool Equals(BlockHash other)
Parameters
Type Name Description
BlockHash other
Returns
Type Description
System.Boolean
See Also
Hash
| Improve this Doc View Source

Equals(Object)

A value type to represent SHA-256 digest of Block data.

Declaration
[Pure]
public override readonly bool Equals(object obj)
Parameters
Type Name Description
Object obj
Returns
Type Description
System.Boolean
Overrides
System.ValueType.Equals(System.Object)
See Also
Hash
| Improve this Doc View Source

FromHashDigest(HashDigest<SHA256>)

Converts a given HashDigest<T> into a BlockHash value.

Declaration
[Pure]
public static BlockHash FromHashDigest(HashDigest<SHA256> hashDigest)
Parameters
Type Name Description
HashDigest<SHA256> hashDigest

A SHA-256 digest.

Returns
Type Description
BlockHash

A block hash corresponding to the hashDigest.

See Also
Hash
| Improve this Doc View Source

FromString(String)

Converts a given hexadecimal representation of a block hash into a BlockHash value.

This is an inverse function of ToString() method.

Declaration
[Pure]
public static BlockHash FromString(string hex)
Parameters
Type Name Description
String hex

A hexadecimal representation of a BlockHash.

Returns
Type Description
BlockHash

A corresponding BlockHash value.

Exceptions
Type Condition
System.ArgumentNullException

Thrown when the given hex is null.

ArgumentOutOfRangeException

Thrown when the length of the given hex string is an odd number.

FormatException

Thrown when the given hex string is not a valid hexadecimal string.

ArgumentOutOfRangeException

Thrown when the given hex's length is not 64.

See Also
ToString()
| Improve this Doc View Source

GetHashCode()

A value type to represent SHA-256 digest of Block data.

Declaration
[Pure]
public override readonly int GetHashCode()
Returns
Type Description
Int32
Overrides
ValueType.GetHashCode()
See Also
Hash
| Improve this Doc View Source

GetObjectData(SerializationInfo, StreamingContext)

A value type to represent SHA-256 digest of Block data.

Declaration
public readonly void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
SerializationInfo info
StreamingContext context
See Also
Hash
| Improve this Doc View Source

ToByteArray()

Gets a bare mutable System.Byte array of the block hash.

Declaration
[Pure]
public readonly byte[] ToByteArray()
Returns
Type Description
System.Byte[]

A new mutable System.Byte array of the block hash. Since a returned array is created every time the method is called, any mutations on that array does not affect to the block hash object.

See Also
ByteArray
| Improve this Doc View Source

ToString()

A value type to represent SHA-256 digest of Block data.

Declaration
[Pure]
public override readonly string ToString()
Returns
Type Description
String
Overrides
System.ValueType.ToString()
See Also
Hash

Implements

System.Runtime.Serialization.ISerializable
System.IEquatable<T>
Bencodex.IBencodable

See Also

Hash
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2023 Planetarium