-
Notifications
You must be signed in to change notification settings - Fork 10
/
collectall
executable file
·51 lines (43 loc) · 1.53 KB
/
collectall
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
#!/bin/bash
#
# Loop and collect every UTXO until completely consolidated
#
# Usage: collectall <coinname> <exclude_amount (optional - consolidate all but this value)
# e.g. ./collectall KMD 0.0001
#
# If exclude_amount is specified, it will ignore these values
# @author webworker01
#
scriptpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $scriptpath/main
cd "${BASH_SOURCE%/*}" || exit
# Specify coin
if [[ -z $1 ]]; then
echo "collectall <coinname> <exclude_amount (optional - consolidate all but this value)"
exit 0
fi
coin=$1
if [[ $1 != "KMD" ]]; then
coin=$1
asset=" -ac_name=${1}"
else
coin="KMD"
asset=""
fi
if [[ -z $2 ]]; then
exclude_amount=0
else
exclude_amount=$2
fi
# Get current UTXO amount
unspent_amount=$($komodocli $asset listunspent | jq --arg checkaddr $nn_address --arg exclude_amount $exclude_amount '[.[] | select(.amount!=($exclude_amount|tonumber) and .address==$checkaddr and .spendable==true)] | length')
log "collectall" "unspent_amount: $unspent_amount"
c=0
while (( unspent_amount > 1)); do
txid=$(consolidateUTXOs ${coin} ${exclude_amount})
waitForConfirm ${coin} ${txid}
unspent_amount=$($komodocli $asset listunspent | jq --arg checkaddr $nn_address --arg exclude_amount $exclude_amount '[.[] | select(.amount!=($exclude_amount|tonumber) and .address==$checkaddr and .spendable==true)] | length')
log "collectall" "Consolidate TX: $txid New unspent_amount: $unspent_amount"
c=$((c+1))
done
log "collectall" "Consolidation completed x${c}"