Fix relative path
parent
022cf49eea
commit
65fa534743
|
@ -1,17 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
## TODO: Prendre en compte les transactions déjà appliqués
|
||||
[ "$EUID" -ne 0 ] && sudo="sudo" || sudo=""
|
||||
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
|
||||
|
||||
start=`date +%s`
|
||||
date=$(date +'%d-%m-%y à %H:%M')
|
||||
echo "### $date ###"
|
||||
|
||||
## Initialisation
|
||||
DUNITER=$(grep g1_node ../config/config.php | awk '{ print $3}' | tr -d ';' | tr -d "'")
|
||||
DUNITER=$(grep g1_node $SCRIPTPATH/../config/config.php | awk '{ print $3}' | tr -d ';' | tr -d "'")
|
||||
TXBLOCKS=$(curl -s $DUNITER/blockchain/with/tx | jq '.result.blocks[]')
|
||||
TXBLOCKS=$(echo "$TXBLOCKS" | tail -n 2 | tr '\n' ' ')
|
||||
keyword="\[Achat GMarche] : "
|
||||
[ ! -e .loc_hash ] && touch .loc_hash
|
||||
[ ! -e $SCRIPTPATH/.loc_hash ] && touch $SCRIPTPATH/.loc_hash
|
||||
|
||||
## Récupération des transactions avec commentaire GMarche
|
||||
|
||||
|
@ -19,9 +20,9 @@ for i in $TXBLOCKS; do
|
|||
result=$(curl -s $DUNITER/blockchain/block/$i | jq '.transactions[].hash, .transactions[].comment' | grep -v '""' | tr -d '"' | grep -B1 "$keyword")
|
||||
rhash=$(echo "$result" | head -n1)
|
||||
rcom=$(echo "$result" | tail -n1)
|
||||
if [[ ! -z $result && -z $(grep $rhash .loc_hash) ]]; then
|
||||
if [[ ! -z $result && -z $(grep $rhash $SCRIPTPATH/.loc_hash) ]]; then
|
||||
isSell+=$(echo -e "$rcom;")
|
||||
echo "$rhash" >> .loc_hash
|
||||
echo "$rhash" >> $SCRIPTPATH/.loc_hash
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
@ -29,15 +30,15 @@ done
|
|||
## Ajout des transactions en piscine pour les users GMarche
|
||||
|
||||
req="SELECT pubkey FROM users;"
|
||||
usersPubkeys=$(sudo mysql --database gmarche -e "$req" | grep .)
|
||||
usersPubkeys=$($sudo mysql --database gmarche -e "$req" | grep .)
|
||||
|
||||
for i in $usersPubkeys; do
|
||||
result=$(curl -s $DUNITER/tx/history/$i/pending | jq '. | select(.history.sending == [])' | jq '.history.pending[].hash,.history.pending[].comment' | tr -d '"')
|
||||
rhash=$(echo "$result" | head -n1)
|
||||
rcom=$(echo "$result" | tail -n1)
|
||||
if [[ ! -z $result && -z $(grep $rhash .loc_hash) ]]; then
|
||||
if [[ ! -z $result && -z $(grep $rhash $SCRIPTPATH/.loc_hash) ]]; then
|
||||
isSell+=$(echo -e "$rcom;")
|
||||
echo "$rhash" >> .loc_hash
|
||||
echo "$rhash" >> $SCRIPTPATH/.loc_hash
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -51,10 +52,10 @@ IFS=';'; ADDR=($isSell); unset IFS;
|
|||
for i in "${ADDR[@]}"; do
|
||||
#req="UPDATE products SET status = 'solde' WHERE name = '$i';"
|
||||
req="UPDATE products SET quantite = CASE WHEN quantite = 0 THEN quantite ELSE quantite - 1 END WHERE name = '$i';"
|
||||
sudo mysql --database gmarche -e "$req"
|
||||
$sudo mysql --database gmarche -e "$req"
|
||||
done
|
||||
|
||||
#sudo mysql --database gmarche -e "SELECT name,status FROM products;"
|
||||
#$sudo mysql --database gmarche -e "SELECT name,status FROM products;"
|
||||
|
||||
end=`date +%s`
|
||||
runtime=$((end-start))
|
||||
|
|
Loading…
Reference in New Issue