3 using System.Collections.Generic;
8 /// Transaction output.
15 public long nValue = -1;
18 /// Second half of script which contains spending instructions.
20 public CScript scriptPubKey;
23 /// Initialize new CTxOut instance as a copy of another instance.
25 /// <param name="o">CTxOut instance.</param>
26 public CTxOut(CTxOut o)
29 scriptPubKey = o.scriptPubKey;
33 /// Initialize an empty instance of CTxOut class
41 /// Read vout list from byte sequence.
43 /// <param name="wBytes">Reference to byte sequence</param>
44 /// <returns>Outputs array</returns>
45 public static CTxOut[] ReadTxOutList(ref ByteQueue wBytes)
47 int nOutputs = (int)VarInt.ReadVarInt(ref wBytes);
48 CTxOut[] vout =new CTxOut[nOutputs];
50 for (int nIndex = 0; nIndex < nOutputs; nIndex++)
53 vout[nIndex] = new CTxOut();
54 vout[nIndex].nValue = BitConverter.ToUInt32(wBytes.Get(8), 0);
56 int nScriptPKLen = (int)VarInt.ReadVarInt(ref wBytes);
57 vout[nIndex].scriptPubKey = new CScript(wBytes.Get(nScriptPKLen));
64 /// Get raw bytes representation of our output.
66 /// <returns>Byte sequence.</returns>
67 public IList<byte> Bytes
71 List<byte> resultBytes = new List<byte>();
73 resultBytes.AddRange(BitConverter.GetBytes(nValue)); // txout value
75 List<byte> s = new List<byte>(scriptPubKey.Bytes);
77 resultBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptPubKey length
78 resultBytes.AddRange(s); // scriptPubKey
85 /// Null prevouts have -1 value
90 scriptPubKey = new CScript();
94 /// Empty outputs have zero value and empty scriptPubKey
96 public void SetEmpty()
99 scriptPubKey = new CScript();
104 get { return (nValue == -1); }
109 get { return nValue == 0 && scriptPubKey.IsNull; }
112 public override string ToString ()
114 StringBuilder sb = new StringBuilder ();
115 sb.AppendFormat ("CTxOut(nValue={0}, scriptPubKey={1})", nValue, scriptPubKey.ToString());
117 return sb.ToString ();