forked from KMDLabs/LabsNotary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utxosplitter.sh
executable file
·65 lines (55 loc) · 1.99 KB
/
utxosplitter.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
#!/bin/bash
cd "${BASH_SOURCE%/*}" || exit
# Optionally just split UTXOs for a single coin
# e.g "KMD"
specific_coin=$1
kmd_target_utxo_count=50
kmd_split_threshold=25
other_target_utxo_count=20
other_split_threshold=10
date=$(date +%Y-%m-%d:%H:%M:%S)
calc() {
awk "BEGIN { print "$*" }"
}
if [[ -z "${specific_coin}" ]]; then
echo "----------------------------------------"
echo "Splitting UTXOs - ${date}"
echo "KMD target UTXO count: ${kmd_target_utxo_count}"
echo "KMD split threshold: ${kmd_split_threshold}"
echo "Other target UTXO count: ${other_target_utxo_count}"
echo "Other split threshold: ${other_split_threshold}"
echo "----------------------------------------"
fi
./listcoins.sh | while read coin; do
if [[ -z "${specific_coin}" ]] || [[ "${specific_coin}" = "${coin}" ]]; then
cli=$(./listclis.sh ${coin})
if [[ "${coin}" = "KMD" ]]; then
target_utxo_count=$kmd_target_utxo_count
split_threshold=$kmd_split_threshold
else
target_utxo_count=$other_target_utxo_count
split_threshold=$other_split_threshold
fi
satoshis=10000
amount=$(calc $satoshis/100000000)
listunspent=$(${cli} listunspent)
numtotal=$(echo ${listunspent} | jq length)
if [[ "${listunspent}" = "" ]] || [[ ${numtotal} = 0 ]]; then
echo "[$coin] Listuspent call failed aborting!"
else
utxo_count=$(echo ${listunspent} | jq '[.[] | select (.scriptPubKey | length > 60 )]' | grep 0.0001 | wc -l)
echo "[${coin}] Current UTXO count is ${utxo_count}"
utxo_required=$(calc ${target_utxo_count}-${utxo_count})
if [[ ${utxo_required} -gt ${split_threshold} ]]; then
echo "[${coin}] Splitting ${utxo_required} extra UTXOs"
json=$(./splitfunds.sh ${coin} ${utxo_required})
txid=$(echo ${json} | jq -r '.txid')
if [[ ${txid} != "null" ]]; then
echo "[${coin}] Split TXID: ${txid}"
else
echo "[${coin}] Error: $(echo ${json} | jq -r '.error')"
fi
fi
fi
fi
done