mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-03 16:30:42 +02:00
Refactor: Move GetMetadata code out of getaddressinfo
Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior.
This commit is contained in:
parent
9716bbe0f8
commit
a18edd7b38
@ -3756,19 +3756,16 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
|
|||||||
ret.pushKV("label", pwallet->mapAddressBook[dest].name);
|
ret.pushKV("label", pwallet->mapAddressBook[dest].name);
|
||||||
}
|
}
|
||||||
ret.pushKV("ischange", pwallet->IsChange(scriptPubKey));
|
ret.pushKV("ischange", pwallet->IsChange(scriptPubKey));
|
||||||
const CKeyMetadata* meta = nullptr;
|
|
||||||
|
ScriptPubKeyMan* spk_man = pwallet->GetScriptPubKeyMan();
|
||||||
|
if (spk_man) {
|
||||||
CKeyID key_id = GetKeyForDestination(*provider, dest);
|
CKeyID key_id = GetKeyForDestination(*provider, dest);
|
||||||
|
const CKeyMetadata* meta = nullptr;
|
||||||
if (!key_id.IsNull()) {
|
if (!key_id.IsNull()) {
|
||||||
auto it = pwallet->mapKeyMetadata.find(key_id);
|
meta = spk_man->GetMetadata(key_id);
|
||||||
if (it != pwallet->mapKeyMetadata.end()) {
|
|
||||||
meta = &it->second;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!meta) {
|
if (!meta) {
|
||||||
auto it = pwallet->m_script_metadata.find(CScriptID(scriptPubKey));
|
meta = spk_man->GetMetadata(CScriptID(scriptPubKey));
|
||||||
if (it != pwallet->m_script_metadata.end()) {
|
|
||||||
meta = &it->second;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (meta) {
|
if (meta) {
|
||||||
ret.pushKV("timestamp", meta->nCreateTime);
|
ret.pushKV("timestamp", meta->nCreateTime);
|
||||||
@ -3778,6 +3775,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
|
|||||||
ret.pushKV("hdmasterfingerprint", HexStr(meta->key_origin.fingerprint, meta->key_origin.fingerprint + 4));
|
ret.pushKV("hdmasterfingerprint", HexStr(meta->key_origin.fingerprint, meta->key_origin.fingerprint + 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Currently only one label can be associated with an address, return an array
|
// Currently only one label can be associated with an address, return an array
|
||||||
// so the API remains stable if we allow multiple labels to be associated with
|
// so the API remains stable if we allow multiple labels to be associated with
|
||||||
|
@ -382,6 +382,21 @@ size_t LegacyScriptPubKeyMan::KeypoolCountExternalKeys()
|
|||||||
return setExternalKeyPool.size() + set_pre_split_keypool.size();
|
return setExternalKeyPool.size() + set_pre_split_keypool.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata(uint160 id) const
|
||||||
|
{
|
||||||
|
AssertLockHeld(cs_wallet);
|
||||||
|
auto it = mapKeyMetadata.find(CKeyID(id));
|
||||||
|
if (it != mapKeyMetadata.end()) {
|
||||||
|
return &it->second;
|
||||||
|
} else {
|
||||||
|
auto it2 = m_script_metadata.find(CScriptID(id));
|
||||||
|
if (it2 != m_script_metadata.end()) {
|
||||||
|
return &it2->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update wallet first key creation time. This should be called whenever keys
|
* Update wallet first key creation time. This should be called whenever keys
|
||||||
* are added to the wallet, with the oldest key creation time.
|
* are added to the wallet, with the oldest key creation time.
|
||||||
|
@ -163,6 +163,8 @@ public:
|
|||||||
virtual int64_t GetOldestKeyPoolTime() { return GetTime(); }
|
virtual int64_t GetOldestKeyPoolTime() { return GetTime(); }
|
||||||
|
|
||||||
virtual size_t KeypoolCountExternalKeys() { return 0; }
|
virtual size_t KeypoolCountExternalKeys() { return 0; }
|
||||||
|
|
||||||
|
virtual const CKeyMetadata* GetMetadata(uint160 id) const { return nullptr; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProvider
|
class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProvider
|
||||||
@ -265,6 +267,8 @@ public:
|
|||||||
int64_t GetOldestKeyPoolTime() override;
|
int64_t GetOldestKeyPoolTime() override;
|
||||||
size_t KeypoolCountExternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
size_t KeypoolCountExternalKeys() override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
|
|
||||||
|
const CKeyMetadata* GetMetadata(uint160 id) const override;
|
||||||
|
|
||||||
bool CanGetAddresses(bool internal = false) override;
|
bool CanGetAddresses(bool internal = false) override;
|
||||||
|
|
||||||
// Map from Key ID to key metadata.
|
// Map from Key ID to key metadata.
|
||||||
|
@ -1134,8 +1134,6 @@ public:
|
|||||||
std::set<int64_t>& setInternalKeyPool GUARDED_BY(cs_wallet) = m_spk_man->setInternalKeyPool;
|
std::set<int64_t>& setInternalKeyPool GUARDED_BY(cs_wallet) = m_spk_man->setInternalKeyPool;
|
||||||
std::set<int64_t>& setExternalKeyPool GUARDED_BY(cs_wallet) = m_spk_man->setExternalKeyPool;
|
std::set<int64_t>& setExternalKeyPool GUARDED_BY(cs_wallet) = m_spk_man->setExternalKeyPool;
|
||||||
int64_t& nTimeFirstKey GUARDED_BY(cs_wallet) = m_spk_man->nTimeFirstKey;
|
int64_t& nTimeFirstKey GUARDED_BY(cs_wallet) = m_spk_man->nTimeFirstKey;
|
||||||
std::map<CKeyID, CKeyMetadata>& mapKeyMetadata GUARDED_BY(cs_wallet) = m_spk_man->mapKeyMetadata;
|
|
||||||
std::map<CScriptID, CKeyMetadata>& m_script_metadata GUARDED_BY(cs_wallet) = m_spk_man->m_script_metadata;
|
|
||||||
void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(m_spk_man->cs_wallet); m_spk_man->MarkPreSplitKeys(); }
|
void MarkPreSplitKeys() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(m_spk_man->cs_wallet); m_spk_man->MarkPreSplitKeys(); }
|
||||||
void MarkReserveKeysAsUsed(int64_t keypool_id) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(m_spk_man->cs_wallet); m_spk_man->MarkReserveKeysAsUsed(keypool_id); }
|
void MarkReserveKeysAsUsed(int64_t keypool_id) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(m_spk_man->cs_wallet); m_spk_man->MarkReserveKeysAsUsed(keypool_id); }
|
||||||
using CryptedKeyMap = LegacyScriptPubKeyMan::CryptedKeyMap;
|
using CryptedKeyMap = LegacyScriptPubKeyMan::CryptedKeyMap;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user