Add license header.
[NovacoinLibrary.git] / Novacoin / COutPoint.cs
1 \feff/**
2  *  Novacoin classes library
3  *  Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com)
4
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU Affero General Public License as
7  *  published by the Free Software Foundation, either version 3 of the
8  *  License, or (at your option) any later version.
9
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Affero General Public License for more details.
14
15  *  You should have received a copy of the GNU Affero General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 using System;
20 using System.Collections.Generic;
21 using System.Linq;
22 using System.Text;
23
24 namespace Novacoin
25 {
26     public class COutPoint
27     {
28         /// <summary>
29         /// Hash of parent transaction.
30         /// </summary>
31         public Hash256 hash;
32
33         /// <summary>
34         /// Parent input number.
35         /// </summary>
36         public uint n;
37
38         public COutPoint()
39         {
40             hash = new Hash256();
41             n = uint.MaxValue;
42         }
43
44         public COutPoint(Hash256 hashIn, uint nIn)
45         {
46             hash = hashIn;
47             n = nIn;
48         }
49
50         public COutPoint(COutPoint o)
51         {
52             hash = new Hash256(o.hash);
53             n = o.n;
54         }
55
56         public COutPoint(IEnumerable<byte> bytes)
57         {
58             hash = new Hash256(bytes);
59             n = BitConverter.ToUInt32(bytes.ToArray(), 32);
60         }
61
62         public bool IsNull
63         {
64             get { return hash.IsZero && n == uint.MaxValue; }
65         }
66
67         public IList<byte> Bytes
68         {
69             get
70             {
71                 List<byte> r = new List<byte>();
72                 r.AddRange(hash.hashBytes);
73                 r.AddRange(BitConverter.GetBytes(n));
74
75                 return r;
76             }
77         }
78
79         public override string ToString()
80         {
81             StringBuilder sb = new StringBuilder();
82             sb.AppendFormat("COutPoint({0}, {1})", hash.ToString(), n);
83
84             return sb.ToString();
85         }
86
87         
88     }
89
90 }