-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetTXfee.sh
More file actions
202 lines (165 loc) · 5.63 KB
/
Copy pathgetTXfee.sh
File metadata and controls
202 lines (165 loc) · 5.63 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
#!/bin/bash
txID="${1}" #1 represent 1st argument
isShieldedOut=0
isShieldedIn=0
#Check for Orchard
isOrchard=$(./txDetails.sh $txID | jq .orchard)
lenO=${#isOrchard}
#Check for Sapling
isSaplingSpend=$(./txDetails.sh $txID | jq .vShieldedSpend)
isSaplingOutput=$(./txDetails.sh $txID | jq .vShieldedOutput)
isSapling=0
if [[ -z "$isSaplingSpend" ]] || [[ "$isSaplingSpend" == "[]" ]]; then
#no Sapling Spend
isSapling=0
else
isSapling=1
#echo "Sapling Spend tx"
fi
if [[ -z "$isSaplingOutput" ]] || [[ "$isSaplingOutput" == "[]" ]]; then
#no Sapling Output
isSapling=0
else
isSapling=1
#echo "Sapling Output tx"
fi
#Check for Sprout
isSprout=$(./txDetails.sh $txID | jq .vjoinsplit)
lenS=${#isSprout}
if [[ "$lenS" -gt 4 ]] ;then
isShieldedOut=1
fi
#Check vouts
nullCheck=$(./txDetails.sh $txID | jq .vout[])
if [[ -n "$nullCheck" ]] && [[ "$nullCheck" != "" ]];then
voutSum=$(./txDetails.sh $txID | 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=$(./txDetails.sh $txID | jq -r '.orchard.actions | length')
nullCheck=$(./txDetails.sh $txID | 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=$(./txDetails.sh $txID | jq .vin[])
if [[ -n "$nullCheck" ]] && [[ "$nullCheck" != "" ]];then
isCoinbase=$(./txDetails.sh $txID | jq .vin[] | grep -o coinbase)
if [[ "$isCoinbase" = "coinbase" ]];then
vinSum=$(./toCurl.sh getblocksubsidy | jq .totalblocksubsidy)
vinSum=$(echo "($vinSum * 100000000)/1" | bc)
lockbox=$(./toCurl.sh getblocksubsidy | jq .lockboxstreams[].valueZat)
voutSum=$(echo "$voutSum + $lockbox" | bc )
else
if [[ "$nullCheck" == "[]" ]];then
isShieldedIn=1
vinSum=0
else
#loop through vins
length=$(./txDetails.sh $txID | jq -r '.vin | length')
index=0
if [ -f temp.md ]; then
rm temp.md
fi
while [[ "$index" -lt "$length" ]]
do
tempIndex=$(./txDetails.sh $txID | jq .vin[$index].vout)
vinSum=$(./txDetails.sh $txID | 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=$(./txDetails.sh $txID | jq -r '.orchard.actions | length')
nullCheck=$(./txDetails.sh $txID | jq .vout[])
if [[ $shieldCheck -gt 0 ]] && [[ -n "$nullCheck" ]];then
isShieldedIn=1
elif [[ $isSapling -eq 1 ]] && [[ -n "$nullCheck" ]];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
#Check voutSum first
if [[ "$isShieldedOut" -eq 1 ]];then
if [[ "$lenS" -gt 4 ]];then
outValueBalance=$(./txDetails.sh $txID | jq .vjoinsplit[].vpub_newZat | awk '{s+=$1} END {print s}')
elif [[ "$isSapling" -eq 1 ]];then
outValueBalance=$(./txDetails.sh $txID | jq .valueBalanceZat)
if [[ -n "$isOrchard" ]] && [[ "$lenO" -gt 4 ]];then
myOrchard=$(./txDetails.sh $txID | jq .orchard.valueBalanceZat)
outValueBalance=$(echo "$outValueBalance + $myOrchard" | bc)
fi
elif [[ -n "$isOrchard" ]] && [[ "$lenO" -gt 4 ]];then
outValueBalance=$(./txDetails.sh $txID | jq .orchard.valueBalanceZat)
else
echo "debug"
fi
outValueBalance=$(echo "$outValueBalance * -1" | bc)
fi
#Check vinSum second
if [[ "$isShieldedIn" -eq 1 ]];then
#if [ "$lenS" -gt 2 ];then
# vinSum=$(./txDetails.sh $txID | jq .vjoinsplit[].vpub_newZat)
if [[ "$isSapling" -eq 1 ]];then
inValueBalance=$(./txDetails.sh $txID | jq .valueBalanceZat)
if [[ -n "$isOrchard" ]] && [[ "$lenO" -gt 4 ]];then
myOrchard=$(./txDetails.sh $txID | jq .orchard.valueBalanceZat)
inValueBalance=$(echo "$inValueBalance + $myOrchard" | bc)
fi
elif [[ -n "$isOrchard" ]] && [[ "$lenO" -gt 4 ]];then
inValueBalance=$(./txDetails.sh $txID | 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
#echo "vinSum: $vinSum"
#echo "inValueBalance: $inValueBalance"
#echo "voutSum: $voutSum"
#echo "outValueBalance: $outValueBalance"
finalOut=$(echo "$voutSum + $outValueBalance" | bc )
finalIn=$(echo "$vinSum + $inValueBalance" | bc )
#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 "-------------------"
echo "$fee Zats"