From: CryptoManiac Date: Mon, 7 Sep 2015 21:47:13 +0000 (+0300) Subject: GetCoinAge X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=45e1fafb7ee2f8024000bf470367849a5eb78261 GetCoinAge --- 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)