-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.sh
executable file
·221 lines (192 loc) · 5.3 KB
/
metrics.sh
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
mempool () { # function to scrape transactions from mempool
memcall="$(zen-cli getrawmempool)"
time="$(date +%s)"
while IFS=',' read -ra ADDR; do
for i in "${ADDR[@]}"; do
if [[ $i == *"\""* ]]; then
if ! grep -q "${i:3:64}" mempool.txt; then
echo "${i:3:64}, $time">> mempool.txt
fi
fi
done
done <<< "$memcall"
}
send () { # function to create transactions with multiple inputs
zfrom="ztftydJRhDSXvctekQB7e1BRubfhnFWFdgS"
zto="ztcLKgUC9JrN1519ZjXmNy9wXAKnVcFE9tX"
ztwo="0.0001"
zfifty="0.0049"
zmany="0.0199"
sendtwo="$(zen-cli z_sendmany "$zfrom" "[{\"amount\": $ztwo, \"address\": \"$zto\"}]")"
sendfifty="$(zen-cli z_sendmany "$zfrom" "[{\"amount\": $zfifty, \"address\": \"$zto\"}]")"
sendmany="$(zen-cli z_sendmany "$zfrom" "[{\"amount\": $zmany, \"address\": \"$zto\"}]")"
success="\"status\": \"success\","
echo
if [[ $sendtwo = *opid* ]]; then
opr="$(zen-cli z_getoperationresult)"
if [[ "$opr" == *"$success"* ]]; then
echo "$opr" >> metrics.txt
echo "two success"
else
echo
echo "-------------"
echo "failed"
echo "$opr"
echo "-------------"
echo
fi
else
echo "transaction malformed"
fi
echo
echo
if [[ $sendfifty = *opid* ]]; then
opr="$(zen-cli z_getoperationresult)"
if [[ "$opr" == *"$success"* ]]; then
echo "$opr" >> metrics.txt
echo "fifty success"
else
echo
echo "-------------"
echo "failed"
echo "$opr"
echo "-------------"
echo
fi
else
echo "transaction malformed"
fi
echo
echo
if [[ $sendmany = *opid* ]]; then
opr="$(zen-cli z_getoperationresult)"
if [[ "$opr" == *"$success"* ]]; then
echo "$opr" >> metrics.txt
echo "many success"
else
echo
echo "-------------"
echo "failed"
echo "$opr"
echo "-------------"
echo
fi
else
echo "transaction malformed"
fi
echo
}
write_pool () { # reads mempool.txt and retrieves all data to write to csv, clears mempool.txt after
filename="mempool.txt"
error="error code: -5"
write=0
while read -r line
do
txid="${line:0:64}"
creation_time="${line:66}"
blocktime="$(zen-cli getrawtransaction $txid 1 | sed -n 's/.*\"blocktime\": //p')"
delta=$((blocktime - $creation_time))
amounts="$(zen-cli getrawtransaction $txid 1 | sed -n 's/.*\"value\"://p')"
search=","
amount="${amounts%%$search*}"
inputs="$(zen-cli getrawtransaction $txid 1)"
vout="vout"
NumberOfMatches=$(echo "$string" | tr " " "\n" | grep -c "$vout")
num=$(( NumberOfMatches - 1 ))
if (( num < 0 )); then
num=0
fi
outputs="$(zen-cli getrawtransaction $txid 1)"
n="\"n\":"
numofoutputs=$(echo "$outputs" | tr " " "\n" | grep -c "$n")
outnum=$(( numofoutputs - 1 ))
if (( outnum < 0 )); then
num=0
fi
string="$txid, $amount, $creation_time, $blocktime, $delta, $num, $outnum"
echo ${string} | grep --quiet "${error}"
if [ $? = 1 ]; then
if [ -n "$amount" ]; then
if [ -n "$blocktime" ]; then
echo $string >> metrics.csv
write=1
fi
fi
fi
done < "$filename"
if [[ $write = 1 ]]; then
> $filename
fi
}
write_send() { # takes the result of send () and writes data to metrics.csv
echo "$(python3 metrics.py)"
filename="temp.txt"
error="error code: -5"
write=0
while read -r line
do
txid="${line:0:64}"
creation_time="${line:66}"
blocktime="$(zen-cli getrawtransaction $txid 1 | sed -n 's/.*\"blocktime\": //p')"
delta=$((blocktime - $creation_time))
amounts="$(zen-cli getrawtransaction $txid 1 | sed -n 's/.*\"value\"://p')"
search=","
amount="${amounts%%$search*}"
inputs="$(zen-cli getrawtransaction $txid 1)"
vout="vout"
NumberOfMatches=$(echo "$string" | tr " " "\n" | grep -c "$vout")
num=$(( NumberOfMatches - 1 ))
if (( num < 0 )); then
num=0
fi
outputs="$(zen-cli getrawtransaction $txid 1)"
n="\"n\":"
numofoutputs=$(echo "$outputs" | tr " " "\n" | grep -c "$n")
outnum=$(( numofoutputs - 1 ))
if (( outnum < 0 )); then
outnum=0
fi
string="$txid, $amount, $creation_time, $blocktime, $delta, $num, $outnum"
echo ${string} | grep --quiet "${error}"
if [ $? = 1 ]; then
if [ -n "$amount" ]; then
if [ -n "$blocktime" ]; then
echo $string >> metrics.csv
write=1
fi
fi
fi
done < "$filename"
if [[ $write = 1 ]]; then
> $filename
fi
}
echo "txid,amount,creation_time,inclusion_time,delta,number_inputs,number_outputs" > metrics.csv
starthour="$(date +%H)"
startmin="$(date +%M)"
while :
do
diff="$((10#$(date +%M) - startmin ))"
echo $diff
if [[ $diff -lt 0 ]]; then
startmin="$(date +%M)"
elif [[ $diff -lt 15 ]]; then # check to see if same hour as when started
# runs constantly throughout hour
mempool
echo "mempool"
sleep 1
elif [[ $starthour != $(date +%H) ]]; then
write_send
send
starthour="$(date +%H)"
sleep 1
echo "elif"
else # update time
# runs hourly
write_pool
echo "else"
startmin="$(date +%M)"
sleep 1
fi
done