forked from goatpig/BitcoinArmory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayground.cpp
More file actions
144 lines (118 loc) · 2.55 KB
/
playground.cpp
File metadata and controls
144 lines (118 loc) · 2.55 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "BDM_mainthread.h"
//#include <readline/readline.h>
//#include <readline/history.h>
/*
class Pager
{
std::string pagerFile;
std::ofstream stream_;
pid_t child;
public:
Pager()
{
for (int i=0; i < 1000; i++)
{
std::ostringstream ss;
ss << "/tmp/armory-pager-" << getpid() << i;
if (0==mkfifo(ss.str().c_str(), 0600))
{
pagerFile = ss.str();
break;
}
else if (errno == EEXIST)
{
// ok
}
else
{
throw std::runtime_error("Failed to create pager fifo");
}
}
child = vfork();
if (child == 0)
{
execlp("less", "less", "-f", "-r", pagerFile.c_str(), nullptr);
exit(1);
}
else if (child == -1)
{
throw std::runtime_error("Failed to run pager");
}
stream_.open(pagerFile);
}
std::ostream &stream() { return stream_; }
~Pager()
{
if (child != -1)
{
kill(child, SIGHUP);
wait();
}
}
void wait()
{
stream_.close();
int r;
waitpid(child, &r, 0);
child=-1;
unlink(pagerFile.c_str());
}
};
*/
static std::string formattedBtc(uint64_t satoshis)
{
std::ostringstream ss;
ss << satoshis;
std::string s = ss.str();
s.insert(s.length()-8, ".");
return s;
}
class Callback : public BDM_CallBack
{
public:
bool ready=false;
virtual void run(BDMAction action, void* ptr, int block=0)
{
if (action==BDMAction_Ready)
ready=true;
}
virtual void progress(
BDMPhase phase,
const string &walletId,
float progress, unsigned secondsRem,
unsigned progressNumeric
)
{
}
};
class Inject : public BDM_Inject
{
public:
virtual void run()
{
}
};
int main()
{
Log::SetLogFile("/dev/null");
Log::SetLogLevel(LogLvlDebug4);
//signal(SIGINT, SIG_IGN);
//signal(SIGPIPE, SIG_IGN);
BlockDataManagerConfig config;
config.armoryDbType = ARMORY_DB_SUPER;
config.pruneType = DB_PRUNE_NONE;
config.blkFileLocation = std::string(getenv("HOME")) + "/.bitcoin/testnet3/blocks";
config.levelDBLocation = "/mnt/home/charles/tmp/blockchain2";
config.selectNetwork("Test");
BlockDataManagerThread bdmthread(config);
Callback cb;
Inject in;
bdmthread.start(0, &cb, &in);
while (!cb.ready)
{
in.wait(1000);
}
bdmthread.shutdownAndWait();
return 0;
}
// kate: indent-width 3; replace-tabs on;