-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminiscript.json.cpp
More file actions
executable file
·76 lines (61 loc) · 3.05 KB
/
miniscript.json.cpp
File metadata and controls
executable file
·76 lines (61 loc) · 3.05 KB
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
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <stdio.h>
#include <string>
#include <ctype.h>
#include <assert.h>
#include <script/miniscript.h>
#include "compiler.h"
using miniscript::operator"" _mst;
static bool run(std::string&& line, int64_t count) {
if (line.size() && line.back() == '\n') line.pop_back();
if (line.size() == 0) return false;
miniscript::NodeRef<std::string> ret;
double avgcost = 0;
if (Compile(Expand(line), ret, avgcost)) {
auto str = ret->ToString(COMPILER_CTX);
assert(str);
printf(
"\n{ \"X\":\"X\",\n\"total\":\"%17.10f\",\n\"scriptlen\":\"%5i\",\n\"miniscript\":\"%s\"\n }\n",
ret->ScriptSize() + avgcost, (int)ret->ScriptSize(),
Abbreviate(std::move(*str)).c_str()
);
} else if ((ret = miniscript::FromString(Expand(line), COMPILER_CTX))) {
auto ms = ret->ToString(COMPILER_CTX);
assert(ms);
printf("{ \"count\": \"%7li\",\n",(long)count);
printf("\"scriptlen\" : \"%i\",\n",(int)ret->ScriptSize());
printf("\"maxops\" : \"%i\",\n",(int)ret->GetOps());
printf("\"type\" : \"%s\",\n",ret->GetType() << "B"_mst ? "B" : ret->GetType() << "V"_mst ? "V" : ret->GetType() << "W"_mst ? "W" : ret->GetType() << "K"_mst ? "K" : "(invalid)");
printf("\"safe\" : \"%s\",\n",ret->GetType() << "s"_mst ? "yes" : "no");
printf("\"nonmal\" : \"%s\",\n",ret->GetType() << "m"_mst ? "yes" : "no");
printf("\"dissat\" : \"%s\",\n",ret->GetType() << "f"_mst ? "no" : ret->GetType() << "e"_mst ? "unique" : ret->GetType() << "d"_mst ? "yes" : "unknown");
printf("\"input\" : \"%s\",\n",ret->GetType() << "z"_mst ? "0" : ret->GetType() << "o"_mst ? (ret->GetType() << "n"_mst ? "1n" : "1") : ret->GetType() << "n"_mst ? "n" : "-");
printf("\"output\" : \"%s\",\n",ret->GetType() << "u"_mst ? "1" : "nonzero");
printf("\"timelock_mix\" : \"%s\",\n",ret->GetType() << "k"_mst ? "no": "yes");
printf("\"miniscript\" : \"%s\" }\n",Abbreviate(*ms).c_str());
assert(ms);
// printf("%7li\nscriptlen=%i\nmaxops=%i\ntype=%s\nsafe=%s\nnonmal=%s\ndissat=%s\ninput=%s\noutput=%s\ntimelock_mix=%s\nminiscript=%s\n",
// (long)count,
// (int)ret->ScriptSize(),
// (int)ret->GetOps(),
// ret->GetType() << "B"_mst ? "B" : ret->GetType() << "V"_mst ? "V" : ret->GetType() << "W"_mst ? "W" : ret->GetType() << "K"_mst ? "K" : "(invalid)",
// ret->GetType() << "s"_mst ? "yes" : "no",
// ret->GetType() << "m"_mst ? "yes" : "no",
// ret->GetType() << "f"_mst ? "no" : ret->GetType() << "e"_mst ? "unique" : ret->GetType() << "d"_mst ? "yes" : "unknown",
// ret->GetType() << "z"_mst ? "0" : ret->GetType() << "o"_mst ? (ret->GetType() << "n"_mst ? "1n" : "1") : ret->GetType() << "n"_mst ? "n" : "-",
// ret->GetType() << "u"_mst ? "1" : "nonzero",
// ret->GetType() << "k"_mst ? "no": "yes",
// Abbreviate(*ms).c_str());
} else {
printf("Failed to parse as policy or miniscript '%s'\n", line.c_str());
}
return true;
}
int main(void) {
int64_t count = 0;
do {
std::string line;
std::getline(std::cin, line);
if (!run(std::move(line), count++)) break;
} while(true);
}