|
|
|
@ -1,20 +1,20 @@
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
startTime=$(date +'%H:%M')
|
|
|
|
|
day=$(date +'%d-%m-%y')
|
|
|
|
|
id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
|
|
|
|
|
de=$(cat /dev/urandom | tr -dc '0-9' | fold -w 1 | head -n 1)
|
|
|
|
|
### Variable ###
|
|
|
|
|
|
|
|
|
|
DUNITER="http://192.168.9.54:45000"
|
|
|
|
|
DUNITER2="https://g1.duniter.org"
|
|
|
|
|
DUNITER3="https://duniter.g1.1000i100.fr"
|
|
|
|
|
|
|
|
|
|
indexhtml="/var/www/g1-stats/index.html"
|
|
|
|
|
ESNODE="http://g1.data.duniter.fr"
|
|
|
|
|
webLocation="/var/www/g1-stats"
|
|
|
|
|
scriptLocation="/opt/g1-stats"
|
|
|
|
|
###
|
|
|
|
|
|
|
|
|
|
echo "######"
|
|
|
|
|
echo "$day à $startTime"
|
|
|
|
|
### Initialisation des données ###
|
|
|
|
|
startTime=$(date +'%H:%M')
|
|
|
|
|
day=$(date +'%d-%m-%y')
|
|
|
|
|
id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
|
|
|
|
|
indexhtml="$webLocation/index.html"
|
|
|
|
|
echo -e "\n############# $day à $startTime #############\n"
|
|
|
|
|
[[ -z $(which jq) || -z $(which bc) ]] && apt update && apt install jq bc
|
|
|
|
|
echo "Initialisation ..."
|
|
|
|
|
outFile="/tmp/g1-stats-$day-$startTime_$id"
|
|
|
|
@ -28,14 +28,15 @@ nbrMembers=${#MEMBERS[@]}
|
|
|
|
|
lastBloc=${TXBLOCKS[-1]}
|
|
|
|
|
isWeb=$1
|
|
|
|
|
|
|
|
|
|
echo "Heure de début: $startTime"
|
|
|
|
|
### Extraction des adresses Ḡ1 actives ###
|
|
|
|
|
|
|
|
|
|
loopWalletUp() {
|
|
|
|
|
for i in ${TXBLOCKS[*]}; do
|
|
|
|
|
[[ -z ${TXBLOCKS[$i]} ]] && break
|
|
|
|
|
sleep 0.1
|
|
|
|
|
WALLETS0=$(curl -s ${DUNITER}/blockchain/block/${TXBLOCKS[$i]})
|
|
|
|
|
until WALLETS=$(echo $WALLETS0 | jq '.transactions[].outputs[]'); do
|
|
|
|
|
echo -e "iter $iter \n$WALLETS0"
|
|
|
|
|
until WALLETS=$(echo $WALLETS0 | jq '.transactions[].outputs[]' 2>/dev/null); do
|
|
|
|
|
[[ $isWeb != "web" ]] && echo -e "iter $iter \n$WALLETS0"
|
|
|
|
|
sleep 2
|
|
|
|
|
WALLETS0=$(curl -s ${DUNITER}/blockchain/block/${TXBLOCKS[$i]})
|
|
|
|
|
done
|
|
|
|
@ -60,8 +61,11 @@ loopWalletUp() {
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
loopWalletUp
|
|
|
|
|
|
|
|
|
|
### Ecriture des adresses actives dans un fichier tampon ###
|
|
|
|
|
echo -e "$(echo -e "$wallets" | sort -u)" > $outFile
|
|
|
|
|
|
|
|
|
|
### Ajout des membres sans transaction au fichier tampon ###
|
|
|
|
|
loopMembers() {
|
|
|
|
|
iter=0
|
|
|
|
|
for i in ${MEMBERS[*]}; do
|
|
|
|
@ -87,20 +91,34 @@ done
|
|
|
|
|
}
|
|
|
|
|
loopMembers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Calcul du nombre de wallets ###
|
|
|
|
|
nbrTotalWallets=$(cat $outFile | wc -l)
|
|
|
|
|
nbrSimpleWallets=$(echo "$nbrTotalWallets-$nbrMembers" | bc)
|
|
|
|
|
pourcentMbrs=$(echo "scale=1; $nbrMembers*100/$nbrTotalWallets/1" | bc)
|
|
|
|
|
pourcentWallets=$(echo "scale=1; $nbrSimpleWallets*100/$nbrTotalWallets/1" | bc)
|
|
|
|
|
|
|
|
|
|
### Renseignement de l'index web et indexation de l'historique ###
|
|
|
|
|
web() {
|
|
|
|
|
cp /opt/g1-stats/stats.html $indexhtml
|
|
|
|
|
|
|
|
|
|
[ ! -d $webLocation/history/ ] && mkdir -p $webLocation/history/
|
|
|
|
|
[ ! -d $webLocation/css ] && cp -r $scriptLocation/css $webLocation/
|
|
|
|
|
cp $scriptLocation/index-stats.html $indexhtml
|
|
|
|
|
|
|
|
|
|
datePrevious=$(echo $day | awk -F '-' '{ print $3 "-" $2 "-" $1 }')
|
|
|
|
|
datePrevious=$(date +'%y-%m-%d' -d "$datePrevious -1 day")
|
|
|
|
|
datePrevious=$(echo $datePrevious | awk -F '-' '{ print $3 "-" $2 "-" $1 }')
|
|
|
|
|
[[ -z $(ls -l $webLocation/history/ | grep $datePrevious) && -z $(grep '"display:none;" class="previous"' $indexhtml) ]] && sed -i "s/class=\"previous\"/style=\"display:none;\" class=\"previous\"/g" $indexhtml
|
|
|
|
|
dateNext=$(echo $day | awk -F '-' '{ print $3 "-" $2 "-" $1 }')
|
|
|
|
|
dateNext=$(date +'%y-%m-%d' -d "$dateNext +1 day")
|
|
|
|
|
dateNext=$(echo $dateNext | awk -F '-' '{ print $3 "-" $2 "-" $1 }')
|
|
|
|
|
[[ -z $(ls -l $webLocation/history/ | grep $dateNext) && -z $(grep '"display:none;" class="next"' $indexhtml) ]] && sed -i "s/class=\"next\"/style=\"display:none;\" class=\"next\"/g" $indexhtml
|
|
|
|
|
|
|
|
|
|
sed -i "s/_nbrTotalWallets/$nbrTotalWallets/g" $indexhtml
|
|
|
|
|
sed -i "s/_nbrSimpleWallets/$nbrSimpleWallets/g" $indexhtml
|
|
|
|
|
sed -i "s/_nbrMembers/$nbrMembers/g" $indexhtml
|
|
|
|
|
sed -i "s/_pourcentMbrs/$pourcentMbrs/g" $indexhtml
|
|
|
|
|
sed -i "s/_pourcentWallets/$pourcentWallets/g" $indexhtml
|
|
|
|
|
# sed -i "s/_node/$DUNITER/g" $indexhtml
|
|
|
|
|
# sed -i "s/_node/$DUNITER/g" $indexhtml
|
|
|
|
|
sed -i "s/_heure/$startTime/g" $indexhtml
|
|
|
|
|
sed -i "s/_day/$day/g" $indexhtml
|
|
|
|
|
sed -i "s/_txInSimple/$txInSimple/g" $indexhtml
|
|
|
|
@ -112,41 +130,40 @@ web() {
|
|
|
|
|
sed -i "s/_pourcentSimpleWallet/$pourcentSimpleWallet/g" $indexhtml
|
|
|
|
|
sed -i "s/_nonConsumedUDT/$nonConsumedUDT/g" $indexhtml
|
|
|
|
|
sed -i "s/_monetaryMass/$monetaryMass/g" $indexhtml
|
|
|
|
|
chown www-data:www-data $indexhtml 2>/dev/null
|
|
|
|
|
[[ -z $(grep '"display:none;" class="previous"' $indexhtml) ]] && sed -i "s/_datePrevious/$datePrevious/g" $indexhtml
|
|
|
|
|
[[ -z $(grep '"display:none;" class="next"' $indexhtml) ]] && sed -i "s/_dateNext/$dateNext/g" $indexhtml
|
|
|
|
|
|
|
|
|
|
cat "$outFile" | grep . > /var/www/g1-stats/wallets-g1.txt
|
|
|
|
|
echo -e "${MEMBERS[@]}" | sed 's/ /\n/g' > /var/www/g1-stats/wallets-g1-membres.txt
|
|
|
|
|
echo -e "$simpleWallets" > /var/www/g1-stats/wallets-g1-simple.txt
|
|
|
|
|
cat "$outFile" | grep . > $webLocation/wallets-g1.txt
|
|
|
|
|
echo -e "${MEMBERS[@]}" | sed 's/ /\n/g' > $webLocation/wallets-g1-membres.txt
|
|
|
|
|
echo -e "$simpleWallets" > $webLocation/wallets-g1-simple.txt
|
|
|
|
|
|
|
|
|
|
if [[ "$startTime" == "00:00" ]]; then
|
|
|
|
|
cp $indexhtml /var/www/g1-stats/history/index_$day.html
|
|
|
|
|
sed -i "s/style.css/..\/style.css/g" /var/www/g1-stats/history/index_$day.html
|
|
|
|
|
chown -R www-data:www-data /var/www/g1-stats
|
|
|
|
|
cp $indexhtml $webLocation/history/index_$day.html
|
|
|
|
|
sed -i "s/css\/style.css/..\/css\/style.css/g" $webLocation/history/index_$day.html
|
|
|
|
|
sed -i "s/_dateNext/$day/g" $webLocation/history/index_$datePrevious.html
|
|
|
|
|
sed -i "s/style=\"display:none;\" class=\"next\"/class=\"next\"/g" $webLocation/history/index_$datePrevious.html
|
|
|
|
|
fi
|
|
|
|
|
chown -R www-data:www-data $webLocation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
### Affichage du nombre de wallets ###
|
|
|
|
|
echo -e "\n ---\n"
|
|
|
|
|
echo "Noeud: $DUNITER"
|
|
|
|
|
echo "Nombre total de wallet: $nbrTotalWallets"
|
|
|
|
|
echo "Nombre de membres: $nbrMembers (${pourcentMbrs}%)"
|
|
|
|
|
echo "Nombre de simple portefeuille: $nbrSimpleWallets (${pourcentWallets}%)"
|
|
|
|
|
echo -e "\n ---\n"
|
|
|
|
|
|
|
|
|
|
echo "Extraction wallets membres / Simples portefeuille"
|
|
|
|
|
echo -e "\n ---\n"
|
|
|
|
|
|
|
|
|
|
### Isolation des simples portefeuilles ###
|
|
|
|
|
simpleWallets=$(cat $outFile)
|
|
|
|
|
|
|
|
|
|
echo "Isolation des simples portefeuilles..."
|
|
|
|
|
for i in ${MEMBERS[@]}; do
|
|
|
|
|
simpleWallets=$(echo "$simpleWallets" | grep -v "$i")
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
#cat "$outFile" | grep . > /var/www/g1-stats/wallets-g1.txt
|
|
|
|
|
#echo -e "${MEMBERS[@]}" | sed 's/ /\n/g' > /var/www/g1-stats/wallets-g1-membres.txt
|
|
|
|
|
#echo -e "$simpleWallets" > /var/www/g1-stats/wallets-g1-simple.txt
|
|
|
|
|
|
|
|
|
|
echo -e "\n ---\n"
|
|
|
|
|
|
|
|
|
|
### Boucle d'obtention des soldes ###
|
|
|
|
|
getSolde(){
|
|
|
|
|
solde=0
|
|
|
|
|
txInT=0
|
|
|
|
@ -154,11 +171,11 @@ txOutT=0
|
|
|
|
|
nonConsumedUDT=0
|
|
|
|
|
nonConsumedUD=0
|
|
|
|
|
for i in $pubkeys; do
|
|
|
|
|
until txInL=$(curl -s "http://g1.data.duniter.fr/g1/movement/_search?filter_path=hits.hits._source&size=10000&q=recipient:$i&pretty"); do
|
|
|
|
|
until txInL=$(curl -s "$ESNODE/g1/movement/_search?filter_path=hits.hits._source&size=10000&q=recipient:$i&pretty"); do
|
|
|
|
|
echo "Erreur: $i"
|
|
|
|
|
sleep 2
|
|
|
|
|
done
|
|
|
|
|
until txOutL=$(curl -s "http://g1.data.duniter.fr/g1/movement/_search?filter_path=hits.hits._source&size=10000&q=issuer:$i&pretty"); do
|
|
|
|
|
until txOutL=$(curl -s "$ESNODE/g1/movement/_search?filter_path=hits.hits._source&size=10000&q=issuer:$i&pretty"); do
|
|
|
|
|
echo "Erreur: $i"
|
|
|
|
|
sleep 2
|
|
|
|
|
done
|
|
|
|
@ -191,9 +208,7 @@ soldeSimple=$(echo $soldeSimpleBrut | tr . , | sed ':a;s/\B[0-9]\{3\}\>/.&/;ta')
|
|
|
|
|
echo -e "Reçus simples wallets:\t $txInSimple"
|
|
|
|
|
echo -e "Envoyé simples wallets:\t $txOutSimple"
|
|
|
|
|
echo -e "Soldes simples wallets:\t $soldeSimple"
|
|
|
|
|
|
|
|
|
|
echo -e "\n ---\n"
|
|
|
|
|
|
|
|
|
|
echo "Récupération du solde des membres..."
|
|
|
|
|
|
|
|
|
|
pubkeys=${MEMBERS[@]}
|
|
|
|
@ -207,6 +222,7 @@ echo -e "Envoyé membres:\t $txOutMembers"
|
|
|
|
|
echo -e "Soldes membres:\t $soldeMembers"
|
|
|
|
|
echo -e "Total DU non consumés:\t $nonConsumedUDT"
|
|
|
|
|
|
|
|
|
|
### Calcul de la masse monétaire et du pourcentage de Ḡ1 sur les simples portefeuilles ###
|
|
|
|
|
monetaryMass=$(curl -s ${DUNITER}/blockchain/current | jq .monetaryMass)
|
|
|
|
|
monetaryMassBrut=$(echo -e "scale=2; ($monetaryMass/100)/1" | bc)
|
|
|
|
|
monetaryMass=$(echo "$monetaryMassBrut" | tr . , | sed ':a;s/\B[0-9]\{3\}\>/.&/;ta')
|
|
|
|
@ -219,6 +235,7 @@ echo -e "Masse Monétaire:\t $monetaryMass Ḡ1"
|
|
|
|
|
|
|
|
|
|
[[ $isWeb == "web" ]] && web
|
|
|
|
|
|
|
|
|
|
### Fin de programme ###
|
|
|
|
|
rm $outFile
|
|
|
|
|
day=$(date +'%d-%m-%y')
|
|
|
|
|
echo "$day - Heure de fin: $(date +'%H:%M')"
|