/// <summary>
/// One cent = 10000 satoshis.
/// </summary>
- public const ulong nCent = 10000;
+ public const long nCent = 10000;
/// <summary>
/// One coin = 1000000 satoshis.
/// </summary>
- public const ulong nCoin = 1000000;
+ public const long nCoin = 1000000;
/// <summary>
/// Sanity checking threshold.
/// </summary>
- public const ulong nMaxMoney = 2000000000 * nCoin;
+ public const long nMaxMoney = 2000000000 * nCoin;
- public const ulong nMinTxFee = nCent / 10;
- public const ulong nMinRelayTxFee = nCent / 50;
- public const ulong nMinTxoutAmount = nCent / 100;
+ public const long nMinTxFee = nCent / 10;
+ public const long nMinRelayTxFee = nCent / 50;
+ public const long nMinTxoutAmount = nCent / 100;
/// <summary>
/// Maximum transaction size is 250Kb
return true;
}
- TxOutItem txOutCursor = null;
for (int i = 0; i < vin.Length; i++)
{
var outpoint = vin[i].prevout;
- if (!CBlockStore.Instance.GetTxOutCursor(outpoint, ref txOutCursor))
+ TxOutItem txOutCursor;
+ if (!CBlockStore.Instance.GetTxOutCursor(outpoint, out txOutCursor))
return false;
if (!ScriptCode.VerifyScript(vin[i].scriptSig, txOutCursor.scriptPubKey, this, i, (int)scriptflag.SCRIPT_VERIFY_P2SH, 0))
get
{
uint nSigOps = 0;
- foreach (var txin in vin)
+
+ if (!IsCoinBase)
{
- nSigOps += txin.scriptSig.GetSigOpCount(false);
+ // http://lists.linuxfoundation.org/pipermail/bitcoin-dev/2012-July/001718.html
+
+ foreach (var txin in vin)
+ {
+ nSigOps += txin.scriptSig.GetSigOpCount(false);
+ }
}
+
foreach (var txout in vout)
{
nSigOps += txout.scriptPubKey.GetSigOpCount(false);
}
// Check for empty or overflow output values
- ulong nValueOut = 0;
+ long nValueOut = 0;
for (int i = 0; i < vout.Length; i++)
{
CTxOut txout = vout[i];
{
// Fill outputs array
vout[nCurrentOutput] = new CTxOut();
- vout[nCurrentOutput].nValue = reader.ReadUInt64();
+ vout[nCurrentOutput].nValue = reader.ReadInt64();
int nScriptPKLen = (int)VarInt.ReadVarInt(ref reader);
vout[nCurrentOutput].scriptPubKey = new CScript(reader.ReadBytes(nScriptPKLen));
/// <summary>
/// Amount of novacoins spent by this transaction.
/// </summary>
- public ulong nValueOut
+ public long nValueOut
{
get
{
- ulong nValueOut = 0;
+ long nValueOut = 0;
foreach (var txout in vout)
{
nValueOut += txout.nValue;
return sb.ToString();
}
- public static bool MoneyRange(ulong nValue) { return (nValue <= nMaxMoney); }
+ public static bool MoneyRange(long nValue) { return (nValue <= nMaxMoney); }
/// <summary>
/// Get total sigops.
/// </summary>
/// <param name="inputs">Reference to innputs map.</param>
/// <returns>Sum of inputs.</returns>
- public ulong GetValueIn(ref Dictionary<COutPoint, TxOutItem> inputs)
+ public long GetValueIn(ref Dictionary<COutPoint, TxOutItem> inputs)
{
if (IsCoinBase)
{
return 0;
}
- ulong nResult = 0;
+ long nResult = 0;
for (int i = 0; i < vin.Length; i++)
{
nResult += GetOutputFor(vin[i], ref inputs).nValue;
return new CTxOut(outItem.nValue, outItem.scriptPubKey);
}
- internal bool GetCoinAge(ref Dictionary<COutPoint, TxOutItem> inputs, out ulong nCoinAge)
+ /// <summary>
+ /// Calculate coin*age.
+ ///
+ /// Note, only those coins meeting minimum age requirement counts.
+ /// </summary>
+ /// <param name="inputs">Inputs set.</param>
+ /// <param name="nCoinAge">Coin age calculation result.</param>
+ /// <returns>Result</returns>
+ public bool GetCoinAge(ref Dictionary<COutPoint, TxOutItem> inputs, out long nCoinAge)
{
- throw new NotImplementedException();
+ BigInteger bnCentSecond = 0; // coin age in the unit of cent-seconds
+ nCoinAge = 0;
+
+ if (IsCoinBase)
+ {
+ // Nothing spent by coinbase, coinage is always zero.
+ return true;
+ }
+
+ for( var i = 0; i<vin.Length; i++)
+ {
+ var prevout = vin[i].prevout;
+ Contract.Assert(inputs.ContainsKey(prevout));
+ var input = inputs[prevout];
+
+ CBlockStoreItem parentBlockCursor;
+ var merkleItem = CBlockStore.Instance.GetMerkleCursor(input, out parentBlockCursor);
+
+ if (merkleItem == null)
+ {
+ return false; // Unable to find merkle node
+ }
+
+ if (nTime < merkleItem.nTime)
+ {
+ return false; // Transaction timestamp violation
+ }
+
+ if (parentBlockCursor.nTime + StakeModifier.nStakeMinAge > nTime)
+ {
+ continue; // only count coins meeting min age requirement
+ }
+
+ long nValueIn = input.nValue;
+ bnCentSecond += new BigInteger(nValueIn) * (nTime - merkleItem.nTime) / nCent;
+ }
+
+ BigInteger bnCoinDay = bnCentSecond * nCent / nCoin / (24 * 60 * 60);
+ nCoinAge = (long)bnCoinDay;
+
+ return true;
}
- public ulong GetMinFee(uint nBlockSize, bool fAllowFree, MinFeeMode mode)
+ public long GetMinFee(uint nBlockSize, bool fAllowFree, MinFeeMode mode)
{
- ulong nMinTxFee = CTransaction.nMinTxFee, nMinRelayTxFee = CTransaction.nMinRelayTxFee;
+ long nMinTxFee = CTransaction.nMinTxFee, nMinRelayTxFee = CTransaction.nMinRelayTxFee;
uint nBytes = Size;
if (IsCoinStake)
}
// Base fee is either nMinTxFee or nMinRelayTxFee
- ulong nBaseFee = (mode == MinFeeMode.GMF_RELAY) ? nMinRelayTxFee : nMinTxFee;
+ long nBaseFee = (mode == MinFeeMode.GMF_RELAY) ? nMinRelayTxFee : nMinTxFee;
uint nNewBlockSize = nBlockSize + nBytes;
- ulong nMinFee = (1 + (ulong)nBytes / 1000) * nBaseFee;
+ long nMinFee = (1 + (long)nBytes / 1000) * nBaseFee;
if (fAllowFree)
{