-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathzsend
More file actions
executable file
·78 lines (63 loc) · 2.3 KB
/
zsend
File metadata and controls
executable file
·78 lines (63 loc) · 2.3 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
#!/bin/bash
#
# Script to simplify sending a specified amount to/from z addressess
#
# Usage: zsend <coinname> <fromaddress> <toaddress> <amounttosend> <memo>
#
# @author webworker01
#
scriptpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $scriptpath/main
if [[ -z $1 ]] || [[ -z $2 ]] || [[ -z $3 ]] || [[ -z $4 ]]; then
echo "Usage: zsend <coinname> <fromaddress> <toaddress> <amounttosend> <memo (optional)>"
exit 0
fi
if [[ ${1^^} != "KMD" ]]; then
coin=${1^^}
asset="-ac_name=${coin}"
else
coin="KMD"
asset=""
fi
fromaddress=$2
toaddress=$3
amounttosend=$4
memo=$5
feeamount=0.0001
#get balance
zbalance=$($komodocli $asset z_getbalance $fromaddress)
if (( $(echo "$amounttosend + $feeamount > $zbalance" | bc -l) )); then
echo "You cannot send more than your shielded balanced of $zbalance!"
exit 0
fi
change=$( printf "%.8f" $(bc -l <<< "($zbalance-$amounttosend-$feeamount)") )
echo "Balance: $zbalance"
echo "Send: $amounttosend"
echo "Fee: $feeamount"
echo "Change: $change"
if [[ ! -z ${memo} ]]; then
hexmemo=$(echo -n ${memo} | xxd -ps -u -l 512 -c 512)
reversehexmemo=$(echo -n ${hexmemo} | xxd -r -p)
if [[ "${reversehexmemo}" != "${memo}" ]]; then
echo "Warning your memo may have been truncated because it is too long:"
echo ${reversehexmemo}
fi
memotxstring=",\"memo\":\"${hexmemo}\""
else
memotxstring=""
fi
if [[ $change == "0.00000000" ]]; then
echo "${komodocli} ${asset} z_sendmany ${fromaddress} '[{"address":\"${toaddress}\","amount":${amounttosend}${memotxstring}}]' 1"
else
echo "${komodocli} ${asset} z_sendmany ${fromaddress} '[{"address":\"${toaddress}\","amount":${amounttosend}${memotxstring}},{"address":\"${fromaddress}\","amount":${change}]' 1"
fi
read -p "Do you want to execute this transaction? (y/n)" -n 1 DOZSEND
echo
if [[ $DOZSEND =~ ^[Yy]$ ]]; then
if [[ $change == "0.00000000" ]]; then
opid=$( ${komodocli} ${asset} z_sendmany ${fromaddress} '[{"address":"'''${toaddress}'''","amount":'''${amounttosend}${memotxstring}'''}]' 1 )
else
opid=$( ${komodocli} ${asset} z_sendmany ${fromaddress} '[{"address":"'''${toaddress}'''","amount":'''${amounttosend}${memotxstring}'''},{"address":"'''${fromaddress}'''","amount":'''${change}'''}]' 1 )
fi
echo $opid
fi