From 7fcbe7dc112b3d35a5066e6d181f286fb630f744 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 4 Apr 2019 12:45:32 -0700 Subject: Keep full pubkeys in FlatSigningProvider::origins Github-Pull: #15749 Rebased-From: 9a93c91c882265c908ea18496cd1bc271be914d4 --- src/script/descriptor.cpp | 2 +- src/script/sign.cpp | 8 +++++++- src/script/sign.h | 2 +- src/test/descriptor_tests.cpp | 4 ++-- src/wallet/rpcdump.cpp | 4 ++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 43448d7222..a333d4d4ac 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -436,7 +436,7 @@ public: pubkeys.reserve(entries.size()); for (auto& entry : entries) { pubkeys.push_back(entry.first); - out.origins.emplace(entry.first.GetID(), std::move(entry.second)); + out.origins.emplace(entry.first.GetID(), std::make_pair(CPubKey(entry.first), std::move(entry.second))); } if (m_script_arg) { for (const auto& subscript : subscripts) { diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 320956d0c4..36dd68a3d8 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -483,7 +483,13 @@ bool HidingSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& inf bool FlatSigningProvider::GetCScript(const CScriptID& scriptid, CScript& script) const { return LookupHelper(scripts, scriptid, script); } bool FlatSigningProvider::GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const { return LookupHelper(pubkeys, keyid, pubkey); } -bool FlatSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const { return LookupHelper(origins, keyid, info); } +bool FlatSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const +{ + std::pair out; + bool ret = LookupHelper(origins, keyid, out); + if (ret) info = std::move(out.second); + return ret; +} bool FlatSigningProvider::GetKey(const CKeyID& keyid, CKey& key) const { return LookupHelper(keys, keyid, key); } FlatSigningProvider Merge(const FlatSigningProvider& a, const FlatSigningProvider& b) diff --git a/src/script/sign.h b/src/script/sign.h index 491fb54c45..f746325b90 100644 --- a/src/script/sign.h +++ b/src/script/sign.h @@ -77,7 +77,7 @@ struct FlatSigningProvider final : public SigningProvider { std::map scripts; std::map pubkeys; - std::map origins; + std::map> origins; std::map keys; bool GetCScript(const CScriptID& scriptid, CScript& script) const override; diff --git a/src/test/descriptor_tests.cpp b/src/test/descriptor_tests.cpp index ff2b8d4fc9..826615cb51 100644 --- a/src/test/descriptor_tests.cpp +++ b/src/test/descriptor_tests.cpp @@ -154,8 +154,8 @@ void Check(const std::string& prv, const std::string& pub, int flags, const std: // Test whether the observed key path is present in the 'paths' variable (which contains expected, unobserved paths), // and then remove it from that set. for (const auto& origin : script_provider.origins) { - BOOST_CHECK_MESSAGE(paths.count(origin.second.path), "Unexpected key path: " + prv); - left_paths.erase(origin.second.path); + BOOST_CHECK_MESSAGE(paths.count(origin.second.second.path), "Unexpected key path: " + prv); + left_paths.erase(origin.second.second.path); } } } diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index bdf901dee4..779dcaf061 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -896,7 +896,7 @@ struct ImportData // Output data std::set import_scripts; std::map used_keys; //!< Import these private keys if available (the value indicates whether if the key is required for solvability) - std::map key_origins; + std::map> key_origins; }; enum class ScriptContext @@ -1283,7 +1283,7 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con } const auto& key_orig_it = import_data.key_origins.find(id); if (key_orig_it != import_data.key_origins.end()) { - pwallet->AddKeyOrigin(pubkey, key_orig_it->second); + pwallet->AddKeyOrigin(pubkey, key_orig_it->second.second); } pwallet->mapKeyMetadata[id].nCreateTime = timestamp; -- cgit v1.2.3