3 using System.Collections.Generic;
8 /// Transaction output.
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
40 /// Read vout list from byte sequence.
42 /// <param name="wBytes">Reference to byte sequence</param>
43 /// <returns>Outputs array</returns>
44 public static CTxOut[] ReadTxOutList(ref WrappedList<byte> wBytes)
46 int nOutputs = (int)VarInt.ReadVarInt(ref wBytes);
47 CTxOut[] vout =new CTxOut[nOutputs];
49 for (int nIndex = 0; nIndex < nOutputs; nIndex++)
52 vout[nIndex] = new CTxOut();
53 vout[nIndex].nValue = BitConverter.ToUInt32(wBytes.GetItems(8), 0);
55 int nScriptPKLen = (int)VarInt.ReadVarInt(ref wBytes);
56 vout[nIndex].scriptPubKey = new CScript(wBytes.GetItems(nScriptPKLen));
63 /// Get raw bytes representation of our output.
65 /// <returns>Byte sequence.</returns>
66 public IList<byte> Bytes
70 List<byte> resultBytes = new List<byte>();
72 resultBytes.AddRange(BitConverter.GetBytes(nValue)); // txout value
74 List<byte> s = new List<byte>(scriptPubKey.Bytes);
76 resultBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptPubKey length
77 resultBytes.AddRange(s); // scriptPubKey
83 public override string ToString ()
85 StringBuilder sb = new StringBuilder ();
86 sb.AppendFormat ("CTxOut(nValue={0}, scriptPubKey={1})", nValue, scriptPubKey.ToString());
88 return sb.ToString ();