From 8bf72a01b4ad2a2bd232d46828024f3b50f51209 Mon Sep 17 00:00:00 2001 From: poka Date: Fri, 16 Oct 2020 21:14:11 +0200 Subject: [PATCH] Add new script to get balance of each wallets --- scripts/walletsBalance.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 scripts/walletsBalance.sh diff --git a/scripts/walletsBalance.sh b/scripts/walletsBalance.sh new file mode 100755 index 0000000..6745b94 --- /dev/null +++ b/scripts/walletsBalance.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Récupération du chemin absolut du répertoir du script actuel +GPATH="$( cd "$(dirname "$0")" ; pwd -P )/.." +[[ ! -f $GPATH/.env ]] && cp $GPATH/.env.example $GPATH/.env +source $GPATH/.env +node=$(cut -d '/' -f3 <<<"$DUNITER") + +rm -f silkaj_error.log + +work() { + for i in $wallets; do + exec() { + balance=$(silkaj -p $node balance $i) + } + exec + while [[ $? == 1 ]]; do echo "Erreur $i $k" | tee -a silkaj_error.log; ((k++)); exec; done + unset k + balance=$(awk '/Total Quantitative =/ { print $4 }' <<<"$balance") + + [[ $1 == "members" ]] && username=$(curl -m 20 -s $DUNITER/wot/members | jq -r --arg pubkey "$i" '.results[] | select(.pubkey==$pubkey) | .uid') + formatedBalance="$balance"$'\t'"$i" + [[ $username ]] && formatedBalance="$formatedBalance"$'\t'"$username" + unset username + echo "$formatedBalance" + + totalBalance="$totalBalance"$'\n'"$formatedBalance" + + # For tests only +# [[ $i == "13fn6X3XWVgshHTgS8beZMo9XiyScx6MB6yPsBB5ZBia" ]] && break +# [[ $i == "12JDJibbgZPRfD6Hoecg8rQRvCR5VYrMnqzfhQYmAr3k" ]] && break + done +} + +wallets=$(curl -s https://g1-stats.axiom-team.fr/data/wallets-g1-membres.txt) +work members +wallets=$(curl -s https://g1-stats.axiom-team.fr/data/wallets-g1-simple.txt) +work + +totalBalance=$(sort -nr <<<$totalBalance) +grep . <<<"$totalBalance" > $GPATH/db/wallets_balance.txt