Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | static UniValue getnewaddress(const Config &config, | ||||
} | } | ||||
CKeyID keyID = newKey.GetID(); | CKeyID keyID = newKey.GetID(); | ||||
pwallet->SetAddressBook(keyID, label, "receive"); | pwallet->SetAddressBook(keyID, label, "receive"); | ||||
return EncodeDestination(keyID); | return EncodeDestination(keyID); | ||||
} | } | ||||
CTxDestination GetLabelAddress(CWallet *const pwallet, const std::string &label, | CTxDestination GetLabelDestination(CWallet *const pwallet, | ||||
const std::string &label, | |||||
bool bForceNew = false) { | bool bForceNew = false) { | ||||
CPubKey pubKey; | CTxDestination dest; | ||||
if (!pwallet->GetLabelAddress(pubKey, label, bForceNew)) { | if (!pwallet->GetLabelDestination(dest, label, bForceNew)) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_KEYPOOL_RAN_OUT, | RPC_WALLET_KEYPOOL_RAN_OUT, | ||||
"Error: Keypool ran out, please call keypoolrefill first"); | "Error: Keypool ran out, please call keypoolrefill first"); | ||||
} | } | ||||
return pubKey.GetID(); | return dest; | ||||
} | } | ||||
UniValue getlabeladdress(const Config &config, const JSONRPCRequest &request) { | UniValue getlabeladdress(const Config &config, const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
Show All 18 Lines | UniValue getlabeladdress(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
LOCK2(cs_main, pwallet->cs_wallet); | LOCK2(cs_main, pwallet->cs_wallet); | ||||
// Parse the label first so we don't generate a key if there's an error | // Parse the label first so we don't generate a key if there's an error | ||||
std::string label = LabelFromValue(request.params[0]); | std::string label = LabelFromValue(request.params[0]); | ||||
UniValue ret(UniValue::VSTR); | UniValue ret(UniValue::VSTR); | ||||
ret = EncodeDestination(GetLabelAddress(pwallet, label)); | ret = EncodeDestination(GetLabelDestination(pwallet, label)); | ||||
return ret; | return ret; | ||||
} | } | ||||
static UniValue getrawchangeaddress(const Config &config, | static UniValue getrawchangeaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | CWallet *const pwallet = GetWalletForJSONRPCRequest(request); | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | UniValue setlabel(const Config &config, const JSONRPCRequest &request) { | ||||
} | } | ||||
// Only add the label if the address is yours. | // Only add the label if the address is yours. | ||||
if (IsMine(*pwallet, dest)) { | if (IsMine(*pwallet, dest)) { | ||||
// Detect when changing the label of an address that is the 'unused | // Detect when changing the label of an address that is the 'unused | ||||
// current key' of another label: | // current key' of another label: | ||||
if (pwallet->mapAddressBook.count(dest)) { | if (pwallet->mapAddressBook.count(dest)) { | ||||
std::string old_label = pwallet->mapAddressBook[dest].name; | std::string old_label = pwallet->mapAddressBook[dest].name; | ||||
if (dest == GetLabelAddress(pwallet, old_label)) { | if (dest == GetLabelDestination(pwallet, old_label)) { | ||||
GetLabelAddress(pwallet, old_label, true); | GetLabelDestination(pwallet, old_label, true); | ||||
} | } | ||||
} | } | ||||
pwallet->SetAddressBook(dest, label, "receive"); | pwallet->SetAddressBook(dest, label, "receive"); | ||||
} else { | } else { | ||||
throw JSONRPCError(RPC_MISC_ERROR, | throw JSONRPCError(RPC_MISC_ERROR, | ||||
"setlabel can only be used with own address"); | "setlabel can only be used with own address"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 3,655 Lines • Show Last 20 Lines |