-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmassa-guard.sh
99 lines (90 loc) · 2.76 KB
/
massa-guard.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
#!/bin/bash
#====================== Configuration ==========================#
# Default values
MASSAGUARD=1
# Global configuration
. /massa-guard/config/default_config.ini
# Custom configuration
source <(grep = $PATH_CONF_MASSAGUARD/config.ini)
# Import custom library
. /massa-guard/sources/lib.sh
# Wait node booststrap
WaitBootstrap
#====================== Check and load ==========================#
# Load Wallet and Node key or create it and stake wallet
CheckOrCreateWalletAndNodeKey
# Get stacking addresses
WalletAddresses=($(GetWalletAddresses))
#==================== Massa-guard circle =========================#
# Infinite check
while true
do
# If massa-guard features enabled
if [ $MASSAGUARD -eq 1 ]
then
# Check node status
CheckNodeResponsive
NodeResponsive=$?
# Check ram consumption percent in integer
CheckNodeRam
NodeRam=$?
# Restart node if issue
CheckAndReloadNode "$NodeRam" "$NodeResponsive"
if [ $? -eq 0 ]
then
# If new day log file get wallets balance
if [ ! -e $PATH_LOGS_MASSAGUARD/$(date +%Y%m%d)-massa_guard.txt ]
then
# Create log file of the day
touch $PATH_LOGS_MASSAGUARD/$(date +%Y%m%d)-massa_guard.txt
# For every wallets
for WalletAddress in "${WalletAddresses[@]}"; do
# Get candidate rolls
CandidateRolls=$(GetCandidateRoll "$WalletAddress")
# Get MAS amount
MasBalance=$(GetMASAmount "$WalletAddress")
# Log Wallet balance
LogWalletsBalance "$CandidateRolls" "$MasBalance" "$WalletAddress"
done
fi
# For each wallet addresses
for WalletAddress in "${WalletAddresses[@]}"; do
# Get candidate rolls
CandidateRolls=$(GetCandidateRoll "$WalletAddress")
# Get MAS amount
MasBalance=$(GetMASAmount "$WalletAddress")
# Buy max roll or 1 roll if possible when candidate roll amount = 0
BuyOrSellRoll "$CandidateRolls" "$MasBalance" "$WalletAddress"
done
# If logs are disable
if ([ $NODE_LOGS -eq 0 ] && [ -e $PATH_LOGS_MASSANODE/current.txt ])
then
# Delete logs file during container execution
rm $PATH_LOGS_MASSANODE/current.txt $PATH_NODE/logs.txt > /dev/null 2&>1
fi
# If dynamical IP feature enable and public IP is new
if ([ $DYN_PUB_IP -eq 1 ] && [ $(CheckPublicIP) -eq 1 ])
then
# Refresh config.toml + restart node + [Depracated since Mainnet] push new IP to massabot
RefreshPublicIP
fi
fi
# Check and update node if autoupdate feature is enable and upate available
if [ $AUTOUPDATE -eq 1 ]
then
CheckAndUpdateNode
fi
# Backup new wallet if new exist
BackupNewWallets
# Log events
if [ ! ${#Events[@]} -eq 0 ]
then
LogEvents "${Events[@]}"
unset Events
fi
fi
# Wait before next loop
sleep 2m
# Refresh configuration value
source <(grep = $PATH_CONF_MASSAGUARD/config.ini)
done