X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=Novacoin%2FCTxIn.cs;h=44c21ad59b796741432a49713e7fd336645092b0;hb=f1d2e217ae6e24a84edfa98ca3471a8a836ecaa7;hp=a33606a6b95efbacde8242db1bf59434070dd76e;hpb=0279648337efe9bbe32b5204e247529243805484;p=NovacoinLibrary.git diff --git a/Novacoin/CTxIn.cs b/Novacoin/CTxIn.cs index a33606a..44c21ad 100644 --- a/Novacoin/CTxIn.cs +++ b/Novacoin/CTxIn.cs @@ -22,10 +22,28 @@ using System.Collections.Generic; namespace Novacoin { - /// - /// Transaction input. - /// - public class CTxIn + [Serializable] + public class TxInConstructorException : Exception + { + public TxInConstructorException() + { + } + + public TxInConstructorException(string message) + : base(message) + { + } + + public TxInConstructorException(string message, Exception inner) + : base(message, inner) + { + } + } + + /// + /// Transaction input. + /// + public class CTxIn { /// /// Previous input data @@ -69,21 +87,42 @@ namespace Novacoin /// Inputs array public static CTxIn[] ReadTxInList(ref ByteQueue wBytes) { - // Get amount - int nInputs = (int)wBytes.GetVarInt(); - var vin = new CTxIn[nInputs]; - - for (int nIndex = 0; nIndex < nInputs; nIndex++) + try { - // 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); + // Get amount + int nInputs = (int)wBytes.GetVarInt(); + 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); + } + + // Return inputs array + return vin; } + catch (Exception e) + { + throw new TxInConstructorException("Desirealization failed.", e); + } + } - // Return inputs array - return vin; + /// + /// Serialized size + /// + public int Size + { + get { + int nSize = 40; // COutPoint, nSequence + nSize += VarInt.GetEncodedSize(scriptSig.Size); + nSize += scriptSig.Size; + + return nSize; + } } /// @@ -138,4 +177,3 @@ namespace Novacoin } } -