1
#nullable enable
2
using System;
3
using System.Collections.Immutable;
4
using System.Diagnostics.CodeAnalysis;
5
using System.Linq;
6

7
namespace Libplanet.Tx
8
{
9
    /// <summary>
10
    /// The exception that is thrown when a given
11
    /// <see cref="InvalidTxException.TxId"/> cannot be found.
12
    /// The exception that is thrown when a <see cref="Transaction{T}"/>'s
13
    /// <see cref="Transaction{T}.Actions"/> try to update any
14
    /// <see cref="Address"/>es that are not included in
15
    /// <see cref="Transaction{T}.UpdatedAddresses"/> (i.e., <see
16
    /// cref="Address"/>es that <see cref="Transaction{T}"/>'s
17
    /// <see cref="Transaction{T}.Signer"/> granted to update.)
18
    /// </summary>
19
    public class InvalidTxUpdatedAddressesException : InvalidTxException
20
    {
21
        /// <summary>
22
        /// Creates a new <see cref="InvalidTxUpdatedAddressesException"/>
23
        /// object.
24
        /// </summary>
25
        /// <param name="txid">The invalid <see cref="Transaction{T}"/>'s
26
        /// <see cref="Transaction{T}.Id"/>.  It is automatically included to
27
        /// the <see cref="Exception.Message"/> string.</param>
28
        /// <param name="updatableAddresses">Specifies the
29
        /// <see cref="UpdatableAddresses"/>.</param>
30
        /// <param name="updatedAddresses">Specifies the
31
        /// <see cref="UpdatedAddresses"/>.</param>
32
        /// <param name="message">Specifies the <see cref="Exception.Message"/>.
33
        /// </param>
34
        [SuppressMessage(
35
            "Microsoft.StyleCop.CSharp.ReadabilityRules",
36
            "SA1118",
37
            Justification = "A long error message should be multiline.")]
38
        public InvalidTxUpdatedAddressesException(
39
            TxId txid,
40
            IImmutableSet<Address> updatableAddresses,
41
            IImmutableSet<Address> updatedAddresses,
42
            string message
43
        )
44 1
            : base(
45 1
                txid,
46 1
                $"{message}\n" +
47 1
                $"Updatable addresses: {ListAddresses(updatableAddresses)}\n" +
48 1
                $"Updated addresses: {ListAddresses(updatedAddresses)}"
49 1
            )
50 1
        {
51 1
            UpdatableAddresses = updatableAddresses;
52 1
            UpdatedAddresses = updatedAddresses;
53 1
        }
54

55
        /// <summary>
56
        /// Expected <see cref="Address"/>es to be updated.  That means,
57
        /// <see cref="Address"/>es that <see cref="Transaction{T}"/>'s
58
        /// <see cref="Transaction{T}.Signer"/> granted to update.
59
        /// </summary>
60 0
        public IImmutableSet<Address> UpdatableAddresses { get; }
61

62
        /// <summary>
63
        /// <see cref="Address"/>es that <see cref="Transaction{T}.Actions"/>
64
        /// actually try to update.
65
        /// </summary>
66 0
        public IImmutableSet<Address> UpdatedAddresses { get; }
67

68
        private static string ListAddresses(IImmutableSet<Address> addresses) =>
69 1
            string.Join(", ", addresses.Select(a => a.ToHex()).OrderBy(a => a));
70
    }
71
}

Read our documentation on viewing source code .

Loading