| 257 | } |
| 258 | |
| 259 | bool CWallet::GetKey(const CKeyID &address, CKey& keyOut) const |
| 260 | { |
| 261 | LOCK(cs_wallet); |
| 262 | std::map<CKeyID, CHDPubKey>::const_iterator mi = mapHdPubKeys.find(address); |
| 263 | if (mi != mapHdPubKeys.end()) |
| 264 | { |
| 265 | // if the key has been found in mapHdPubKeys, derive it on the fly |
| 266 | const CHDPubKey &hdPubKey = (*mi).second; |
| 267 | CHDChain hdChainCurrent; |
| 268 | if (!GetHDChain(hdChainCurrent)) |
| 269 | throw std::runtime_error(std::string(__func__) + ": GetHDChain failed"); |
| 270 | if (!DecryptHDChain(hdChainCurrent)) |
| 271 | throw std::runtime_error(std::string(__func__) + ": DecryptHDChainSeed failed"); |
| 272 | // make sure seed matches this chain |
| 273 | if (hdChainCurrent.GetID() != hdChainCurrent.GetSeedHash()) |
| 274 | throw std::runtime_error(std::string(__func__) + ": Wrong HD chain!"); |
| 275 | |
| 276 | CExtKey extkey; |
| 277 | hdChainCurrent.DeriveChildExtKey(hdPubKey.nAccountIndex, hdPubKey.nChangeIndex != 0, hdPubKey.extPubKey.nChild, extkey); |
| 278 | keyOut = extkey.key; |
| 279 | |
| 280 | return true; |
| 281 | } |
| 282 | else { |
| 283 | return CCryptoKeyStore::GetKey(address, keyOut); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | bool CWallet::HaveKey(const CKeyID &address) const |
| 288 | { |
nothing calls this directly
no test coverage detected