Move prev/next sb height logic from rpc to CSuperblock::GetNearestSuperblocksHeights (#1919)
This commit is contained in:
parent
312088b560
commit
0670695fea
@ -523,6 +523,25 @@ bool CSuperblock::IsValidBlockHeight(int nBlockHeight)
|
||||
((nBlockHeight % Params().GetConsensus().nSuperblockCycle) == 0);
|
||||
}
|
||||
|
||||
void CSuperblock::GetNearestSuperblocksHeights(int nBlockHeight, int& nLastSuperblockRet, int& nNextSuperblockRet)
|
||||
{
|
||||
const Consensus::Params& consensusParams = Params().GetConsensus();
|
||||
int nSuperblockStartBlock = consensusParams.nSuperblockStartBlock;
|
||||
int nSuperblockCycle = consensusParams.nSuperblockCycle;
|
||||
|
||||
// Get first superblock
|
||||
int nFirstSuperblockOffset = (nSuperblockCycle - nSuperblockStartBlock % nSuperblockCycle) % nSuperblockCycle;
|
||||
int nFirstSuperblock = nSuperblockStartBlock + nFirstSuperblockOffset;
|
||||
|
||||
if(nBlockHeight < nFirstSuperblock) {
|
||||
nLastSuperblockRet = 0;
|
||||
nNextSuperblockRet = nFirstSuperblock;
|
||||
} else {
|
||||
nLastSuperblockRet = nBlockHeight - nBlockHeight % nSuperblockCycle;
|
||||
nNextSuperblockRet = nLastSuperblockRet + nSuperblockCycle;
|
||||
}
|
||||
}
|
||||
|
||||
CAmount CSuperblock::GetPaymentsLimit(int nBlockHeight)
|
||||
{
|
||||
const Consensus::Params& consensusParams = Params().GetConsensus();
|
||||
|
@ -160,6 +160,7 @@ public:
|
||||
CSuperblock(uint256& nHash);
|
||||
|
||||
static bool IsValidBlockHeight(int nBlockHeight);
|
||||
static void GetNearestSuperblocksHeights(int nBlockHeight, int& nLastSuperblockRet, int& nNextSuperblockRet);
|
||||
static CAmount GetPaymentsLimit(int nBlockHeight);
|
||||
|
||||
int GetStatus() { return nStatus; }
|
||||
|
@ -931,31 +931,12 @@ UniValue getgovernanceinfo(const JSONRPCRequest& request)
|
||||
);
|
||||
}
|
||||
|
||||
// Compute last/next superblock
|
||||
int nLastSuperblock, nNextSuperblock;
|
||||
LOCK(cs_main);
|
||||
|
||||
// Get current block height
|
||||
int nBlockHeight = 0;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
nBlockHeight = (int)chainActive.Height();
|
||||
}
|
||||
int nLastSuperblock = 0, nNextSuperblock = 0;
|
||||
int nBlockHeight = chainActive.Height();
|
||||
|
||||
// Get chain parameters
|
||||
int nSuperblockStartBlock = Params().GetConsensus().nSuperblockStartBlock;
|
||||
int nSuperblockCycle = Params().GetConsensus().nSuperblockCycle;
|
||||
|
||||
// Get first superblock
|
||||
int nFirstSuperblockOffset = (nSuperblockCycle - nSuperblockStartBlock % nSuperblockCycle) % nSuperblockCycle;
|
||||
int nFirstSuperblock = nSuperblockStartBlock + nFirstSuperblockOffset;
|
||||
|
||||
if(nBlockHeight < nFirstSuperblock){
|
||||
nLastSuperblock = 0;
|
||||
nNextSuperblock = nFirstSuperblock;
|
||||
} else {
|
||||
nLastSuperblock = nBlockHeight - nBlockHeight % nSuperblockCycle;
|
||||
nNextSuperblock = nLastSuperblock + nSuperblockCycle;
|
||||
}
|
||||
CSuperblock::GetNearestSuperblocksHeights(nBlockHeight, nLastSuperblock, nNextSuperblock);
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("governanceminquorum", Params().GetConsensus().nGovernanceMinQuorum));
|
||||
|
Loading…
Reference in New Issue
Block a user