* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-using System;
-using System.Diagnostics.Contracts;
-
namespace Novacoin
{
- public class CKeyID : Hash160
+ /// <summary>
+ /// Represents the key identifier. Internal state is calculated as Hash160(pubkey).
+ /// </summary>
+ public class CKeyID : uint160
{
- public CKeyID(Hash160 pubKeyHash)
+ public CKeyID() : base()
+ {
+ }
+
+ public CKeyID(CKeyID KeyID) : base(KeyID)
{
- _hashBytes = pubKeyHash;
}
- internal CKeyID(byte[] hashBytes)
+ public CKeyID(uint160 pubKeyHash) : base(pubKeyHash)
{
- Contract.Requires<ArgumentException>(hashBytes.Length == 20, "Your data doesn't seem like a hash160 of some value.");
+ }
- _hashBytes = hashBytes;
+ public CKeyID(byte[] hashBytes) : base(hashBytes)
+ {
}
+ /// <summary>
+ /// Generate Pay-to-PubkeyHash address
+ /// </summary>
+ /// <returns>Base58 formatted novacoin address</returns>
public override string ToString()
{
return (new CNovacoinAddress(this)).ToString();
/// hash_length_byte hash_bytes
/// </summary>
/// <param name="hash">Hash160 instance</param>
- public void AddHash(Hash160 hash)
+ public void AddHash(uint160 hash)
{
- codeBytes.Add((byte)hash.hashSize);
+ codeBytes.Add((byte)hash.Size);
codeBytes.AddRange((byte[])hash);
}
/// hash_length_byte hash_bytes
/// </summary>
/// <param name="hash">Hash256 instance</param>
- public void AddHash(Hash256 hash)
+ public void AddHash(uint256 hash)
{
- codeBytes.Add((byte)hash.hashSize);
+ codeBytes.Add((byte)hash.Size);
codeBytes.AddRange((byte[])hash);
}
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-using System;
-using System.Diagnostics.Contracts;
-
namespace Novacoin
{
- public class CScriptID : Hash160
+ /// <summary>
+ /// Represents the script identifier. Internal value is calculated as Hash160(script).
+ /// </summary>
+ public class CScriptID : uint160
{
- public CScriptID(Hash160 scriptHash)
+ public CScriptID() : base()
+ {
+ }
+
+ public CScriptID(CScriptID KeyID) : base(KeyID)
{
- _hashBytes = scriptHash;
}
- internal CScriptID(byte[] hashBytes)
+ public CScriptID(uint160 pubKeyHash) : base(pubKeyHash)
{
- Contract.Requires<ArgumentException>(hashBytes.Length == 20, "Your data doesn't seem like a hash160 of some value.");
+ }
- _hashBytes = hashBytes;
+ public CScriptID(byte[] hashBytes) : base(hashBytes)
+ {
}
+ /// <summary>
+ /// Generate Pay-to-ScriptHash address
+ /// </summary>
+ /// <returns>Base58 formatted novacoin address</returns>
public override string ToString()
{
return (new CNovacoinAddress(this)).ToString();
using System;
+using System.Collections.Generic;
using System.Diagnostics.Contracts;
namespace Novacoin
/// <summary>
/// Base class for uint256 and uint160.
/// </summary>
- public class base_uint : IComparable<base_uint>, IEquatable<base_uint>
+ public class base_uint : IComparable<base_uint>, IEquatable<base_uint>, IEqualityComparer<base_uint>
{
protected int nWidth;
protected uint[] pn;
return pn[0];
}
+ /// <summary>
+ /// Total size in bytes.
+ /// </summary>
public int Size
{
get
{
- return nWidth;
+ return nWidth * sizeof(uint);
}
}
}
+ #region Comparison operations
public static bool operator <(base_uint a, base_uint b)
{
for (int i = a.nWidth - 1; i >= 0; i--)
}
return true;
}
+ #endregion
+ #region Equality operators
public static bool operator ==(base_uint a, base_uint b)
{
if (object.ReferenceEquals(a, b))
{
return (!(a == b));
}
+ #endregion
+ #region Cast oerations
+ /// <summary>
+ /// True cast operator
+ /// </summary>
+ /// <param name="a"></param>
+ /// <returns></returns>
public static bool operator true(base_uint a)
{
return (a != 0);
}
+ /// <summary>
+ /// False cast operator.
+ /// </summary>
+ /// <param name="a">Value</param>
+ /// <returns>Boolean result</returns>
public static bool operator false(base_uint a)
{
return (a == 0);
}
+ /// <summary>
+ /// Imlicit byte[] cast operator.
+ /// </summary>
+ /// <param name="a">Value</param>
public static implicit operator byte[] (base_uint a)
{
return Interop.LEBytes(a.pn);
}
+ #endregion
private static bool ArraysEqual(uint[] a, uint[] b)
{
return true;
}
- public override int GetHashCode()
+
+ #region IEqualityComparer
+ public bool Equals(base_uint a, base_uint b)
{
- int hash = 17;
- unchecked
+ if (object.ReferenceEquals(a, b))
{
- foreach (var element in pn)
- {
- hash = hash * 31 + element.GetHashCode();
- }
+ return true;
}
- return hash;
+
+ return ArraysEqual(a.pn, b.pn);
}
+ public int GetHashCode(base_uint a)
+ {
+ return a.GetHashCode();
+ }
+
+ #endregion
+
+ #region IComparable
public int CompareTo(base_uint item)
{
if (this > item)
return 0;
}
+ #endregion
+ #region IEquatable
public bool Equals(base_uint a)
{
if (a == null)
return ArraysEqual(pn, a.pn);
}
+ public override int GetHashCode()
+ {
+ int hash = 17;
+ unchecked
+ {
+ foreach (var element in pn)
+ {
+ hash = hash * 31 + element.GetHashCode();
+ }
+ }
+ return hash;
+ }
+
public override bool Equals(object o)
{
return Equals(o as base_uint);
}
+ #endregion
public override string ToString()
{