using System.Text;
using System.Collections.Generic;
using System.Security.Cryptography;
+using System.Diagnostics.Contracts;
namespace Novacoin
{
}
/// <summary>
+ /// Serialized size
+ /// </summary>
+ public int Size
+ {
+ get
+ {
+ int nSize = 80 + VarInt.GetEncodedSize(vtx.Length); // CBlockHeader + NumTx
+
+ foreach (var tx in vtx)
+ {
+ nSize += tx.Size;
+ }
+
+ nSize += VarInt.GetEncodedSize(signature.Length) + signature.Length;
+
+ return nSize;
+ }
+ }
+
+ /// <summary>
+ /// Get transaction offset inside block.
+ /// </summary>
+ /// <param name="nTx">Transaction index.</param>
+ /// <returns>Offset in bytes from the beginning of block header.</returns>
+ public int GetTxOffset(int nTx)
+ {
+ Contract.Requires<ArgumentException>(nTx >= 0 && nTx < vtx.Length, "Transaction index you've specified is incorrect.");
+
+ int nOffset = 80 + VarInt.GetEncodedSize(vtx.Length); // CBlockHeader + NumTx
+
+ for (int i = 0; i < nTx; i++)
+ {
+ nOffset += vtx[nTx].Size;
+ }
+
+ return nOffset;
+ }
+
+ /// <summary>
/// Merkle root
/// </summary>
public Hash256 hashMerkleRoot
/// </summary>
public uint n;
+ /// <summary>
+ /// Out reference is always 36 bytes long.
+ /// </summary>
+ public const int Size = 36;
+
public COutPoint()
{
hash = new Hash256();
return script.codeBytes.ToArray();
}
+ /// <summary>
+ /// Script size
+ /// </summary>
+ public int Size
+ {
+ get { return codeBytes.Count; }
+ }
+
public CScriptID ScriptID
{
get { return new CScriptID(Hash160.Compute160(codeBytes.ToArray())); }
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++)
}
/// <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>
}
/// <summary>
+ /// Serialized size
+ /// </summary>
+ public int Size
+ {
+ get {
+ int nSize = 40; // COutPoint, nSequence
+ nSize += VarInt.GetEncodedSize(scriptSig.Size);
+ nSize += scriptSig.Size;
+
+ return nSize;
+ }
+ }
+
+ /// <summary>
/// Get raw bytes representation of our input.
/// </summary>
/// <returns>Byte sequence.</returns>
resultBytes.AddRange(BitConverter.GetBytes(output.nValue)); // txout value
- var s = (byte[])output.scriptPubKey;
+ byte[] s = output.scriptPubKey;
resultBytes.AddRange(VarInt.EncodeVarInt(s.Length)); // scriptPubKey length
resultBytes.AddRange(s); // scriptPubKey
get { return nValue == 0 && scriptPubKey.IsNull; }
}
- public override string ToString ()
+ /// <summary>
+ /// Serialized size
+ /// </summary>
+ public int Size
+ {
+ get
+ {
+ var nScriptSize = scriptPubKey.Size;
+ return 8 + VarInt.GetEncodedSize(nScriptSize) + nScriptSize;
+ }
+ }
+
+ public override string ToString ()
{
var sb = new StringBuilder ();
sb.AppendFormat ("CTxOut(nValue={0}, scriptPubKey={1})", nValue, scriptPubKey.ToString());