-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetTXfeeII.sh
More file actions
265 lines (220 loc) · 6.93 KB
/
getTXfeeII.sh
File metadata and controls
265 lines (220 loc) · 6.93 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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/bash
txID="${1}" #1 represent 1st argument
isShieldedOut=0
isShieldedIn=0
./toCurl.sh getrawtransaction $txID 1 > txidJSON
#rawTx=$txJSON
#Check for Orchard
isOrchard=$(cat txidJSON | jq .orchard)
lenO=${#isOrchard}
#Check for Sapling
isSaplingSpend=$(cat txidJSON | jq .vShieldedSpend)
isSaplingOutput=$(cat txidJSON | jq .vShieldedOutput)
isSapling=0
if [[ -z "$isSaplingSpend" ]] || [[ "$isSaplingSpend" == "[]" ]]; then
#no Sapling Spend
isSapling=0
if [[ -z "$isSaplingOutput" ]] || [[ "$isSaplingOutput" == "[]" ]]; then
#echo "test"
#no Sapling Output
isSapling=0
else
isSapling=1
#echo "Sapling Output tx"
fi
else
isSapling=1
#echo "Sapling Spend tx"
fi
#if [[ -z "$isSaplingOutput" ]] || [[ "$isSaplingOutput" == "[]" ]]; then
#
# echo "test"
# #no Sapling Output
# isSapling=0
#else
# isSapling=1
# #echo "Sapling Output tx"
#fi
#Check for Sprout
isSprout=$(cat txidJSON | jq .vjoinsplit)
lenS=${#isSprout}
if [[ "$lenS" -gt 4 ]] ;then
isShieldedOut=1
fi
#Check vouts
nullCheck=$(cat txidJSON | jq .vout[])
if [[ -n "$nullCheck" ]] && [[ "$nullCheck" != "" ]];then
voutSum=$(cat txidJSON | jq -r '.vout[] | .valueZat' | awk '{s+=$1} END {OFMT="%f";print s}')
#If coinbase, add lockbox portion see line 63
#check for mix txids here
shieldCheck=$(cat txidJSON | jq -r '.orchard.actions | length')
nullCheck=$(cat txidJSON | jq .vin[])
if [[ $shieldCheck -gt 0 ]] && [[ -n "$nullCheck" ]];then
isShieldedOut=1
elif [[ $isSapling -eq 1 ]] && [[ -n "$nullCheck" ]];then
isShieldedOut=1
fi
else
isShieldedOut=1
voutSum=0
fi
#Check vins
nullCheck=$(cat txidJSON | jq .vin[])
if [[ -n "$nullCheck" ]] && [[ "$nullCheck" != "" ]];then
isCoinbase=$(cat txidJSON | jq .vin[] | grep -o coinbase)
if [[ "$isCoinbase" == "coinbase" ]];then
#1046400 canopy starts subsidy
cBlock=$(cat txidJSON | jq .height)
if [[ "$cBlock" -ge 1046400 ]];then
vinSum=$(./toCurl.sh getblocksubsidy $cBlock | jq .totalblocksubsidy)
vinSum=$(echo "($vinSum * 100000000)/1" | bc)
#NU6 lockbox starts
if [[ "$cBlock" -ge 2726400 ]];then
lockbox=$(./toCurl.sh getblocksubsidy $cBlock | jq .lockboxstreams[].valueZat)
else
#lockbox=$(./toCurl.sh getblocksubsidy 2726399 | jq .fundingstreams[].valueZat)
lockbox=0
fi
else
vinSum=0
lockbox=0
fi
voutSum=$(echo "$voutSum + $lockbox" | bc )
else
if [[ "$nullCheck" == "[]" ]];then
isShieldedIn=1
vinSum=0
else
#loop through vins
length=$(cat txidJSON | jq -r '.vin | length')
index=0
if [ -f temp.md ]; then
rm temp.md
fi
while [[ "$index" -lt "$length" ]]
do
tempIndex=$(cat txidJSON | jq .vin[$index].vout)
vinSum=$(cat txidJSON | jq .vin[$index].txid | xargs -n1 ./txDetails.sh | jq .vout[$tempIndex].valueZat)
echo $vinSum >> temp.md
index=$((($index + 1)))
done
vinSum=$(cat temp.md | awk '{s+=$1} END {OFMT="%f";print s}')
fi
shieldCheck=$(cat txidJSON | jq -r '.orchard.actions | length')
nullCheck=$(cat txidJSON | jq .vout[])
if [[ $shieldCheck -gt 0 ]] && [[ -n "$nullCheck" ]] && [[ $vinSum -eq 0 ]];then
isShieldedIn=1
elif [[ $isSapling -eq 1 ]] && [[ -n "$nullCheck" ]];then
isShieldedIn=1
#elif [[ "$lenS" -gt 4 ]];then
# isShieldedIn=1
fi
fi
else
isShieldedIn=1
vinSum=0
fi
# If Shielded, update Sums based on type of Shielding
outValueBalance=0 #voutSum
inValueBalance=0 #vinSum
#echo "isShieldedOut: $isShieldedOut"
#echo "isShieldedIn : $isShieldedIn"
#Check voutSum first
if [[ "$isShieldedOut" -eq 1 ]];then
if [[ "$lenS" -gt 4 ]];then
#vpub_oldZat vs newZat check
temp=$(cat txidJSON | jq .valueBalanceZat)
if [[ "$temp" -ne 0 ]];then
outValueBalance=$temp
else
outValueBalance=$(cat txidJSON | jq .vjoinsplit[].vpub_oldZat | awk '{s+=$1} END {print s}')
outValueBalance=$(echo "$outValueBalance * -1" | bc)
fi
elif [[ "$isSapling" -eq 1 ]];then
outValueBalance=$(cat txidJSON | jq .valueBalanceZat)
if [[ -n "$isOrchard" ]] && [[ "$lenO" -gt 4 ]];then
myOrchard=$(cat txidJSON | jq .orchard.valueBalanceZat)
outValueBalance=$(echo "$outValueBalance + $myOrchard" | bc)
fi
elif [[ -n "$isOrchard" ]] && [[ "$lenO" -gt 4 ]];then
outValueBalance=$(cat txidJSON | jq .orchard.valueBalanceZat)
else
echo "debug"
fi
outValueBalance=$(echo "$outValueBalance * -1" | bc)
fi
#Check vinSum second
if [[ "$isShieldedIn" -eq 1 ]];then
#echo "lenS: $lenS"
if [ "$lenS" -gt 4 ];then
#echo "test"
vinSum=$(cat txidJSON | jq .vjoinsplit[].vpub_newZat | awk '{s+=$1} END {print s}')
fi
if [[ "$isSapling" -eq 1 ]];then
inValueBalance=$(cat txidJSON | jq .valueBalanceZat)
if [[ -n "$isOrchard" ]] && [[ "$lenO" -gt 4 ]];then
myOrchard=$(cat txidJSON | jq .orchard.valueBalanceZat)
inValueBalance=$(echo "$inValueBalance + $myOrchard" | bc)
fi
elif [[ -n "$isOrchard" ]] && [[ "$lenO" -gt 4 ]];then
inValueBalance=$(cat txidJSON | jq .orchard.valueBalanceZat)
else
echo "debug"
fi
fi
if [[ "$isSapling" -eq 0 ]] && [[ -z $vinSum ]];then
if [[ $inValueBalance -lt 0 ]];then
inValueBalance=0
fi
#finalIn=$inValueBalance
elif [[ "$isSapling" -eq 1 ]];then
if [[ $inValueBalance -lt 0 ]];then
inValueBalance=0
fi
fi
if [[ "$isSapling" -eq 0 ]] && [[ -z "$voutSum" ]];then
if [[ "$outValueBalance" -lt 0 ]];then
outValueBalance=0
fi
#finalOut=$outValueBalance
elif [[ "$isSapling" -eq 1 ]];then
if [[ "$outValueBalance" -lt 0 ]];then
outValueBalance=0
fi
fi
if [[ "$isCoinbase" = "coinbase" ]];then
outValueBalance=0
inValueBalance=0
vinSum=0
voutSum=0
fi
#echo "vinSum: $vinSum"
#echo "inValueBalance: $inValueBalance"
#echo "voutSum: $voutSum"
#echo "outValueBalance: $outValueBalance"
finalOut=$(echo "$voutSum + $outValueBalance" | bc )
finalIn=$(echo "$vinSum + $inValueBalance" | bc )
#echo "finalOut: $finalOut"
#echo "finalIn : $finalIn"
#finalOut=$((( $voutSum + $outValueBalance )))
#finalIn=$((( $vinSum + $inValueBalance )))
#if Coinbase tx, swap signs
if [[ "$isCoinbase" == "coinbase" ]];then
fee=$(echo "$finalOut - $finalIn"| bc)
else
fee=$(echo "$finalIn - $finalOut"| bc)
fi
finalOut=$(echo "scale=2; $finalOut / 100000000" | bc)
finalIn=$(echo "scale=2; $finalIn / 100000000" | bc)
#echo "In : $vinSum ZEC"
#echo "Out : $voutSum ZEC"
#echo "-------------------"
if [[ $fee -eq 0 ]]; then
printf '%05.0f Zats' $fee
else
echo "$fee Zats"
fi
#echo "$fee Zats"
if [ -f temp.md ]; then
rm temp.md
fi