/// <summary>
/// Version of transaction schema.
/// </summary>
- public uint nVersion = 1;
+ public uint nVersion;
/// <summary>
/// Transaction timestamp.
/// </summary>
- public uint nTime = 0;
+ public uint nTime;
/// <summary>
/// Array of transaction inputs
/// <summary>
/// Block height or timestamp when transaction is final
/// </summary>
- public uint nLockTime = 0;
+ public uint nLockTime;
/// <summary>
/// Initialize an empty instance
// Initialize empty input and output arrays. Please note that such
// configuration is not valid for real transaction, you have to supply
// at least one input and one output.
+ nVersion = 1;
+ nTime = 0;
vin = new CTxIn[0];
vout = new CTxOut[0];
+ nLockTime = 0;
}
/// <summary>
nVersion = BitConverter.ToUInt32(wBytes.Get(4), 0);
nTime = BitConverter.ToUInt32(wBytes.Get(4), 0);
- int nInputs = (int)(int)wBytes.GetVarInt();
+ int nInputs = (int)wBytes.GetVarInt();
vin = new CTxIn[nInputs];
for (int nCurrentInput = 0; nCurrentInput < nInputs; nCurrentInput++)
{
// Fill outputs array
vout[nCurrentOutput] = new CTxOut();
- vout[nCurrentOutput].nValue = BitConverter.ToInt64(wBytes.Get(8), 0);
+ vout[nCurrentOutput].nValue = BitConverter.ToUInt64(wBytes.Get(8), 0);
int nScriptPKLen = (int)wBytes.GetVarInt();
vout[nCurrentOutput].scriptPubKey = new CScript(wBytes.Get(nScriptPKLen));
}
/// <summary>
+ /// Serialized size
+ /// </summary>
+ public int Size
+ {
+ get
+ {
+ int nSize = 12; // nVersion, nTime, nLockLime
+
+ nSize += VarInt.GetEncodedSize(vin.Length);
+ nSize += VarInt.GetEncodedSize(vout.Length);
+
+ foreach (var input in vin)
+ {
+ nSize += input.Size;
+ }
+
+ foreach (var output in vout)
+ {
+ nSize += output.Size;
+ }
+
+ return nSize;
+ }
+ }
+
+ /// <summary>
/// Read transactions array which is encoded in the block body.
/// </summary>
/// <param name="wTxBytes">Bytes sequence</param>