mirror of
https://github.com/AskDavis/Casinotest.git
synced 2026-01-01 05:05:57 -08:00
Added getcoinsupply to rpc wallet calls
This commit is contained in:
@@ -265,6 +265,7 @@ static const CRPCCommand vRPCCommands[] =
|
|||||||
{ "lockunspent", &lockunspent, false, false, true },
|
{ "lockunspent", &lockunspent, false, false, true },
|
||||||
{ "listlockunspent", &listlockunspent, false, false, true },
|
{ "listlockunspent", &listlockunspent, false, false, true },
|
||||||
{ "verifychain", &verifychain, true, false, false },
|
{ "verifychain", &verifychain, true, false, false },
|
||||||
|
{ "getcoinsupply", &getcoinsupply, true, false, false },
|
||||||
};
|
};
|
||||||
|
|
||||||
CRPCTable::CRPCTable()
|
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 == "importprivkey" && n > 2) ConvertTo<bool>(params[2]);
|
||||||
if (strMethod == "verifychain" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
if (strMethod == "verifychain" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
||||||
if (strMethod == "verifychain" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
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;
|
return params;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 gettxout(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value verifychain(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
|
#endif
|
||||||
|
|||||||
41
src/main.cpp
41
src/main.cpp
@@ -1124,6 +1124,47 @@ int64 static GetBlockValue(int nHeight, int64 nFees)
|
|||||||
return nSubsidy + 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 nTargetTimespan = 0.25 * 24 * 60 * 60; // CasinoCoin: 0.25 day / 6 hours
|
||||||
static const int64 nTargetSpacing = 1 * 30; // CasinoCoin: 30 seconds
|
static const int64 nTargetSpacing = 1 * 30; // CasinoCoin: 30 seconds
|
||||||
static const int64 nInterval = nTargetTimespan / nTargetSpacing;
|
static const int64 nInterval = nTargetTimespan / nTargetSpacing;
|
||||||
|
|||||||
@@ -191,12 +191,8 @@ CBlockIndex * InsertBlockIndex(uint256 hash);
|
|||||||
bool VerifySignature(const CCoins& txFrom, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType);
|
bool VerifySignature(const CCoins& txFrom, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType);
|
||||||
/** Abort with a message */
|
/** Abort with a message */
|
||||||
bool AbortNode(const std::string &msg);
|
bool AbortNode(const std::string &msg);
|
||||||
|
/** Get total coin supply for block height */
|
||||||
|
int64 GetTotalCoinSupply(int nHeight, bool noCheckpoints);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,21 +21,21 @@ USE_UPNP:=-
|
|||||||
USE_IPV6:=1
|
USE_IPV6:=1
|
||||||
|
|
||||||
DEPSDIR?=/usr/local
|
DEPSDIR?=/usr/local
|
||||||
BOOST_SUFFIX?=-mgw46-mt-s-1_53
|
BOOST_SUFFIX?=-mgw49-mt-s-1_55
|
||||||
|
|
||||||
INCLUDEPATHS= \
|
INCLUDEPATHS= \
|
||||||
-I"$(CURDIR)" \
|
-I"$(CURDIR)" \
|
||||||
-I"E:\crypto\deps\boost_1_53_0" \
|
-I"C:\deps\boost_1_55_0" \
|
||||||
-I"E:\crypto\deps\db-4.8.30.NC\build_unix" \
|
-I"C:\deps\db-4.8.30.NC\build_unix" \
|
||||||
-I"E:\crypto\deps\openssl-1.0.1b\include" \
|
-I"C:\deps\openssl-1.0.1p\include" \
|
||||||
-I"E:\crypto\deps\qrencode-3.4.3"
|
-I"C:\deps\qrencode-3.4.3"
|
||||||
|
|
||||||
LIBPATHS= \
|
LIBPATHS= \
|
||||||
-L"$(CURDIR)/leveldb" \
|
-L"$(CURDIR)/leveldb" \
|
||||||
-L"E:\crypto\deps\boost_1_53_0\stage\lib" \
|
-L"C:\deps\boost_1_55_0\stage\lib" \
|
||||||
-L"E:\crypto\deps\db-4.8.30.NC\build_unix" \
|
-L"C:\deps\db-4.8.30.NC\build_unix" \
|
||||||
-L"E:\crypto\deps\openssl-1.0.1b" \
|
-L"C:\deps\openssl-1.0.1p" \
|
||||||
-L"E:\crypto\deps\qrencode-3.4.3\.libs"
|
-L"C:\deps\qrencode-3.4.3\.libs"
|
||||||
|
|
||||||
LIBS= \
|
LIBS= \
|
||||||
-l leveldb \
|
-l leveldb \
|
||||||
|
|||||||
@@ -1607,3 +1607,22 @@ Value listlockunspent(const Array& params, bool fHelp)
|
|||||||
return ret;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user