-
Notifications
You must be signed in to change notification settings - Fork 8
/
functions
108 lines (93 loc) · 2.23 KB
/
functions
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
#!/bin/bash
# functions file for mmtools
#
# @author webworker01
#
#31 = red (default)
#32 = green
#33 = yellow
#34 = blue
log()
{
local category=$1
local message=$2
local color=$3
local mode=$4
case $color in
red)
colorcode=31
;;
green)
colorcode=32
;;
yellow)
colorcode=33
;;
blue)
colorcode=34
;;
*)
colorcode=32
;;
esac
if [[ $mode != "echo" ]] && [[ ! -z $mmtoolslogfile ]]; then
echo "${datetime} [${category}] ${message}" >> $mmtoolslogfile
fi
if [[ $mode != "file" ]]; then
printf "\033[0;${colorcode}m${datetime} [${category}] ${message}\033[0m\n"
fi
}
rand()
{
echo $(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
}
sendRaw()
{
local rawtx=$1
local acname=$2
if [[ ! -z $acname ]] && [[ $acname != "KMD" ]]; then
asset=" -ac_name=${acname}"
else
asset=""
fi
if [[ ! -z $rawtx ]]; then
# nlocktime=$(printf "%08x" $(date +%s) | dd conv=swab 2> /dev/null | rev)
nlocktime="00000000"
hex=${rawtx::-8}$nlocktime
txtail=000000000000000000000000000000
hex=${hex::-38}${nlocktime}${txtail}
signedtx=$($komodocli $asset signrawtransaction $hex | jq -r '.hex')
if [[ ! -z $signedtx ]]; then
rawtxid=$($komodocli $asset sendrawtransaction $signedtx)
else
rawtxid="failed no signed tx"
fi
echo "${rawtxid}"
else
echo "failed"
fi
}
timeSince ()
{
local currentimestamp=$(date +%s)
local timecompare=$1
if [ ! -z $timecompare ] && [[ $timecompare != "null" ]]; then
local t=$((currentimestamp-timecompare))
local d=$((t/60/60/24))
local h=$((t/60/60%24))
local m=$((t/60%60))
local s=$((t%60))
if (( d > 0 )); then
echo -n "${d}D"
fi
if (( d < 2 && h > 0 )); then
echo -n "${h}h"
fi
if (( d == 0 && h < 4 && m > 0 )); then
echo -n "${m}m"
fi
if (( d == 0 && h == 0 && m == 0 )); then
echo -n "${s}s"
fi
fi
}