Skip to content

Commit

Permalink
Addressed more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus-kirk committed Jan 23, 2024
1 parent 126206f commit 6af2857
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Transactions/AccountSignatureMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ internal static AccountSignatureMap From(Grpc.V2.AccountSignatureMap map)
var dict = new Dictionary<AccountKeyIndex, byte[]>();
foreach (var s in map.Signatures)
{
// The GRPC api states that keys must not exceed 2^8, so this should be safe.
dict.Add(new AccountKeyIndex((byte)s.Key), s.Value.Value.ToByteArray());
}
return Create(dict);
Expand All @@ -76,14 +77,13 @@ public bool Equals(AccountSignatureMap? other) => other != null &&
/// <summary>Gets hash code.</summary>
public override int GetHashCode()
{
// Based on https://stackoverflow.com/questions/1646807/quick-and-simple-hash-code-combinations
unchecked
{
var hash = 17;
foreach (var (key, val) in this.Signatures)
{
hash = (hash * 31) + key.GetHashCode();
hash = (hash * 31) + Helpers.HashCode.GetHashCodeByteArray(val);
hash += key.GetHashCode();
hash += Helpers.HashCode.GetHashCodeByteArray(val);
}
return hash;
}
Expand Down Expand Up @@ -136,6 +136,7 @@ internal static UpdateInstructionSignatureMap From(Grpc.V2.SignatureMap map)
var dict = new Dictionary<UpdateKeysIndex, byte[]>();
foreach (var s in map.Signatures)
{
// The GRPC api states that keys must not exceed 2^8, so this should be safe.
dict.Add(new UpdateKeysIndex((byte)s.Key), s.Value.Value.ToByteArray());
}
return Create(dict);
Expand All @@ -150,14 +151,13 @@ public bool Equals(UpdateInstructionSignatureMap? other) => other != null &&
/// <summary>Gets hash code.</summary>
public override int GetHashCode()
{
// Based on https://stackoverflow.com/questions/1646807/quick-and-simple-hash-code-combinations
unchecked
{
var hash = 17;
foreach (var (key, val) in this.Signatures)
{
hash = (hash * 31) + key.GetHashCode();
hash = (hash * 31) + Helpers.HashCode.GetHashCodeByteArray(val);
hash += key.GetHashCode();
hash += Helpers.HashCode.GetHashCodeByteArray(val);
}
return hash;
}
Expand Down

0 comments on commit 6af2857

Please sign in to comment.