forked from cyberomanov/ironfish-mbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mbs.sh
210 lines (168 loc) · 6.73 KB
/
mbs.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#/usr/bin/bash
function PrintTime() {
echo -e "[ $(date +"%d-%m-%y | %T") ]"
}
function GetRandomMintFunc() {
RANDOM_MINT=0
while [ $(echo "${RANDOM_MINT} < 1000" | bc) -eq 1 ]; do
RANDOM_MINT=$(awk 'BEGIN {
# seed
srand()
print int(1 + rand() * 10000)
}')
done
echo ${RANDOM_MINT}
}
function GetRandomPercFunc() {
RANDOM_PERC=0
while [ $(echo "${RANDOM_PERC} < ${1}" | bc) -eq 1 ] || [ $(echo "${RANDOM_PERC} > ${2}" | bc) -eq 1 ]; do
RANDOM_PERC=$(awk 'BEGIN {
# seed
srand()
print int(1 + rand() * 100)
}')
done
echo ${RANDOM_PERC}
}
function WaitTransactionToBeCompleted() {
HASH=${1}
START_FROM_ZERO="false"
TRANSACTION_STATUS="unconfirmed."
while [[ ${TRANSACTION_STATUS} != "confirmed" ]] && [[ ${TRANSACTION_STATUS} != "expired" ]]; do
TRANSACTION_STATUS=$(${BIN} wallet:transaction ${HASH} | grep "Status: " | sed "s/Status: //")
if [[ ${TRANSACTION_STATUS} == "unconfirmed" ]] || [[ ${TRANSACTION_STATUS} == "pending" ]]; then
echo -e "$(PrintTime) hash: ${HASH}, status: ${TRANSACTION_STATUS}."
sleep 20
elif [[ ${TRANSACTION_STATUS} == "confirmed" ]]; then
echo -e "$(PrintTime) hash: ${HASH}, status: ${TRANSACTION_STATUS}.\n"
elif [[ ${TRANSACTION_STATUS} == "expired" ]]; then
echo -e "$(PrintTime) hash: ${HASH}, status: ${TRANSACTION_STATUS}.\n\nthis is not okay, starting from zero.\n"
START_FROM_ZERO="true"
else
START_FROM_ZERO="true"
echo -e "$(PrintTime) hash: ${HASH}, status: ${TRANSACTION_STATUS}.\n\nunknown status, ping @cyberomanov. starting from zero.\n"
fi
done
}
function GetBalanceFunc() {
if [[ ${1} == '' ]]; then
${BIN} wallet:balance | grep -o "[0-9]\+.[0-9]*" | tail -1
else
${BIN} wallet:balance --assetId=${1} | grep -Eo "[0-9]+([.][0-9]+)?" | tail -1
fi
}
function MintFunc() {
RANDOM_MINT=$(GetRandomMintFunc)
RESULT=$(echo "Y" | ${BIN} wallet:mint --name=${GRAFFITI} --metadata=${GRAFFITI} --amount=${RANDOM_MINT} --fee=0.00000001 | tr -d '\0')
CheckResultFunc "MINT [ ${RANDOM_MINT} ]" "${RESULT}"
}
function BurnFunc() {
BALANCE=$(GetBalanceFunc "${IDENTIFIER}")
RANDOM_PERC=$(GetRandomPercFunc "30" "60")
let "BURN_AMOUNT = ${BALANCE%.*} / 100 * ${RANDOM_PERC}"
RESULT=$(echo "Y" | ${BIN} wallet:burn --assetId=${IDENTIFIER} --amount=${BURN_AMOUNT} --fee=0.00000001 | tr -d '\0')
CheckResultFunc "BURN [ ${RANDOM_PERC}% of ${BALANCE%.*} = ${BURN_AMOUNT} ]" "${RESULT}"
}
function SendFunc() {
BALANCE=$(GetBalanceFunc "${IDENTIFIER}")
RANDOM_PERC=$(GetRandomPercFunc "80" "99")
let "SEND_AMOUNT = ${BALANCE%.*} / 100 * ${RANDOM_PERC}"
ADDRESS_TO_SEND="dfc2679369551e64e3950e06a88e68466e813c63b100283520045925adbe59ca"
RESULT=$(echo "Y" | ${BIN} wallet:send --assetId=${IDENTIFIER} --amount=${SEND_AMOUNT} --to=${ADDRESS_TO_SEND} --memo="${GRAFFITI}" --fee=0.00000001 | tr -d '\0')
CheckResultFunc "SEND [ ${RANDOM_PERC}% of ${BALANCE%.*} = ${SEND_AMOUNT} ]" "${RESULT}"
}
function GetTransactionHashFunc() {
INPUT=${1}
HASH=$(echo ${INPUT} | grep -Eo "Transaction Hash: [a-z0-9]*" | sed "s/Transaction Hash: //")
echo ${HASH}
}
function CheckResultFunc() {
FUNC_RESULT="fail"
FUNCTION_NAME=${1}
FUNCTION_RESULT=${2}
if [[ ${FUNCTION_RESULT} == *"Transaction Hash"* ]]; then
FUNC_RESULT="success"
echo -e "\n/////////////////// [ ${FUNCTION_NAME} | SUCCESS | #${FUNC_TRY} ] ///////////////////\n"
WaitTransactionToBeCompleted $(GetTransactionHashFunc "${FUNCTION_RESULT}")
if [[ ${FUNCTION_NAME} == *"MINT"* ]]; then
IDENTIFIER=$(echo ${RESULT} | grep -Eo "Asset Identifier: [a-z0-9]*" | sed "s/Asset Identifier: //")
fi
else
echo -e "\n/////////////////// [ ${FUNCTION_NAME} | FAIL | #${FUNC_TRY} ] ///////////////////\n"
fi
}
function FaucetRequestFunc() {
echo
if [[ ${1} != '' ]]; then
FAUCET_RESULT=$(echo -e "${1}\n\n" | ironfish faucet)
if [[ ${FAUCET_RESULT} == *"Congratulations"* ]]; then
echo -e "${1}.\n\n$(PrintTime) faucet just added your request to the queue.\n"
else
echo -e "${1}.\n\n$(PrintTime) faucet request failed.\n"
fi
else
FAUCET_RESULT=$(echo -e "\n\n" | ironfish faucet)
if [[ ${FAUCET_RESULT} == *"Congratulations"* ]]; then
echo -e "...\n\n$(PrintTime) faucet just added your request to the queue.\n"
else
echo -e "...\n\n$(PrintTime) faucet request failed.\n"
fi
fi
}
function GetBinaryFunc() {
BINARY=$(which ironfish)
if [[ ${BINARY} == "" ]]; then
DOCKER_CONTAINER=$(docker ps | grep ironfish | awk '{ print $1 }')
DOCKER_TEST=$(docker exec -it ${DOCKER_CONTAINER} ironfish)
if [[ ${DOCKER_TEST} == *"Error"* ]]; then
echo -e "$(PrintTime) i don't know where is your 'ironfish' binary. set it manually."
else
BINARY="docker exec -i ${DOCKER_CONTAINER} ironfish"
fi
fi
echo ${BINARY}
}
function TryUntilSuccessLocalFunc() {
FUNCTION=${1}
FUNC_RESULT="fail"
FUNC_TRY=0
MAX_TRIES=100
while [[ ${FUNC_RESULT} == "fail" ]] && [[ ${FUNC_TRY} != ${MAX_TRIES} ]]; do
FUNC_TRY=$((FUNC_TRY + 1))
${FUNCTION}
sleep 10
done
if [[ ${FUNC_TRY} == ${MAX_TRIES} ]]; then
START_FROM_ZERO="true"
echo -e "\n$(PrintTime) this is not okay, sorry.\n"
fi
}
function MainFunc() {
MAIL=${1}
BIN=$(GetBinaryFunc)
GRAFFITI=$(echo $(${BIN} config:get blockGraffiti) | sed 's/\"//g')
if [[ ${MAIL} != "" ]]; then
FaucetRequestFunc "${MAIL}"
else
FaucetRequestFunc
fi
if [ $(echo "$(GetBalanceFunc) > 0.00000003" | bc ) -eq 1 ]; then
TryUntilSuccessLocalFunc "MintFunc"
if [[ ${START_FROM_ZERO} == "false" ]]; then
TryUntilSuccessLocalFunc "BurnFunc"
fi
if [[ ${START_FROM_ZERO} == "false" ]]; then
TryUntilSuccessLocalFunc "SendFunc"
fi
if [[ ${START_FROM_ZERO} == "false" ]]; then
echo -e "assetId: ${IDENTIFIER}.\n"
fi
echo -e "balance of \$IRON: $(GetBalanceFunc)."
echo -e "balance of \$${GRAFFITI}: $(GetBalanceFunc "${IDENTIFIER}").\n"
echo -e "with love by @cyberomanov."
else
echo -e "$(PrintTime) not enough balance. minimum required: \$IRON 0.00000003, but you have only: \$IRON $(GetBalanceFunc). if it's a bug, try in a few minutes.\n"
break
fi
}
MainFunc "${1}"