Skip to content

Commit 66c2cad

Browse files
committed
Rename BIP32PubkeyProvider.m_extkey to m_root_extkey
Renaming clarifies that m_extkey is actually the root extkey that keys are derived from.
1 parent df55d44 commit 66c2cad

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/script/descriptor.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,19 @@ enum class DeriveType {
254254
/** An object representing a parsed extended public key in a descriptor. */
255255
class BIP32PubkeyProvider final : public PubkeyProvider
256256
{
257-
CExtPubKey m_extkey;
257+
// Root xpub, path, and final derivation step type being used, if any
258+
CExtPubKey m_root_extkey;
258259
KeyPath m_path;
259260
DeriveType m_derive;
260261

261262
bool GetExtKey(const SigningProvider& arg, CExtKey& ret) const
262263
{
263264
CKey key;
264-
if (!arg.GetKey(m_extkey.pubkey.GetID(), key)) return false;
265-
ret.nDepth = m_extkey.nDepth;
266-
std::copy(m_extkey.vchFingerprint, m_extkey.vchFingerprint + sizeof(ret.vchFingerprint), ret.vchFingerprint);
267-
ret.nChild = m_extkey.nChild;
268-
ret.chaincode = m_extkey.chaincode;
265+
if (!arg.GetKey(m_root_extkey.pubkey.GetID(), key)) return false;
266+
ret.nDepth = m_root_extkey.nDepth;
267+
std::copy(m_root_extkey.vchFingerprint, m_root_extkey.vchFingerprint + sizeof(ret.vchFingerprint), ret.vchFingerprint);
268+
ret.nChild = m_root_extkey.nChild;
269+
ret.chaincode = m_root_extkey.chaincode;
269270
ret.key = key;
270271
return true;
271272
}
@@ -280,7 +281,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider
280281
}
281282

282283
public:
283-
BIP32PubkeyProvider(uint32_t exp_index, const CExtPubKey& extkey, KeyPath path, DeriveType derive) : PubkeyProvider(exp_index), m_extkey(extkey), m_path(std::move(path)), m_derive(derive) {}
284+
BIP32PubkeyProvider(uint32_t exp_index, const CExtPubKey& extkey, KeyPath path, DeriveType derive) : PubkeyProvider(exp_index), m_root_extkey(extkey), m_path(std::move(path)), m_derive(derive) {}
284285
bool IsRange() const override { return m_derive != DeriveType::NO; }
285286
size_t GetSize() const override { return 33; }
286287
bool GetPubKey(int pos, const SigningProvider& arg, CPubKey* key, KeyOriginInfo& info) const override
@@ -292,7 +293,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider
292293
*key = priv_key.GetPubKey();
293294
} else {
294295
// TODO: optimize by caching
295-
CExtPubKey extkey = m_extkey;
296+
CExtPubKey extkey = m_root_extkey;
296297
for (auto entry : m_path) {
297298
extkey.Derive(extkey, entry);
298299
}
@@ -301,7 +302,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider
301302
*key = extkey.pubkey;
302303
}
303304
}
304-
CKeyID keyid = m_extkey.pubkey.GetID();
305+
CKeyID keyid = m_root_extkey.pubkey.GetID();
305306
std::copy(keyid.begin(), keyid.begin() + sizeof(info.fingerprint), info.fingerprint);
306307
info.path = m_path;
307308
if (m_derive == DeriveType::UNHARDENED) info.path.push_back((uint32_t)pos);
@@ -310,7 +311,7 @@ class BIP32PubkeyProvider final : public PubkeyProvider
310311
}
311312
std::string ToString() const override
312313
{
313-
std::string ret = EncodeExtPubKey(m_extkey) + FormatHDKeypath(m_path);
314+
std::string ret = EncodeExtPubKey(m_root_extkey) + FormatHDKeypath(m_path);
314315
if (IsRange()) {
315316
ret += "/*";
316317
if (m_derive == DeriveType::HARDENED) ret += '\'';

0 commit comments

Comments
 (0)