/// <summary>
/// Input value.
/// </summary>
- public ulong nValue;
+ public long nValue = -1;
/// <summary>
/// Second half of script which contains spending instructions.
/// </summary>
- public byte[] scriptPubKey;
+ public CScript scriptPubKey;
/// <summary>
/// Initialize new CTxOut instance as a copy of another instance.
/// </summary>
public CTxOut()
{
+ SetEmpty();
}
/// <summary>
{
// Fill outputs array
vout[nIndex] = new CTxOut();
- vout[nIndex].nValue = Interop.LEBytesToUInt64(wBytes.GetItems(8));
- vout[nIndex].scriptPubKey = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
+ vout[nIndex].nValue = BitConverter.ToUInt32(wBytes.GetItems(8), 0);
+
+ int nScriptPKLen = (int)VarInt.ReadVarInt(ref wBytes);
+ vout[nIndex].scriptPubKey = new CScript(wBytes.GetItems(nScriptPKLen));
}
return vout;
/// Get raw bytes representation of our output.
/// </summary>
/// <returns>Byte sequence.</returns>
- public IList<byte> ToBytes()
+ public IList<byte> Bytes
{
- List<byte> resultBytes = new List<byte>();
+ get
+ {
+ List<byte> resultBytes = new List<byte>();
+
+ resultBytes.AddRange(BitConverter.GetBytes(nValue)); // txout value
- resultBytes.AddRange(Interop.LEBytes(nValue)); // txout value
- resultBytes.AddRange(VarInt.EncodeVarInt(scriptPubKey.LongLength)); // scriptPubKey length
- resultBytes.AddRange(scriptPubKey); // scriptPubKey
+ List<byte> s = new List<byte>(scriptPubKey.Bytes);
- return resultBytes;
+ resultBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptPubKey length
+ resultBytes.AddRange(s); // scriptPubKey
+
+ return resultBytes;
+ }
+ }
+
+ /// <summary>
+ /// Null prevouts have -1 value
+ /// </summary>
+ public void SetNull()
+ {
+ nValue = -1;
+ scriptPubKey = new CScript();
+ }
+
+ /// <summary>
+ /// Empty outputs have zero value and empty scriptPubKey
+ /// </summary>
+ public void SetEmpty()
+ {
+ nValue = 0;
+ scriptPubKey = new CScript();
+ }
+
+ public bool IsNull
+ {
+ get { return (nValue == -1); }
+ }
+
+ public bool IsEmpty
+ {
+ get { return nValue == 0 && scriptPubKey.IsNull; }
}
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
- sb.AppendFormat ("CTxOut(nValue={0},scriptPubKey={1})", nValue, (new CScript(scriptPubKey)).ToString());
+ sb.AppendFormat ("CTxOut(nValue={0}, scriptPubKey={1})", nValue, scriptPubKey.ToString());
return sb.ToString ();
}