aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2019-05-08 14:03:29 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2019-08-06 17:11:12 -0700
commit26d3fad1093dfc697048313be7a96c9adf723654 (patch)
treec3b4b85506298304ff339ba92f518353a177fa63 /src/script
parent104b3a5069c937383e6f88f2f3fb804ef61b208f (diff)
Add unmodified-but-with-checksum to getdescriptorinfo
Diffstat (limited to 'src/script')
-rw-r--r--src/script/descriptor.cpp8
-rw-r--r--src/script/descriptor.h8
2 files changed, 16 insertions, 0 deletions
diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp
index 95b949e9c2..a39cf635aa 100644
--- a/src/script/descriptor.cpp
+++ b/src/script/descriptor.cpp
@@ -938,6 +938,14 @@ std::unique_ptr<Descriptor> Parse(const std::string& descriptor, FlatSigningProv
return nullptr;
}
+std::string GetDescriptorChecksum(const std::string& descriptor)
+{
+ std::string ret;
+ Span<const char> sp(descriptor.data(), descriptor.size());
+ if (!CheckChecksum(sp, false, &ret)) return "";
+ return ret;
+}
+
std::unique_ptr<Descriptor> InferDescriptor(const CScript& script, const SigningProvider& provider)
{
return InferScript(script, ParseScriptContext::TOP, provider);
diff --git a/src/script/descriptor.h b/src/script/descriptor.h
index 29915c6c92..8c937d7fe5 100644
--- a/src/script/descriptor.h
+++ b/src/script/descriptor.h
@@ -81,6 +81,14 @@ struct Descriptor {
*/
std::unique_ptr<Descriptor> Parse(const std::string& descriptor, FlatSigningProvider& out, bool require_checksum = false);
+/** Get the checksum for a descriptor.
+ *
+ * If it already has one, and it is correct, return the checksum in the input.
+ * If it already has one that is wrong, return "".
+ * If it does not already have one, return the checksum that would need to be added.
+ */
+std::string GetDescriptorChecksum(const std::string& descriptor);
+
/** Find a descriptor for the specified script, using information from provider where possible.
*
* A non-ranged descriptor which only generates the specified script will be returned in all