mirror of https://github.com/oxen-io/oxen-core.git
Include SN status info info list_current_stakes()
Adds unlock height, funded, and decommissioned info to returned stake info.
This commit is contained in:
parent
a91c491111
commit
d9f19ca463
|
@ -2092,7 +2092,7 @@ namespace rpc {
|
|||
uint64_t requested_unlock_height; // The height at which contributions will be released and the Service Node expires. 0 if not requested yet.
|
||||
uint64_t last_reward_block_height; // The height that determines when this service node will next receive a reward. This field is updated when receiving a reward, but is also updated when a SN is activated, recommissioned, or has an IP change position reset.
|
||||
uint32_t last_reward_transaction_index; // When multiple Service Nodes register (or become active/reactivated) at the same height (i.e. have the same last_reward_block_height), this field contains the activating transaction position in the block which is used to break ties in determining which SN is next in the reward list.
|
||||
bool active; // True if fully funded and not currently decommissioned (and so `active && !funded` implicitly defines decommissioned)
|
||||
bool active; // True if fully funded and not currently decommissioned (and so `funded && !active` implicitly defines decommissioned)
|
||||
bool funded; // True if the required stakes have been submitted to activate this Service Node
|
||||
uint64_t state_height; // If active: the state at which the service node became active (i.e. fully staked height, or last recommissioning); if decommissioned: the decommissioning height; if awaiting: the last contribution (or registration) height
|
||||
uint32_t decommission_count; // The number of times the Service Node has been decommissioned since registration
|
||||
|
|
|
@ -1064,17 +1064,24 @@ uint64_t WalletImpl::unlockedBalance(uint32_t accountIndex) const
|
|||
}
|
||||
|
||||
EXPORT
|
||||
std::vector<std::pair<std::string, uint64_t>>* WalletImpl::listCurrentStakes() const
|
||||
std::vector<Wallet::stake_info>* WalletImpl::listCurrentStakes() const
|
||||
{
|
||||
std::vector<std::pair<std::string, uint64_t>>* stakes = new std::vector<std::pair<std::string, uint64_t>>;
|
||||
auto* stakes = new std::vector<Wallet::stake_info>;
|
||||
|
||||
auto response = wallet()->list_current_stakes();
|
||||
auto main_addr = mainAddress();
|
||||
|
||||
for (const auto& node_info : response)
|
||||
for (const auto& contributor : node_info.contributors)
|
||||
if (contributor.address == main_addr)
|
||||
stakes->push_back(std::make_pair(node_info.service_node_pubkey, contributor.amount));
|
||||
if (contributor.address == main_addr) {
|
||||
auto& info = stakes->emplace_back();
|
||||
info.sn_pubkey = node_info.service_node_pubkey;
|
||||
info.stake = contributor.amount;
|
||||
if (node_info.requested_unlock_height != 0)
|
||||
info.unlock_height = node_info.requested_unlock_height;
|
||||
info.awaiting = !node_info.funded;
|
||||
info.decommissioned = node_info.funded && !node_info.active;
|
||||
}
|
||||
|
||||
return stakes;
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ public:
|
|||
bool trustedDaemon() const override;
|
||||
uint64_t balance(uint32_t accountIndex = 0) const override;
|
||||
uint64_t unlockedBalance(uint32_t accountIndex = 0) const override;
|
||||
std::vector<std::pair<std::string, uint64_t>>* listCurrentStakes() const override;
|
||||
std::vector<Wallet::stake_info>* listCurrentStakes() const override;
|
||||
uint64_t blockChainHeight() const override;
|
||||
uint64_t approximateBlockChainHeight() const override;
|
||||
uint64_t estimateBlockChainHeight() const override;
|
||||
|
|
|
@ -609,11 +609,20 @@ struct Wallet
|
|||
return result;
|
||||
}
|
||||
|
||||
// Information returned about stakes in listCurrentStakes()
|
||||
struct stake_info {
|
||||
std::string sn_pubkey;
|
||||
uint64_t stake = 0;
|
||||
std::optional<uint64_t> unlock_height;
|
||||
bool awaiting = false;
|
||||
bool decommissioned = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief listCurrentStakes - returns a list of the wallets locked stakes, provides both service node address and the staked amount
|
||||
* @brief listCurrentStakes - returns a list of the wallets locked stake info (see above).
|
||||
* @return
|
||||
*/
|
||||
virtual std::vector<std::pair<std::string, uint64_t>>* listCurrentStakes() const = 0;
|
||||
virtual std::vector<stake_info>* listCurrentStakes() const = 0;
|
||||
|
||||
/**
|
||||
* @brief watchOnly - checks if wallet is watch only
|
||||
|
|
|
@ -13008,8 +13008,8 @@ std::vector<rpc::GET_SERVICE_NODES::response::entry> wallet2::list_current_stake
|
|||
return service_node_states;
|
||||
}
|
||||
|
||||
cryptonote::account_public_address const primary_address = this->get_address();
|
||||
for (rpc::GET_SERVICE_NODES::response::entry const &node_info : all_nodes)
|
||||
const auto primary_address = this->get_address();
|
||||
for (auto& node_info : all_nodes)
|
||||
{
|
||||
for (const auto& contributor : node_info.contributors)
|
||||
{
|
||||
|
@ -13022,7 +13022,8 @@ std::vector<rpc::GET_SERVICE_NODES::response::entry> wallet2::list_current_stake
|
|||
if (primary_address != address_info.address)
|
||||
continue;
|
||||
|
||||
service_node_states.push_back(node_info);
|
||||
service_node_states.push_back(std::move(node_info));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue