Browse Source

Current G1sms code

qo-op 6 months ago
parent
commit
131cfcc487

+ 1 - 1
_chain

@@ -1 +1 @@
-QmeNcQbpgX1e3SYZq2PweqYVKeYM923gGCkmLrLpZuKUbQ
+QmamXocniF5ccFdSpNZ9K4qCv8NwJqu8UR9kc5xfSMkBFv

+ 3 - 0
_comments

@@ -182,3 +182,6 @@ OK
 2020-01-02: g1sms.preoni
 2020-01-04: BACKUP
 2020-01-06: bugs
+2020-01-06: silkaj TX init bad keys
+2020-01-07: 
+2020-01-07: g1.presles.fr

+ 1 - 1
_nanodate

@@ -1 +1 @@
-1578331888355885994
+1578394685159072524

BIN
_publishkey.gpg


+ 2 - 1
shell/cron_CODE.backup.sh

@@ -40,7 +40,8 @@ cd ..
 echo "PLEASE WAIT...."
 echo "GIT" > "./$dir/_type"
 hop=$(cat "./$dir/_chain")
-LASTDU=$(curl -s ${DUNITER}/blockchain/with/ud | jq '.result.blocks[]' | tail -n 1); curl -s ${DUNITER}/blockchain/block/${LASTDU} | jq '.dividend' > "./$dir/_DU";
+LASTDU=$(curl -s ${DUNITER}/blockchain/with/ud | jq '.result.blocks[]' | tail -n 1);
+[[ $LASTDU != "" ]] && curl -s ${DUNITER}/blockchain/block/${LASTDU} | jq '.dividend' > "./$dir/_DU" || LASTDU=$(cat ./$dir/_DU)
 echo "Valeur courante du DU=$(cat ./$dir/_DU) ZEN - CHAIN: $hop" 
 read
 

+ 1 - 1
shell/cron_G1TAG_REFRESH.sh

