descriptor: ToPrivateString() pass if at least 1 priv key exists

- Refactor Descriptor::ToPrivateString() to allow descriptors with
  missing private keys to be printed. Useful in descriptors with
  multiple keys e.g tr() etc.
- The existing behaviour of listdescriptors is preserved as much as
  possible, if no private keys are availablle ToPrivateString will
  return false
This commit is contained in:
Novo
2025-08-01 14:31:25 +01:00
parent 5c4db25b61
commit 9e5e9824f1
6 changed files with 90 additions and 30 deletions

View File

@@ -124,10 +124,14 @@ struct ParserContext {
return a < b;
}
std::optional<std::string> ToString(const Key& key) const
std::optional<std::string> ToString(const Key& key, bool& has_priv_key) const
{
has_priv_key = false;
auto it = TEST_DATA.dummy_key_idx_map.find(key);
if (it == TEST_DATA.dummy_key_idx_map.end()) return {};
if (it == TEST_DATA.dummy_key_idx_map.end()) {
return HexStr(key);
}
has_priv_key = true;
uint8_t idx = it->second;
return HexStr(std::span{&idx, 1});
}