Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: Add private_key_available to beaconstatus #1833

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/neuralnet/beacon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "neuralnet/beacon.h"
#include "neuralnet/contract/contract.h"
#include "util.h"
#include "wallet/wallet.h"

#include <algorithm>

Expand Down Expand Up @@ -170,6 +171,11 @@ std::string Beacon::GetVerificationCode() const
return EncodeBase58(key_id.begin(), key_id.end());
}

bool Beacon::WalletHasPrivateKey(const CWallet* const wallet) const
{
return wallet->HaveKey(m_public_key.GetID());
}

std::string Beacon::ToString() const
{
return EncodeBase64(
Expand Down
11 changes: 11 additions & 0 deletions src/neuralnet/beacon.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class CBitcoinAddress;
class CTransaction;
class CWallet;

namespace NN {

Expand Down Expand Up @@ -161,6 +162,16 @@ class Beacon
//!
std::string GetVerificationCode() const;

//!
//! \brief Determine whether the given wallet contains a private key for
//! this beacon's public key. Because this function is intended to work
//! even if the wallet is locked, it does not check whether the keypair is
//! actually valid.
//!
//! \return \c true if the wallet contains a matching private key.
//!
bool WalletHasPrivateKey(const CWallet* const wallet) const;

//!
//! \brief Get the legacy string representation of a version 1 beacon
//! contract.
Expand Down
4 changes: 3 additions & 1 deletion src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ UniValue beaconstatus(const UniValue& params, bool fHelp)
UniValue active(UniValue::VARR);
UniValue pending(UniValue::VARR);

LOCK(cs_main);
LOCK2(cs_main, pwalletMain->cs_wallet);

const NN::BeaconRegistry& beacons = NN::GetBeaconRegistry();

Expand All @@ -922,6 +922,7 @@ UniValue beaconstatus(const UniValue& params, bool fHelp)
entry.pushKV("timestamp", TimestampToHRDate(beacon->m_timestamp));
entry.pushKV("address", beacon->GetAddress().ToString());
entry.pushKV("public_key", beacon->m_public_key.ToString());
entry.pushKV("private_key_available", beacon->WalletHasPrivateKey(pwalletMain));
entry.pushKV("magnitude", NN::Quorum::GetMagnitude(*cpid).Floating());
entry.pushKV("verification_code", beacon->GetVerificationCode());
entry.pushKV("is_mine", is_mine);
Expand All @@ -939,6 +940,7 @@ UniValue beaconstatus(const UniValue& params, bool fHelp)
entry.pushKV("timestamp", TimestampToHRDate(beacon->m_timestamp));
entry.pushKV("address", beacon->GetAddress().ToString());
entry.pushKV("public_key", beacon->m_public_key.ToString());
entry.pushKV("private_key_available", beacon->WalletHasPrivateKey(pwalletMain));
entry.pushKV("magnitude", 0);
entry.pushKV("verification_code", beacon->GetVerificationCode());
entry.pushKV("is_mine", is_mine);
Expand Down