Skip to content

Commit

Permalink
added CalculateHash helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry committed Sep 3, 2020
1 parent 89842e1 commit 4cea6d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/neo/Network/P2P/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Neo.Cryptography;
using Neo.Network.P2P.Payloads;
using System.IO;

Expand All @@ -21,5 +22,15 @@ public static byte[] GetHashData(this IVerifiable verifiable, uint magic)
return ms.ToArray();
}
}

public static UInt256 CalculateHash(this IVerifiable verifiable)
{
return CalculateHash(verifiable, ProtocolSettings.Default.Magic);
}

public static UInt256 CalculateHash(this IVerifiable verifiable, uint magic)
{
return new UInt256(Crypto.Hash256(verifiable.GetHashData(magic)));
}
}
}
2 changes: 1 addition & 1 deletion src/neo/Network/P2P/Payloads/BlockBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public UInt256 Hash
{
if (_hash == null)
{
_hash = new UInt256(Crypto.Hash256(this.GetHashData()));
_hash = this.CalculateHash();
}
return _hash;
}
Expand Down
2 changes: 1 addition & 1 deletion src/neo/Network/P2P/Payloads/ConsensusPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public UInt256 Hash
{
if (_hash == null)
{
_hash = new UInt256(Crypto.Hash256(this.GetHashData()));
_hash = this.CalculateHash();
}
return _hash;
}
Expand Down
2 changes: 1 addition & 1 deletion src/neo/Network/P2P/Payloads/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public UInt256 Hash
{
if (_hash == null)
{
_hash = new UInt256(Crypto.Hash256(this.GetHashData()));
_hash = this.CalculateHash();
}
return _hash;
}
Expand Down

0 comments on commit 4cea6d0

Please sign in to comment.