-
Notifications
You must be signed in to change notification settings - Fork 10
/
cronsplit
executable file
·134 lines (111 loc) · 4.24 KB
/
cronsplit
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
#!/bin/bash
#
# Split funds cron job
#
# Suggest setting up 2 crontabs, 1 for komodo and assetchains and the other hourly for longer potential blocktimes
#
# crontab -e
# */15 * * * * /home/komodo/nntools/cronsplit
# 1 * * * * /home/komodo/nntools/cronsplit long
#
# @author webworker01
#
scriptpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $scriptpath/main
utxoamt=0.00010000
splitamount=10000
skipshort=('DPOW')
skiplong=('DPOW')
doSplit() {
local coin=$1
acutxo=$($komodocli -ac_name=${coin} listunspent | jq --arg amt "$utxoamt" '[.[] | select(.amount==($amt|tonumber))] | length')
if (( acutxo < acutxoqty )); then
if [[ ! ${sproutcoins[*]} =~ ${coin} ]]; then
echo "${coin} utxos sapling: $acutxo"
splitter=$($scriptpath/splitfunds ${coin} $acutxoqty)
else
echo "${coin} utxos sprout: $acutxo"
splitter=$($scriptpath/splitfunds ${coin} $acutxoqty 0)
fi
log "cronsplit" "${coin} - utxos: $acutxo - txid: $splitter"
fi
}
#no params in cli indicates just the short list of kmd specific coins
if [[ -z $1 ]]; then
kmdutxos=$($komodocli listunspent | jq --arg amt "$utxoamt" '[.[] | select(.amount==($amt|tonumber))] | length')
if (( kmdutxos < kmdutxoqty )); then
echo "KMD utxos: $kmdutxos"
splitter=$($scriptpath/splitfunds KMD $kmdutxoqty)
log "cronsplit" "KMD - utxos: $kmdutxos - $splitter"
fi
if (( thirdpartycoins < 1 )); then
for coins in "${coinlist[@]}"; do
coin=($coins)
if [[ ! ${ignoreacs[*]} =~ ${coin[0]} ]] && [[ ! ${skipshort[*]} =~ ${coin[0]} ]]; then
doSplit ${coin[0]}
fi
done
else
for coins in "${coinsthird[@]}"; do
coin=($coins)
if [[ ${komodolike[*]} =~ ${coin[0]} ]]; then
doSplit ${coin[0]}
fi
done
fi
else
declare -a othercoins=()
if (( thirdpartycoins < 1 )); then
for i in ${!coinsfirst[@]}; do
othercoins[$i]="${coinsfirst[$i]}"
done
else
for i in ${!coinsthird[@]}; do
othercoins[$i]="${coinsthird[$i]}"
done
fi
#for now any param indicates to run the long running coins (e.g. btc game chips) run this every hour or something?
for coins in "${othercoins[@]}"; do
coin=($coins)
if [[ ${skiplong[*]} =~ ${coin[0]} ]] || [[ ${komodolike[*]} =~ ${coin[0]} ]]; then
continue
fi
usebigsplit=('GAME' 'EMC2' 'AYA' 'MIL')
if [[ ${usebigsplit[*]} =~ ${coin[0]} ]]; then
coinsutxoamount=0.00100000
coinsplitamount=100000
else
coinsutxoamount=$utxoamt
coinsplitamount=$splitamount
fi
# if [[ ${coin[0]} == "BTC" ]]; then
# otherutxoqty=$btcutxoqty
# fi
if [[ ${coin[0]} == "LTC" ]]; then
otherutxoqty=$ltcutxoqty
fi
eval $(echo coincli=${coin[1]})
otherutxo=$(${coincli} listunspent | jq --arg amt "$coinsutxoamount" '[.[] | select(.amount==($amt|tonumber))] | length')
if (( otherutxo < otherutxoqty )); then
echo "${coin[0]} utxos: $otherutxo"
cointosplit=${coin[0]}
raw_tx=$(curl -s --url "http://127.0.0.1:$iguanaport" --data "{\"coin\":\"${cointosplit}\",\"agent\":\"iguana\",\"method\":\"splitfunds\",\"satoshis\":\"$coinsplitamount\",\"sendflag\":1,\"duplicates\":$otherutxoqty}")
raw_tx=$(jq -r .result <<< $raw_tx)
if [[ ! -z $raw_tx ]]; then
usesignrawtxwallet=('AYA')
if [[ ${usesignrawtxwallet[*]} =~ ${coin[0]} ]]; then
signed_tx=$(${coincli} signrawtransactionwithwallet ${raw_tx})
else
signed_tx=$(${coincli} signrawtransaction ${raw_tx})
fi
signed_tx=$(jq -r .hex <<< $signed_tx)
if [[ ! -z $signed_tx ]]; then
txid=$(${coincli} sendrawtransaction ${signed_tx})
if [[ ! -z $txid ]]; then
log "cronsplit" "${coin[0]} - utxos: ${otherutxo} - ${txid}"
fi
fi
fi
fi
done
fi