From 45e1fafb7ee2f8024000bf470367849a5eb78261 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Tue, 8 Sep 2015 00:47:13 +0300 Subject: [PATCH] GetCoinAge --- Novacoin/CTransaction.cs | 52 ++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 50 insertions(+), 2 deletions(-) diff --git a/Novacoin/CTransaction.cs b/Novacoin/CTransaction.cs index 3ebde5f..e0630aa 100644 --- a/Novacoin/CTransaction.cs +++ b/Novacoin/CTransaction.cs @@ -557,9 +557,57 @@ namespace Novacoin return new CTxOut(outItem.nValue, outItem.scriptPubKey); } - internal bool GetCoinAge(ref Dictionary inputs, out ulong nCoinAge) + /// + /// Calculate coin*age. + /// + /// Note, only those coins meeting minimum age requirement counts. + /// + /// Inputs set. + /// Coin age calculation result. + /// Result + public bool GetCoinAge(ref Dictionary inputs, out ulong 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 nTime) + { + continue; // only count coins meeting min age requirement + } + + ulong nValueIn = input.nValue; + bnCentSecond += new BigInteger(nValueIn) * (nTime - merkleItem.nTime) / nCent; + } + + BigInteger bnCoinDay = bnCentSecond * nCent / nCoin / (24 * 60 * 60); + nCoinAge = (ulong)bnCoinDay; + + return true; } public ulong GetMinFee(uint nBlockSize, bool fAllowFree, MinFeeMode mode) -- 1.7.1