g1-stats/g1-stats.sh

63 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
################################################################################
# Author: Poka (poka@p2p.legal)
# Version: 0.2.0
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
# Git: https://git.p2p.legal/axiom-team/g1-stats
################################################################################
# Stop if error
set -e
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
if [[ -e $SCRIPTPATH/.env ]]; then source $SCRIPTPATH/.env; else echo "Veuillez créer votre fichier .env inspiré de .env.example" && exit 1; fi
### Initialisation des données ###
startTime=$(date +'%H:%M')
day=$(date +'%y-%m-%d')
dayP=$(date +'%d-%m-%y')
indexhtml="$WEBPATH/index.html"
echo -e "\n############# $day à $startTime #############\n"
[[ -z $(which jq) || -z $(which bc) ]] && apt update && apt install jq bc
echo "Initialisation ..."
TXBLOCKS=$(cat $SCRIPTPATH/db/txblocs) #kopa
TXBLOCKS=$(curl -s ${DUNITER}/blockchain/with/tx | jq '.result.blocks[]')
#TXBLOCKS=($(echo "$TXBLOCKS" | sort -hu | awk '{printf $1" "}'))
unset 'TXBLOCKS[${#TXBLOCKS[@]}-1]'
membresPubkeys=$(curl -s ${DUNITER}/wot/members | jq -r '.results[].pubkey')
#membresPubkeys=$(cat db/membresPubkeys) #kopa
nbrMembers=$(echo "$membresPubkeys" | wc -l)
lastBloc=${TXBLOCKS[-1]}
udBlocs=$(curl -s ${DUNITER}/blockchain/with/ud | jq '.result.blocks[]')
isWeb=$1
jsonFile="$SCRIPTPATH/db/daily.json"
### On source les fonctions
source $SCRIPTPATH/lib/functions.sh
source $SCRIPTPATH/lib/scanTxWallets.sh
### Extraction des adresses Ḡ1 actives
scanTxWallets $1 #kopa
### Calcul la somme des soldes portefeuilles et membres
sumSoldes
### Ajout des membres sans transaction
addMembers
### Calcul du nombre de wallets
nbrWallets
### Affichage des stats
displayStats
### Renseignement de l'index web et indexation de l'historique
# source $SCRIPTPATH/lib/functions.sh # On source les fonctions de nouveau
[[ $isWeb == "web" ]] && web
### Fin de programme
day=$(date +'%d-%m-%y')
echo -e " ---"
echo "$day - Heure de fin: $(date +'%H:%M')"