Skip to content

Commit

Permalink
Update getstakingstatus RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone authored and Duddino committed May 2, 2023
1 parent 2653f90 commit 54eff47
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4344,8 +4344,10 @@ UniValue getstakingstatus(const JSONRPCRequest& request)
" \"haveconnections\": true|false, (boolean) whether network connections are present\n"
" \"mnsync\": true|false, (boolean) whether the required masternode/spork data is synced\n"
" \"walletunlocked\": true|false, (boolean) whether the wallet is unlocked\n"
" \"stakeablecoins\": n (numeric) number of stakeable UTXOs\n"
" \"stakingbalance\": d (numeric) PIV value of the stakeable coins (minus reserve balance, if any)\n"
" \"transparent_stakeable_coins\": n (numeric) number of transparent stakeable UTXOs\n"
" \"shield_stakeables_notes\": n (numeric) number of shield stakeable notes\n"
" \"transparent_staking_balance\": d (numeric) PIV value of the stakeable coins (minus reserve balance, if any)\n"
" \"shield_staking_balance\": d (numeric) shield PIV value of the stakeable coins (minus reserve balance, if any)\n"
" \"stakesplitthreshold\": d (numeric) value of the current threshold for stake split\n"
" \"lastattempt_age\": n (numeric) seconds since last stake attempt\n"
" \"lastattempt_depth\": n (numeric) depth of the block on top of which the last stake attempt was made\n"
Expand All @@ -4371,9 +4373,13 @@ UniValue getstakingstatus(const JSONRPCRequest& request)
obj.pushKV("mnsync", !masternodeSync.NotCompleted());
obj.pushKV("walletunlocked", !pwallet->IsLocked());
std::vector<CStakeableOutput> vCoins;
std::vector<CStakeableShieldNote> vShieldCoins;
pwallet->StakeableCoins(&vCoins);
obj.pushKV("stakeablecoins", (int)vCoins.size());
obj.pushKV("stakingbalance", ValueFromAmount(pwallet->GetStakingBalance(fColdStaking)));
pwallet->StakeableShieldNotes(&vShieldCoins);
obj.pushKV("transparent_stakeable_coins", (int)vCoins.size());
obj.pushKV("shield_stakeables_notes", (int)vShieldCoins.size());
obj.pushKV("transparent_staking_balance", ValueFromAmount(pwallet->GetStakingBalance(fColdStaking)));
obj.pushKV("shield_staking_balance", ValueFromAmount(pwallet->GetShieldStakingBalance()));
obj.pushKV("stakesplitthreshold", ValueFromAmount(pwallet->nStakeSplitThreshold));
CStakerStatus* ss = pwallet->pStakerStatus;
if (ss) {
Expand Down
11 changes: 11 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2175,6 +2175,17 @@ CAmount CWallet::GetStakingBalance(const bool fIncludeColdStaking) const
}));
}

CAmount CWallet::GetShieldStakingBalance()
{
std::vector<CStakeableShieldNote> vShieldCoins;
CAmount total = 0;
this->StakeableShieldNotes(&vShieldCoins);
for (auto it = vShieldCoins.begin(); it < vShieldCoins.end(); it++) {
total += it->note.note.value();
}
return total;
}

CAmount CWallet::GetDelegatedBalance() const
{
return loopTxsBalance([](const uint256& id, const CWalletTx& pcoin, CAmount& nTotal) {
Expand Down
1 change: 1 addition & 0 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
CAmount GetColdStakingBalance() const; // delegated coins for which we have the staking key
CAmount GetImmatureColdStakingBalance() const;
CAmount GetStakingBalance(const bool fIncludeColdStaking = true) const;
CAmount GetShieldStakingBalance();
CAmount GetDelegatedBalance() const; // delegated coins for which we have the spending key
CAmount GetImmatureDelegatedBalance() const;
CAmount GetLockedCoins() const;
Expand Down

0 comments on commit 54eff47

Please sign in to comment.