Added getcoinsupply to rpc wallet calls

This commit is contained in:
Andre Jochems
2015-11-23 15:48:52 +01:00
parent fe5ec6cb5b
commit 93b1e17402
6 changed files with 76 additions and 15 deletions

View File

@@ -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<std::stri
if (strMethod == "importprivkey" && n > 2) ConvertTo<bool>(params[2]);
if (strMethod == "verifychain" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "verifychain" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "getcoinsupply" && n > 0) ConvertTo<boost::int64_t>(params[0], true);
if (strMethod == "getcoinsupply" && n > 1) ConvertTo<bool>(params[1], true);
return params;
}

View File

@@ -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

View File

@@ -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;

View File

@@ -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);

View File

@@ -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 \

View File

@@ -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);
}