diff options
| author | Pieter Wuille <[email protected]> | 2018-07-19 17:56:52 -0700 |
|---|---|---|
| committer | Pieter Wuille <[email protected]> | 2018-08-13 08:46:23 -0700 |
| commit | 03a99586a398ee38f40c3b72d24c6a2ba4b88579 (patch) | |
| tree | 01ee901a790cd5d2446e36bedc31aacbf92e2d91 /src | |
| parent | [MOVEONLY] Move ParseHDKeypath to utilstrencodings (diff) | |
| download | discoin-03a99586a398ee38f40c3b72d24c6a2ba4b88579.tar.xz discoin-03a99586a398ee38f40c3b72d24c6a2ba4b88579.zip | |
Implement key origin lookup in CWallet
Diffstat (limited to 'src')
| -rw-r--r-- | src/wallet/rpcwallet.cpp | 21 | ||||
| -rw-r--r-- | src/wallet/wallet.cpp | 26 | ||||
| -rw-r--r-- | src/wallet/wallet.h | 2 |
3 files changed, 30 insertions, 19 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index aa7f5312b..0fcdd780a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4429,26 +4429,9 @@ void AddKeypathToMap(const CWallet* pwallet, const CKeyID& keyID, std::map<CPubK if (!pwallet->GetPubKey(keyID, vchPubKey)) { return; } - CKeyMetadata meta; - auto it = pwallet->mapKeyMetadata.find(keyID); - if (it != pwallet->mapKeyMetadata.end()) { - meta = it->second; - } KeyOriginInfo info; - if (!meta.hdKeypath.empty()) { - if (!ParseHDKeypath(meta.hdKeypath, info.path)) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "Internal keypath is broken"); - } - // Get the proper master key id - CKey key; - pwallet->GetKey(meta.hd_seed_id, key); - CExtKey masterKey; - masterKey.SetSeed(key.begin(), key.size()); - // Compute identifier - CKeyID masterid = masterKey.key.GetPubKey().GetID(); - std::copy(masterid.begin(), masterid.begin() + 4, info.fingerprint); - } else { // Single pubkeys get the master fingerprint of themselves - std::copy(keyID.begin(), keyID.begin() + 4, info.fingerprint); + if (!pwallet->GetKeyOrigin(keyID, info)) { + throw JSONRPCError(RPC_INTERNAL_ERROR, "Internal keypath is broken"); } hd_keypaths.emplace(vchPubKey, std::move(info)); } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5a7fdf9a8..92ffc3c10 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4466,3 +4466,29 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu } return groups; } + +bool CWallet::GetKeyOrigin(const CKeyID& keyID, KeyOriginInfo& info) const +{ + CKeyMetadata meta; + { + LOCK(cs_wallet); + auto it = mapKeyMetadata.find(keyID); + if (it != mapKeyMetadata.end()) { + meta = it->second; + } + } + if (!meta.hdKeypath.empty()) { + if (!ParseHDKeypath(meta.hdKeypath, info.path)) return false; + // Get the proper master key id + CKey key; + GetKey(meta.hd_seed_id, key); + CExtKey masterKey; + masterKey.SetSeed(key.begin(), key.size()); + // Compute identifier + CKeyID masterid = masterKey.key.GetPubKey().GetID(); + std::copy(masterid.begin(), masterid.begin() + 4, info.fingerprint); + } else { // Single pubkeys get the master fingerprint of themselves + std::copy(keyID.begin(), keyID.begin() + 4, info.fingerprint); + } + return true; +} diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 57b22c0e4..e9f6a4524 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1211,6 +1211,8 @@ public: LogPrintf(("%s " + fmt).c_str(), GetDisplayName(), parameters...); }; + /** Implement lookup of key origin information through wallet key metadata. */ + bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override; }; /** A key allocated from the key pool. */ |