Partialy rewrite scripts/walletsBalance.sh:

* support both silkaj and jaklis
* add a field "position"
* add some id to have anchors for url, eg: .../wallets_balance.html#k2ny7YAdmzReQxAayyJZsyVYwYhVyax2thKcGknmQy5nQ
* add links payto://g1/..., cf. https://tools.ietf.org/html/rfc8905
This commit is contained in:
Jean-Jacques Brucker 2021-03-08 16:12:30 +01:00
parent ba0f91404c
commit ef23a0a66d
3 changed files with 36 additions and 30 deletions

View File

@ -1,44 +1,51 @@
#!/bin/bash
# Récupération du chemin absolut du répertoir du script actuel
# Récupération du chemin absolu du répertoire 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")
#Check if Jaklis is installed
[[ -z $JAKLIS ]] && JAKLIS=$(which silkaj)
[[ -z $JAKLIS ]] && echo "Erreur: Vous devez installer Jaklis." && exit 1
#Check if ed is installed
which ed || { echo "$0: Error: please install ed" >&2 ; exit 1 ; }
#Check if Jaklis or silkaj is installed
if [[ "$JAKLIS" ]] ; then
exec() {
jsonResult=$($JAKLIS idBalance -p $i) || return $?
balance=$(echo "$jsonResult" | jq -r '.balance')
username=$(echo "$jsonResult" | jq -r '.username')
}
elif which silkaj ; then
exec() {
balance=$(silkaj -p "$node" balance "$i") || return $?
balance=$(sed -n 's,.* \([\.0-9]\+\) Ğ1.*,\1,p' <<<$balance)
username=$(silkaj -p "$node" id "$i") || return $?
username=$(sed -n 's,.*: \(.*\)$,\1,p' <<<$username)
}
else
echo "$0: Error: you should use Jaklis or install silkaj." >&2
exit 1
fi
work() {
for i in $wallets; do
exec() {
jsonResult=$($JAKLIS idBalance -p $i 2>/dev/null)
}
exec
while [[ $? == 1 ]]; do echo "Erreur $k: $i"; ((k++)); exec; done
unset k
for i in $wallets; do
((j++))
# For tests only
#(( j > 42 )) && break
balance=$(echo "$jsonResult" | jq -r '.balance')
username=$(echo "$jsonResult" | jq -r '.username')
formatedBalance=$(printf "%-10s | %-45s | %-1s" $balance $i $username)
unset k
while ! exec ; do echo "Erreur $?: retry=$((k)) wallet=$i"; ((k++ > 9999)) && break ; sleep $((RANDOM%8)) ; done
if [[ $1 == "members" ]]; then
htmlBloc="$htmlBloc"$'\n'"<tr><td>$balance</td><td>$i</td><td><b>$username</b></td></tr>"
unset username
else
htmlBloc="$htmlBloc"$'\n'"<tr><td>$balance</td><td>$i</td><td>$username</td></tr>"
fi
unset balance
formatedBalance=$(printf "%-10s | %-45s | %-1s" $balance $i $username)
echo "$formatedBalance" | tee -a /tmp/balance-g1.txt
[[ $1 == "members" ]] && username="<b>$username</b>"
htmlBloc="$htmlBloc<td>$balance</td><td><a id=\"k$i\" href=\"payto://g1/$i\">$i</a></td><td><b>$username</b></td>"$'\n'
totalBalance="$totalBalance"$'\n'"$formatedBalance"
echo "$formatedBalance" | tee -a /tmp/balance-g1.txt | sed "s,^,$j | ,"
# For tests only
# [[ $i == "13fn6X3XWVgshHTgS8beZMo9XiyScx6MB6yPsBB5ZBia" ]] && break
# [[ $i == "12JDJibbgZPRfD6Hoecg8rQRvCR5VYrMnqzfhQYmAr3k" ]] && break
done
totalBalance="$totalBalance$formatedBalance"$'\n'
done
}
wallets=$(cat $WEBPATH/data/wallets-g1-membres.txt 2>/dev/null)
@ -57,7 +64,7 @@ cp $GPATH/tpl/css/wallets_balance.css $WEBPATH/css/
cp $GPATH/tpl/js/wallets_balance.js $WEBPATH/js/
cp $GPATH/tpl/wallets_balance.html $WEBPATH/data/wallets_balance.html
sort -Vr <<<"$htmlBloc" > /tmp/solde_g1_html.txt
sort -Vr <<<"$htmlBloc" | awk '{ print "<tr id=\"p"NR"\"><td>"NR"</td>"$0"</tr>" ; }' > /tmp/solde_g1_html.txt
printf '%s\n' '/_LINE/r /tmp/solde_g1_html.txt' 1 '/_LINE/d' w | ed $WEBPATH/data/wallets_balance.html > /dev/null
sed -i "0,/_DATE/s//$(date '+%d-%m-%Y')/" $WEBPATH/data/wallets_balance.html
rm /tmp/solde_g1_html.txt

View File

@ -47,7 +47,6 @@ body {
/* Add a grey background color to the table header and on hover */
background-color: #B69776;
cursor: pointer;
position: sticky;
top: 0px;
}

View File

@ -10,7 +10,7 @@
<input type="checkbox" id="splw" value="splw" checked><label for="splw">Afficher les simples portefeuilles</label>
<table id="soldes">
<tr><th>Solde (Ḡ1)</th><th>Clé publique</th><th>Identifiant utilisateur</th></tr>
<tr><th>Position</th><th>Solde (Ḡ1)</th><th>Clé publique</th><th>Identifiant utilisateur</th></tr>
_LINE
</table>