3 using System.Collections.Generic;
8 /// Transaction output.
18 /// Second half of script which contains spending instructions.
20 public byte[] 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);
54 vout[nIndex].scriptPubKey = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
61 /// Get raw bytes representation of our output.
63 /// <returns>Byte sequence.</returns>
64 public IList<byte> ToBytes()
66 List<byte> resultBytes = new List<byte>();
68 resultBytes.AddRange(BitConverter.GetBytes(nValue)); // txout value
69 resultBytes.AddRange(VarInt.EncodeVarInt(scriptPubKey.LongLength)); // scriptPubKey length
70 resultBytes.AddRange(scriptPubKey); // scriptPubKey
75 public override string ToString ()
77 StringBuilder sb = new StringBuilder ();
78 sb.AppendFormat ("CTxOut(nValue={0}, scriptPubKey={1})", nValue, (new CScript(scriptPubKey)).ToString());
80 return sb.ToString ();