VarInt class, TxIn/TXOut/Tx serializarion, some CKey and CPubKey methods
[NovacoinLibrary.git] / Novacoin / CTxIn.cs
1 \feffusing System;
2 using System.Text;
3 using System.Collections.Generic;
4
5 namespace Novacoin
6 {
7         /// <summary>
8         /// Transaction input.
9         /// </summary>
10         public class CTxIn
11         {
12                 /// <summary>
13                 /// Hash of parent transaction.
14                 /// </summary>
15                 private Hash256 txID = new Hash256();
16
17                 /// <summary>
18                 /// Parent input number.
19                 /// </summary>
20                 private uint nInput = 0;
21
22                 /// <summary>
23                 /// First half of script, signatures for the scriptPubKey
24                 /// </summary>
25                 private byte[] scriptSig;
26
27                 /// <summary>
28                 /// Transaction variant number, irrelevant if nLockTime isn't specified. Its value is 0xffffffff by default.
29                 /// </summary>
30                 private uint nSequence = 0xffffffff;
31
32                 public CTxIn ()
33                 {
34                 }
35
36         public IList<byte> ToBytes()
37         {
38             List<byte> inputBytes = new List<byte>();
39
40
41             inputBytes.AddRange(txID.hashBytes); // Input transaction id
42             inputBytes.AddRange(Interop.LEBytes(nInput)); // Input number
43             inputBytes.AddRange(VarInt.EncodeVarInt(scriptSig.LongLength)); // Scriptsig length
44             inputBytes.AddRange(scriptSig); // ScriptSig
45             inputBytes.AddRange(Interop.LEBytes(nSequence)); // Sequence
46
47             return inputBytes;
48         }
49
50                 public override string ToString ()
51                 {
52                         StringBuilder sb = new StringBuilder ();
53                         sb.AppendFormat ("CTxIn(txId={0},n={1},scriptSig={2}", nInput, nInput, scriptSig.ToString());
54
55                         return sb.ToString ();
56                 }
57
58         }
59 }
60