Skip to content

Commit

Permalink
wip: labels
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 authored and josibake committed Sep 11, 2023
1 parent 8b2eff1 commit 47a5cb0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/wallet/scriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace wallet {
//! Value for the first BIP 32 hardened derivation. Can be used as a bit mask and as a value. See BIP 32 for more details.
const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000;

util::Result<CTxDestination> LegacyScriptPubKeyMan::GetNewDestination(const OutputType type)
util::Result<CTxDestination> LegacyScriptPubKeyMan::GetNewDestination(const OutputType type, const std::string& label)
{
if (LEGACY_OUTPUT_TYPES.count(type) == 0) {
return util::Error{_("Error: Legacy wallets only support the \"legacy\", \"p2sh-segwit\", and \"bech32\" address types")};
Expand Down Expand Up @@ -1980,7 +1980,7 @@ bool LegacyScriptPubKeyMan::DeleteRecords()
return batch.EraseRecords(DBKeys::LEGACY_TYPES);
}

util::Result<CTxDestination> DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type)
util::Result<CTxDestination> DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, const std::string& label)
{
// Returns true if this descriptor supports getting new addresses. Conditions where we may be unable to fetch them (e.g. locked) are caught later
if (!CanGetAddresses()) {
Expand Down Expand Up @@ -2086,7 +2086,7 @@ bool DescriptorScriptPubKeyMan::Encrypt(const CKeyingMaterial& master_key, Walle
util::Result<CTxDestination> DescriptorScriptPubKeyMan::GetReservedDestination(const OutputType type, bool internal, int64_t& index, CKeyPool& keypool)
{
LOCK(cs_desc_man);
auto op_dest = GetNewDestination(type);
auto op_dest = GetNewDestination(type, "");
index = m_wallet_descriptor.next_index - 1;
return op_dest;
}
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/scriptpubkeyman.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class ScriptPubKeyMan
public:
explicit ScriptPubKeyMan(WalletStorage& storage) : m_storage(storage) {}
virtual ~ScriptPubKeyMan() {};
virtual util::Result<CTxDestination> GetNewDestination(const OutputType type) { return util::Error{Untranslated("Not supported")}; }
virtual util::Result<CTxDestination> GetNewDestination(const OutputType type, const std::string& label) { return util::Error{Untranslated("Not supported")}; }
virtual isminetype IsMine(const CScript& script) const { return ISMINE_NO; }

//! Check that the given decryption key is valid for this ScriptPubKeyMan, i.e. it decrypts all of the keys handled by it.
Expand Down Expand Up @@ -376,7 +376,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
public:
LegacyScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size) : ScriptPubKeyMan(storage), m_keypool_size(keypool_size) {}

util::Result<CTxDestination> GetNewDestination(const OutputType type) override;
util::Result<CTxDestination> GetNewDestination(const OutputType type, const std::string& label) override;
isminetype IsMine(const CScript& script) const override;

bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override;
Expand Down Expand Up @@ -598,7 +598,7 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan

mutable RecursiveMutex cs_desc_man;

util::Result<CTxDestination> GetNewDestination(const OutputType type) override;
util::Result<CTxDestination> GetNewDestination(const OutputType type, const std::string& label) override;
isminetype IsMine(const CScript& script) const override;

bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override;
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/silentpayments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ void SilentPaymentsSPKM::SetupLabels(int64_t labels_size)
m_change_address.m_spend_pubkey = m_address.m_spend_pubkey.AddTweak(m_change_label.first.data());
}

util::Result<CTxDestination> SilentPaymentsSPKM::GetNewDestination(const OutputType type)
util::Result<CTxDestination> SilentPaymentsSPKM::GetNewDestination(const OutputType type, const std::string& label)
{
LOCK(cs_sp_man);
if (type != OutputType::SILENT_PAYMENT) {
Expand Down
5 changes: 4 additions & 1 deletion src/wallet/silentpayments.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ class SilentPaymentsSPKM : public ScriptPubKeyMan
int64_t m_creation_time;

//! Number of labels that have been requested (highest label index + 1)
//! Note that this may be different from the labels map as a label may end up being used even when not in the map (e.g. a restored backup)
int64_t m_labels_used;
//! Map label strings to label ints
std::unordered_map<std::string, int64_t> m_labels;

//! 256-bit ID
uint256 m_id;
Expand All @@ -72,7 +75,7 @@ class SilentPaymentsSPKM : public ScriptPubKeyMan

mutable RecursiveMutex cs_sp_man;

util::Result<CTxDestination> GetNewDestination(const OutputType type) override;
util::Result<CTxDestination> GetNewDestination(const OutputType type, const std::string& label) override;
isminetype IsMine(const CScript& script) const override;

bool CheckDecryptionKey(const CKeyingMaterial& master_key, bool accept_no_keys = false) override;
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/test/walletload_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_load_ckey, TestingSetup)
BOOST_CHECK(legacy_spkm->SetupGeneration(true));

// Retrieve a key
CTxDestination dest = *Assert(legacy_spkm->GetNewDestination(OutputType::LEGACY));
CTxDestination dest = *Assert(legacy_spkm->GetNewDestination(OutputType::LEGACY, ""));
CKeyID key_id = GetKeyForDestination(*legacy_spkm, dest);
CKey first_key;
BOOST_CHECK(legacy_spkm->GetKey(key_id, first_key));
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2505,7 +2505,7 @@ util::Result<CTxDestination> CWallet::GetNewDestination(const OutputType type, c
return util::Error{strprintf(_("Error: No %s addresses available."), FormatOutputType(type))};
}

auto op_dest = spk_man->GetNewDestination(type);
auto op_dest = spk_man->GetNewDestination(type, label);
if (op_dest) {
SetAddressBook(*op_dest, label, AddressPurpose::RECEIVE);
}
Expand Down

0 comments on commit 47a5cb0

Please sign in to comment.