From ceb29b1743bf06dc06be28c2c37925515812ccf3 Mon Sep 17 00:00:00 2001 From: Chanhyuck Ko Date: Tue, 14 Jan 2025 19:45:19 +0900 Subject: [PATCH] chore: remove deprecated serialization for exceptions --- .../InvalidConsensusMessageException.cs | 20 ++----------- .../InvalidHeightIncreasingException.cs | 20 +------------ .../Consensus/InvalidMaj23Exception.cs | 30 ++----------------- .../Consensus/InvalidProposalException.cs | 30 ++----------------- .../Consensus/InvalidVoteException.cs | 30 ++----------------- .../InvalidMessageContentException.cs | 20 ------------- .../InvalidStateTargetException.cs | 6 ---- src/Libplanet.Net/NoSwarmContextException.cs | 9 ------ src/Libplanet.Net/PeerNotFoundException.cs | 9 ------ .../Protocols/PeerDiscoveryException.cs | 9 ------ .../Protocols/PingTimeoutException.cs | 22 -------------- src/Libplanet.Net/SwarmException.cs | 9 ------ .../Transports/CommunicationFailException.cs | 21 +------------ .../DifferentAppProtocolVersionException.cs | 23 -------------- .../Transports/InvalidCredentialException.cs | 19 ------------ .../InvalidMessageSignatureException.cs | 23 -------------- .../InvalidMessageTimestampException.cs | 21 ------------- .../Transports/SendMessageFailException.cs | 14 --------- .../Transports/TransportException.cs | 9 ------ 19 files changed, 10 insertions(+), 334 deletions(-) diff --git a/src/Libplanet.Net/Consensus/InvalidConsensusMessageException.cs b/src/Libplanet.Net/Consensus/InvalidConsensusMessageException.cs index 9e95251ac61..1f300892297 100644 --- a/src/Libplanet.Net/Consensus/InvalidConsensusMessageException.cs +++ b/src/Libplanet.Net/Consensus/InvalidConsensusMessageException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; using Libplanet.Net.Messages; namespace Libplanet.Net.Consensus @@ -13,7 +12,7 @@ namespace Libplanet.Net.Consensus public class InvalidConsensusMessageException : InvalidMessageContentException { /// - /// Initializes a new instance of class. + /// Initializes a new instance of the class. /// /// The error message that explains the reason for the exception. /// @@ -30,7 +29,7 @@ public InvalidConsensusMessageException( } /// - /// Initializes a new instance of class. + /// Initializes a new instance of the class. /// /// The error message that explains the reason for the exception. /// @@ -40,20 +39,5 @@ public InvalidConsensusMessageException(string message, MessageContent receivedM : base(message, receivedMessage) { } - - /// - /// Initializes a new instance of the - /// class with serialized data. - /// - /// The - /// that holds the serialized object data about the exception being thrown. - /// - /// The - /// that contains contextual information about the source or destination. - /// - protected InvalidConsensusMessageException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } } diff --git a/src/Libplanet.Net/Consensus/InvalidHeightIncreasingException.cs b/src/Libplanet.Net/Consensus/InvalidHeightIncreasingException.cs index b0b6a309cd8..1b49f007c3f 100644 --- a/src/Libplanet.Net/Consensus/InvalidHeightIncreasingException.cs +++ b/src/Libplanet.Net/Consensus/InvalidHeightIncreasingException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; using Libplanet.Blockchain; namespace Libplanet.Net.Consensus @@ -12,7 +11,7 @@ namespace Libplanet.Net.Consensus public class InvalidHeightIncreasingException : Exception { /// - /// Initializes a new instance of class. + /// Initializes a new instance of the class. /// /// The error message that explains the reason for the exception. /// @@ -20,22 +19,5 @@ public InvalidHeightIncreasingException(string message) : base(message) { } - - /// - /// Initializes a new instance of the - /// class with serialized data. - /// - /// The - /// that holds the serialized object data about the exception being thrown. - /// - /// The - /// that contains contextual information about the source or destination. - /// - protected InvalidHeightIncreasingException( - SerializationInfo info, - StreamingContext context) - : base(info, context) - { - } } } diff --git a/src/Libplanet.Net/Consensus/InvalidMaj23Exception.cs b/src/Libplanet.Net/Consensus/InvalidMaj23Exception.cs index 5e570c893b3..8e7dabe7d13 100644 --- a/src/Libplanet.Net/Consensus/InvalidMaj23Exception.cs +++ b/src/Libplanet.Net/Consensus/InvalidMaj23Exception.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; using Libplanet.Consensus; namespace Libplanet.Net.Consensus @@ -13,7 +12,7 @@ namespace Libplanet.Net.Consensus public class InvalidMaj23Exception : Exception { /// - /// Initializes a new instance of class. + /// Initializes a new instance of the class. /// /// The error message that explains the reason for the exception. /// @@ -31,7 +30,7 @@ public InvalidMaj23Exception( } /// - /// Initializes a new instance of class. + /// Initializes a new instance of the class. /// /// The error message that explains the reason for the exception. /// @@ -43,31 +42,6 @@ public InvalidMaj23Exception(string message, Maj23 maj23) Maj23 = maj23; } - /// - /// Initializes a new instance of the - /// class with serialized data. - /// - /// The - /// that holds the serialized object data about the exception being thrown. - /// - /// The - /// that contains contextual information about the source or destination. - /// - protected InvalidMaj23Exception(SerializationInfo info, StreamingContext context) - { - Maj23 = - info.GetValue(nameof(Maj23), typeof(Maj23)) as Maj23 ?? - throw new SerializationException( - $"{nameof(Maj23)} is expected to be a non-null {nameof(Maj23)}."); - } - public Maj23 Maj23 { get; } - - public override void GetObjectData( - SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue(nameof(Maj23), Maj23); - } } } diff --git a/src/Libplanet.Net/Consensus/InvalidProposalException.cs b/src/Libplanet.Net/Consensus/InvalidProposalException.cs index 16b8b300f12..45bbdac864e 100644 --- a/src/Libplanet.Net/Consensus/InvalidProposalException.cs +++ b/src/Libplanet.Net/Consensus/InvalidProposalException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; using Libplanet.Consensus; namespace Libplanet.Net.Consensus @@ -13,7 +12,7 @@ namespace Libplanet.Net.Consensus public class InvalidProposalException : Exception { /// - /// Initializes a new instance of class. + /// Initializes a new instance of the class. /// /// The error message that explains the reason for the exception. /// @@ -31,7 +30,7 @@ public InvalidProposalException( } /// - /// Initializes a new instance of class. + /// Initializes a new instance of the class. /// /// The error message that explains the reason for the exception. /// @@ -43,31 +42,6 @@ public InvalidProposalException(string message, Proposal proposal) Proposal = proposal; } - /// - /// Initializes a new instance of the - /// class with serialized data. - /// - /// The - /// that holds the serialized object data about the exception being thrown. - /// - /// The - /// that contains contextual information about the source or destination. - /// - protected InvalidProposalException(SerializationInfo info, StreamingContext context) - { - Proposal = - info.GetValue(nameof(Proposal), typeof(Proposal)) as Proposal ?? - throw new SerializationException( - $"{nameof(Proposal)} is expected to be a non-null {nameof(Proposal)}."); - } - public Proposal Proposal { get; } - - public override void GetObjectData( - SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue(nameof(Proposal), Proposal); - } } } diff --git a/src/Libplanet.Net/Consensus/InvalidVoteException.cs b/src/Libplanet.Net/Consensus/InvalidVoteException.cs index 5d3c9201e8b..a952cd36d30 100644 --- a/src/Libplanet.Net/Consensus/InvalidVoteException.cs +++ b/src/Libplanet.Net/Consensus/InvalidVoteException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; using Libplanet.Types.Consensus; namespace Libplanet.Net.Consensus @@ -13,7 +12,7 @@ namespace Libplanet.Net.Consensus public class InvalidVoteException : Exception { /// - /// Initializes a new instance of class. + /// Initializes a new instance of the class. /// /// The error message that explains the reason for the exception. /// @@ -31,7 +30,7 @@ public InvalidVoteException( } /// - /// Initializes a new instance of class. + /// Initializes a new instance of the class. /// /// The error message that explains the reason for the exception. /// @@ -43,31 +42,6 @@ public InvalidVoteException(string message, Vote vote) Vote = vote; } - /// - /// Initializes a new instance of the - /// class with serialized data. - /// - /// The - /// that holds the serialized object data about the exception being thrown. - /// - /// The - /// that contains contextual information about the source or destination. - /// - protected InvalidVoteException(SerializationInfo info, StreamingContext context) - { - Vote = - info.GetValue(nameof(Vote), typeof(Vote)) as Vote ?? - throw new SerializationException( - $"{nameof(Vote)} is expected to be a non-null {nameof(Vote)}."); - } - public Vote Vote { get; } - - public override void GetObjectData( - SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue(nameof(Vote), Vote); - } } } diff --git a/src/Libplanet.Net/InvalidMessageContentException.cs b/src/Libplanet.Net/InvalidMessageContentException.cs index 830b235ffdd..d3f40800f27 100644 --- a/src/Libplanet.Net/InvalidMessageContentException.cs +++ b/src/Libplanet.Net/InvalidMessageContentException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; using Libplanet.Net.Messages; namespace Libplanet.Net @@ -23,25 +22,6 @@ internal InvalidMessageContentException(string message, MessageContent content) Content = content; } - protected InvalidMessageContentException( - SerializationInfo info, - StreamingContext context - ) - : base(info, context) - { - Content = - info.GetValue(nameof(Content), typeof(MessageContent)) as MessageContent ?? - throw new SerializationException( - $"{nameof(Content)} is expected to be a non-null {nameof(Message)}."); - } - internal MessageContent Content { get; } - - public override void GetObjectData( - SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue(nameof(Content), Content); - } } } diff --git a/src/Libplanet.Net/InvalidStateTargetException.cs b/src/Libplanet.Net/InvalidStateTargetException.cs index e216764a117..704a77d4454 100644 --- a/src/Libplanet.Net/InvalidStateTargetException.cs +++ b/src/Libplanet.Net/InvalidStateTargetException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace Libplanet.Net { @@ -19,10 +18,5 @@ public InvalidStateTargetException(string message, Exception innerException) : base(message, innerException) { } - - protected InvalidStateTargetException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } } diff --git a/src/Libplanet.Net/NoSwarmContextException.cs b/src/Libplanet.Net/NoSwarmContextException.cs index df75c9168eb..3d3ef4a6210 100644 --- a/src/Libplanet.Net/NoSwarmContextException.cs +++ b/src/Libplanet.Net/NoSwarmContextException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace Libplanet.Net { @@ -19,13 +18,5 @@ public NoSwarmContextException(string message, Exception innerException) : base(message, innerException) { } - - protected NoSwarmContextException( - SerializationInfo info, - StreamingContext context - ) - : base(info, context) - { - } } } diff --git a/src/Libplanet.Net/PeerNotFoundException.cs b/src/Libplanet.Net/PeerNotFoundException.cs index fd01d2e3d4b..97cfe222a9a 100644 --- a/src/Libplanet.Net/PeerNotFoundException.cs +++ b/src/Libplanet.Net/PeerNotFoundException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace Libplanet.Net { @@ -19,13 +18,5 @@ public PeerNotFoundException(string message, Exception innerException) : base(message, innerException) { } - - protected PeerNotFoundException( - SerializationInfo info, - StreamingContext context - ) - : base(info, context) - { - } } } diff --git a/src/Libplanet.Net/Protocols/PeerDiscoveryException.cs b/src/Libplanet.Net/Protocols/PeerDiscoveryException.cs index 9e5fc27fe1a..eda206ab31e 100644 --- a/src/Libplanet.Net/Protocols/PeerDiscoveryException.cs +++ b/src/Libplanet.Net/Protocols/PeerDiscoveryException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace Libplanet.Net.Protocols { @@ -18,13 +17,5 @@ public PeerDiscoveryException(string message, Exception innerException) : base(message, innerException) { } - - protected PeerDiscoveryException( - SerializationInfo info, - StreamingContext context - ) - : base(info, context) - { - } } } diff --git a/src/Libplanet.Net/Protocols/PingTimeoutException.cs b/src/Libplanet.Net/Protocols/PingTimeoutException.cs index ec40b608c44..37d8aa05f1c 100644 --- a/src/Libplanet.Net/Protocols/PingTimeoutException.cs +++ b/src/Libplanet.Net/Protocols/PingTimeoutException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace Libplanet.Net.Protocols { @@ -24,27 +23,6 @@ public PingTimeoutException(string message, BoundPeer target, Exception innerExc Target = target; } - protected PingTimeoutException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - Target = info.GetValue(nameof(Target), typeof(BoundPeer)) is BoundPeer target - ? target - : throw new SerializationException( - $"{nameof(Target)} is expected to be a non-null {nameof(BoundPeer)}."); - } - public BoundPeer Target { get; private set; } - - public override void GetObjectData( - SerializationInfo info, StreamingContext context) - { - if (info is null) - { - throw new System.ArgumentNullException(nameof(info)); - } - - base.GetObjectData(info, context); - info.AddValue(nameof(Target), Target); - } } } diff --git a/src/Libplanet.Net/SwarmException.cs b/src/Libplanet.Net/SwarmException.cs index cb2d6e84b82..074a3a62b56 100644 --- a/src/Libplanet.Net/SwarmException.cs +++ b/src/Libplanet.Net/SwarmException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace Libplanet.Net { @@ -19,13 +18,5 @@ public SwarmException(string message, Exception innerException) : base(message, innerException) { } - - protected SwarmException( - SerializationInfo info, - StreamingContext context - ) - : base(info, context) - { - } } } diff --git a/src/Libplanet.Net/Transports/CommunicationFailException.cs b/src/Libplanet.Net/Transports/CommunicationFailException.cs index 7743d916b24..2f88d736d5b 100644 --- a/src/Libplanet.Net/Transports/CommunicationFailException.cs +++ b/src/Libplanet.Net/Transports/CommunicationFailException.cs @@ -1,6 +1,4 @@ using System; -using System.Runtime.Serialization; -using Libplanet.Common.Serialization; using Libplanet.Net.Messages; namespace Libplanet.Net.Transports @@ -8,7 +6,7 @@ namespace Libplanet.Net.Transports /// /// An thrown when fail to complete a sending and receiving messages /// cycle via for one of the expected reasons such as normal timeout, - /// receiving a invalid reply, etc. + /// receiving an invalid reply, etc. /// [Serializable] public class CommunicationFailException : Exception @@ -34,25 +32,8 @@ public CommunicationFailException( MessageType = messageType; } - public CommunicationFailException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - Peer = info.GetValue(nameof(Peer)); - MessageType = info.GetValue(nameof(MessageType), typeof(MessageContent.MessageType)) - is MessageContent.MessageType messageType - ? messageType - : throw new SerializationException($"{nameof(MessageType)} is of an invalid type."); - } - public BoundPeer Peer { get; } public MessageContent.MessageType MessageType { get; } - - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue(nameof(Peer), Peer); - info.AddValue(nameof(MessageType), MessageType, typeof(MessageContent.MessageType)); - } } } diff --git a/src/Libplanet.Net/Transports/DifferentAppProtocolVersionException.cs b/src/Libplanet.Net/Transports/DifferentAppProtocolVersionException.cs index 2eaaacc1f1c..a613e9a2cff 100644 --- a/src/Libplanet.Net/Transports/DifferentAppProtocolVersionException.cs +++ b/src/Libplanet.Net/Transports/DifferentAppProtocolVersionException.cs @@ -1,6 +1,4 @@ using System; -using System.Runtime.Serialization; -using Libplanet.Common.Serialization; using Libplanet.Net.Messages; namespace Libplanet.Net.Transports @@ -37,18 +35,6 @@ public DifferentAppProtocolVersionException( Trusted = trusted; } - protected DifferentAppProtocolVersionException( - SerializationInfo info, - StreamingContext context) - : base(info, context) - { - ExpectedApv = AppProtocolVersion.FromToken( - info.GetValue(nameof(ExpectedApv))); - ActualApv = AppProtocolVersion.FromToken( - info.GetValue(nameof(ActualApv))); - Trusted = info.GetValue(nameof(Trusted)); - } - /// /// The protocol version of the current . /// @@ -64,14 +50,5 @@ protected DifferentAppProtocolVersionException( /// Whether is signed by a trusted signer. /// public bool Trusted { get; } - - public override void GetObjectData( - SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue(nameof(ExpectedApv), ExpectedApv.Token); - info.AddValue(nameof(ActualApv), ActualApv.Token); - info.AddValue(nameof(Trusted), Trusted); - } } } diff --git a/src/Libplanet.Net/Transports/InvalidCredentialException.cs b/src/Libplanet.Net/Transports/InvalidCredentialException.cs index d9c7fd1c1f8..d7e48b7ae68 100644 --- a/src/Libplanet.Net/Transports/InvalidCredentialException.cs +++ b/src/Libplanet.Net/Transports/InvalidCredentialException.cs @@ -1,6 +1,4 @@ using System; -using System.Runtime.Serialization; -using Libplanet.Common.Serialization; using Libplanet.Crypto; using Libplanet.Net.Messages; @@ -23,25 +21,8 @@ internal InvalidCredentialException( Actual = actual; } - protected InvalidCredentialException( - SerializationInfo info, - StreamingContext context) - : base(info, context) - { - Expected = new PublicKey(info.GetValue(nameof(Expected))); - Actual = new PublicKey(info.GetValue(nameof(Actual))); - } - public PublicKey Expected { get; private set; } public PublicKey Actual { get; private set; } - - public override void GetObjectData( - SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue(nameof(Expected), Expected.Format(true)); - info.AddValue(nameof(Actual), Actual.Format(true)); - } } } diff --git a/src/Libplanet.Net/Transports/InvalidMessageSignatureException.cs b/src/Libplanet.Net/Transports/InvalidMessageSignatureException.cs index b90540468c9..d24ed40d748 100644 --- a/src/Libplanet.Net/Transports/InvalidMessageSignatureException.cs +++ b/src/Libplanet.Net/Transports/InvalidMessageSignatureException.cs @@ -1,6 +1,4 @@ using System; -using System.Runtime.Serialization; -using Libplanet.Common.Serialization; using Libplanet.Crypto; using Libplanet.Net.Messages; @@ -27,17 +25,6 @@ internal InvalidMessageSignatureException( Signature = signature; } - protected InvalidMessageSignatureException( - SerializationInfo info, - StreamingContext context) - : base(info, context) - { - Peer = info.GetValue(nameof(Peer)); - PublicKey = new PublicKey(info.GetValue(nameof(PublicKey))); - MessageToVerify = info.GetValue(nameof(MessageToVerify)); - Signature = info.GetValue(nameof(Signature)); - } - public BoundPeer Peer { get; } public PublicKey PublicKey { get; } @@ -45,15 +32,5 @@ protected InvalidMessageSignatureException( public byte[] MessageToVerify { get; } public byte[] Signature { get; } - - public override void GetObjectData( - SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue(nameof(Peer), Peer); - info.AddValue(nameof(PublicKey), PublicKey.Format(true)); - info.AddValue(nameof(MessageToVerify), MessageToVerify); - info.AddValue(nameof(Signature), Signature); - } } } diff --git a/src/Libplanet.Net/Transports/InvalidMessageTimestampException.cs b/src/Libplanet.Net/Transports/InvalidMessageTimestampException.cs index 56fb2f2ad56..13e49f570dd 100644 --- a/src/Libplanet.Net/Transports/InvalidMessageTimestampException.cs +++ b/src/Libplanet.Net/Transports/InvalidMessageTimestampException.cs @@ -1,6 +1,4 @@ using System; -using System.Runtime.Serialization; -using Libplanet.Common.Serialization; using Libplanet.Net.Messages; namespace Libplanet.Net.Transports @@ -24,29 +22,10 @@ internal InvalidMessageTimestampException( CurrentOffset = currentOffset; } - protected InvalidMessageTimestampException( - SerializationInfo info, - StreamingContext context) - : base(info, context) - { - CreatedOffset = info.GetValue(nameof(CreatedOffset)); - Buffer = info.GetValue(nameof(Buffer)); - CurrentOffset = info.GetValue(nameof(CurrentOffset)); - } - internal DateTimeOffset CreatedOffset { get; private set; } internal TimeSpan? Buffer { get; private set; } internal DateTimeOffset CurrentOffset { get; private set; } - - public override void GetObjectData( - SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue(nameof(CreatedOffset), CreatedOffset); - info.AddValue(nameof(Buffer), Buffer); - info.AddValue(nameof(CurrentOffset), CurrentOffset); - } } } diff --git a/src/Libplanet.Net/Transports/SendMessageFailException.cs b/src/Libplanet.Net/Transports/SendMessageFailException.cs index eb71c1bbd9b..1b022cf5ff0 100644 --- a/src/Libplanet.Net/Transports/SendMessageFailException.cs +++ b/src/Libplanet.Net/Transports/SendMessageFailException.cs @@ -1,6 +1,4 @@ using System; -using System.Runtime.Serialization; -using Libplanet.Common.Serialization; using Libplanet.Net.Messages; namespace Libplanet.Net.Transports @@ -23,18 +21,6 @@ internal SendMessageFailException(string message, BoundPeer peer, Exception inne Peer = peer; } - protected SendMessageFailException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - Peer = info.GetValue(nameof(Peer)); - } - public BoundPeer Peer { get; } - - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue(nameof(Peer), Peer); - } } } diff --git a/src/Libplanet.Net/Transports/TransportException.cs b/src/Libplanet.Net/Transports/TransportException.cs index 3f7fced7f7a..a70390f055b 100644 --- a/src/Libplanet.Net/Transports/TransportException.cs +++ b/src/Libplanet.Net/Transports/TransportException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace Libplanet.Net.Transports { @@ -19,13 +18,5 @@ public TransportException(string message, Exception innerException) : base(message, innerException) { } - - protected TransportException( - SerializationInfo info, - StreamingContext context - ) - : base(info, context) - { - } } }