Skip to content

Commit

Permalink
Merge #2609: [RPC] Shield address setlabel/getaddressesbylabel
Browse files Browse the repository at this point in the history
db68b90 [RPC] Shield address setlabel/getaddressesbylabel (Fuzzbawls)

Pull request description:

  This adds shield address support to the `setlabel` and
  `getaddressesbylabel` RPC commands. `setlabel` now accepts and validates
   shield address input argument, where `getaddressesbylabel` now returns
   shield addresses with a label matching the input argument.

  Companion to #2600 that allows CLI users to set a label for shield addresses
  after-the-fact, as well as see shield addresses with an assigned label in the
  response of `getaddressesbylabel`

  Also added relevant release notes for the changes in #2600.

  Regression tests added as well to cover the `setlabel` command.

ACKs for top commit:
  random-zebra:
    ACK db68b90
  furszy:
    code ACK db68b90, merging..

Tree-SHA512: 3344849a612c36eddd00ff30110b7cf48b044976dc1312c8b2769c8df33d8ffd971e5a4142424cbaabd90ea8632b4c9da83a001f90cce044b487a477fe8870c2
  • Loading branch information
furszy committed Nov 19, 2021
2 parents f8cc0dc + db68b90 commit ce94ee6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
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

0 comments on commit ce94ee6

Please sign in to comment.