Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 3,311 Lines • ▼ Show 20 Lines | static UniValue getwalletinfo(const Config &config, | ||||
obj.pushKV("balance", ValueFromAmount(pwallet->GetBalance())); | obj.pushKV("balance", ValueFromAmount(pwallet->GetBalance())); | ||||
obj.pushKV("unconfirmed_balance", | obj.pushKV("unconfirmed_balance", | ||||
ValueFromAmount(pwallet->GetUnconfirmedBalance())); | ValueFromAmount(pwallet->GetUnconfirmedBalance())); | ||||
obj.pushKV("immature_balance", | obj.pushKV("immature_balance", | ||||
ValueFromAmount(pwallet->GetImmatureBalance())); | ValueFromAmount(pwallet->GetImmatureBalance())); | ||||
obj.pushKV("txcount", (int)pwallet->mapWallet.size()); | obj.pushKV("txcount", (int)pwallet->mapWallet.size()); | ||||
obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime()); | obj.pushKV("keypoololdest", pwallet->GetOldestKeyPoolTime()); | ||||
obj.pushKV("keypoolsize", (int64_t)kpExternalSize); | obj.pushKV("keypoolsize", (int64_t)kpExternalSize); | ||||
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID; | CKeyID seed_id = pwallet->GetHDChain().seed_id; | ||||
if (!masterKeyID.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) { | if (!seed_id.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) { | ||||
obj.pushKV("keypoolsize_hd_internal", | obj.pushKV("keypoolsize_hd_internal", | ||||
int64_t(pwallet->GetKeyPoolSize() - kpExternalSize)); | int64_t(pwallet->GetKeyPoolSize() - kpExternalSize)); | ||||
} | } | ||||
if (pwallet->IsCrypted()) { | if (pwallet->IsCrypted()) { | ||||
obj.pushKV("unlocked_until", pwallet->nRelockTime); | obj.pushKV("unlocked_until", pwallet->nRelockTime); | ||||
} | } | ||||
obj.pushKV("paytxfee", ValueFromAmount(pwallet->m_pay_tx_fee.GetFeePerK())); | obj.pushKV("paytxfee", ValueFromAmount(pwallet->m_pay_tx_fee.GetFeePerK())); | ||||
if (!masterKeyID.IsNull()) { | if (!seed_id.IsNull()) { | ||||
obj.pushKV("hdmasterkeyid", masterKeyID.GetHex()); | obj.pushKV("hdmasterkeyid", seed_id.GetHex()); | ||||
} | } | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue listwallets(const Config &config, | static UniValue listwallets(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
▲ Show 20 Lines • Show All 1,144 Lines • ▼ Show 20 Lines | if (!meta) { | ||||
if (it != pwallet->m_script_metadata.end()) { | if (it != pwallet->m_script_metadata.end()) { | ||||
meta = &it->second; | meta = &it->second; | ||||
} | } | ||||
} | } | ||||
if (meta) { | if (meta) { | ||||
ret.pushKV("timestamp", meta->nCreateTime); | ret.pushKV("timestamp", meta->nCreateTime); | ||||
if (!meta->hdKeypath.empty()) { | if (!meta->hdKeypath.empty()) { | ||||
ret.pushKV("hdkeypath", meta->hdKeypath); | ret.pushKV("hdkeypath", meta->hdKeypath); | ||||
ret.pushKV("hdmasterkeyid", meta->hdMasterKeyID.GetHex()); | ret.pushKV("hdmasterkeyid", meta->hd_seed_id.GetHex()); | ||||
} | } | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue sethdseed(const Config &config, const JSONRPCRequest &request) { | static UniValue sethdseed(const Config &config, const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | static UniValue sethdseed(const Config &config, const JSONRPCRequest &request) { | ||||
bool flush_key_pool = true; | bool flush_key_pool = true; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
flush_key_pool = request.params[0].get_bool(); | flush_key_pool = request.params[0].get_bool(); | ||||
} | } | ||||
CPubKey master_pub_key; | CPubKey master_pub_key; | ||||
if (request.params[1].isNull()) { | if (request.params[1].isNull()) { | ||||
master_pub_key = pwallet->GenerateNewHDMasterKey(); | master_pub_key = pwallet->GenerateNewSeed(); | ||||
} else { | } else { | ||||
CKey key = DecodeSecret(request.params[1].get_str()); | CKey key = DecodeSecret(request.params[1].get_str()); | ||||
if (!key.IsValid()) { | if (!key.IsValid()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Invalid private key"); | "Invalid private key"); | ||||
} | } | ||||
if (HaveKey(*pwallet, key)) { | if (HaveKey(*pwallet, key)) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Already have this key (either as an HD seed or " | "Already have this key (either as an HD seed or " | ||||
"as a loose private key)"); | "as a loose private key)"); | ||||
} | } | ||||
master_pub_key = pwallet->DeriveNewMasterHDKey(key); | master_pub_key = pwallet->DeriveNewSeed(key); | ||||
} | } | ||||
pwallet->SetHDMasterKey(master_pub_key); | pwallet->SetHDSeed(master_pub_key); | ||||
if (flush_key_pool) { | if (flush_key_pool) { | ||||
pwallet->NewKeyPool(); | pwallet->NewKeyPool(); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
// clang-format off | // clang-format off | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |