mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +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;
|
||||
}
|
||||
|
||||
int CSuperblock::GetSuperblockHeight(bool last)
|
||||
void CSuperblock::GetSuperblockHeight(int& nBlockHeight, int& nLastSuperblock, int& nNextSuperblock)
|
||||
{
|
||||
// Get current block height
|
||||
int 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;
|
||||
// Get current block height if nothing was provided
|
||||
if(nBlockHeight == 0)
|
||||
nBlockHeight = (int)chainActive.Height();
|
||||
|
||||
// Special case: return first superblock if the current block height is below the first superblock during sync
|
||||
if(nBlockHeight < Params().GetConsensus().nSuperblockStartBlock){
|
||||
nLastSuperBlock = 0;
|
||||
nNextSuperBlock = Params().GetConsensus().nSuperblockStartBlock;
|
||||
nLastSuperblock = 0;
|
||||
nNextSuperblock = Params().GetConsensus().nSuperblockStartBlock;
|
||||
return;
|
||||
}
|
||||
|
||||
if(last)
|
||||
return nLastSuperBlock;
|
||||
else
|
||||
return nNextSuperBlock;
|
||||
// Get last superblock
|
||||
nLastSuperblock = nBlockHeight - ((nBlockHeight - Params().GetConsensus().nSuperblockStartBlock) % Params().GetConsensus().nSuperblockCycle);
|
||||
|
||||
// Get next superblock
|
||||
nNextSuperblock = nLastSuperblock + Params().GetConsensus().nSuperblockCycle;
|
||||
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ public:
|
||||
|
||||
static bool IsValidBlockHeight(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; }
|
||||
void SetStatus(int nStatusIn) { nStatus = nStatusIn; }
|
||||
|
@ -657,19 +657,33 @@ UniValue getsuperblockbudget(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(
|
||||
"getsuperblockheight\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"
|
||||
"lastsuperblock (numeric) the height of the last superblock\n"
|
||||
"nextsuperblock (numeric) the height of the next superblock\n"
|
||||
"lastsuperblock (numeric) the height of the last 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);
|
||||
obj.push_back(Pair("lastsuperblock", CSuperblock::GetSuperblockHeight(true)));
|
||||
obj.push_back(Pair("nextsuperblock", CSuperblock::GetSuperblockHeight(false)));
|
||||
obj.push_back(Pair("lastsuperblock", nLastSuperblock));
|
||||
obj.push_back(Pair("nextsuperblock", nNextSuperblock));
|
||||
|
||||
return obj;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user