G1sms/shell/sms_BILLETCHK.sh

86 lines
3.2 KiB
Bash
Raw Normal View History

2019-11-27 23:43:32 +01:00
#!/bin/bash
# If 4 words provided => Check if Billet exists and return BILLET AMOUNT VALUE
# If 7 words provided => if Billet exists, transfer AMOUNT to PHONE & destroy BILLET
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
source ./shell/init.sh
source ./shell/functions.sh
log "X sms_BILLETCHK.sh $0"
PHONE="$1"
2020-03-12 15:06:22 +01:00
CODE=""
2019-11-27 23:43:32 +01:00
# Construct billet path
2020-03-12 15:06:22 +01:00
bpath=$(echo "$2 $3" | sed 's/ /_/g')
[[ -d "./billets/$bpath" ]] && CODE="$2 $3" && SEC="$4 $5 $6 $7" && zpath=$bpath
oldpath=$(echo "$2 $3 $4 $5" | sed 's/ /_/g')
[[ -d "./billets/$oldpath" ]] && CODE="$2 $3 $4 $5" && SEC="$6 $7 $8" && zpath=$oldpath
2019-11-27 23:43:32 +01:00
2020-03-12 15:06:22 +01:00
if [[ $CODE != "" ]]; then
SECRET=$(cat "./billets/$zpath/note.secret")
SALT=$(cat "./billets/$zpath/note.salt")
VALbillet=$(cat "./billets/$zpath/note.love")
UNIT="LOVE"
BILLETPUBKEY=$(cat "./billets/$zpath/note.pubkey")
2019-11-27 23:43:32 +01:00
2020-03-12 15:06:22 +01:00
G1=$(./silkaj/silkaj amount "$BILLETPUBKEY")
2019-11-27 23:43:32 +01:00
log "Billet: $AMOUNTG1 ($VALbillet $UNIT): $BILLETPUBKEY"
# NO GOOD SECRET
if [[ "$SEC" != "$SECRET" ]]; then
# SEND ACTUAL BILLET VALUE
mess="[G1SMS]
Billet de $VALbillet $UNIT Valide!
2020-03-12 15:06:22 +01:00
Valeur: $G1 G1
2019-11-27 23:43:32 +01:00
https://www.g1sms.fr/contact"
sms_SEND "$PHONE" "$mess"
2020-03-12 15:06:22 +01:00
log "BILLETCHK: $VALbillet $UNIT ($G1 G1)"
log_history $PHONE "BILLET_CHK, $G1, $zpath"
2019-11-27 23:43:32 +01:00
else
# TRANSFER & DESTROY
sms_INIT_ACCOUNT "$PHONE" "NOSMS"
if [[ "$UNKNOWN" == "unknown" ]]; then
# Account creation
sms_INIT_ACCOUNT "$PHONE"
fi
2020-03-12 15:06:22 +01:00
################ BUG SILKAJ TX
log "python3 ./shell/key_create_dunikey.py $CODE / $SEC $SALT"
# [[ $SALT != "" ]] && PAY=$(./silkaj/silkaj transaction --auth-scrypt -salt="$CODE" -password="$SEC $SALT" --amount="$G1" --output="$PUBKEY" --comment="THIRD_PARTY_MANAGER:$NODE_G1PUBKEY:ENCAISSEMENT:$CODE" -y) \
# || PAY=$(./silkaj/silkaj transaction --auth-scrypt -salt="$CODE" -password="$SEC" --amount="$G1" --output="$PUBKEY" --comment="THIRD_PARTY_MANAGER:$NODE_G1PUBKEY:ENCAISSEMENT:$CODE" -y)
# MAKE .dunikey file and use latest silkaj
[[ $SALT != "" ]] && python3 ./shell/key_create_dunikey.py "$CODE" "$SEC $SALT" \
|| python3 ./shell/key_create_dunikey.py "$CODE" "$SEC"
log "silkaj -p duniter-g1.p2p.legal:443 -af --file /tmp/secret.dunikey tx --output $PUBKEY --amount $G1"
PAY=$(silkaj -p duniter-g1.p2p.legal:443 -af --file /tmp/secret.dunikey tx --output $PUBKEY --amount $G1 -y)
log "$PAY"
### TODO AMELIORER ANALYSE DU RETOUR SILKAJ
2019-11-27 23:43:32 +01:00
if [[ "$(echo $PAY | cut -d '|' -f 1)" != "KO" ]]; then
# DESTROY BILLET
2020-03-12 15:06:22 +01:00
rm -Rf ./billets/$zpath
2019-11-27 23:43:32 +01:00
# DESTROY PUBLIC CACHE in /tmp
2020-03-12 15:06:22 +01:00
if [ -d "/tmp/billets_valides/$zpath" ]; then
rm -Rf /tmp/billets_valides/$zpath
2019-11-27 23:43:32 +01:00
fi
SOLDE=$(./silkaj/silkaj amount "$PUBKEY")
mess="[G1SMS]
2020-03-12 15:06:22 +01:00
ENCAISSEMENT de $VALbillet $UNIT ($G1 G1)
2019-12-21 22:58:36 +01:00
dans portefeuille $UIDNA ($PHONE)
2019-11-27 23:43:32 +01:00
OK!
Solde: $SOLDE G1"
sms_SEND "$PHONE" "$mess"
2020-03-12 15:06:22 +01:00
log "BILLETCHK DESTROY: $VALbillet $UNIT ($G1 G1)"
2019-11-27 23:43:32 +01:00
log "=> $PUBKEY"
2020-03-12 15:06:22 +01:00
log_history $PHONE "BILLET_CHK, $G1, $zpath, $PUBKEY"
2019-11-27 23:43:32 +01:00
else
2020-03-12 15:06:22 +01:00
sms_ERROR "$PHONE" "Erreur! Transaction Impossible! Valeur du G1Billet $G1 G1. Contactez $ADMINPSEUDO : $ADMINPHONE"
2019-11-27 23:43:32 +01:00
fi
fi
else
2020-03-12 15:06:22 +01:00
sms_SEND "$PHONE" "BILLET \"$CODE\" inconnu !!"
log_history $PHONE "BILLET_CHK, ERROR, $zpath"
2019-11-27 23:43:32 +01:00
fi
log "END sms_BILLETCHK.sh"
log "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"