diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 0bc8500..a4ac78f 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -265,6 +265,7 @@ static const CRPCCommand vRPCCommands[] = { "lockunspent", &lockunspent, false, false, true }, { "listlockunspent", &listlockunspent, false, false, true }, { "verifychain", &verifychain, true, false, false }, + { "getcoinsupply", &getcoinsupply, true, false, false }, }; CRPCTable::CRPCTable() @@ -1194,6 +1195,8 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 2) ConvertTo(params[2]); if (strMethod == "verifychain" && n > 0) ConvertTo(params[0]); if (strMethod == "verifychain" && n > 1) ConvertTo(params[1]); + if (strMethod == "getcoinsupply" && n > 0) ConvertTo(params[0], true); + if (strMethod == "getcoinsupply" && n > 1) ConvertTo(params[1], true); return params; } diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index bea7712..b7a2bbc 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -206,4 +206,6 @@ extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getcoinsupply(const json_spirit::Array& params, bool fHelp); + #endif diff --git a/src/main.cpp b/src/main.cpp index 147cc78..553d005 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1124,6 +1124,47 @@ int64 static GetBlockValue(int nHeight, int64 nFees) return nSubsidy + nFees; } +int64 GetTotalCoinSupply(int nHeight, bool noCheckpoints) +{ + int64 totalSupply = 0; + int startBlock = 1; + if ( !noCheckpoints ) { + // Reduce the amount of calculations by specifying total checkpoints + int heights[] = { + 100000, 200000, 300000, 400000, 500000, + 600000, 700000, 800000, 900000, 1000000, + 1100000 + }; + int64 supplies[] = { + 482721500000000, 982721500000000, 1482721500000000, 1982721500000000, 2482721500000000, + 2882721500000000, 2982721500000000, 3082721500000000, 3182721500000000, 3282721500000000, + 3382721500000000 + }; + if (nHeight>=1 ) { + int numHeights = (int)(sizeof(heights)/sizeof(heights[0])); +// int numSupplies = (int)(sizeof(supplies)/sizeof(supplies[0])); +// if (nHeight>heights[numHeights-1]) { +// nHeight = heights[numHeights-1]; +// } + for (int i=(numHeights-1); i>=0; i--) { + if ( heights[i] <= nHeight ) { + if (i>=0) { + totalSupply = supplies[i]; + startBlock = heights[i] + 1; + break; + } + } + } + } + } + if ( nHeight>=1 ) { + for (int i = startBlock; i <= nHeight; i++) { + totalSupply += GetBlockValue( i, 0 ); + } + } + return totalSupply; +} + static const int64 nTargetTimespan = 0.25 * 24 * 60 * 60; // CasinoCoin: 0.25 day / 6 hours static const int64 nTargetSpacing = 1 * 30; // CasinoCoin: 30 seconds static const int64 nInterval = nTargetTimespan / nTargetSpacing; diff --git a/src/main.h b/src/main.h index 72c320b..32fd37e 100644 --- a/src/main.h +++ b/src/main.h @@ -191,12 +191,8 @@ CBlockIndex * InsertBlockIndex(uint256 hash); bool VerifySignature(const CCoins& txFrom, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType); /** Abort with a message */ bool AbortNode(const std::string &msg); - - - - - - +/** Get total coin supply for block height */ +int64 GetTotalCoinSupply(int nHeight, bool noCheckpoints); diff --git a/src/makefile.mingw b/src/makefile.mingw index 0d468ee..34b492e 100644 --- a/src/makefile.mingw +++ b/src/makefile.mingw @@ -21,21 +21,21 @@ USE_UPNP:=- USE_IPV6:=1 DEPSDIR?=/usr/local -BOOST_SUFFIX?=-mgw46-mt-s-1_53 +BOOST_SUFFIX?=-mgw49-mt-s-1_55 INCLUDEPATHS= \ -I"$(CURDIR)" \ - -I"E:\crypto\deps\boost_1_53_0" \ - -I"E:\crypto\deps\db-4.8.30.NC\build_unix" \ - -I"E:\crypto\deps\openssl-1.0.1b\include" \ - -I"E:\crypto\deps\qrencode-3.4.3" + -I"C:\deps\boost_1_55_0" \ + -I"C:\deps\db-4.8.30.NC\build_unix" \ + -I"C:\deps\openssl-1.0.1p\include" \ + -I"C:\deps\qrencode-3.4.3" LIBPATHS= \ -L"$(CURDIR)/leveldb" \ - -L"E:\crypto\deps\boost_1_53_0\stage\lib" \ - -L"E:\crypto\deps\db-4.8.30.NC\build_unix" \ - -L"E:\crypto\deps\openssl-1.0.1b" \ - -L"E:\crypto\deps\qrencode-3.4.3\.libs" + -L"C:\deps\boost_1_55_0\stage\lib" \ + -L"C:\deps\db-4.8.30.NC\build_unix" \ + -L"C:\deps\openssl-1.0.1p" \ + -L"C:\deps\qrencode-3.4.3\.libs" LIBS= \ -l leveldb \ diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index b184ae7..5748c5d 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -1607,3 +1607,22 @@ Value listlockunspent(const Array& params, bool fHelp) return ret; } +Value getcoinsupply(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 2) + throw runtime_error( + "getcoinsupply [height]\n" + "Returns the total number of issued coins at the current block.\n" + "Pass in [height] to inform about the coin supply for a certain block."); + + int height = nBestHeight; + bool noCheckpoints = false; + if (params.size() > 0) { + height = (int) params[0].get_int(); + if(params.size() > 1){ + noCheckpoints = (bool) params[1].get_bool(); + } + } + int64 coinSupply = GetTotalCoinSupply(height,noCheckpoints); + return ValueFromAmount(coinSupply); +}