3 using System.Collections.Generic;
8 /// Transaction output.
18 /// Second half of script which contains spending instructions.
20 private 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 /// Parse input byte sequence and initialize new CTxOut instance.
35 /// <param name="bytes">Byte sequence.</param>
36 public CTxOut(IList<byte> bytes)
38 WrappedList<byte> wBytes = new WrappedList<byte>(bytes);
40 nValue = Interop.LEBytesToUInt64(wBytes.GetItems(8));
41 int spkLength = (int)VarInt.ReadVarInt(wBytes);
43 scriptPubKey = wBytes.GetItems(spkLength);
47 /// Get raw bytes representation of our output.
49 /// <returns>Byte sequence.</returns>
50 public IList<byte> ToBytes()
52 List<byte> resultBytes = new List<byte>();
54 resultBytes.AddRange(Interop.LEBytes(nValue)); // txout value
55 resultBytes.AddRange(VarInt.EncodeVarInt(scriptPubKey.LongLength)); // scriptPubKey length
56 resultBytes.AddRange(scriptPubKey); // scriptPubKey
61 public override string ToString ()
63 StringBuilder sb = new StringBuilder ();
64 sb.AppendFormat ("CTxOut(nValue={0},scriptPubKey={1}", nValue, scriptPubKey.ToString());
66 return sb.ToString ();