X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=Novacoin%2FCTxIn.cs;h=480e1d1b49ee5a93c67e6c7fd088efe89a4c7da9;hb=c4aad1332d39a5bdd66e9e8004932dc99baf44e5;hp=cd205ab3960c0715ceeb1e877ff11f5ecd9d05f1;hpb=5c9959adf8c0173dce35d97042f1b93d593fee0d;p=NovacoinLibrary.git
diff --git a/Novacoin/CTxIn.cs b/Novacoin/CTxIn.cs
index cd205ab..480e1d1 100644
--- a/Novacoin/CTxIn.cs
+++ b/Novacoin/CTxIn.cs
@@ -19,6 +19,7 @@
using System;
using System.Text;
using System.Collections.Generic;
+using System.IO;
namespace Novacoin
{
@@ -83,23 +84,23 @@ namespace Novacoin
///
/// Read vin list from byte sequence.
///
- /// Reference to byte sequence
+ /// Reference to binary reader
/// Inputs array
- public static CTxIn[] ReadTxInList(ref ByteQueue wBytes)
+ internal static CTxIn[] ReadTxInList(ref BinaryReader reader)
{
try
{
// Get amount
- int nInputs = (int)wBytes.GetVarInt();
+ int nInputs = (int)VarInt.ReadVarInt(ref reader);
var vin = new CTxIn[nInputs];
for (int nIndex = 0; nIndex < nInputs; nIndex++)
{
// Fill inputs array
vin[nIndex] = new CTxIn();
- vin[nIndex].prevout = new COutPoint(wBytes.Get(36));
- vin[nIndex].scriptSig = new CScript(wBytes.Get((int)wBytes.GetVarInt()));
- vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.Get(4), 0);
+ vin[nIndex].prevout = new COutPoint(reader.ReadBytes(36));
+ vin[nIndex].scriptSig = new CScript(reader.ReadBytes((int)VarInt.ReadVarInt(ref reader)));
+ vin[nIndex].nSequence = reader.ReadUInt32();
}
// Return inputs array
@@ -107,17 +108,17 @@ namespace Novacoin
}
catch (Exception e)
{
- throw new TxInConstructorException("Deserealization failed.", e);
+ throw new TxInConstructorException("Desirealization failed.", e);
}
}
///
/// Serialized size
///
- public int Size
+ public uint Size
{
get {
- int nSize = 40; // COutPoint, nSequence
+ uint nSize = 40; // COutPoint, nSequence
nSize += VarInt.GetEncodedSize(scriptSig.Size);
nSize += scriptSig.Size;
@@ -131,19 +132,19 @@ namespace Novacoin
/// Byte sequence.
public static implicit operator byte[] (CTxIn input)
{
- var inputBytes = new List();
+ var stream = new MemoryStream();
+ var writer = new BinaryWriter(stream);
- inputBytes.AddRange((byte[])input.prevout); // prevout
+ writer.Write(input.prevout); // prevout
+ writer.Write(VarInt.EncodeVarInt(input.scriptSig.Size)); // scriptSig length
+ writer.Write(input.scriptSig); // scriptSig
+ writer.Write(input.nSequence); // nSequence
- var s = (byte[])input.scriptSig;
- inputBytes.AddRange(VarInt.EncodeVarInt(s.Length)); // scriptSig length
- inputBytes.AddRange(s); // scriptSig
- inputBytes.AddRange(BitConverter.GetBytes(input.nSequence)); // Sequence
-
- return inputBytes.ToArray();
+ var inputBytes = stream.ToArray();
+ writer.Close();
+ return inputBytes;
}
-
public bool IsFinal
{
get { return (nSequence == uint.MaxValue); }
@@ -161,7 +162,7 @@ namespace Novacoin
}
else
{
- sb.AppendFormat(", scriptsig={0}", scriptSig.ToString());
+ sb.AppendFormat(", scriptsig={0}", scriptSig);
}
if (nSequence != uint.MaxValue)