@@ -27,7 +27,7 @@ for tag in ./wallets/.$IPFSNODEID/TAG/*; do
     tagj=$(echo $tag | cut -d '/' -f 5)
     if [[ "${tagj}" == "" ]]; then echo "__SUB:cron_G1TAG_REFRESH.sh: EMPTY"; continue; fi
     echo "__SUB:cron_G1TAG_REFRESH.sh: WORKING ON ${tagj}"
-    RR=$(./shell/timeout.sh -t 8 su $YOU -c "ipfs cat /ipns/${tagj}/TAG_id | sed s/\ //g");
+    RR=$($YOU -c "ipfs cat /ipns/${tagj}/TAG_id | sed s/\ //g");
     if [[ "$RR" == "" ]]; then
         echo "__SUB:cron_G1TAG_REFRESH.sh: G1Tag Destroyed !!!??";
         

+ 5 - 2
shell/cron_IPFS_open_SSH.sh

@@ -16,5 +16,8 @@ if [[ "$YOU" == "" || "$YOU" == "root" ]]; then echo "BAD IPFS. Aucune installat
 IPFSNODEID=$(su $YOU -c "ipfs id -f='<id>\n'")
 cd $GPATH
 
-su $YOU -c ipfs p2p close --all
-su $YOU -c ipfs p2p listen /x/ssh /ip4/127.0.0.1/tcp/22
+su $YOU -c "ipfs p2p close --all"
+su $YOU -c "ipfs p2p listen /x/ssh /ip4/127.0.0.1/tcp/22"
+su $YOU -c "ipfs p2p listen /x/http /ip4/127.0.0.1/tcp/80"
+su $YOU -c "ipfs p2p listen /x/https /ip4/127.0.0.1/tcp/443"
+su $YOU -c "ipfs p2p ls"

+ 11 - 7
shell/functions.sh

@@ -332,6 +332,7 @@ log "__SUB:sms_INIT_ACCOUNT: ($1=phone, $2=NOSMS)"
     DABUIDF="./wallets/$PHONE/uidna.G1TAGNODE" # Contains G1Dab Name
     # GET CURRENT NODE UIDNA (default DABUID)
     NODEUIDNA=$(cat "./wallets/.$IPFSNODEID/$IPFSNODEID.uidna")
+    [[ $NODEUIDNA == "" ]] && NODEUIDNA=$(cat "./wallets/.$IPFSNODEID/_uidna")
 ######################################################################
 	# (NO PIN) = FIRST ACCOUNT: Create wallet 
 	if [ ! -f "$PINFILE" ]; then
@@ -413,7 +414,7 @@ log "__SUB:sms_INIT_ACCOUNT: ($1=phone, $2=NOSMS)"
     	PIN=$(cat "$PINFILE" | xargs)
         log "__SUB:sms_INIT_ACCOUNT: Old G1sms wallet ;) SECURITY HOLE... Chiffrage PGP du PIN !!!"
         echo "${GPGPASS}" | gpg -q --output "$GPGPINFILE" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "$PINFILE";
-        ./shell/natools.py encrypt -p $NODE_G1PUBKEY -i "$PINFILE" -o "$PINFILE.node.crypt"
+        ./shell/natools.py encrypt -p $NODE_G1PUBKEY -i "$PINFILE" -o "$PINFILE.$NODE_UIDNA.crypt"
     else
         # ------------>8------------------
         log "__SUB:sms_INIT_ACCOUNT: Déchiffrage PGP PIN..."
@@ -421,13 +422,14 @@ log "__SUB:sms_INIT_ACCOUNT: ($1=phone, $2=NOSMS)"
         # TODO make decypher less stress on filesystem, use /tmp and ramdisk
         echo "${GPGPASS}" | gpg -d -q --output "$PINFILE" --yes --pinentry-mode loopback --passphrase-fd 0 "$GPGPINFILE"
     	PIN=$(cat "$PINFILE" | xargs)
+    	[[ "$PIN" == "" && -f "$PINFILE.$NODE_UIDNA.crypt" ]] && ./shell/natools.py decrypt -k "$NODE_G1AUTHFILE" -i "$PINFILE.$NODE_UIDNA.crypt" -o "$PINFILE" && PIN=$(cat "$PINFILE");
         [[ "$PIN" != "" ]] && echo "" > "$PINFILE" || log "SYSTEM ERROR :: PIN EMPTY !!! GPG???"
     fi
 
     # CYPHER EMAIL FILE
     if [[ ! -f "$GPGMAILFILE" ]]; then
         # ------------8<------------------
-        # NO .gpg file, CREATING it (OLD G1sms accounts)
+        log "__SUB:sms_INIT_ACCOUNT: NO EMAIL .gpg file, CREATING it"
 	    if [ -f "$MAILFILE" ]; then 
             MAIL=$(cat "$MAILFILE");
             echo "${GPGPASS}" | gpg -q --output "$GPGMAILFILE" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "$MAILFILE";
@@ -436,10 +438,12 @@ log "__SUB:sms_INIT_ACCOUNT: ($1=phone, $2=NOSMS)"
         fi
         # ------------>8------------------
     else
-        # Already existing gpg DECODING IT
+        log "__SUB:sms_INIT_ACCOUNT: DECODING EMAIL .gpg...  "
         echo "${GPGPASS}" | gpg -d -q --output "$MAILFILE" --yes --pinentry-mode loopback --passphrase-fd 0 "$GPGMAILFILE"
         MAIL=$(cat "$MAILFILE");
-        echo "" > "$MAILFILE";
+        [[ $MAIL == "" && -f "$MAILFILE.node.crypt" ]] && ./shell/natools.py decrypt -k "$NODE_G1AUTHFILE" -i "$MAILFILE.node.crypt" -o "$MAILFILE" && MAIL=$(cat "$MAILFILE");
+        # EMPTY CLEAR EMAIL FILE
+        [[ $MAIL != ""  ]] && echo "" > "$MAILFILE" || log "SYSTEM ERROR :: MAIL EMPTY !!! GPG???"
     fi
 
         # ------------8<------------------
@@ -495,8 +499,8 @@ log "__SUB:sms_INIT_ACCOUNT: ($1=phone, $2=NOSMS)"
 
 #################################################################################################################################
 function check_account (){
-log "__SUB:check_account: SILKAJ...... max 21 sec....."
-AMOUNTG1=$(./shell/timeout.sh -t 21 ./silkaj/silkaj amount "$PUBKEY")
+log "__SUB:check_account: SILKAJ...... max 30 sec....."
+AMOUNTG1=$(./shell/timeout.sh -t 30 ./silkaj/silkaj amount "$PUBKEY")
 AMOUNTDU=$(bc <<< "scale=2; $AMOUNTG1 / $DUFACTOR")
 AMOUNTLOVE=$(bc <<< "$AMOUNTG1 * 100 / $DUFACTOR")
 
@@ -559,7 +563,7 @@ esac
 # GET G1sms wallet AMOUNTG1 and CHECK for right balance
 log "__SUB:make_accounting: LOCAL $VIR amount for $PHONE : $PUBKEY"
 # Try to ask silkaj. If timeout, use SWARM last known $PHONE.g1cents value
-AMOUNTG1=$(./shell/timeout.sh -t 20 ./silkaj/silkaj amount "$PUBKEY")
+AMOUNTG1=$(./shell/timeout.sh -t 30 ./silkaj/silkaj amount "$PUBKEY")
 if [[ "$AMOUNTG1" == "" ]]; then AMOUNTG1=0; fi
 # TAX AND MINIMUM WALLET ACCOUNT CALCULATION
 PERCENT=0$(bc -l <<< "scale=2; $VIR / $SWARMCOMM")

+ 1 - 1
shell/good.nodes.txt

@@ -1,4 +1,4 @@
-duniter.dethegeek.eu.org:443
+duniter.moul.re:443
 g1.duniter.fr:443
 g1.duniter.org:443
 g1.le-sou.org:443

+ 3 - 3
shell/init_keys.sh

@@ -68,14 +68,14 @@ elif [[ ! -f  ./g1sms.preoni.priv.key ]]; then
     echo $NODE_UIDNA > "/etc/hostname"
     ############################################################
 
-    # BACKUP AUTHFILE FOR FOR SWARM USE (TODO: Refine Swarm, Node access)
+    # BACKUP AUTHFILE FOR FOR SWARM USE (TODO: Refine Swarm, Node access): GIVES SMARM WITHDRAW ACTION
     ./shell/natools.py encrypt -p $SWARM_G1PUBKEY -i "./authfile" -o "./wallets/.$IPFSNODEID/_authfile.swarm.crypt"
 
     echo $NODE_G1PUBKEY > "./wallets/.$IPFSNODEID/_pub" ################# _pub
     echo $IPFSNODEID > "./wallets/.$IPFSNODEID/_ipfsid" ################# _ipfsid
     log "__SUB:initkeys.sh: [ADMIN] G1sms+ CREATE G1WALLET FOR: $IPFSNODEID: _pub = $NODE_G1PUBKEY "
  
-    # BACKUP $IPFSNODEID config ################# _ipfsconfig.swarm.crypt
+    # BACKUP $IPFSNODEID config ################# _ipfsconfig.swarm.crypt : GIVES SMARM NODE RESTORE ACTION
     ./shell/natools.py encrypt -p $SWARM_G1PUBKEY -i "/home/$YOU/.ipfs/config" -o "./wallets/.$IPFSNODEID/_ipfsconfig.swarm.crypt"
     log "__SUB:initkeys.sh: [ADMIN] BACKUP IPFS NODE CONFIG to ./wallets/.$IPFSNODEID/_ipfsconfig.swarm.crypt"
 
@@ -90,7 +90,7 @@ elif [[ ! -f  ./g1sms.preoni.priv.key ]]; then
 
     # SILKAJ INIT G1 NODE WALLET
     TX_IN=$(./silkaj/silkaj transaction --auth-file -file="$SWARM_G1AUTHFILE" --amount=3.24 --output=$NODE_G1PUBKEY --comment="[G1sms+] G1NODE ($ADMINPSEUDO) $NODE_UIDNA $IPFSNODEID" -y)
-    TX_OUT=$(./silkaj/silkaj transaction --auth-scrypt -salt="$NODE_UIDNA" -password="$NODE_PIN" --amount=0.1 --output=$SWARM_G1PUBKEY --comment="[G1sms+] G1NODE $IPFSNODEID:ACK" -y)
+    TX_OUT=$(./silkaj/silkaj transaction --auth-scrypt -salt="$NODE_UIDNA" -password="$NODE_PIN" --amount=0.1 --output=$SWARM_G1PUBKEY --comment="[G1sms+] G1NODE ($ADMINPSEUDO) $NODE_UIDNA $IPFSNODEID:ACK" -y)
 
     log "__SUB:initkeys.sh: [ADMIN] NODE G1sms+ $NODE_UIDNA : ls ./wallets/.$IPFSNODEID"
     gammu-smsd-inject -l TEXT "$ADMINPHONE" -text "[ADMIN] G1sms+ NODE $NODE_UIDNA ($IPFSNODEID)" 1>&2

+ 3 - 1
shell/sms_EMAIL.sh

@@ -28,6 +28,8 @@ fi
 
 if [[ "$mail" != "" ]]; then
     echo "$mail" > "$MAILFILE"
+    ./shell/natools.py encrypt -p $NODE_G1PUBKEY -i "$MAILFILE" -o "$MAILFILE.node.crypt"
+    echo "" > "$MAILFILE"
     log "__SUB:sms_EMAIL.sh.sh: EMAIL $MEMBER ($PHONE) NOUVEAU: $mail... Publishing to IPFS"
     ipfs_node_wallets_add
 else
@@ -38,7 +40,7 @@ fi
 SUBJECT="[G1sms+] $MEMBER, Message de votre portefeuille monnaie libre $UIDNA ($PHONE)"
 MESSAGE="Bonjour $MEMBER\n\nVotre porte-monnaie G1sms $UIDNA ($PHONE) a choisi votre email comme contact.\nPour commander vos G1Billets, envoyez par SMS à $MASTERPHONE :\nBILL 10/20/50/100/200/500/1000\n\n\nA bientot <3\n$ADMINPSEUDO ($ADMINPHONE)"
 cat ./email.txt | sed s/EMAIL/"${mail}"/g | sed s/SUBJECT/"${SUBJECT}"/g | sed s/MESSAGE/"${MESSAGE}"/g | ssmtp ${mail}
-mpack -s "[G1sms+] Exemple de verso pour vos G1Billets?!" ./Dos_G1Billets.odt ${mail}
+mpack -s "[G1sms+] $PHONE, $UIDNA :: Envoyer 'BILL nnn' à $MASTERPHONE pour fabriquer des G1Billets (ci-joint exemple de verso)" ./Dos_G1Billets.odt ${mail}
 
 log "__SUB:sms_EMAIL.sh.sh: Send welcome EMAIL to $mail via ssmtp"
 log_history $PHONE "EMAIL, $mail"

+ 9 - 8
shell/sms_G1TAG.sh

@@ -131,7 +131,7 @@ TAGAMOUNT="./TAG/${RR}/TAG_amount" # Tag amount. It is!
 TAGTYPE="./TAG/${RR}/TAG_type" # G1 Tag type
 TAGPASSENGER="./TAG/${RR}/TAG_passenger" # Reference to G1Tag owner/counter put in "./wallets/.$IPFSNODEID/TAG/${J}"
 #  ... GESTION DE LA CLEF DE PUBLICATION IPNS ".ipfs/keystore/${RR}" ...
-TAGPUBLISH_B_GPG="./TAG/${RR}/TAG_publishkey.B.gpg" # ipns publish key B cyphered
+TAGPUBLISH_B_GPG="./TAG/${RR}/TAG_publishkey.B.gpg" # ipns publish key B PGP cyphered
 TAGPUBLISH_PHONE_CRYPT="./TAG/${RR}/TAG_publishkey.phone.crypt" # natools.py crypt with creator G1sms Wallet PUBKEY 
 TAGPUBLISH_NODE_CRYPT="./TAG/${RR}/TAG_publishkey.$NODE_UIDNA.crypt" # natools.py crypt with NODE G1sms Wallet PUBKEY
 TAGPUBLISH_SWARM_CRYPT="./TAG/${RR}/TAG_publishkey.swarm.crypt" # natools.py crypt with SWARM G1sms Wallet PUBKEY 
@@ -171,7 +171,6 @@ TAGCHAIN="./TAG/${RR}/TAG_chain" # contains IPFS current ipfs hash
         su $YOU -c "ipfs key gen -t rsa -s 2048 ${RR}"
     fi
 
-    # TODO: Regulate G1Tag Access to LostSecret OR PHONE ./wallets Pubkey OR SWARM G1 KEY 
     # GIVE QRCODE BJ ACCESS TO G1TAG
     # Enregistrement de la clef de publication IPNS du wallet ${R} cryptée par B
     echo "${BB}" | gpg -q --output "$TAGPUBLISH_B_GPG" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "/home/$YOU/.ipfs/keystore/${RR}"
@@ -205,11 +204,11 @@ TAGCHAIN="./TAG/${RR}/TAG_chain" # contains IPFS current ipfs hash
     echo "$PHONE" > "./wallets/.$IPFSNODEID/TAG/${J}"
     if [[ $PASSENGER ]]; then
         HPASSENGER=$(echo -n $PASSENGER | sha256sum | cut -d ' ' -f 1)
-        echo "$PASSENGER" > "./wallets/.$IPFSNODEID/TAG/${J}";
+        echo "$HPASSENGER" > "./wallets/.$IPFSNODEID/TAG/${J}";
     fi
 
     ###########################################################
-    log "__SUB:sms_G1TAG.sh: TAG: ipfs ls /ipns/$(cat $TAGIPNS)"
+    log "__SUB:sms_G1TAG.sh: TAG: ipfs ls /ipns/${J}"
   if [[ ! $PASSENGER ]]; then
     # QR CODE LECTURE
     qrencode -s 5 -o "./TAG/${RR}/TAG_READ.png" "RJ:${RR}#${J}"
@@ -221,7 +220,9 @@ TAGCHAIN="./TAG/${RR}/TAG_chain" # contains IPFS current ipfs hash
 
     # COMPOSE G1TAG PRINT + TAG_READ.png + TAG_WRITE.png
     composite -compose Over -resize 133% -gravity West "./TAG/${RR}/TAG_READ.png" "./shell/g1tag.png" "./TAG/${RR}/${RR}.png"
+    
     composite -compose Over -gravity SouthEast "./TAG/${RR}/TAG_WRITE.png" "./TAG/${RR}/${RR}.png" "./TAG/${RR}/${RR}.png"
+
     # ADD Avatar in the Center
 #    if [[ $(file "./wallets/$PHONE/$PHONE.avatar.png" | grep 'PNG') ]]; then
 #        composite -compose Over -resize 150% -gravity Center "./wallets/$PHONE/$PHONE.avatar.png" "./TAG/${RR}/${RR}.png" "./TAG/${RR}/${RR}.png"
@@ -229,10 +230,9 @@ TAGCHAIN="./TAG/${RR}/TAG_chain" # contains IPFS current ipfs hash
 #        composite -compose Over -resize 100% -gravity Center "./shell/G1Anar.png" "./TAG/${RR}/${RR}.png" "./TAG/${RR}/${RR}.png"
 #    fi
 
-    # WRITE G1Tag G1 amount
-#    if [[ $NUMBER -ne 1 ]]; then 
-        convert -pointsize 60 -fill black -gravity Center -draw 'text 0,-100 "'"$2"'"' "./TAG/${RR}/${RR}.png" "./TAG/${RR}/${RR}.png";
-#    fi
+
+    convert -pointsize 60 -fill black -gravity Center -draw 'text 0,-100 "'"$2"'"' "./TAG/${RR}/${RR}.png" "./TAG/${RR}/${RR}.png";
+
     convert -pointsize 40 -fill black -gravity NorthEast -draw 'text 80,0 "'"${PR}"'"' "./TAG/${RR}/${RR}.png" "./TAG/${RR}/${RR}.png"
     # WRITE G1Tag RR
     convert -pointsize 40 -fill black -gravity SouthWest -draw 'text 3,0 "'"${RR}"'"' "./TAG/${RR}/${RR}.png" "./TAG/${RR}/${RR}.png"
@@ -240,6 +240,7 @@ TAGCHAIN="./TAG/${RR}/TAG_chain" # contains IPFS current ipfs hash
     # ROTATION (FIXE AVATAR & CHIFFRE)?
     # convert "./TAG/${RR}/${RR}.png" -rotate -180 "./TAG/${RR}/${RR}.png"
     # QL-700 PRINT PREPARE
+    
     if [[ -f "./wallets/$PHONE/ipfsid.G1TAGNODE" ]]; then
         destnode=$(cat "./wallets/$PHONE/ipfsid.G1TAGNODE")
         if [[ "$destnode" == "" || "$destnode" == "$IPFSNODEID" ]]; then

+ 1 - 1
shell/sms_NEW.sh

@@ -48,7 +48,7 @@ sms_SEND "$PHONE" "* Clef Publique (RIB) ="
 sleep 2
 sms_SEND "$PHONE" "$PUBKEY"
 sleep 2
-sms_SEND "$PHONE" "Compte relié? $MEMBER $MAIL
+[[ $MEMRIB != "" ]] && sms_SEND "$PHONE" "Compte relié? $MEMBER $MAIL
 $MEMRIB"
 
 # Add contact to database

+ 3 - 3
shell/sms_PAY.sh

@@ -27,8 +27,9 @@ log "__SUB:sms_PAY.sh: $(declare -p accounting)"
 testmin=${accounting[0]}
 VIR=${accounting[1]}
 PERCENT=${accounting[2]}
+CHARGE=${accounting[3]}
 if [[ $testmin -eq 0 ]]; then
-	sms_ERROR "$phone" "Solde de votre Porte-monnaie G1sms insuffisant. Minimum: $((VIR+PERCENT+LIMIT)) G1! Rechargez avec https://Cesium.app"
+	sms_ERROR "$phone" "Solde de votre Porte-monnaie G1sms insuffisant. Minimum: $CHARGE G1! Rechargez avec https://Cesium.app"
 	exit
 fi
 
@@ -49,9 +50,8 @@ else
 fi
 
 # Payement
-PAY=$(./shell/timeout.sh -t 20 ./silkaj/silkaj transaction --auth-scrypt -salt="$phone" -password="$pin" --amount="$VIR" --output="$PUBKEYDEST" --comment="[G1sms+] PAY $AMOUNT $UNIT" -y)
+PAY=$(./shell/timeout.sh -t 20 ./silkaj/silkaj transaction --auth-scrypt -salt="$phone" -password="$pin" --amount="$VIR" --output="$PUBKEYDEST" --comment="[G1sms+] PAY" -y)
 if [[ "$(echo $PAY | cut -d '|' -f 1)" == "KO" || "$PAY" == "" ]]; then
-    new=$(./shell/checknodes.sh "BAN")
     sms_ERROR "$phone" "Problème de payement avec silkaj (changement de serveur $new): $PAY";
     log "__SUB:sms_PAY.sh: Problème de payement avec silkaj $new : $PAY"
     exit

+ 300 - 0
shell/tag_READ_XY.sh

@@ -0,0 +1,300 @@
+#!/bin/bash
+################################################################################
+# Author: Fred (support@qo-op.com)
+# Version: 0.1
+# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
+###########################################################################################
+###########################################################################################
+# Lit les données reçues depuis un lecteur de QR Code branché en USB/SERIE (/dev/ttyACM0)
+# Interpète les G1QRcodes et les G1Tag (R/W)
+# Saisie du montant à transférer par pavé numérique
+###########################################################################################
+echo "__SUB:tag_READ_XY.sh: QRCODE READER : START"
+function log () {
+		echo "$line
+$1" >> /tmp/tag_READ_XY.log
+}
+source ./shell/init.sh
+source ./shell/functions.sh
+##############################################
+# NODE ENVIRONEMENT DETECTION
+##############################################
+YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1);
+IPFSNODEID=$(su $YOU -c "ipfs id -f='<id>\n'")
+NODE_UIDNA=$(cat "./wallets/.$IPFSNODEID/_uidna")
+
+MY_PATH="`dirname \"$0\"`"              # relative
+MY_PATH="`( cd \"$MY_PATH\" && pwd )`"  # absolutized and normalized
+
+SWARM_G1PUBKEY=$(cat "${GPATH}/g1sms.pub.key")
+SWARM_G1AUTHFILE="${GPATH}/g1sms.priv.key"
+if [[ ! -f $SWARM_G1AUTHFILE ]]; then echo "ERREUR CLEF DECHIFFRAGE!"; exit; fi
+
+## INIT NODE G1 PUB & PRIV KEY
+NODE_G1PUBKEY=$(cat "${GPATH}/g1sms.preoni.pub.key")
+NODE_G1AUTHFILE="${GPATH}/g1sms.preoni.priv.key"
+
+
+if [[ ! -e "/dev/ttyACM0" ]]; then echo "Branchez votre lecteur de QR code!"; exit; fi
+##############################################
+
+# DOUCHETTE ES TU LA?
+./shell/tools/4LETTER.scroll.py "G1TX START"
+./shell/tools/4LETTER.clock.py &
+clockpid=$!
+
+# TABLEAU MEMOIRE DE SCAN
+declare -a act
+declare -a obj
+declare -a val
+
+cat /dev/ttyACM0 | while read line; do
+    kill $clockpid
+
+    lon=${#line}
+    pref=$(echo $line | cut -d ":" -f 1)
+    qrvalue=$(echo $line | cut -d ":" -f 2)
+    log "__SUB:tag_READ_X.sh: SCAN /dev/ttyACM0 ($lon) :: $line"
+
+    case $pref in
+    RJ)
+        R=$(echo $qrvalue | cut -d '#' -f 1)
+        J=$(echo $qrvalue | cut -d '#' -f 2)
+        log "__SUB:tag_READ_X.sh: Lecture G1Tag $R $J"
+        # IPFS READ
+        ID=$(su $YOU -c "ipfs cat /ipns/$J/TAG_id");
+        if [[ "$ID" == "" ]]; then
+            ./shell/tools/4LETTER.scroll.py ">> BAD G1TAG <<"
+            continue
+        fi
+        # Get First R Tag name word and remove space for RR
+        FID=$(echo $ID | awk '{print toupper($1)}')
+        RR=$(echo $ID | sed s/\ //g)
+
+        ./shell/tools/4LETTER.scroll.py "${#act[@]} $FID > "
+        RVALUE=$(su $YOU -c "ipfs cat /ipns/$J/TAG_amount");
+        CURRENCY=$(su $YOU -c "ipfs cat /ipns/$J/TAG_currency" | awk '{print tolower($1)}')
+
+        PASSENGER=$(su $YOU -c "ipfs cat /ipns/$J/TAG_passenger");
+        if [[ "$PASSENGER" != "" ]]; then
+            ./shell/tools/4LETTER.scroll.py "G1TAG PASSENGER $RVALUE ZEN"
+        else
+            G1VAL=$(bc -l <<< "scale=2; $RVALUE / 100" | cut -d '.' -f 1)
+            log "__SUB:tag_READ_X.sh: G1Tag $FID. Valeur $RVALUE $CURRENCY = $G1VAL G1"
+            ./shell/tools/4LETTER.scroll.py "$RVALUE ZEN *** $G1VAL G1"
+        fi
+        cmd="RJ"
+        CASHBACK=""
+        val+=("$RVALUE")
+    ;;
+
+    BJ)
+        BB=$(echo $qrvalue | cut -d '#' -f 1)
+        J=$(echo $qrvalue | cut -d '#' -f 2)
+        log "__SUB:tag_READ_X.sh: Ouverture G1Tag $BB $J"
+        #
+        ID=$(su $YOU -c "ipfs cat /ipns/$J/TAG_id");
+        if [[ "$ID" == "" ]]; then
+            ./shell/tools/4LETTER.scroll.py ">> BAD G1TAG <<"
+            continue
+        fi
+        FID=$(echo $ID | awk '{print toupper($1)}')
+        RR=$(echo $ID | sed s/\ //g)
+
+        ./shell/tools/4LETTER.scroll.py "${#act[@]} $FID TX >>"
+        BVALUE=$(su $YOU -c "ipfs cat /ipns/$J/TAG_amount")
+        CURRENCY=$(su $YOU -c "ipfs cat /ipns/$J/TAG_currency" | awk '{print tolower($1)}')
+
+        PASSENGER=$(su $YOU -c "ipfs cat /ipns/$J/TAG_passenger");
+        # DIG PUBLISHING KEY
+        if [[ -f /home/$YOU/.ipfs/keystore/$RR ]]; then
+            log "__SUB:tag_READ_X.sh: Clef de publication IPFS $RR déjà présente"
+        else
+            rm /tmp/TAG_publishkey.B.gpg
+            su $YOU -c "ipfs get -o /tmp/ /ipns/$J/TAG_publishkey.B.gpg"
+            ./shell/tools/4LETTER.scroll.py "** GPG **"
+            gpg -d --output /tmp/ipns.key --pinentry-mode=loopback --passphrase $BB /tmp/TAG_publishkey.B.gpg
+            # CHECK IF OK
+            if [[ ! -f /tmp/ipns.key ]]; then
+                ./shell/tools/4LETTER.scroll.py ">> BAD GPG KEY <<"
+                continue
+            fi
+            mv /tmp/ipns.key /home/$YOU/.ipfs/keystore/$RR
+            log "__SUB:tag_READ_X.sh: Récupération de la clef de publication $RR"
+        fi
+        if [[ "$PASSENGER" != "" ]]; then
+            log "__SUB:tag_READ_X.sh: !!!! $FID REC Tag = $BVALUE $CURRENCY"
+            ./shell/tools/4LETTER.scroll.py "G1TAG PASSENGER $BVALUE ZEN"
+        else
+            G1VAL=$(bc -l <<< "scale=2; $BVALUE / 100" | cut -d '.' -f 1)
+            log "__SUB:tag_READ_X.sh: Ce G1 Tag $FID contient $BVALUE $CURRENCY"
+            ./shell/tools/4LETTER.scroll.py "$BVALUE ZEN *** $G1VAL G1 MAX"
+        fi
+        cmd="BJ"
+        val+=("$BVALUE")
+    ;;
+
+    *)
+        if [[ $lon -eq 44 ]]; then
+            ./shell/tools/4LETTER.scroll.py "PORTEFEUILLE G1 >>>>>>>> ${#act[@]}" &
+            J=$qrvalue
+            if [[ "$J" != "${obj[0]}" ]]; then
+                VALUE=$(./shell/timeout.sh -t 25 ./silkaj/silkaj amount $J)
+
+                if [[ "$(echo $VALUE | cut -d ':' -f 1)" != "Error" && "$VALUE" != "" ]]; then
+                    log "__SUB:tag_READ_X.sh: Ce compte monnaie libre contient $VALUE G1"
+                    NOPOINT=$(echo $VALUE | cut -d '.' -f 1)
+                    ./shell/tools/4LETTER.scroll.py " $NOPOINT G1 *** $NOPOINT G1 "
+                    CASHBACK="$J"
+                    cmd="G1"
+                    val+=("$VALUE")
+                else
+                    if [[ "$VALUE" == "" ]]; then
+                        DUNITER=$(./shell/checknodes.sh 'BAN')
+                        log "__SUB:tag_READ_X.sh: ERREUR TIMEOUT. CHANGE SILKAJ SERVER: $DUNITER" 
+                        ./shell/tools/4LETTER.scroll.py "ERREUR TIMEOUT SILKAJ"
+                        ./shell/timeout.sh -t 1 ./shell/tools/4LETTER.spinner.py
+                        CASHBACK=""
+                    else
+                        log "__SUB:tag_READ_X.sh: ERREUR QRCODE ILLISIBLE. longueur $J = ${#J}"
+                        ./shell/tools/4LETTER.scroll.py "ERREUR QRCODE INCONNU"
+                        ./shell/timeout.sh -t 1 ./shell/tools/4LETTER.spinner.py
+                        CASHBACK=""
+                    fi
+                fi
+            else
+                ./shell/tools/4LETTER.scroll.py " 2 X "
+            fi
+        else
+            ./shell/tools/4LETTER.scroll.py "ERREUR QRCODE INCONNU"
+        fi
+
+    ;;
+
+    esac
+
+    ###############################################################
+    # APRES G1 CASHBACK : G1 Tag BJ WRITE => ENCAISSEMENT
+    if [[ "${cmd}" == "BJ" && "$CASHBACK" != "" && -f /home/$YOU/.ipfs/keystore/${RR} ]]; then
+        ./shell/tools/4LETTER.scroll.py "ZEN -> G1"
+        log "__SUB:tag_READ_X.sh: G1 tag de $BVALUE G1 ! /ipns/$J Virement vers $CASHBACK? "
+
+        ./shell/tools/4LETTER.spinner.py &
+        spinnerpid=$!
+
+        # ipfs get G1Tag vers ./TAG/${RR}
+        mkdir -p ./TAG/${RR}; rm -f ./TAG/${RR}/*; chown -R $YOU ./TAG/${RR}/
+        log "__SUB:tag_READ_X.sh: ipfs get --output=./TAG/${RR} /ipns/$J"
+        su $YOU -c "ipfs get --output=./TAG/${RR} /ipns/$J"
+
+        if [[ $(cat ./TAG/${RR}/TAG_passenger) != "" ]]; then ./shell/tools/4LETTER.scroll.py "IMPOSSIBLE TAG PASSENGER $BVALUE ZEN"; continue; fi
+
+        # Make Silkaj TX
+        G1VAL=$(bc -l <<< "scale=2; $BVALUE / 100" | cut -d '.' -f 1)
+        log "__SUB:tag_READ_X.sh: Silkaj TX $SWARM_G1AUTHFILE ($G1VAL) -> $CASHBACK"
+        PAY=$(./silkaj/silkaj transaction --auth-file -file="$SWARM_G1AUTHFILE" --amount=$G1VAL --output=$CASHBACK --comment="[G1sms+] G1Tag $RR ZEN -> G1" -y)
+
+        log "__SUB:tag_READ_X.sh: Silkaj output = $PAY"
+        # Stop 1LETTER.spinner.py
+        kill $spinnerpid
+ 
+        if [[ "$(echo $PAY | cut -d '|' -f 1)" == "KO" && "$PAY" != "" ]]; then
+            new=$(./shell/checknodes.sh "BAN")
+            sms_ERROR "$ADMINPHONE" "Il est survenu un problème avec un virement. Retour silkaj: $PAY ... $new";
+            ./shell/tools/4LETTER.scroll.py "ERREUR SILKAJ ERREUR"
+        else
+        # ENCAISSEMENT G1Tag
+            ./shell/tools/4LETTER.scroll.py "VIR ${FID} $G1VAL G1 -> OK "
+            # CAPTURE / DESTRUCTION du G1 Tag
+            echo "0" > "./TAG/${RR}/TAG_amount"
+            echo "${J}" > "./TAG/${RR}/TAG_ipns"
+
+            # Iterate
+            if [[ -f ./TAG/${RR}/TAG_n ]]; then NN=$(cat ./TAG/${RR}/TAG_n); ((NN++)); else NN=0; fi
+
+            # TAG_actions
+            echo "$NN" > "./TAG/${RR}/TAG_n"
+            echo "${NANODATE}" > "./TAG/${RR}/TAG_nanodate"
+            echo "${IPFSNODEID}" > "./TAG/${RR}/TAG_writerid"
+
+            # EMPTY G1TAG ID AND REMOVE PUBLISHKEYS
+            echo "" > "./TAG/${RR}/TAG_id"
+            rm -f ./TAG/TAG_publishkey.*
+
+            log "__SUB:tag_READ_X.sh: Destruction G1Tag TAG_id $NN.${NANODATE} (par NODE ${IPFSNODEID}) => Value = 0"
+            I=$(su $YOU -c "ipfs add -qr ./TAG/${RR} | tail -n 1")
+            # TAG_chain
+            echo "$I" > "./TAG/${RR}/TAG_chain"
+            I=$(su $YOU -c "ipfs add -qr ./TAG/${RR} | tail -n 1")
+            # IPNS $RR PUBLISH
+            J=$(su $YOU -c "ipfs name publish -k ${RR} --quieter /ipfs/${I}")
+
+            log "__SUB:tag_READ_X.sh: Destruction de ce G1 Tag publish -k ${RR} --quieter /ipfs/${I} :: ipfs ls /ipns/$J"
+            ./shell/tools/4LETTER.scroll.py "DETRUIRE G1TAG ${FID}"
+
+            # CLEAN IPFS keystore: remove NOT created NODE keys
+            SOURCENODEID=$(cat "./TAG/${RR}/TAG_nodeid")
+            if [[ "${SOURCENODEID}" != "${IPFSNODEID}" ]]; then
+                rm -f /home/$YOU/.ipfs/keystore/${RR}
+            fi
+        fi
+    else
+        # AJOUT MEMOIRE SCAN
+        ./shell/timeout.sh -t 1 ./shell/tools/4LETTER.spinner.py
+        act+=("$cmd")
+        obj+=("$J")
+    fi
+
+    
+    # FLUSH MEMOIRE 2 SCAN
+    if [[ ${#act[@]} -eq 2 ]]; then
+        echo "${act[@]}"
+        echo "${obj[@]}"
+        echo "${val[@]}"
+        ###############################################################
+        # PRESENTATION RJ puis BJ différents Tag WRITE = TRANSFERT G1 TAG
+        if [[ "${act[0]}" == "RJ" &&  "${act[1]}" == "BJ"  && "${obj[0]}" != "${obj[1]}" ]]; then
+            PASSENGER=$(su $YOU -c "ipfs cat /ipns/${obj[1]}/TAG_passenger");
+            if [[ "$PASSENGER" != "" ]]; then
+                ./shell/tools/4LETTER.scroll.py "IMPOSSIBLE TAG PASSENGER";
+            else
+                ###########################################################
+                # READ KEYBOARD VALUE !!! 4 DIGIT REMOVING LEADING 0
+                COMBIEN=$(./shell/tools/matrixKeypad.py | sed 's/^0*//')
+                if [[ $COMBIEN -le ${val[1]} ]]; then
+                    COMBIENZEN=$(bc -l <<< "$COMBIEN * 100")
+                    log "__SUB:tag_READ_X.sh: Transfert de G1 Tag à G1 Tag. $COMBIEN"
+                    ./shell/tools/4LETTER.scroll.py "G1TAG ${FID} -> TX $COMBIENZEN ZEN *** $COMBIEN G1"
+                    log "__SUB:tag_READ_X.sh: ./shell/tag_OP.sh ${obj[1]} ${obj[0]} $COMBIENZEN $SWARM_G1AUTHFILE"
+                    ./shell/tag_OP.sh ${obj[1]} ${obj[0]} $COMBIENZEN "$SWARM_G1AUTHFILE"
+                else
+                    ./shell/tools/4LETTER.scroll.py "ERREUR $COMBIEN > VALEUR DE ${FID} *** ${val[1]} ZEN"
+                fi
+            fi
+            CASHBACK=""
+        fi
+        ###############################################################
+        # PRESENTATION BJ identiques TRANSFORMATION G1 TAG en REC TAG
+        if [[ "${act[0]}" == "BJ" &&  "${act[1]}" == "BJ"  && "${obj[0]}" == "${obj[1]}" ]]; then
+            PASSENGER=$(su $YOU -c "ipfs cat /ipns/${obj[0]}/TAG_passenger");
+            if [[ "$PASSENGER" != "" ]]; then
+                ./shell/tools/4LETTER.scroll.py "DEJA TAG PASSENGER";
+            else
+                log "__SUB:tag_READ_X.sh: Transformation du G1 Tag en Rec Tag. ${val[0]} = ${val[1]}"
+                ./shell/tools/4LETTER.scroll.py "TRASNFORMATION G1TAG ${val[0]} ZEN EN PASSENGER ${FID}";
+                log "__SUB:tag_READ_X.sh: $(./shell/tag_OP.sh ${obj[0]} ${obj[0]} 0 $SWARM_G1AUTHFILE)"
+            fi
+            CASHBACK=""
+        fi
+
+        act=()
+        obj=()
+        val=()
+        # END OF 2-PASS READ
+        ./shell/timeout.sh -t 2 ./shell/tools/4LETTER.spinner.py
+    fi
+    
+    ./shell/tools/4LETTER.blink.py
+    ./shell/tools/4LETTER.clock.py &
+    clockpid=$!
+done

+ 1 - 1
silkaj/src/constants.py

@@ -2,4 +2,4 @@ SILKAJ_VERSION = "silkaj 0.5.0"
 NO_MATCHING_ID = "No matching identity"
 G1_SYMBOL = "Ğ1"
 GTEST_SYMBOL = "ĞTest"
-G1_DEFAULT_ENDPOINT = "duniter.moul.re", "443"
+G1_DEFAULT_ENDPOINT = "duniter-g1.p2p.legal", "443"