Skip to content

Commit b8ed76f

Browse files
committed
[RPC] Add CStakerStatus data to getstakingstatus
1 parent d2d5f08 commit b8ed76f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/miner.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
121121

122122
// Create new block
123123
std::unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
124-
if (!pblocktemplate.get())
125-
return NULL;
124+
if (!pblocktemplate.get()) return nullptr;
126125
CBlock* pblock = &pblocktemplate->block; // pointer for convenience
127126

128127
// Tip
129128
CBlockIndex* pindexPrev = GetChainTip();
130-
if (!pindexPrev)
131-
return nullptr;
129+
if (!pindexPrev) return nullptr;
132130

133131
const int nHeight = pindexPrev->nHeight + 1;
134132

src/rpc/misc.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,13 +594,17 @@ UniValue getstakingstatus(const UniValue& params, bool fHelp)
594594

595595
"\nResult:\n"
596596
"{\n"
597-
" \"validtime\": true|false, (boolean) if the chain tip is within staking phases\n"
597+
" \"staking_enabled\": true|false, (boolean) if staking is enabled/disabled in pivx.conf\n"
598+
" \"tiptime\": n, (integer) chain tip blocktime\n"
598599
" \"haveconnections\": true|false, (boolean) if network connections are present\n"
599600
" \"walletunlocked\": true|false, (boolean) if the wallet is unlocked\n"
600601
" \"mintablecoins\": true|false, (boolean) if the wallet has mintable coins\n"
601602
" \"enoughcoins\": true|false, (boolean) if available coins are greater than reserve balance\n"
602603
" \"mnsync\": true|false, (boolean) if masternode data is synced\n"
603-
" \"staking status\": true|false, (boolean) if the wallet is staking or not\n"
604+
" \"hashLastStakeAttempt\": xxx (hex string) hash of last block on top of which the miner attempted to stake\n"
605+
" \"heightLastStakeAttempt\": n (integer) height of last block on top of which the miner attempted to stake\n"
606+
" \"timeLastStakeAttempt\": n (integer) time of last attempted stake\n"
607+
" \"staking_status\": true|false, (boolean) if the wallet is staking or not\n"
604608
"}\n"
605609

606610
"\nExamples:\n" +
@@ -613,15 +617,21 @@ UniValue getstakingstatus(const UniValue& params, bool fHelp)
613617
#endif
614618

615619
UniValue obj(UniValue::VOBJ);
616-
obj.push_back(Pair("validtime", chainActive.Tip()->nTime > 1471482000));
620+
obj.push_back(Pair("staking_enabled", GetBoolArg("-staking", true)));
621+
obj.push_back(Pair("tiptime", (int)chainActive.Tip()->nTime));
617622
obj.push_back(Pair("haveconnections", !vNodes.empty()));
618623
if (pwalletMain) {
619624
obj.push_back(Pair("walletunlocked", !pwalletMain->IsLocked()));
620625
obj.push_back(Pair("mintablecoins", pwalletMain->MintableCoins()));
621-
obj.push_back(Pair("enoughcoins", nReserveBalance <= pwalletMain->GetBalance()));
626+
obj.push_back(Pair("enoughcoins", nReserveBalance <= pwalletMain->GetStakingBalance(GetBoolArg("-coldstaking", true))));
622627
}
623628
obj.push_back(Pair("mnsync", masternodeSync.IsSynced()));
624-
obj.push_back(Pair("staking status", pwalletMain->pStakerStatus->IsActive()));
629+
uint256 lastHash = pwalletMain->pStakerStatus->GetLastHash();
630+
obj.push_back(Pair("hashLastStakeAttempt", lastHash.GetHex()));
631+
obj.push_back(Pair("heightLastStakeAttempt", (mapBlockIndex.count(lastHash) > 0 ?
632+
mapBlockIndex.at(lastHash)->nHeight : -1)) );
633+
obj.push_back(Pair("timeLastStakeAttempt", pwalletMain->pStakerStatus->GetLastTime()));
634+
obj.push_back(Pair("staking_status", pwalletMain->pStakerStatus->IsActive()));
625635

626636
return obj;
627637
}

0 commit comments

Comments
 (0)