TrimArray() simplification
[NovacoinLibrary.git] / Novacoin / Checkpoints.cs
1 using System;
2
3 namespace Novacoin
4 {
5     public static class HashCheckpoints
6     {
7         private static Tuple<uint, uint256, uint>[] checkpoints = new Tuple<uint, uint256, uint>[]
8             {
9                 new Tuple<uint, uint256, uint>(0, NetInfo.nHashGenesisBlock, 1360105017),
10                 new Tuple<uint, uint256, uint>(200000, new uint256("0000000000029f8bbf66e6ea6f3e5db55009404aae0fe395a53dd33142b2bff2"), 1441127233),
11             };
12
13         /// <summary>
14         /// Last checkpoint height.
15         /// </summary>
16         public static uint TotalBlocksEstimate { get { return checkpoints[checkpoints.Length - 1].Item1; } }
17
18         /// <summary>
19         /// Last checkpoint timestamp.
20         /// </summary>
21         public static uint LastCheckpointTime { get { return checkpoints[checkpoints.Length - 1].Item3; } }
22
23         /// <summary>
24         /// Block hash verification.
25         /// </summary>
26         /// <param name="nHeight">Block height.</param>
27         /// <param name="nBlockHash">Block hash.</param>
28         /// <returns></returns>
29         public static bool Verify(uint nHeight, uint256 nBlockHash)
30         {
31             foreach (var checkpoint in checkpoints)
32             {
33                 if (checkpoint.Item1 == nHeight)
34                 {
35                     return nBlockHash == checkpoint.Item2;
36                 }
37             }
38
39             return true;
40         }
41     }
42
43     public static class ModifierCheckpoints
44     {
45         /// <summary>
46         /// Stake modifier checkpoints
47         /// </summary>
48         private static Tuple<uint, uint>[] modifierCheckpoints = new Tuple<uint, uint>[]
49             {
50                 new Tuple<uint, uint>( 0, 0x0e00670bu ),
51                 new Tuple<uint, uint>(200000, 0x01ec1503u )
52             };
53
54         /// <summary>
55         /// Check stake modifier checkpoints.
56         /// </summary>
57         /// <param name="nHeight">Block height.</param>
58         /// <param name="nStakeModifierChecksum">Modifier checksum value.</param>
59         /// <returns>Result</returns>
60         public static bool Verify(uint nHeight, uint nStakeModifierChecksum)
61         {
62             foreach (var checkpoint in modifierCheckpoints)
63             {
64                 if (checkpoint.Item1 == nHeight)
65                 {
66                     return checkpoint.Item2 == nStakeModifierChecksum;
67                 }
68             }
69
70             return true;
71         }
72     }
73 }