forked from axiom-team/astroport
106 lines
4.0 KiB
Bash
Executable File
106 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
################################################################################
|
|
# Author: Fred (support@qo-op.com)
|
|
# Version: 1.0
|
|
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
|
################################################################################
|
|
source ./init.sh
|
|
source ./functions.sh
|
|
log "__SUB:sms_VIR.sh: START ($1=phone, $2=AMOUNT, $3=VIRDEST)"
|
|
|
|
phone="$1"
|
|
AMOUNT="$2"
|
|
VIRDEST="$3"
|
|
|
|
# Initialise PHONE, PIN, PUBKEY, UNIT
|
|
sms_INIT_ACCOUNT "$phone" "NOSMS"
|
|
if [[ $MEMBER == "" ]]; then MEMBER=$UIDNA; fi
|
|
member=$MEMBER
|
|
if [[ "$AMOUNT" == "" ]]; then
|
|
sms_ERROR "$phone" "Montant incorrect!!
|
|
Ex:
|
|
VIR 100, pour virer 100 $UNIT vers votre compte relié.
|
|
VIR 100 $ADMINPSEUDO, pour virer 100 $UNIT à $ADMINPSEUDO"
|
|
exit 1
|
|
fi
|
|
|
|
###########################################################
|
|
# CALCULATE if wallet have enough for VIR+PERCENT
|
|
AMOUNT="$2"
|
|
accounting=($(make_accounting))
|
|
log "__SUB:sms_VIR.sh: $(declare -p accounting)"
|
|
testmin=${accounting[0]}
|
|
VIR=${accounting[1]}
|
|
PERCENT=${accounting[2]}
|
|
if [[ $testmin -eq 0 ]]; then
|
|
sms_ERROR "$PHONE" "Solde de votre Porte-monnaie G1sms insuffisant. Minimum $VIR + $LIMIT G1! Rechargez par Cesium."
|
|
exit
|
|
fi
|
|
|
|
###########################################################
|
|
# FIND VIRDEST into wallets, wallest-swarm OR duniter (silkaj)
|
|
if [[ "$VIRDEST" == "" || "$VIRDEST" == "$MEMBER" ]]; then
|
|
# VIR TO MEMBER PHONE OWNER
|
|
DESTMEM="$MEMBER"
|
|
DESTRIB="$MEMRIB"
|
|
log "__SUB:sms_VIR.sh: SEND TO MEMBER related wallet!!! $DESTRIB "
|
|
else
|
|
log "__SUB:sms_VIR.sh: SEARCH $VIRDEST related wallet!!! $DESTRIB "
|
|
DESTMEM="$VIRDEST"
|
|
# SEARCH IN WALLETS
|
|
LOCAL=$(grep -Rwl "$DESTMEM" /home/$YOU/.zen/g1sms_wallets/*/_uidname | tail -n 1 | cut -f 6 -d '/')
|
|
if [[ "$LOCAL" == "" ]]; then LOCAL=$(grep -Rwl "$DESTMEM" /home/$YOU/.zen/g1sms_wallets/*/_uidna | tail -n 1 | cut -f 6 -d '/'); fi
|
|
if [[ "$LOCAL" != "" ]]; then
|
|
# LOCAL G1sms account
|
|
DESTRIB=$(cat /home/$YOU/.zen/g1sms_wallets/$LOCAL/_pub)
|
|
DESTPHONE=$LOCAL
|
|
log "__SUB:sms_VIR.sh: FOUND LOCAL ($MASTERPHONE) G1sms+ wallet: $DESTRIB ($LOCAL)"
|
|
else
|
|
|
|
##################### REWRITE TODO
|
|
# SEARCH IN WALLETS SWARM (MEMBER THEN UIDNA)
|
|
# INSWARM=$(grep -Rwl "$DESTMEM" /home/$YOU/.zen/g1sms_wallets_swarm/*/*.uidname | tail -n 1 | cut -f 3 -d '/')
|
|
# if [[ "$INSWARM" == "" ]]; then INSWARM=$(grep -Rwl "$DESTMEM" /home/$YOU/.zen/g1sms_wallets_swarm/*/*.uidna | tail -n 1 | cut -f 3 -d '/'); fi
|
|
# if [[ "$INSWARM" != "" ]]; then
|
|
# REMOTENODE=$(cat /home/$YOU/.zen/g1sms_wallets_swarm/$INSWARM/MASTERPHONE.sms)
|
|
# DESTRIB=$(cat /home/$YOU/.zen/g1sms_wallets_swarm/$INSWARM/$INSWARM.pub)
|
|
# DESTPHONE=$INSWARM
|
|
# log "__SUB:sms_VIR.sh: FOUND SWARM ($REMOTENODE) G1sms+ wallet: $DESTRIB ($INSWARM)"
|
|
# else
|
|
##################### REWRITE TODO
|
|
# SEARCH WITH SILKAJ
|
|
DESTRIB=$(silkaj id "$DESTMEM" | grep -w "$DESTMEM" | awk '{print $2}')
|
|
log "__SUB:sms_VIR.sh: OUT OFF SWARM MEMBER wallet: $DESTRIB"
|
|
# fi
|
|
fi
|
|
fi
|
|
|
|
|
|
if [[ "$DESTRIB" != "" ]]; then
|
|
duniter_server=$(./tools/duniter_getnode.sh)
|
|
PAY=$(silkaj -p "$duniter_server" -af --file /home/$YOU/.zen/g1sms_wallets/$PHONE/secret.dunikey tx --output "$DESTRIB" --amount "$VIR" --comment "[G1sms+] VIR $VIR G1" -y)
|
|
if [[ "$(echo $PAY | grep 'successful')" != "" && "$PAY" != "" ]]; then
|
|
log "__SUB:sms_VIR.sh: VIREMENT VERS $DESTMEM OK"
|
|
mess="[G1sms+] $MEMBER
|
|
$PAY"
|
|
sms_SEND "$PHONE" "$mess"
|
|
# Send DESTPHONE sms
|
|
if [[ "$DESTPHONE" != "" ]]; then
|
|
sms_SEND "$DESTPHONE" "Bonjour $DESTMEM. Vous venez de recevoir un virement de $AMOUNT $UNIT ($VIR G1) de la part de $member portefeuille $UIDNA"
|
|
fi
|
|
else
|
|
sms_SEND "$ADMINPHONE" "$PAY";
|
|
fi
|
|
|
|
[[ -f /home/$YOU/.zen/g1sms_wallets/$PHONE ]] && chown -R $YOU /home/$YOU/.zen/g1sms_wallets/$PHONE
|
|
|
|
else
|
|
log "__SUB:sms_VIR.sh: ERROR $MEMBER: $DESTMEM DESTRIB NOT FOUND"
|
|
mess="[G1sms+] Virement annulé...
|
|
Membre: $DESTMEM inconnu! Vérifiez son existence."
|
|
sms_SEND "$PHONE" "$mess"
|
|
fi
|
|
|
|
log "__SUB:sms_VIR.sh: END ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
|
exit
|