mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 21:42:47 +01:00
[RPC] new command 'getsuperblockheight' [update 1]
This commit is contained in:
parent
da58cf0da3
commit
2436067c76
@ -546,27 +546,24 @@ CAmount CSuperblock::GetPaymentsLimit(int nBlockHeight)
|
|||||||
return nPaymentsLimit;
|
return nPaymentsLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CSuperblock::GetSuperblockHeight(bool last)
|
void CSuperblock::GetSuperblockHeight(int& nBlockHeight, int& nLastSuperblock, int& nNextSuperblock)
|
||||||
{
|
{
|
||||||
// Get current block height
|
// Get current block height if nothing was provided
|
||||||
int nBlockHeight = (int)chainActive.Height();
|
if(nBlockHeight == 0)
|
||||||
|
nBlockHeight = (int)chainActive.Height();
|
||||||
// Get last superblock
|
|
||||||
int nLastSuperBlock = nBlockHeight - ((nBlockHeight - Params().GetConsensus().nSuperblockStartBlock) % Params().GetConsensus().nSuperblockCycle);
|
|
||||||
|
|
||||||
// Get next superblock
|
|
||||||
int nNextSuperBlock = nLastSuperBlock + Params().GetConsensus().nSuperblockCycle;
|
|
||||||
|
|
||||||
// Special case: return first superblock if the current block height is below the first superblock during sync
|
// Special case: return first superblock if the current block height is below the first superblock during sync
|
||||||
if(nBlockHeight < Params().GetConsensus().nSuperblockStartBlock){
|
if(nBlockHeight < Params().GetConsensus().nSuperblockStartBlock){
|
||||||
nLastSuperBlock = 0;
|
nLastSuperblock = 0;
|
||||||
nNextSuperBlock = Params().GetConsensus().nSuperblockStartBlock;
|
nNextSuperblock = Params().GetConsensus().nSuperblockStartBlock;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(last)
|
// Get last superblock
|
||||||
return nLastSuperBlock;
|
nLastSuperblock = nBlockHeight - ((nBlockHeight - Params().GetConsensus().nSuperblockStartBlock) % Params().GetConsensus().nSuperblockCycle);
|
||||||
else
|
|
||||||
return nNextSuperBlock;
|
// Get next superblock
|
||||||
|
nNextSuperblock = nLastSuperblock + Params().GetConsensus().nSuperblockCycle;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ public:
|
|||||||
|
|
||||||
static bool IsValidBlockHeight(int nBlockHeight);
|
static bool IsValidBlockHeight(int nBlockHeight);
|
||||||
static CAmount GetPaymentsLimit(int nBlockHeight);
|
static CAmount GetPaymentsLimit(int nBlockHeight);
|
||||||
static int GetSuperblockHeight(bool last);
|
static void GetSuperblockHeight(int& nBlockHeight, int& nLastSuperblock, int& nNextSuperblock);
|
||||||
|
|
||||||
int GetStatus() { return nStatus; }
|
int GetStatus() { return nStatus; }
|
||||||
void SetStatus(int nStatusIn) { nStatus = nStatusIn; }
|
void SetStatus(int nStatusIn) { nStatus = nStatusIn; }
|
||||||
|
@ -657,19 +657,33 @@ UniValue getsuperblockbudget(const UniValue& params, bool fHelp)
|
|||||||
|
|
||||||
UniValue getsuperblockheight(const UniValue& params, bool fHelp)
|
UniValue getsuperblockheight(const UniValue& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp) {
|
int nBlockHeight = 0;
|
||||||
|
int nLastSuperblock, nNextSuperblock;
|
||||||
|
|
||||||
|
if (fHelp || params.size() > 1) {
|
||||||
throw runtime_error(
|
throw runtime_error(
|
||||||
"getsuperblockheight\n"
|
"getsuperblockheight\n"
|
||||||
"\nReturns the block height of the last/next superblock.\n"
|
"\nReturns the block height of the last/next superblock.\n"
|
||||||
|
"\nArguments:\n"
|
||||||
|
"1. index (numeric, optional, default = current blockchain height) The block index\n"
|
||||||
"\nResult:\n"
|
"\nResult:\n"
|
||||||
"lastsuperblock (numeric) the height of the last superblock\n"
|
"lastsuperblock (numeric) the height of the last superblock\n"
|
||||||
"nextsuperblock (numeric) the height of the next superblock\n"
|
"nextsuperblock (numeric) the height of the next superblock\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(params.size() == 1)
|
||||||
|
nBlockHeight = params[0].get_int();
|
||||||
|
|
||||||
|
if (nBlockHeight < 0) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
|
||||||
|
}
|
||||||
|
|
||||||
|
CSuperblock::GetSuperblockHeight(nBlockHeight, nLastSuperblock, nNextSuperblock);
|
||||||
|
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
obj.push_back(Pair("lastsuperblock", CSuperblock::GetSuperblockHeight(true)));
|
obj.push_back(Pair("lastsuperblock", nLastSuperblock));
|
||||||
obj.push_back(Pair("nextsuperblock", CSuperblock::GetSuperblockHeight(false)));
|
obj.push_back(Pair("nextsuperblock", nNextSuperblock));
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user