using System;
using System.Collections.Generic;
-using System.Linq;
+using System.Diagnostics.Contracts;
using System.Text;
namespace Novacoin
/// </summary>
public uint n;
+ /// <summary>
+ /// Out reference is always 36 bytes long.
+ /// </summary>
+ public const int Size = 36;
+
public COutPoint()
{
hash = new Hash256();
n = o.n;
}
- public COutPoint(IEnumerable<byte> bytes)
+ public COutPoint(byte[] bytes)
{
+ Contract.Requires<ArgumentException>(bytes.Length == 36, "Any valid outpoint reference data item is exactly 36 bytes long.");
+
hash = new Hash256(bytes);
- n = BitConverter.ToUInt32(bytes.ToArray(), 32);
+ n = BitConverter.ToUInt32(bytes, 32);
}
public bool IsNull
get { return hash.IsZero && n == uint.MaxValue; }
}
- public IList<byte> Bytes
+ public static implicit operator byte[] (COutPoint o)
{
- get
- {
- List<byte> r = new List<byte>();
- r.AddRange(hash.hashBytes);
- r.AddRange(BitConverter.GetBytes(n));
-
- return r;
- }
+ var r = new List<byte>();
+ r.AddRange((byte[])o.hash);
+ r.AddRange(BitConverter.GetBytes(o.n));
+
+ return r.ToArray();
}
public override string ToString()
{
- StringBuilder sb = new StringBuilder();
+ var sb = new StringBuilder();
sb.AppendFormat("COutPoint({0}, {1})", hash.ToString(), n);
return sb.ToString();