#!/bin/bash ######################################################################## # Version: 0.5 # License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) ######################################################################## # PAD COCODING : https://pad.p2p.legal/s/G1PalPay # This script monitors G1 Blockchain ######################################################################## MY_PATH="`dirname \"$0\"`" # relative MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized ME="${0##*/}" . "${MY_PATH}/../tools/my.sh" CESIUM=${myCESIUM} GCHANGE=${myGCHANGE} echo "$ME RUNNING" ######################################################################## # PALPAY SERVICE : MONITOR INCOMING TX & NEW TIDDLERS ######################################################################## ######################################################################## INDEX="$1" ## TW file [[ ! ${INDEX} ]] && INDEX="$HOME/.zen/game/players/.current/ipfs/moa/index.html" [[ ! -s ${INDEX} ]] && echo "ERROR - Please provide path to source TW index.html" && exit 1 [[ ! -s ${INDEX} ]] && echo "ERROR - Fichier TW absent. ${INDEX}" && exit 1 PLAYER="$2" ## PLAYER [[ ! ${PLAYER} ]] && PLAYER="$(cat ~/.zen/game/players/.current/.player 2>/dev/null)" [[ ! ${PLAYER} ]] && echo "ERROR - Please provide PLAYER" && exit 1 ASTRONAUTENS=$(ipfs key list -l | grep -w ${PLAYER} | cut -d ' ' -f1) ## TW /ipns/ [[ ! ${ASTRONAUTENS} ]] && echo "ERROR - Clef IPNS ${PLAYER} introuvable!" && exit 1 G1PUB=$(cat ~/.zen/game/players/${PLAYER}/.g1pub) ## PLAYER WALLET [[ ! $G1PUB ]] && echo "ERROR - G1PUB ${PLAYER} VIDE" && exit 1 # Extract tag=tube from TW MOATS="$3" [[ ! ${MOATS} ]] && MOATS=$(date -u +"%Y%m%d%H%M%S%4N") ################################################################### ## CREATE APP NODE PLAYER PUBLICATION DIRECTORY ################################################################### mkdir -p $HOME/.zen/tmp/${IPFSNODEID}/G1PalPay/${PLAYER}/ mkdir -p $HOME/.zen/game/players/${PLAYER}/G1PalPay/ mkdir -p $HOME/.zen/tmp/${MOATS} echo "=========== ( ◕‿◕) (◕‿◕ ) ============== ${PLAYER} ${INDEX}" echo "(✜‿‿✜) G1PalPay : CHECK LAST 10 TX comment" # CHECK LAST 10 INCOMING PAYMENTS ~/.zen/Astroport.ONE/tools/timeout.sh -t 12 \ ${MY_PATH}/../tools/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey history -n 10 -j > $HOME/.zen/game/players/${PLAYER}/G1PalPay/${PLAYER}.duniter.history.json [[ ! -s $HOME/.zen/game/players/${PLAYER}/G1PalPay/${PLAYER}.duniter.history.json ]] \ && echo "NO PAYMENT HISTORY.......................... EXIT" \ && exit 1 ############################## ########################################################## ############# CHECK FOR N1COMMANDs IN PAYMENT COMMENT # TODO check amout > 0 ################################################################# # LOG / cat $HOME/.zen/game/players/${PLAYER}/G1PalPay/${PLAYER}.duniter.history.json | jq -rc .[] ## TREAT ANY COMMENT STARTING WITH N1: ## EXTRACT /ASTROBOT/N1ProgramNames ls ${MY_PATH}/../ASTROBOT/ | grep "N1" | cut -d "." -f 1 > ~/.zen/tmp/${MOATS}/N1PROG while read prog; do cat $HOME/.zen/game/players/${PLAYER}/G1PalPay/${PLAYER}.duniter.history.json | jq -rc .[] | grep "$prog" >> ~/.zen/tmp/${MOATS}/myN1.json done < ~/.zen/tmp/${MOATS}/N1PROG # got N1 incoming TX while read NLINE; do ## COMMENT FORMAT = N1$CMD:$TH:$TRAIL TXIDATE=$(echo ${NLINE} | jq -r .date) TXIPUBKEY=$(echo ${NLINE} | jq -r .pubkey) COMMENT=$(echo ${NLINE} | jq -r .comment) CMD=$(echo ${COMMENT} | cut -d ':' -f 1 | cut -c -12 ) # Maximum 12 characters CMD # Verify last recorded acting date (avoid running twice) [[ $(cat ~/.zen/game/players/${PLAYER}/.ndate) -ge $TXIDATE ]] \ && echo "$CMD $TXIDATE from $TXIPUBKEY ALREADY TREATED - continue" \ && continue TH=$(echo ${COMMENT} | cut -d ':' -f 2) TRAIL=$(echo ${COMMENT} | cut -d ':' -f 3-) if [[ -s ${MY_PATH}/../ASTROBOT/${CMD}.sh ]]; then echo "RECEIVED CMD=${CMD} from ${TXIPUBKEY}" ${MY_PATH}/../ASTROBOT/${CMD}.sh ${INDEX} ${PLAYER} ${MOATS} ${TXIPUBKEY} ${TH} ${TRAIL} ## WELL DONE . [[ $? == 0 ]] && echo "${CMD} DONE" && echo "$TXIDATE" > ~/.zen/game/players/${PLAYER}/.ndate ## MEMORIZE LAST TXIDATE else echo "NOT A N1 COMMAND ${COMMENT}" fi done < ~/.zen/tmp/${MOATS}/myN1.json ######################################################################################## ############# CHECK FOR EMAILs IN PAYMENT COMMENT ## DEBUG ## cat $HOME/.zen/game/players/${PLAYER}/G1PalPay/${PLAYER}.duniter.history.json | jq -r ################################################################# cat $HOME/.zen/game/players/${PLAYER}/G1PalPay/${PLAYER}.duniter.history.json | jq -rc .[] | grep '@' > ~/.zen/tmp/${MOATS}/myPalPay.json # IF COMMENT CONTAINS EMAIL ADDRESSES # SPREAD & TRANSFER AMOUNT TO NEXT (REMOVING IT FROM LIST)... Other G1PalPay will continue the transmission... ######################################################################## ## GET @ in JSON INLINE while read LINE; do echo "${LINE}" JSON=${LINE} TXIDATE=$(echo $JSON | jq -r .date) TXIPUBKEY=$(echo $JSON | jq -r .pubkey) TXIAMOUNT=$(echo $JSON | jq -r .amount) TXIAMOUNTUD=$(echo $JSON | jq -r .amountUD) COMMENT=$(echo $JSON | jq -r .comment) [[ $(cat ~/.zen/game/players/${PLAYER}/.atdate) -ge $TXIDATE ]] \ && echo "PalPay $TXIDATE from $TXIPUBKEY ALREADY TREATED - continue" \ && continue ## GET EMAILS FROM COMMENT TXIMAILS=($(echo "$COMMENT" | grep -E -o "\b[a-zA-Z0-9.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b")) echo "$TXIDATE $TXIPUBKEY $TXIAMOUNT [$TXIAMOUNTUD] $TXIMAILS % $SHARE %" [[ $(echo "$TXIAMOUNT < 0" | bc) ]] \ && echo "TX-OUT" \ && echo "$TXIDATE" > ~/.zen/game/players/${PLAYER}/.atdate \ && continue ## DIVIDE INCOMING AMOUNT TO SHARE echo "N=${#TXIMAILS[@]}" N=${#TXIMAILS[@]} SHAREE=$(echo "scale=2; $TXIAMOUNT / $N" | bc) SHARE=$(makecoord ${SHAREE}) ## SHARE is received AMOUT divided by numbers of EMAILS in comment # let's loop over TXIMAILS for EMAIL in "${TXIMAILS[@]}"; do [[ ${EMAIL} == $PLAYER ]] \ && echo "ME MYSELF" \ && echo "$TXIDATE" > ~/.zen/game/players/${PLAYER}/.atdate \ && continue echo "EMAIL : ${EMAIL}" ASTROTW="" STAMP="" ASTROG1="" ASTROIPFS="" ASTROFEED="" # RESET VAR $($MY_PATH/../tools/search_for_this_email_in_players.sh ${EMAIL}) ## export ASTROTW and more echo "export ASTROPORT=${ASTROPORT} ASTROTW=${ASTROTW} ASTROG1=${ASTROG1} ASTROMAIL=${EMAIL} ASTROFEED=${FEEDNS}" [[ ${ASTROTW} == "" ]] && ASTROTW=${ASTRONAUTENS} if [[ ! ${ASTROTW} ]]; then echo "# PLAYER INCONNU $(date)" fi [[ ! ${ASTROG1} ]] \ && echo "