diff --git a/CHANGES.md b/CHANGES.md index e83fd2af23b..efe7530e3be 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -121,6 +121,8 @@ To be released. constructor. [[#1012]] - Added `cacheSize` optional parameter to `BlockSet()` constructor. [[#1013]] + - Removed `Address(SerializationInfo, StreamingContext)` constructor. + [[#1022]] - Removed constructors from `InvalidMessageException` class. [[#1021]] ### Backward-incompatible network protocol changes @@ -366,6 +368,7 @@ To be released. [#1012]: https://github.com/planetarium/libplanet/pull/1012 [#1013]: https://github.com/planetarium/libplanet/pull/1013 [#1021]: https://github.com/planetarium/libplanet/pull/1021 +[#1022]: https://github.com/planetarium/libplanet/pull/1022 [sleep mode]: https://en.wikipedia.org/wiki/Sleep_mode diff --git a/Libplanet/Address.cs b/Libplanet/Address.cs index 6aac754e519..694e50b321b 100644 --- a/Libplanet/Address.cs +++ b/Libplanet/Address.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Immutable; using System.Diagnostics.Contracts; @@ -93,13 +94,6 @@ public Address(byte[] address) { } - public Address( - SerializationInfo info, - StreamingContext context) - : this(info.GetValue("address")) - { - } - /// /// Derives the corresponding from a . @@ -138,6 +132,14 @@ public Address(string hex) { } + private Address( + SerializationInfo info, + StreamingContext context) + : this(info?.GetValue("address") ?? + throw new SerializationException("Missing the address field.")) + { + } + /// /// An immutable array of 20 s that represent this /// . @@ -223,9 +225,7 @@ public override string ToString() } /// - public void GetObjectData( - SerializationInfo info, - StreamingContext context) + public void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("address", ToByteArray()); } @@ -246,7 +246,7 @@ int IComparable
.CompareTo(Address other) return 0; } - int IComparable.CompareTo(object obj) + int IComparable.CompareTo(object? obj) { if (obj is Address other) { diff --git a/Libplanet/AddressExtensions.cs b/Libplanet/AddressExtensions.cs index c6c73785eaa..1e4acccdbdb 100644 --- a/Libplanet/AddressExtensions.cs +++ b/Libplanet/AddressExtensions.cs @@ -1,3 +1,4 @@ +#nullable enable using Libplanet.Crypto; namespace Libplanet diff --git a/Libplanet/ByteArrayExtensions.cs b/Libplanet/ByteArrayExtensions.cs index 7e414996d4e..67431264731 100644 --- a/Libplanet/ByteArrayExtensions.cs +++ b/Libplanet/ByteArrayExtensions.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Diagnostics.Contracts; @@ -22,7 +23,7 @@ public static class ByteArrayExtensions /// or is null. /// [Pure] - public static bool StartsWith(this byte[] bytes, byte[] prefix) + public static bool StartsWith(this byte[]? bytes, byte[]? prefix) { if (bytes is null) { diff --git a/Libplanet/ByteUtil.cs b/Libplanet/ByteUtil.cs index 26eb115c42a..7a1b1730e30 100644 --- a/Libplanet/ByteUtil.cs +++ b/Libplanet/ByteUtil.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Immutable; using System.Diagnostics.Contracts; @@ -74,7 +75,6 @@ public static string Hex(byte[] bytes) } string s = BitConverter.ToString(bytes); - return s.Replace("-", string.Empty).ToLower(CultureInfo.InvariantCulture); } diff --git a/Libplanet/FixedSizedQueue.cs b/Libplanet/FixedSizedQueue.cs index 30f6baf6ea0..ff2943f4ae5 100644 --- a/Libplanet/FixedSizedQueue.cs +++ b/Libplanet/FixedSizedQueue.cs @@ -1,3 +1,4 @@ +#nullable enable using System.Collections.Concurrent; namespace Libplanet diff --git a/Libplanet/HashDigest.cs b/Libplanet/HashDigest.cs index e6ff2aeb180..82b75c9604f 100644 --- a/Libplanet/HashDigest.cs +++ b/Libplanet/HashDigest.cs @@ -1,8 +1,10 @@ +#nullable enable using System; using System.Collections.Immutable; using System.Diagnostics.Contracts; using System.Linq; using System.Numerics; +using System.Reflection; using System.Security.Cryptography; namespace Libplanet @@ -35,8 +37,9 @@ namespace Libplanet static HashDigest() { - var thunk = (T)typeof(T).GetMethod("Create", new Type[0]).Invoke( - null, new object[0]); + MethodInfo? method = typeof(T).GetMethod("Create", new Type[0]); + T thunk = method?.Invoke(null, new object[0]) as T + ?? throw new InvalidCastException($"Failed to instantiate {typeof(T).FullName}."); Size = thunk.HashSize / 8; _defaultByteArray = new byte[Size]; @@ -206,7 +209,7 @@ public override string ToString() } [Pure] - public override bool Equals(object obj) + public override bool Equals(object? obj) { return obj is IEquatable> other ? other.Equals(this) diff --git a/Libplanet/Hashcash.cs b/Libplanet/Hashcash.cs index e4ec9a8725d..3e164f59323 100644 --- a/Libplanet/Hashcash.cs +++ b/Libplanet/Hashcash.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Security.Cryptography; using System.Threading; diff --git a/Libplanet/Nonce.cs b/Libplanet/Nonce.cs index d3d89eb838a..f4f72802770 100644 --- a/Libplanet/Nonce.cs +++ b/Libplanet/Nonce.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Immutable; using System.Diagnostics.Contracts;