You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

189 lines
7.1 KiB

#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 1.0
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
########################################################################
# \\///
# qo-op
############# $ME DELAY
########################################################################
echo "
_(_)_ _(_)_
@@@@ (_)@(_) @@@@ (_)@(_) @@@@
@@()@@ wWWWw (_)\ @@()@@ wWWWw (_)\ @@()@@ wWWWw
@@@@ (___) \|/ @@@@ (___) \|/ @@@@ (___)
/ Y \| / Y \| / Y
\ | \ |/ | / \ | \ |/ | / \ | \ |/
\\|// \\|/// \\\|// \\|// \\|/// \\\|// \\|// \\|///
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# [ASTROPORT](https://astroport.com)
# ex: ./$ME \"10 days\"
# Survey Node G1 Wallet for TX/IN Commands in received comments ...
########################################################################
"
DELAY="$1"
ipfsnodeid=$(ipfs id -f='<id>\n')
[[ "$ipfsnodeid" == "" ]] && echo "$USER Please Install IPFS !!" && exit 1
[[ ! -d ~/.zen/cache/g1_TX_inputs ]] && mkdir -p ~/.zen/cache/g1_TX_inputs # Directory containing G1 blockchain incoming TX Scan
[[ ! -d ~/.zen/ipfs ]] && mkdir -p ~/.zen/ipfs # Directory where NODE store SMS & other Channel Wallets
[[ ! -d ~/.zen/ipfs_swarm ]] && mkdir -p ~/.zen/ipfs_swarm # Local copy of all SSB friends IPFS Nodes published ipfs
#########################################################################################################
# GET G1 PUBKEY FROM SCUTTLEBUTT or $2 (DEBUG)
[[ $DELAY == "" ]] && DELAY="60 days" && echo "*** HELP ***" && echo "./$ME \"duration\" (default $DELAY)" && echo "************" && echo
DELAYUNIT=$(echo $DELAY | cut -d ' ' -f 2)
# g1pub=$2 # DEBUG
[[ ! -f ~/.ssb/secret.dunikey ]] && $MY_PATH/tools/secret2dunikey.sh
g1pub=$(cat ~/.ssb/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
[[ "$g1pub" == "" ]] && echo "$USER Missing ~/.ssb/secret : Please Install Scuttlebutt server !" && exit 1;
#########################################################################################################
echo "======================================="
echo "IPFS Node ID = $ipfsnodeid
__
_|_ _ _| |\ | _ _| _ /__/| _.|| __|_
(_| |(/_(_|< | \|(_)(_|(/_ \_| | \/\/(_|||(/_|_
last $DELAY
G1 PUBKEY = $g1pub
"
# PREPARE TIMESTAMP LIMITS
TIMEBEFORE=$(date -u --date="-$DELAY" +"%s")
TIMESTAMP=$(date -u +"%s")
# GET DUNITER SERVER
DUNITERNODE=$($MY_PATH/tools/duniter_getnode.sh)
DUNITERURL="https://$DUNITERNODE"
# GET BLOCKCHAIN TX FOR TIME WINDOW
curl -s $DUNITERURL/tx/history/$g1pub/times/$TIMEBEFORE/$TIMESTAMP > /tmp/g1_TX.scan.txt
TXNB=$(cat /tmp/g1_TX.scan.txt | wc -l)
echo "
$DUNITERURL/tx/history/$g1pub/times/$TIMEBEFORE/$TIMESTAMP
___
|\/ ._ ._ _ |_ _ ._
G1 |/\ | ||_|| | ||_)(/_|
$TXNB
"
# Choose between "history.received" OR "history.pending" depending on DELAY
if [[ $DELAYUNIT != "minutes" && $DELAYUNIT != "minute" ]]; then
# HOW MANY TX DO WE HAVE...
TXnb=$(cat /tmp/g1_TX.scan.txt | jq '.history.received[].hash' | wc -l)
echo "During $DELAY, detected $TXnb TX... Now looking for INPUT TX..."
# PARSE $TXnb TX
line=1
while [[ $line -le $TXnb ]]; do
# GET TX HASH
TXhash=$(cat /tmp/g1_TX.scan.txt | jq -r '.history.received[].hash' | head -n $line | tail -n 1 )
# IT IS A NEW TX?
if [[ ! -f ~/.zen/cache/g1_TX_inputs/zen.$TXhash ]]; then
# GET LAST TX ISSUER
ISSUER=$(cat /tmp/g1_TX.scan.txt | jq -r '.history.received[].issuers[0]' | head -n $line | tail -n 1)
[[ $ISSUER == $g1pub ]] && ((line++)) && continue ## TX/OUT CONTINUE
echo $ISSUER > ~/.zen/cache/g1_TX_inputs/zen.$TXhash
# GET OUTPUTS AND MAKE ZEN=G1*100 SUM
ZEN=$(cat /tmp/g1_TX.scan.txt | jq -r '.history.received[].outputs[]' | grep $g1pub | head -n $line | tail -n 1 | cut -d ':' -f 1)
# GET COMMENT
COMMENT=$(cat /tmp/g1_TX.scan.txt | jq '.history.received' | jq -r '.[].comment' | head -n $line | tail -n 1)
# echo "TX-IN $ISSUER => $g1pub"
echo "Received $ZEN Zen From $ISSUER :: $COMMENT :: ($TXhash)"
CMD=$(echo "$COMMENT" | awk '{print toupper($1)}')
echo "
___ ___ _ ___ _
|\/ | |\ ||_)| || |_) _ _ _ o _ _|
|/\ _|_| \|| |_|| | \(/_(_(/_|\/(/_(_|
"
case "$CMD" in
ZEN)
# Create ZenTAG QRCode
$MY_PATH/zen_MAKE.sh $ZEN $TXhash
;;
*)
echo "$TXhash = $ZEN ZEN ($COMMENT)"
# $MY_PATH/zen_MAKE.sh "ME" $TXhash
;;
esac
fi
((line++))
done
else
# MINUTE DELAY = pending // TODO: if anyone succeed in passing $VAR in jq command, both can be merge...
# HOW MANY TX DO WE HAVE...
TXnb=$(cat /tmp/g1_TX.scan.txt | jq '.history.pending[].hash' | wc -l)
echo "During $DELAY, detected $TXnb TX... Now looking for INPUT TX..."
# PARSE $TXnb TX
line=1
while [[ $line -le $TXnb ]]; do
TXhash=$(cat /tmp/g1_TX.scan.txt | jq -r '.history.pending[].hash' | head -n $line | tail -n 1)
# IT IS A NEW TX/IN?
if [[ ! -f ~/.zen/cache/g1_TX_inputs/zen.$TXhash ]]; then
# GET LAST RX ISSUER
ISSUER=$(cat /tmp/g1_TX.scan.txt | jq -r '.history.pending[].issuers[0]' | head -n $line | tail -n 1)
[[ $ISSUER == $g1pub ]] && ((line++)) && continue ## TX/OUT CONTINUE
echo $ISSUER > ~/.zen/cache/g1_TX_inputs/zen.$TXhash
# GET OUTPUTS AND MAKE ZEN SUM
ZEN=$(cat /tmp/g1_TX.scan.txt | jq -r '.history.pending[].outputs[]' | grep $g1pub | head -n $line | tail -n 1 | cut -d ':' -f 1)
# GET COMMENT
COMMENT=$(cat /tmp/g1_TX.scan.txt | jq '.history.pending' | jq -r '.[].comment' | head -n $line | tail -n 1)
# echo "TX-IN $ISSUER => $g1pub"
echo "Pending $ZEN Zen From $ISSUER :: $COMMENT :: ($TXhash)"
CMD=$(echo "$COMMENT" | awk '{print toupper($1)}')
echo "
___ ___ _ ___ _
|\/ | |\ ||_)| || |_)_ ._ _|o._ _
|/\ _|_| \|| |_|| | (/_| |(_||| |(_|
_|
"
case "$CMD" in
ZEN)
# Create ZenTAG QRCode
$MY_PATH/zen_MAKE.sh $ZEN $TXhash
;;
*)
echo "$TXhash = $ZEN ZEN ($COMMENT)"
# $MY_PATH/zen_MAKE.sh "ME" $TXhash
;;
esac
fi
((line++))
done
fi
echo "FINISH ! ls ~/.zen/cache/g1_TX_inputs/
__
|\ | _ _| _ /__/| \ /_.|| __|_ |_ _.| _.._ _ _
| \|(_)(_|(/_ \_| | \/\/(_|||(/_|_ |_)(_||(_|| |(_(/_
silkaj -p $DUNITERNODE balance $g1pub
"
exit 0