Append big-endian value with zeros if its size is less than used by specific data...
authorCryptoManiac <balthazar@yandex.ru>
Mon, 24 Aug 2015 04:08:28 +0000 (07:08 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Mon, 24 Aug 2015 04:08:28 +0000 (07:08 +0300)
Novacoin/Interop.cs
NovacoinTest/Program.cs

index 9f1b425..545e361 100644 (file)
@@ -98,6 +98,10 @@ namespace Novacoin
 
         public static ushort BEBytesToUInt16(byte[] bytes)
         {
+            if (bytes.Length < sizeof(ushort))
+            {
+                Array.Resize(ref bytes, sizeof(ushort));
+            }
             if (bytes.Length != sizeof(ushort))
             {
                 throw new InteropException("Array size doesn't match the ushort data type.");
@@ -110,7 +114,11 @@ namespace Novacoin
 
         public static uint BEBytesToUInt32(byte[] bytes)
         {
-            if (bytes.Length != sizeof(uint))
+            if (bytes.Length < sizeof(uint))
+            {
+                Array.Resize(ref bytes, sizeof(uint));
+            }
+            else if (bytes.Length != sizeof(uint))
             {
                 throw new InteropException("Array size doesn't match the uint data type.");
             }
@@ -122,7 +130,11 @@ namespace Novacoin
 
         public static ulong BEBytesToUInt64(byte[] bytes)
         {
-            if (bytes.Length != sizeof(ulong))
+            if (bytes.Length < sizeof(ulong))
+            {
+                Array.Resize(ref bytes, sizeof(ulong));
+            }
+            else if (bytes.Length != sizeof(ulong))
             {
                 throw new InteropException("Array size doesn't match the ulong data type.");
             }
index 0fc0176..9dbb5c5 100644 (file)
@@ -207,6 +207,8 @@ namespace NovacoinTest
 
             Console.WriteLine("--- Pay-to-ScriptHash test ---");
 
+            // TODO: this test doesn't pass correctly, something wrong here.
+
             var txFrom = new CTransaction(Interop.HexToArray("010000009c2011520173dc34b7fba54bcc9bd6e08e5b112fa69320879b7e43cb4f4f1992a14571a43c140000006a473044022031966a63cbf90d4f8aea72c14a4d6762446b4985963f537ca5c3ddf5a110a7d702205e49f2fee16a4cf8da1ab26ddd819fb127d00b63409878a989b3b86d41d88e250121023842ed96bb829f62559dca2c94fbd146e76597695f3f967cb789216c7fa5adc3ffffffff02ec36f910000000001976a9140fa4d848a8faa1097a3f186ce5edcaed5ee260ee88ac20a107000000000017a91482cc61dbc6840b36e8ed42c6e9c16425a3bad3508700000000"));
             var txToP2SH = new CTransaction(Interop.HexToArray("010000004c23115201d33e0feda63734135abcae51dd91a7d905b335ba0da1ac02cc02680c2d33096501000000dc00493046022100d449e5c7bd81db06f47546538b18d92092b0cb0210f549022db3880d569ab34202210083f7f93ed9f30c44bfb19541c4cccfb54e1c7004611417f9cb785e0def1a6ff90148304502207c44b870abfb35f58cbe48283010417d009101100bd18ba491b9c9783b822eb40221009aa4d966b7ef6dec66cc56f53fc352b087761bd1807b05c01897a74697cb31f9014752210205be3a707f5ff2a547a00466b729454ef052c3e83029f21f39d1052e1441ac74210373c1aee17cfd9fda5df7179a105236c18ab79fab8050ebc312fc95d580c209d452aeffffffff01107a0700000000001976a91420d9eab07eb7d1a0b610166009194a8d3d6eb2fd88ac00000000"));