New interop methods, ToString() implementation for transaction structures + quick...
[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         /// Initialize an empty instance of CTxOut class
34         /// </summary>
35         public CTxOut()
36         {
37         }
38
39         /// <summary>
40         /// Get raw bytes representation of our output.
41         /// </summary>
42         /// <returns>Byte sequence.</returns>
43         public IList<byte> ToBytes()
44         {
45             List<byte> resultBytes = new List<byte>();
46
47             resultBytes.AddRange(Interop.LEBytes(nValue)); // txout value
48             resultBytes.AddRange(VarInt.EncodeVarInt(scriptPubKey.LongLength)); // scriptPubKey length
49             resultBytes.AddRange(scriptPubKey); // scriptPubKey
50
51             return resultBytes;
52         }
53
54                 public override string ToString ()
55                 {
56                         StringBuilder sb = new StringBuilder ();
57                         sb.AppendFormat ("CTxOut(nValue={0},scriptPubKey={1})", nValue, (new CScript(scriptPubKey)).ToString());
58
59                         return sb.ToString ();
60                 }
61         }
62 }
63