Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/misc.cpp
Show First 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | #ifdef ENABLE_WALLET | ||||
if (pwallet) { | if (pwallet) { | ||||
obj.pushKV("walletversion", pwallet->GetVersion()); | obj.pushKV("walletversion", pwallet->GetVersion()); | ||||
obj.pushKV("balance", ValueFromAmount(pwallet->GetBalance())); | obj.pushKV("balance", ValueFromAmount(pwallet->GetBalance())); | ||||
} | } | ||||
#endif | #endif | ||||
obj.pushKV("blocks", (int)chainActive.Height()); | obj.pushKV("blocks", (int)chainActive.Height()); | ||||
obj.pushKV("timeoffset", GetTimeOffset()); | obj.pushKV("timeoffset", GetTimeOffset()); | ||||
if (g_connman) { | if (g_connman) { | ||||
obj.push_back( | obj.pushKV("connections", | ||||
Pair("connections", | (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)); | ||||
(int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL))); | |||||
} | } | ||||
obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() | obj.pushKV("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() | ||||
: std::string()))); | : std::string())); | ||||
obj.pushKV("difficulty", double(GetDifficulty(chainActive.Tip()))); | obj.pushKV("difficulty", double(GetDifficulty(chainActive.Tip()))); | ||||
obj.push_back(Pair("testnet", | obj.pushKV("testnet", | ||||
config.GetChainParams().NetworkIDString() == | config.GetChainParams().NetworkIDString() == | ||||
CBaseChainParams::TESTNET)); | CBaseChainParams::TESTNET); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
if (pwallet) { | if (pwallet) { | ||||
obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime()); | obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime()); | ||||
obj.pushKV("keypoolsize", (int)pwallet->GetKeyPoolSize()); | obj.pushKV("keypoolsize", (int)pwallet->GetKeyPoolSize()); | ||||
} | } | ||||
if (pwallet && pwallet->IsCrypted()) { | if (pwallet && pwallet->IsCrypted()) { | ||||
obj.pushKV("unlocked_until", pwallet->nRelockTime); | obj.pushKV("unlocked_until", pwallet->nRelockTime); | ||||
} | } | ||||
obj.pushKV("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())); | obj.pushKV("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())); | ||||
#endif | #endif | ||||
obj.push_back(Pair("relayfee", | obj.pushKV("relayfee", | ||||
ValueFromAmount(config.GetMinFeePerKB().GetFeePerK()))); | ValueFromAmount(config.GetMinFeePerKB().GetFeePerK())); | ||||
obj.pushKV("errors", GetWarnings("statusbar")); | obj.pushKV("errors", GetWarnings("statusbar")); | ||||
return obj; | return obj; | ||||
} | } | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
class DescribeAddressVisitor : public boost::static_visitor<UniValue> { | class DescribeAddressVisitor : public boost::static_visitor<UniValue> { | ||||
public: | public: | ||||
CWallet *const pwallet; | CWallet *const pwallet; | ||||
Show All 20 Lines | UniValue operator()(const CScriptID &scriptID) const { | ||||
CScript subscript; | CScript subscript; | ||||
obj.pushKV("isscript", true); | obj.pushKV("isscript", true); | ||||
if (pwallet && pwallet->GetCScript(scriptID, subscript)) { | if (pwallet && pwallet->GetCScript(scriptID, subscript)) { | ||||
std::vector<CTxDestination> addresses; | std::vector<CTxDestination> addresses; | ||||
txnouttype whichType; | txnouttype whichType; | ||||
int nRequired; | int nRequired; | ||||
ExtractDestinations(subscript, whichType, addresses, nRequired); | ExtractDestinations(subscript, whichType, addresses, nRequired); | ||||
obj.pushKV("script", GetTxnOutputType(whichType)); | obj.pushKV("script", GetTxnOutputType(whichType)); | ||||
obj.push_back( | obj.pushKV("hex", HexStr(subscript.begin(), subscript.end())); | ||||
Pair("hex", HexStr(subscript.begin(), subscript.end()))); | |||||
UniValue a(UniValue::VARR); | UniValue a(UniValue::VARR); | ||||
for (const CTxDestination &addr : addresses) { | for (const CTxDestination &addr : addresses) { | ||||
a.push_back(EncodeDestination(addr)); | a.push_back(EncodeDestination(addr)); | ||||
} | } | ||||
obj.pushKV("addresses", a); | obj.pushKV("addresses", a); | ||||
if (whichType == TX_MULTISIG) { | if (whichType == TX_MULTISIG) { | ||||
obj.pushKV("sigsrequired", nRequired); | obj.pushKV("sigsrequired", nRequired); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | #endif | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
ret.pushKV("isvalid", isValid); | ret.pushKV("isvalid", isValid); | ||||
if (isValid) { | if (isValid) { | ||||
std::string currentAddress = EncodeDestination(dest); | std::string currentAddress = EncodeDestination(dest); | ||||
ret.pushKV("address", currentAddress); | ret.pushKV("address", currentAddress); | ||||
CScript scriptPubKey = GetScriptForDestination(dest); | CScript scriptPubKey = GetScriptForDestination(dest); | ||||
ret.push_back(Pair("scriptPubKey", | ret.pushKV("scriptPubKey", | ||||
HexStr(scriptPubKey.begin(), scriptPubKey.end()))); | HexStr(scriptPubKey.begin(), scriptPubKey.end())); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
isminetype mine = pwallet ? IsMine(*pwallet, dest) : ISMINE_NO; | isminetype mine = pwallet ? IsMine(*pwallet, dest) : ISMINE_NO; | ||||
ret.pushKV("ismine", (mine & ISMINE_SPENDABLE) ? true : false); | ret.pushKV("ismine", (mine & ISMINE_SPENDABLE) ? true : false); | ||||
ret.push_back( | ret.pushKV("iswatchonly", (mine & ISMINE_WATCH_ONLY) ? true : false); | ||||
Pair("iswatchonly", (mine & ISMINE_WATCH_ONLY) ? true : false)); | |||||
UniValue detail = | UniValue detail = | ||||
boost::apply_visitor(DescribeAddressVisitor(pwallet), dest); | boost::apply_visitor(DescribeAddressVisitor(pwallet), dest); | ||||
ret.pushKVs(detail); | ret.pushKVs(detail); | ||||
if (pwallet && pwallet->mapAddressBook.count(dest)) { | if (pwallet && pwallet->mapAddressBook.count(dest)) { | ||||
ret.pushKV("account", pwallet->mapAddressBook[dest].name); | ret.pushKV("account", pwallet->mapAddressBook[dest].name); | ||||
} | } | ||||
if (pwallet) { | if (pwallet) { | ||||
const auto &meta = pwallet->mapKeyMetadata; | const auto &meta = pwallet->mapKeyMetadata; | ||||
const CKeyID *keyID = boost::get<CKeyID>(&dest); | const CKeyID *keyID = boost::get<CKeyID>(&dest); | ||||
auto it = keyID ? meta.find(*keyID) : meta.end(); | auto it = keyID ? meta.find(*keyID) : meta.end(); | ||||
if (it == meta.end()) { | if (it == meta.end()) { | ||||
it = meta.find(CScriptID(scriptPubKey)); | it = meta.find(CScriptID(scriptPubKey)); | ||||
} | } | ||||
if (it != meta.end()) { | if (it != meta.end()) { | ||||
ret.pushKV("timestamp", it->second.nCreateTime); | ret.pushKV("timestamp", it->second.nCreateTime); | ||||
if (!it->second.hdKeypath.empty()) { | if (!it->second.hdKeypath.empty()) { | ||||
ret.pushKV("hdkeypath", it->second.hdKeypath); | ret.pushKV("hdkeypath", it->second.hdKeypath); | ||||
ret.push_back(Pair("hdmasterkeyid", | ret.pushKV("hdmasterkeyid", | ||||
it->second.hdMasterKeyID.GetHex())); | it->second.hdMasterKeyID.GetHex()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 414 Lines • Show Last 20 Lines |