forked from alexenglish/VerusExtras
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathchunksend.sh
executable file
·65 lines (54 loc) · 1.83 KB
/
chunksend.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
#Copyright Alex English September 2018
#This script comes with no warranty whatsoever. Use at your own risk.
#Tested on Ubuntu 17.10
#Make sure you have a correct path set for the verus cli
#This script will send funds to the specified address in separate transactions
#This is useful if you'd like to manage the size of the UTXOs, such as for staking.
#First arg - address to send to
#Second arg - amount to send
#Third arg - size of chunks - defaults to 2500 if not set
if ! source "$( dirname "${BASH_SOURCE[0]}" )"/config; then
echo "Failed to source config file. Please make sure you have the whole VerusExtras repo or at least also have the config file."
exit 1
fi
#Check for bc dependency
if ! command -v bc &> /dev/null ; then
echo "Please install bc (a command-line calculator)"
exit 1
fi
if [ "$#" -lt 2 ]; then
echo -e "Useage: ./chunksend.sh <ADDRESS> <AMOUNTTOSEND> (CHUNKSIZE)\nChunk size defaults to 1000"
exit
fi
#Check for address arg presence and format
ADDR=$1
if [ "${#ADDR}" -ne 34 ]; then
echo "Recipient address is not the correct length"
exit
fi
#Check for amount arg presence
AMT=$2
if [ -z "$AMT" ]; then
echo "No amount to send given"
exit
fi
CHUNK=$3
#set a default value if CHUNK is null
CHUNK=${CHUNK:-2500}
SENT=0
printf "Sending $AMT to $ADDR in chunks of $CHUNK\n" | tee chunktxlog
while (exit $(bc<<<"$SENT >= $AMT")); do
LEFT=$(bc<<<"$AMT - $SENT")
if [ "$(bc<<<"$LEFT >= $CHUNK")" -eq 1 ]; then
#send a full chunk
echo "Sending $CHUNK to $ADDR"
SENT=$(bc<<<"$SENT + $CHUNK")
$VERUS sendtoaddress "$ADDR" "$CHUNK" | tee -a chunktxlog
else
#send the last, partial chunk
echo "Sending $LEFT to $ADDR"
SENT=$(bc<<<"$SENT + $LEFT")
$VERUS sendtoaddress "$ADDR" "$LEFT" | tee -a chunktxlog
fi
done