Preliminary block checkings.
[NovacoinLibrary.git] / Novacoin / CKeyStore.cs
index 8d6ab98..8eb9e9d 100644 (file)
@@ -21,6 +21,7 @@ using SQLite.Net;
 using SQLite.Net.Attributes;
 using SQLite.Net.Interop;
 using SQLite.Net.Platform.Generic;
+using System;
 using System.IO;
 using System.Linq;
 
@@ -68,7 +69,7 @@ namespace Novacoin
         /// Item creation time
         /// </summary>
         [Indexed]
-        public int nTime { get; set; }
+        public uint nTime { get; set; }
     }
 
     /// <summary>
@@ -106,11 +107,11 @@ namespace Novacoin
     /// <summary>
     /// Key storage
     /// </summary>
-    public class CKeyStore
+    public class CKeyStore : IDisposable
     {
+        private bool disposed = false;
         private object LockObj = new object();
         private SQLiteConnection dbConn = null;
-
         private int nKeyPoolSize = 100;
 
         /// <summary>
@@ -139,13 +140,35 @@ namespace Novacoin
 
         ~CKeyStore()
         {
-            if (dbConn != null)
+            Dispose(false);
+        }
+
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        protected virtual void Dispose(bool disposing)
+        {
+            if (!disposed)
             {
-                dbConn.Close();
-                dbConn = null;
+                if (disposing)
+                {
+                    // Free other state (managed objects).
+                }
+
+                if (dbConn != null)
+                {
+                    dbConn.Close();
+                    dbConn = null;
+                }
+
+                disposed = true;
             }
         }
 
+
         /// <summary>
         /// Generate keys and insert them to key store.
         /// </summary>