From 7571090eb0a6a93e9fd3eaf0003c53097019f7ef Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Fri, 8 Mar 2019 00:57:58 +0900 Subject: [PATCH] Address.Size constant --- CHANGES.md | 1 + Libplanet/Address.cs | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e2d08d34aba..e7263ce90dd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -30,6 +30,7 @@ To be released. [[#120], [#123] by Yang Chun Ung, [#126], [#127]] - `Address` and `TxId` are now serializable. [[#99], [#124] by Qria] + - Added `Address.Size` constant, which is fixed to the `Int32` 20. - `Swarm.AddPeersAsync()` was fixed so that unreachable `Peer`s are ignored. [[#128]] diff --git a/Libplanet/Address.cs b/Libplanet/Address.cs index a8679b9a557..f61cbed1808 100644 --- a/Libplanet/Address.cs +++ b/Libplanet/Address.cs @@ -43,6 +43,12 @@ namespace Libplanet public partial struct Address : ISerializable #pragma warning restore CS0282 { + /// + /// The s size that each takes. + /// It is 20 s. + /// + public const int Size = 20; + private ImmutableArray _byteArray; /// @@ -67,7 +73,7 @@ public Address(byte[] address) throw new NullReferenceException("address must not be null"); } - if (address.Length != 20) + if (address.Length != Size) { throw new ArgumentException("address must be 20 bytes"); } @@ -142,7 +148,7 @@ public ImmutableArray ByteArray { if (_byteArray.IsDefault) { - _byteArray = new byte[20].ToImmutableArray(); + _byteArray = new byte[Size].ToImmutableArray(); } return _byteArray; @@ -245,7 +251,7 @@ private static byte[] DeriveAddress(PublicKey key) byte[] hashPayload = key.Format(false).Skip(1).ToArray(); var output = CalculateHash(hashPayload); - return output.Skip(output.Length - 20).ToArray(); + return output.Skip(output.Length - Size).ToArray(); } private static byte[] DeriveAddress(string hex)