CTransaction constructor. Also, trying to remove some excessive code.
[NovacoinLibrary.git] / Novacoin / CTxOut.cs
1 \feffusing System;
2 using System.Text;
3 using System.Collections.Generic;
4
5 namespace Novacoin
6 {
7         /// <summary>
8         /// Transaction output.
9         /// </summary>
10         public class CTxOut
11         {
12                 /// <summary>
13                 /// Input value.
14                 /// </summary>
15         public ulong nValue;
16
17                 /// <summary>
18                 /// Second half of script which contains spending instructions.
19                 /// </summary>
20         public byte[] scriptPubKey;
21
22         /// <summary>
23         /// Initialize new CTxOut instance as a copy of another instance.
24         /// </summary>
25         /// <param name="o">CTxOut instance.</param>
26         public CTxOut(CTxOut o)
27         {
28             nValue = o.nValue;
29             scriptPubKey = o.scriptPubKey;
30         }
31
32         /// <summary>
33         /// Get raw bytes representation of our output.
34         /// </summary>
35         /// <returns>Byte sequence.</returns>
36         public IList<byte> ToBytes()
37         {
38             List<byte> resultBytes = new List<byte>();
39
40             resultBytes.AddRange(Interop.LEBytes(nValue)); // txout value
41             resultBytes.AddRange(VarInt.EncodeVarInt(scriptPubKey.LongLength)); // scriptPubKey length
42             resultBytes.AddRange(scriptPubKey); // scriptPubKey
43
44             return resultBytes;
45         }
46
47                 public override string ToString ()
48                 {
49                         StringBuilder sb = new StringBuilder ();
50                         sb.AppendFormat ("CTxOut(nValue={0},scriptPubKey={1}", nValue, scriptPubKey.ToString());
51
52                         return sb.ToString ();
53                 }
54         }
55 }
56