Transaction script verification, unserealize exceptions
[NovacoinLibrary.git] / Novacoin / ByteQueue.cs
index 11601bb..9752c02 100644 (file)
@@ -40,6 +40,11 @@ namespace Novacoin
         }
     }
 
+    /// <summary>
+    /// Stream of bytes.
+    /// 
+    /// TODO: rewrite using MemoryStream
+    /// </summary>
     public class ByteQueue
     {
         private int _Index;
@@ -79,6 +84,18 @@ namespace Novacoin
             return _Elements[_Index++];
         }
 
+        public bool TryGet(ref byte Element)
+        {
+            if (_Elements.Count <= _Index)
+            {
+                return false;
+            }
+
+            Element = _Elements[_Index++];
+
+            return true;
+        }
+
         public byte GetCurrent()
         {
             return _Elements[_Index];
@@ -94,6 +111,19 @@ namespace Novacoin
             return result;
         }
 
+        public bool TryGet(int nCount, ref byte[] Elements)
+        {
+            if (Count - Index < nCount)
+            {
+                return false;
+            }
+
+            Elements = _Elements.GetRange(_Index, nCount).ToArray();
+            _Index += nCount;
+
+            return true;
+        }
+
         public byte[] GetCurrent(int nCount)
         {
             Contract.Requires<ArgumentException>(Count - Index >= nCount, "nCount is greater than amount of elements.");
@@ -103,6 +133,18 @@ namespace Novacoin
             return result;
         }
 
+        public bool TryGetCurrent(int nCount, ref byte[] Elements)
+        {
+            if (Count - Index < nCount)
+            {
+                return false;
+            }
+
+            Elements = _Elements.GetRange(_Index, nCount).ToArray();
+
+            return true;
+        }
+
         /// <summary>
         /// Current index value
         /// </summary>