示例#1
0
        UnmarshalPreEvaluationBlockHeader(Dictionary marshaled)
        {
            BlockMetadata         metadata    = UnmarshalBlockMetadata(marshaled);
            var                   nonce       = new Nonce(marshaled.GetValue <Binary>(NonceKey).ByteArray);
            ImmutableArray <byte>?preEvalHash = marshaled.ContainsKey(PreEvaluationHashKey)
                ? marshaled.GetValue <Binary>(PreEvaluationHashKey).ByteArray
                : (ImmutableArray <byte>?)null;

            return(metadata, nonce, preEvalHash);
        }
示例#2
0
        public static BlockMetadata UnmarshalBlockMetadata(Dictionary marshaled)
        {
            var metadata = new BlockMetadata
            {
                ProtocolVersion = marshaled.ContainsKey(ProtocolVersionKey)
                    ? (int)marshaled.GetValue <Integer>(ProtocolVersionKey)
                    : 0,
                Index     = UnmarshalBlockMetadataIndex(marshaled),
                Timestamp = DateTimeOffset.ParseExact(
                    marshaled.GetValue <Text>(TimestampKey),
                    TimestampFormat,
                    CultureInfo.InvariantCulture
                    ),
                Difficulty      = marshaled.GetValue <Integer>(DifficultyKey),
                TotalDifficulty = marshaled.GetValue <Integer>(TotalDifficultyKey),
                PreviousHash    = marshaled.ContainsKey(PreviousHashKey)
                    ? new BlockHash(marshaled.GetValue <Binary>(PreviousHashKey).ByteArray)
                    : (BlockHash?)null,
                TxHash = marshaled.ContainsKey(TxHashKey)
                    ? new HashDigest <SHA256>(
                    marshaled.GetValue <Binary>(TxHashKey).ByteArray)
                    : (HashDigest <SHA256>?)null,
            };

            if (marshaled.ContainsKey(PublicKeyKey))
            {
                metadata.PublicKey =
                    new PublicKey(marshaled.GetValue <Binary>(PublicKeyKey).ByteArray);
            }
            else
            {
                metadata.Miner = new Address(marshaled.GetValue <Binary>(MinerKey).ByteArray);
            }

            return(metadata);
        }
示例#3
0
 /// <summary>
 /// Unsafely creates a <see cref="PreEvaluationBlockHeader"/> instance with its
 /// <paramref name="metadata"/>, and a <paramref name="proof"/> which is probably
 /// considered as to be valid.
 /// </summary>
 /// <param name="metadata">Block's metadata.</param>
 /// <param name="hashAlgorithm">The hash algorithm used for calculating
 /// <see cref="PreEvaluationHash"/>.</param>
 /// <param name="proof">A pair of the valid proof-of-work nonce which is probably considered
 /// as to satisfy the required <see cref="Difficulty"/>, and the hash digest which is
 /// probably considered as to be derived from the block <paramref name="metadata"/> and the
 /// nonce.</param>
 /// <exception cref="InvalidBlockPreEvaluationHashException">Thrown when the given proof's
 /// hash is invalid.</exception>
 /// <remarks>This does not verify if a <paramref name="proof"/>'s hash is derived from
 /// the block <paramref name="metadata"/> and the proof nonce.  Therefore, this unsafe
 /// constructor shouldn't be used except for <see
 /// cref="BlockContent{T}.Mine(HashAlgorithmType, CancellationToken)"/> method.</remarks>
 internal PreEvaluationBlockHeader(
     BlockMetadata metadata,
     HashAlgorithmType hashAlgorithm,
     in (Nonce Nonce, ImmutableArray <byte> PreEvaluationHash) proof