using System;
using System.Text;
using System.Collections.Generic;
+using System.IO;
namespace Novacoin
{
/// <summary>
/// Input value.
/// </summary>
- public long nValue = -1;
+ public ulong nValue = ulong.MaxValue;
/// <summary>
/// Second half of script which contains spending instructions.
{
// Fill outputs array
vout[nIndex] = new CTxOut();
- vout[nIndex].nValue = BitConverter.ToUInt32(wBytes.Get(8), 0);
+ vout[nIndex].nValue = BitConverter.ToUInt64(wBytes.Get(8), 0);
int nScriptPKLen = (int)wBytes.GetVarInt();
vout[nIndex].scriptPubKey = new CScript(wBytes.Get(nScriptPKLen));
/// Get raw bytes representation of our output.
/// </summary>
/// <returns>Byte sequence.</returns>
- public IList<byte> Bytes
+ public static implicit operator byte[] (CTxOut output)
{
- get
- {
- var resultBytes = new List<byte>();
+ var stream = new MemoryStream();
+ var writer = new BinaryWriter(stream);
- resultBytes.AddRange(BitConverter.GetBytes(nValue)); // txout value
+ writer.Write(output.nValue); // txout value
+ writer.Write(VarInt.EncodeVarInt(output.scriptPubKey.Size)); // scriptPubKey length
+ writer.Write(output.scriptPubKey); // scriptPubKey
- var s = scriptPubKey.Bytes;
- resultBytes.AddRange(VarInt.EncodeVarInt(s.Length)); // scriptPubKey length
- resultBytes.AddRange(s); // scriptPubKey
+ var resultBytes = stream.ToArray();
- return resultBytes;
- }
+ writer.Close();
+
+ return resultBytes;
}
/// <summary>
/// </summary>
public void SetNull()
{
- nValue = -1;
+ nValue = ulong.MaxValue;
scriptPubKey = new CScript();
}
public bool IsNull
{
- get { return (nValue == -1); }
+ get { return (nValue == ulong.MaxValue); }
}
public bool IsEmpty
get { return nValue == 0 && scriptPubKey.IsNull; }
}
- public override string ToString ()
+ /// <summary>
+ /// Serialized size
+ /// </summary>
+ public int Size
+ {
+ get
+ {
+ var nScriptSize = scriptPubKey.Size;
+ return 8 + VarInt.GetEncodedSize(nScriptSize) + nScriptSize;
+ }
+ }
+
+ public override string ToString ()
{
var sb = new StringBuilder ();
sb.AppendFormat ("CTxOut(nValue={0}, scriptPubKey={1})", nValue, scriptPubKey.ToString());