forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wallet: move GetID() to Descriptor, add test vectors
This ensures that ToString(COMPAT) can't be changed accidentally.
- Loading branch information
Showing
5 changed files
with
89 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,6 +209,8 @@ struct PubkeyProvider | |
|
||
/** Derive a private key, if private data is available in arg. */ | ||
virtual bool GetPrivKey(int pos, const SigningProvider& arg, CKey& key) const = 0; | ||
|
||
virtual uint256 GetID() const = 0; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Sjors
Author
Owner
|
||
}; | ||
|
||
class OriginPubkeyProvider final : public PubkeyProvider | ||
|
@@ -260,6 +262,7 @@ class OriginPubkeyProvider final : public PubkeyProvider | |
{ | ||
return m_provider->GetPrivKey(pos, arg, key); | ||
} | ||
uint256 GetID() const override { return uint256(); } | ||
}; | ||
|
||
/** An object representing a parsed constant public key in a descriptor. */ | ||
|
@@ -305,6 +308,7 @@ class ConstPubkeyProvider final : public PubkeyProvider | |
{ | ||
return arg.GetKey(m_pubkey.GetID(), key); | ||
} | ||
uint256 GetID() const override { return uint256(); } | ||
}; | ||
|
||
enum class DeriveType { | ||
|
@@ -520,6 +524,8 @@ class BIP32PubkeyProvider final : public PubkeyProvider | |
key = extkey.key; | ||
return true; | ||
} | ||
|
||
uint256 GetID() const override { return uint256(); } | ||
}; | ||
|
||
/** Base class for all Descriptor implementations. */ | ||
|
@@ -702,6 +708,15 @@ class DescriptorImpl : public Descriptor | |
} | ||
|
||
std::optional<OutputType> GetOutputType() const override { return std::nullopt; } | ||
|
||
virtual uint256 GetID() const override { | ||
// Always use the apostrophe for spkm ID | ||
std::string desc_str = ToString(/*compat_format=*/true); | ||
uint256 id; | ||
CSHA256().Write((unsigned char*)desc_str.data(), desc_str.size()).Finalize(id.begin()); | ||
return id; | ||
} | ||
|
||
}; | ||
|
||
/** A parsed addr(A) descriptor. */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Why this if it's not being used anywhere and all the implementations return an empty uint256?
Only the
GetID()
in the descriptor struct is enough.