/// <summary>
/// Serialized size
/// </summary>
- public int Size
+ public uint Size
{
get
{
- int nSize = 80 + VarInt.GetEncodedSize(vtx.Length); // CBlockHeader + NumTx
+ uint nSize = 80 + VarInt.GetEncodedSize(vtx.Length); // CBlockHeader + NumTx
foreach (var tx in vtx)
{
nSize += tx.Size;
}
- nSize += VarInt.GetEncodedSize(signature.Length) + signature.Length;
+ nSize += VarInt.GetEncodedSize(signature.Length) + (uint)signature.Length;
return nSize;
}
/// </summary>
/// <param name="nTx">Transaction index.</param>
/// <returns>Offset in bytes from the beginning of block header.</returns>
- public int GetTxOffset(int nTx)
+ public uint 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
+ uint nOffset = 80 + VarInt.GetEncodedSize(vtx.Length); // CBlockHeader + NumTx
for (int i = 0; i < nTx; i++)
{
return false; // unable to get coin age for coinstake
}
- int nTxSize = (tx.nTime > NetInfo.nStakeValidationSwitchTime) ? tx.Size : 0;
ulong nReward = tx.nValueOut - nValueIn;
- ulong nCalculatedReward = CBlock.GetProofOfStakeReward(nCoinAge, cursorBlock.nBits, tx.nTime) - CTransaction.GetMinFee(1, false, CTransaction.MinFeeMode.GMF_BLOCK, nTxSize) + CTransaction.nCent;
+ ulong nCalculatedReward = CBlock.GetProofOfStakeReward(nCoinAge, cursorBlock.nBits, tx.nTime) - tx.GetMinFee(1, false, CTransaction.MinFeeMode.GMF_BLOCK) + CTransaction.nCent;
if (nReward > nCalculatedReward)
{
// get the last item that the scriptSig
// pushes onto the stack:
InstructionQueue wScriptSig = scriptSig.GetInstructionQueue();
- int nScriptSigSize = scriptSig.Size;
+ uint nScriptSigSize = scriptSig.Size;
instruction opcode; // Current instruction
byte[] pushArgs = new byte[0]; // OP_PUSHDATAn argument
/// <summary>
/// Script size
/// </summary>
- public int Size
+ public uint Size
{
- get { return codeBytes.Count; }
+ get { return (uint) codeBytes.Count; }
}
public CScriptID ScriptID
/// One coin = 1000000 satoshis.
/// </summary>
public const ulong nCoin = 1000000;
+
/// <summary>
/// Sanity checking threshold.
/// </summary>
public const ulong nMaxMoney = 2000000000 * nCoin;
+ public const ulong nMinTxFee = nCent / 10;
+ public const ulong nMinRelayTxFee = nCent / 50;
+ public const ulong nMinTxoutAmount = nCent / 100;
+
/// <summary>
/// Maximum transaction size is 250Kb
/// </summary>
/// <summary>
/// Serialized size
/// </summary>
- public int Size
+ public uint Size
{
get
{
- int nSize = 12; // nVersion, nTime, nLockLime
+ uint nSize = 12; // nVersion, nTime, nLockLime
nSize += VarInt.GetEncodedSize(vin.Length);
nSize += VarInt.GetEncodedSize(vout.Length);
throw new NotImplementedException();
}
- internal static ulong GetMinFee(int v1, bool v2, MinFeeMode gMF_BLOCK, int nTxSize)
+ public ulong GetMinFee(uint nBlockSize, bool fAllowFree, MinFeeMode mode)
{
- throw new NotImplementedException();
+ ulong nMinTxFee = CTransaction.nMinTxFee, nMinRelayTxFee = CTransaction.nMinRelayTxFee;
+ uint nBytes = Size;
+
+ if (IsCoinStake)
+ {
+ // Enforce 0.01 as minimum fee for old approach or coinstake
+ nMinTxFee = nCent;
+ nMinRelayTxFee = nCent;
+
+ if (nTime < NetInfo.nStakeValidationSwitchTime)
+ {
+ // Enforce zero size for compatibility with old blocks.
+ nBytes = 0;
+ }
+ }
+
+ // Base fee is either nMinTxFee or nMinRelayTxFee
+ ulong nBaseFee = (mode == MinFeeMode.GMF_RELAY) ? nMinRelayTxFee : nMinTxFee;
+
+ uint nNewBlockSize = nBlockSize + nBytes;
+ ulong nMinFee = (1 + (ulong)nBytes / 1000) * nBaseFee;
+
+ if (fAllowFree)
+ {
+ if (nBlockSize == 1)
+ {
+ // Transactions under 1K are free
+ if (nBytes < 1000)
+ nMinFee = 0;
+ }
+ else
+ {
+ // Free transaction area
+ if (nNewBlockSize < 27000)
+ nMinFee = 0;
+ }
+ }
+
+ // To limit dust spam, require additional MIN_TX_FEE/MIN_RELAY_TX_FEE for
+ // each non empty output which is less than 0.01
+ //
+ // It's safe to ignore empty outputs here, because these inputs are allowed
+ // only for coinbase and coinstake transactions.
+ foreach (var txout in vout)
+ {
+ if (txout.nValue < nCent && !txout.IsEmpty)
+ {
+ nMinFee += nBaseFee;
+ }
+ }
+
+ var nMaxBlockSizeGen = CBlock.nMaxBlockSize / 2;
+
+ // Raise the price as the block approaches full
+ if (nBlockSize != 1 && nNewBlockSize >= nMaxBlockSizeGen / 2)
+ {
+ if (nNewBlockSize >= nMaxBlockSizeGen)
+ {
+ return nMaxMoney;
+ }
+
+ nMinFee *= nMaxBlockSizeGen / (nMaxBlockSizeGen - nNewBlockSize);
+ }
+
+ if (!MoneyRange(nMinFee))
+ {
+ nMinFee = nMaxMoney;
+ }
+
+ return nMinFee;
}
}
}
/// <summary>
/// Serialized size
/// </summary>
- 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;
/// <summary>
/// Serialized size
/// </summary>
- public int Size
+ public uint Size
{
get
{
{
reader.Seek(nBlockPos + nTxOffset, SeekOrigin.Begin); // Seek to transaction offset
- if (nTxSize != reader.Read(buffer, 0, nTxSize))
+ if (nTxSize != reader.Read(buffer, 0, (int)nTxSize))
{
return false;
}
/// Transaction size accessor
/// </summary>
[Ignore]
- public int nTxSize
+ public uint nTxSize
{
- get { return (int)VarInt.DecodeVarInt(TxSize); }
+ get { return (uint)VarInt.DecodeVarInt(TxSize); }
private set { TxSize = VarInt.EncodeVarInt(value); }
}
return EncodeVarInt((ulong)n);
}
- public static int GetEncodedSize(long n)
+ public static uint GetEncodedSize(long n)
{
if (n <= 0xfc)
{