Use CScript for vin and vout,
authorCryptoManiac <balthazar@yandex.ru>
Fri, 21 Aug 2015 00:18:11 +0000 (03:18 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Fri, 21 Aug 2015 00:18:11 +0000 (03:18 +0300)
Novacoin/CBlock.cs
Novacoin/CTransaction.cs
Novacoin/CTxIn.cs
Novacoin/CTxOut.cs

index 46ca9d5..17ffe6a 100644 (file)
@@ -28,7 +28,7 @@ namespace Novacoin
         /// Parse byte sequence and initialize new block instance
         /// </summary>
         /// <param name="blockBytes"></param>
-               public CBlock (List<byte> blockBytes)
+               public CBlock (IList<byte> blockBytes)
                {
             header = new CBlockHeader();
 
index 4467ebe..89c4b11 100644 (file)
@@ -71,7 +71,7 @@ namespace Novacoin
         /// <summary>
         /// Parse byte sequence and initialize new instance of CTransaction
         /// </summary>
-        /// <param name="txBytes"></param>
+        /// <param name="txBytes">Byte sequence</param>
                public CTransaction (IList<byte> txBytes)
                {
             WrappedList<byte> wBytes = new WrappedList<byte>(txBytes);
@@ -88,9 +88,11 @@ namespace Novacoin
                 vin[nCurrentInput] = new CTxIn();
 
                 vin[nCurrentInput].txID = new Hash256(wBytes.GetItems(32));
-                vin[nCurrentInput].n = BitConverter.ToUInt32(wBytes.GetItems(4),0);
-                vin[nCurrentInput].scriptSig = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
-                vin[nCurrentInput].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4),0);
+                vin[nCurrentInput].n = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
+
+                int nScriptSigLen = (int)VarInt.ReadVarInt(ref wBytes);
+                vin[nCurrentInput].scriptSig = new CScript(wBytes.GetItems(nScriptSigLen));
+                vin[nCurrentInput].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
             }
 
             int nOutputs = (int)VarInt.ReadVarInt(ref wBytes);
@@ -100,8 +102,10 @@ namespace Novacoin
             {
                 // Fill outputs array
                 vout[nCurrentOutput] = new CTxOut();
-                vout[nCurrentOutput].nValue = BitConverter.ToUInt64(wBytes.GetItems(8),0);
-                vout[nCurrentOutput].scriptPubKey = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
+                vout[nCurrentOutput].nValue = BitConverter.ToUInt64(wBytes.GetItems(8), 0);
+
+                int nScriptPKLen = (int)VarInt.ReadVarInt(ref wBytes);
+                vout[nCurrentOutput].scriptPubKey = new CScript(wBytes.GetItems(nScriptPKLen));
             }
 
             nLockTime = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
index 7f6aeee..59ddc40 100644 (file)
@@ -22,7 +22,7 @@ namespace Novacoin
                /// <summary>
                /// First half of script, signatures for the scriptPubKey
                /// </summary>
-        public byte[] scriptSig;
+        public CScript scriptSig;
 
                /// <summary>
                /// Transaction variant number, irrelevant if nLockTime isn't specified. Its value is 0xffffffff by default.
@@ -68,7 +68,7 @@ namespace Novacoin
 
                 vin[nIndex].txID = new Hash256(wBytes.GetItems(32));
                 vin[nIndex].n = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
-                vin[nIndex].scriptSig = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
+                vin[nIndex].scriptSig = new CScript(wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes)));
                 vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
             }
 
@@ -88,8 +88,11 @@ namespace Novacoin
 
                 inputBytes.AddRange(txID.hashBytes); // Input transaction id
                 inputBytes.AddRange(BitConverter.GetBytes(n)); // Output number
-                inputBytes.AddRange(VarInt.EncodeVarInt(scriptSig.LongLength)); // scriptSig length
-                inputBytes.AddRange(scriptSig); // scriptSig
+
+                List<byte> s = new List<byte>(scriptSig.Bytes);
+
+                inputBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptSig length
+                inputBytes.AddRange(s); // scriptSig
                 inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence
 
                 return inputBytes;
@@ -107,11 +110,11 @@ namespace Novacoin
 
             if (IsCoinBase)
             {
-                sb.AppendFormat("CTxIn(txId={0}, coinbase={2}, nSequence={3})", txID.ToString(), n, Interop.ToHex(scriptSig), nSequence);
+                sb.AppendFormat("CTxIn(txId={0}, coinbase={2}, nSequence={3})", txID.ToString(), n, Interop.ToHex(scriptSig.Bytes), nSequence);
             }
             else
             {
-                sb.AppendFormat("CTxIn(txId={0}, n={1}, scriptSig={2}, nSequence={3})", txID.ToString(), n, (new CScript(scriptSig)).ToString(), nSequence);
+                sb.AppendFormat("CTxIn(txId={0}, n={1}, scriptSig={2}, nSequence={3})", txID.ToString(), n, scriptSig.ToString(), nSequence);
             }
 
                        return sb.ToString ();
index 9b40a8f..51ae16f 100644 (file)
@@ -17,7 +17,7 @@ namespace Novacoin
                /// <summary>
                /// Second half of script which contains spending instructions.
                /// </summary>
-        public byte[] scriptPubKey;
+        public CScript scriptPubKey;
 
         /// <summary>
         /// Initialize new CTxOut instance as a copy of another instance.
@@ -51,7 +51,9 @@ namespace Novacoin
                 // Fill outputs array
                 vout[nIndex] = new CTxOut();
                 vout[nIndex].nValue = BitConverter.ToUInt32(wBytes.GetItems(8), 0);
-                vout[nIndex].scriptPubKey = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
+
+                int nScriptPKLen = (int)VarInt.ReadVarInt(ref wBytes);
+                vout[nIndex].scriptPubKey = new CScript(wBytes.GetItems(nScriptPKLen));
             }
 
             return vout;
@@ -68,8 +70,11 @@ namespace Novacoin
                 List<byte> resultBytes = new List<byte>();
 
                 resultBytes.AddRange(BitConverter.GetBytes(nValue)); // txout value
-                resultBytes.AddRange(VarInt.EncodeVarInt(scriptPubKey.LongLength)); // scriptPubKey length
-                resultBytes.AddRange(scriptPubKey); // scriptPubKey
+
+                List<byte> s = new List<byte>(scriptPubKey.Bytes);
+
+                resultBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptPubKey length
+                resultBytes.AddRange(s); // scriptPubKey
 
                 return resultBytes;
             }
@@ -78,7 +83,7 @@ namespace Novacoin
                public override string ToString ()
                {
                        StringBuilder sb = new StringBuilder ();
-                       sb.AppendFormat ("CTxOut(nValue={0}, scriptPubKey={1})", nValue, (new CScript(scriptPubKey)).ToString());
+                       sb.AppendFormat ("CTxOut(nValue={0}, scriptPubKey={1})", nValue, scriptPubKey.ToString());
 
                        return sb.ToString ();
                }