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] Shield address setlabel/getaddressesbylabel #2609

Merged
merged 1 commit into from
Nov 19, 2021
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
9 changes: 9 additions & 0 deletions doc/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ The `autocombinerewards` RPC command was soft-deprecated in v5.3.0 and replaced

This command will be fully removed in v6.0.0.

### Shield address support for RPC label commands

The `setlabel` RPC command now supports a shield address input argument to allow users to set labels for shield addresses. Additionally, the `getaddressesbylabel` RPC command will also now return shield addresses with a matching label.

### Specify optional label for getnewshieldaddress

The `getnewshieldaddress` RPC command now takes an optional argument `label (string)` to denote the desired label for the generated address.


*version* Change log
==============

Expand Down
16 changes: 11 additions & 5 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,12 @@ UniValue getaddressesbylabel(const JSONRPCRequest& request)
UniValue ret(UniValue::VOBJ);
for (auto it = pwallet->NewAddressBookIterator(); it.IsValid(); it.Next()) {
auto addrBook = it.GetValue();
if (!addrBook.isShielded() && addrBook.name == label) {
ret.pushKV(EncodeDestination(*it.GetCTxDestKey(), AddressBook::IsColdStakingPurpose(addrBook.purpose)), AddressBookDataToJSON(addrBook, false));
if (addrBook.name == label) {
if (!addrBook.isShielded()) {
ret.pushKV(EncodeDestination(*it.GetCTxDestKey(), AddressBook::IsColdStakingPurpose(addrBook.purpose)), AddressBookDataToJSON(addrBook, false));
} else {
ret.pushKV(Standard::EncodeDestination(*it.GetShieldedDestKey()), AddressBookDataToJSON(addrBook, false));
}
}
}

Expand Down Expand Up @@ -999,9 +1003,11 @@ UniValue setlabel(const JSONRPCRequest& request)

LOCK2(cs_main, pwallet->cs_wallet);

CTxDestination dest = DecodeDestination(request.params[0].get_str());
if (!IsValidDestination(dest))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid PIVX address");
const CWDestination& dest = Standard::DecodeDestination(request.params[0].get_str());
// Make sure the destination is valid
if (!Standard::IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
}

std::string old_label = pwallet->GetNameForAddressBookEntry(dest);
std::string label = LabelFromValue(request.params[1]);
Expand Down
10 changes: 10 additions & 0 deletions test/functional/wallet_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ def run_test(self):
label.verify(node)
assert_raises_rpc_error(-11, "No addresses with label", node.getaddressesbylabel, "")

if not self.options.legacywallet:
# Check that setlabel can assign a label to a new unused shield address.
for label in labels:
shield_address = node.getnewshieldaddress()
node.setlabel(shield_address, label.name)
label.add_address(shield_address)
label.purpose[shield_address] = "shielded_receive"
label.verify(node)
assert_raises_rpc_error(-11, "No addresses with label", node.getaddressesbylabel, "")

# Check that addmultisigaddress can assign labels.
for label in labels:
addresses = []
Expand Down