1
#nullable enable
2
using System;
3
using System.Diagnostics.Contracts;
4
using System.Runtime.Serialization;
5
using System.Security.Cryptography;
6
using Libplanet.Serialization;
7

8
namespace Libplanet.Blocks
9
{
10
    /// <summary>
11
    /// The exception that is thrown when the state root hash in the block has
12
    /// mismatches to the state root hash of the trie on the block executed in local.
13
    /// </summary>
14
    [Serializable]
15
    public class InvalidBlockStateRootHashException : InvalidBlockException
16
    {
17
        /// <summary>
18
        /// Initializes a new instance of the
19
        /// <see cref="InvalidBlockStateRootHashException"/> class.
20
        /// </summary>
21
        /// <param name="expectedStateRootHash">The hash recorded as
22
        /// <see cref="Block{T}.StateRootHash"/>>.</param>
23
        /// <param name="actualStateRootHash">The hash of state trie on the block executed.</param>
24
        /// <param name="message">The message that describes the error.</param>
25
        // FIXME: 'expectedStateRootHash' should be not nullable after it decided
26
        //        to force state root hash.
27
        public InvalidBlockStateRootHashException(
28
            HashDigest<SHA256>? expectedStateRootHash,
29
            HashDigest<SHA256> actualStateRootHash,
30
            string message)
31 1
            : base(message)
32 1
        {
33 1
            ActualStateRootHash = actualStateRootHash;
34 1
            ExpectedStateRootHash = expectedStateRootHash;
35 1
        }
36

37
        private InvalidBlockStateRootHashException(
38
            SerializationInfo info, StreamingContext context)
39 0
            : base(info, context)
40 0
        {
41 0
            ActualStateRootHash =
42 0
                info.GetValue<HashDigest<SHA256>>(nameof(ActualStateRootHash));
43 0
            ExpectedStateRootHash =
44 0
                info.GetValue<HashDigest<SHA256>?>(nameof(ExpectedStateRootHash));
45 0
        }
46

47
        /// <summary>
48
        /// The hash of state trie on the block executed.
49
        /// </summary>
50
        [Pure]
51 0
        public HashDigest<SHA256> ActualStateRootHash { get; }
52

53
        /// <summary>
54
        /// The hash recorded as <see cref="Block{T}.StateRootHash"/>>.
55
        /// </summary>
56
        [Pure]
57 0
        public HashDigest<SHA256>? ExpectedStateRootHash { get; }
58

59
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
60 0
        {
61 0
            base.GetObjectData(info, context);
62

63 0
            info.AddValue(nameof(ActualStateRootHash), ActualStateRootHash);
64 0
            info.AddValue(nameof(ExpectedStateRootHash), ExpectedStateRootHash);
65 0
        }
66
    }
67
}

Read our documentation on viewing source code .

Loading