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.RocksDBStore.Tests/Libplanet.RocksDBStore.Tests.csproj b/Libplanet.RocksDBStore.Tests/Libplanet.RocksDBStore.Tests.csproj index a75d5996f52..ae7e4490410 100644 --- a/Libplanet.RocksDBStore.Tests/Libplanet.RocksDBStore.Tests.csproj +++ b/Libplanet.RocksDBStore.Tests/Libplanet.RocksDBStore.Tests.csproj @@ -43,7 +43,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/Libplanet.RocksDBStore/Libplanet.RocksDBStore.csproj b/Libplanet.RocksDBStore/Libplanet.RocksDBStore.csproj index 1438e15c41f..ccb432afd28 100644 --- a/Libplanet.RocksDBStore/Libplanet.RocksDBStore.csproj +++ b/Libplanet.RocksDBStore/Libplanet.RocksDBStore.csproj @@ -42,7 +42,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/Libplanet.Stun.Tests/Libplanet.Stun.Tests.csproj b/Libplanet.Stun.Tests/Libplanet.Stun.Tests.csproj index cf275fbf2ae..3e25929b4a9 100644 --- a/Libplanet.Stun.Tests/Libplanet.Stun.Tests.csproj +++ b/Libplanet.Stun.Tests/Libplanet.Stun.Tests.csproj @@ -37,7 +37,7 @@ all - + all runtime; build; native; contentfiles; analyzers diff --git a/Libplanet.Stun/Libplanet.Stun.csproj b/Libplanet.Stun/Libplanet.Stun.csproj index 23dfb3f5545..a6b21945a5a 100644 --- a/Libplanet.Stun/Libplanet.Stun.csproj +++ b/Libplanet.Stun/Libplanet.Stun.csproj @@ -30,7 +30,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers diff --git a/Libplanet.Stun/Stun/Messages/StunMessage.cs b/Libplanet.Stun/Stun/Messages/StunMessage.cs index 88e849f7bf3..eee6d74b608 100644 --- a/Libplanet.Stun/Stun/Messages/StunMessage.cs +++ b/Libplanet.Stun/Stun/Messages/StunMessage.cs @@ -115,21 +115,21 @@ public static async Task Parse(Stream stream) MessageMethod.Binding => new BindingSuccessResponse(), MessageMethod.CreatePermission => new CreatePermissionSuccessResponse(), MessageMethod.Refresh => new RefreshSuccessResponse(), - _ => rv + _ => rv, }, MessageClass.ErrorResponse => method switch { MessageMethod.Allocate => new AllocateErrorResponse(), MessageMethod.CreatePermission => new CreatePermissionErrorResponse(), MessageMethod.Refresh => new RefreshErrorResponse(), - _ => rv + _ => rv, }, MessageClass.Indication => method switch { MessageMethod.ConnectionAttempt => new ConnectionAttempt(), - _ => rv + _ => rv, }, - _ => rv + _ => rv, }; if (rv is null) @@ -252,7 +252,7 @@ internal static IEnumerable ParseAttributes( XorRelayedAddress.Parse(payload, transactionId), Attribute.AttributeType.ConnectionId => new ConnectionId(payload), Attribute.AttributeType.Lifetime => new Lifetime((int)payload.ToUInt()), - _ => null + _ => null, }; if (!(attr is null)) diff --git a/Libplanet.Tests.ruleset b/Libplanet.Tests.ruleset index d8c645a02da..69d8060e189 100644 --- a/Libplanet.Tests.ruleset +++ b/Libplanet.Tests.ruleset @@ -12,6 +12,10 @@ + + + + diff --git a/Libplanet.Tests/Action/ActionContextTest.cs b/Libplanet.Tests/Action/ActionContextTest.cs index b23b07cebaa..89309f29e64 100644 --- a/Libplanet.Tests/Action/ActionContextTest.cs +++ b/Libplanet.Tests/Action/ActionContextTest.cs @@ -12,7 +12,7 @@ public class ActionContextTest [Fact] public void RandomShouldBeDeterministic() { - (int seed, int expected)[] testCases = + (int Seed, int Expected)[] testCases = { (0, 1559595546), (1, 534011718), @@ -60,7 +60,7 @@ public void GuidShouldBeDeterministic() randomSeed: 1 ); - (Guid expected, Guid diff)[] testCases = + (Guid Expected, Guid Diff)[] testCases = { ( new Guid("6f460c1a-755d-48e4-ad67-65d5f519dbc8"), diff --git a/Libplanet.Tests/Blockchain/BlockChainTest.cs b/Libplanet.Tests/Blockchain/BlockChainTest.cs index c8987f8d526..7b62d9e49c1 100644 --- a/Libplanet.Tests/Blockchain/BlockChainTest.cs +++ b/Libplanet.Tests/Blockchain/BlockChainTest.cs @@ -2248,7 +2248,7 @@ public async void BlockActionWithMultipleAddress() /// 10 addresses[4] Present /// /// - internal static (Address, Address[] addresses, BlockChain chain) + internal static (Address, Address[] Addresses, BlockChain Chain) MakeIncompleteBlockStates( IStore store, IBlockStatesStore blockStatesStore, @@ -2333,7 +2333,7 @@ void BuildIndex(Guid id, Block block) return (signer, addresses, chain); } - private (Address, Address[] addresses, BlockChain chain) + private (Address, Address[] Addresses, BlockChain Chain) MakeIncompleteBlockStates() => MakeIncompleteBlockStates(_fx.Store, _fx.BlockStatesStore); diff --git a/Libplanet.Tests/Libplanet.Tests.csproj b/Libplanet.Tests/Libplanet.Tests.csproj index 02c847775bc..21bbadc693e 100644 --- a/Libplanet.Tests/Libplanet.Tests.csproj +++ b/Libplanet.Tests/Libplanet.Tests.csproj @@ -42,7 +42,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/Libplanet.ruleset b/Libplanet.ruleset index af8e36a6f55..5eabda05dab 100644 --- a/Libplanet.ruleset +++ b/Libplanet.ruleset @@ -15,6 +15,10 @@ + + + + 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/KeyStore/Kdfs/Pbkdf2.cs b/Libplanet/KeyStore/Kdfs/Pbkdf2.cs index 991e6105ea8..077411241bf 100644 --- a/Libplanet/KeyStore/Kdfs/Pbkdf2.cs +++ b/Libplanet/KeyStore/Kdfs/Pbkdf2.cs @@ -195,7 +195,7 @@ internal static IKdf FromJson(in JsonElement element) throw new InvalidKeyJsonException( "The \"prf\" field must not be null, but a string."), _ => - throw new UnsupportedKeyJsonException($"Unsupported \"prf\" type: \"{prf}\".") + throw new UnsupportedKeyJsonException($"Unsupported \"prf\" type: \"{prf}\"."), }; } } diff --git a/Libplanet/KeyStore/ProtectedPrivateKey.cs b/Libplanet/KeyStore/ProtectedPrivateKey.cs index 0152211d6b1..91fc35b3d77 100644 --- a/Libplanet/KeyStore/ProtectedPrivateKey.cs +++ b/Libplanet/KeyStore/ProtectedPrivateKey.cs @@ -270,7 +270,7 @@ byte[] GetHexProperty(JsonElement element, string fieldName) "aes-128-ctr" => Aes128Ctr.FromJson(cipherParamsElement), _ => throw new UnsupportedKeyJsonException( - $"Unsupported cipher type: \"{cipherType}\".") + $"Unsupported cipher type: \"{cipherType}\"."), }; IKdf kdf; @@ -282,7 +282,7 @@ byte[] GetHexProperty(JsonElement element, string fieldName) "scrypt" => Scrypt.FromJson(kdfParamsElement), _ => throw new UnsupportedKeyJsonException( - $"Unsupported cipher type: \"{kdfType}\".") + $"Unsupported cipher type: \"{kdfType}\"."), }; } catch (ArgumentException e) diff --git a/Libplanet/Libplanet.csproj b/Libplanet/Libplanet.csproj index bc35810dbcb..de62ae6e21b 100644 --- a/Libplanet/Libplanet.csproj +++ b/Libplanet/Libplanet.csproj @@ -81,7 +81,7 @@ https://docs.libplanet.io/ - + all runtime; build; native; contentfiles; analyzers 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;