-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_functions.cpp
68 lines (56 loc) · 2.09 KB
/
script_functions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "script_functions.h"
/*
Functions that help display what a descriptor's corresponding script will look like.
Note: currently some of these scripts will be invalid since if a private key is
provided, then the script is constructed using that as opposed to the private key's
corresponding private key.
*/
std::string get_script_string(const ScriptExpression& script_expr) {
auto it = script_functions.find(script_expr.script_function);
assert(it != script_functions.end());
auto script_f = it->second;
return script_f(script_expr);
}
std::string sh_get_script(const ScriptExpression& script_expr)
{
std::string out{""};
out += "OP_HASH160 hash160(" + get_script_string(std::get<ScriptExpression>(script_expr.script_args[0])) + ") OP_EQUAL";
return out;
}
std::string wsh_get_script(const ScriptExpression& script_expr)
{
std::string out{""};
out += "OP_0 sha256(" + get_script_string(std::get<ScriptExpression>(script_expr.script_args[0])) + ")";
return out;
}
std::string pk_get_script(const ScriptExpression& script_expr)
{
std::string out{""};
out += std::get<KeyExpression>(script_expr.script_args[0]).get_raw_key() + " OP_CHECKSIG";
return out;
}
std::string pkh_get_script(const ScriptExpression& script_expr)
{
std::string out{""};
out += "OP_DUP OP_HASH160 hash160(" + std::get<KeyExpression>(script_expr.script_args[0]).get_raw_key() + ") OP_EQUALVERIFY OP_CHECKSIG";
return out;
}
std::string wpkh_get_script(const ScriptExpression& script_expr)
{
std::string out{""};
out += "OP_0 hash160(" + std::get<KeyExpression>(script_expr.script_args[0]).get_raw_key() + ")";
return out;
}
std::string multi_get_script(const ScriptExpression& script_expr)
{
std::string out{""};
if (script_expr.script_args.size() - 1 <= 16) out += "OP_";
for (const ScriptArg& script_arg : script_expr.script_args)
{
const KeyExpression* ptr_key_expr = std::get_if<KeyExpression>(&script_arg);
assert (ptr_key_expr);
out += ptr_key_expr->get_raw_key();
}
out += "OP_CHECKMULTISIG";
return out;
}