Changeset View
Changeset View
Standalone View
Standalone View
src/script/descriptor.cpp
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | std::string DescriptorChecksum(const Span<const char> &span) { | ||||
std::string ret(8, ' '); | std::string ret(8, ' '); | ||||
for (int j = 0; j < 8; ++j) { | for (int j = 0; j < 8; ++j) { | ||||
ret[j] = CHECKSUM_CHARSET[(c >> (5 * (7 - j))) & 31]; | ret[j] = CHECKSUM_CHARSET[(c >> (5 * (7 - j))) & 31]; | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
std::string AddChecksum(const std::string &str) { | std::string AddChecksum(const std::string &str) { | ||||
return str + "#" + DescriptorChecksum(MakeSpan(str)); | return str + "#" + DescriptorChecksum(str); | ||||
} | } | ||||
//////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////// | ||||
// Internal representation // | // Internal representation // | ||||
//////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////// | ||||
typedef std::vector<uint32_t> KeyPath; | typedef std::vector<uint32_t> KeyPath; | ||||
▲ Show 20 Lines • Show All 1,091 Lines • ▼ Show 20 Lines | bool CheckChecksum(Span<const char> &sp, bool require_checksum, | ||||
} | } | ||||
sp = check_split[0]; | sp = check_split[0]; | ||||
return true; | return true; | ||||
} | } | ||||
std::unique_ptr<Descriptor> Parse(const std::string &descriptor, | std::unique_ptr<Descriptor> Parse(const std::string &descriptor, | ||||
FlatSigningProvider &out, std::string &error, | FlatSigningProvider &out, std::string &error, | ||||
bool require_checksum) { | bool require_checksum) { | ||||
Span<const char> sp(descriptor.data(), descriptor.size()); | Span<const char> sp{descriptor}; | ||||
if (!CheckChecksum(sp, require_checksum, error)) { | if (!CheckChecksum(sp, require_checksum, error)) { | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
auto ret = ParseScript(0, sp, ParseScriptContext::TOP, out, error); | auto ret = ParseScript(0, sp, ParseScriptContext::TOP, out, error); | ||||
if (sp.size() == 0 && ret) { | if (sp.size() == 0 && ret) { | ||||
return std::unique_ptr<Descriptor>(std::move(ret)); | return std::unique_ptr<Descriptor>(std::move(ret)); | ||||
} | } | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
std::string GetDescriptorChecksum(const std::string &descriptor) { | std::string GetDescriptorChecksum(const std::string &descriptor) { | ||||
std::string ret; | std::string ret; | ||||
std::string error; | std::string error; | ||||
Span<const char> sp(descriptor.data(), descriptor.size()); | Span<const char> sp{descriptor}; | ||||
if (!CheckChecksum(sp, false, error, &ret)) { | if (!CheckChecksum(sp, false, error, &ret)) { | ||||
return ""; | return ""; | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
std::unique_ptr<Descriptor> InferDescriptor(const CScript &script, | std::unique_ptr<Descriptor> InferDescriptor(const CScript &script, | ||||
const SigningProvider &provider) { | const SigningProvider &provider) { | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |