Skip to content

Commit

Permalink
Added example.
Browse files Browse the repository at this point in the history
  • Loading branch information
d4ndox committed May 11, 2024
1 parent b89dff7 commit 9ba533f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
8 changes: 8 additions & 0 deletions example/readtx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
inotifywait -m /tmp/mywallet -e create -r |
while read dir action file; do
path=$dir$file;
echo $path;
amount=$(cat $path);
echo "amount = "$amount;
done
32 changes: 32 additions & 0 deletions example/txdetect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Function to handle reading from a pipe
read_pipe() {
local dir="$1"
local file="$2"
local amount

# Set timeout for cat command
if ! amount=$(timeout 25m cat "${dir}/${file}"); then
# Handle timeout - write to syslog and exit
echo "Timeout occurred while reading from $file" >&2
logger "Timeout occurred while reading from $file"
exit 1
fi

echo "Received from $file: $amount"
}

# Trap SIGINT to clean up child processes
trap 'kill $(jobs -p); exit' SIGINT

# Watch for new pipes using inotifywait
inotifywait -m /tmp/mywallet -e create -r |
while read dir action file; do
# Check if the created file is a named pipe
if [ -p "${dir}/${file}" ]; then
echo "New pipe detected: $file"
# Call function to read from pipe in a background process
read_pipe "$dir" "$file" &
fi
done
56 changes: 56 additions & 0 deletions example/txdetectdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

# Function to handle reading from a pipe
read_pipe() {
local dir="$1"
local file="$2"
local amount
local payid=$(printf "%d" "0x$file")

echo $payid
mysql --user=sysadmin \
--password=mypassword \
-e "UPDATE payDB.payments SET STATUS = 'WAITING' WHERE PAYID = $payid;"

# Set timeout for cat command
if ! amount=$(timeout 90m cat "${dir}/${file}"); then
# Handle timeout - write to syslog and exit
echo "Timeout occurred while reading from $file" >&2
logger "Timeout occurred while reading from $file"
mysql --user=sysadmin \
--password=mypassword \
-e "UPDATE payDB.payments SET STATUS = 'TIMEOUT' WHERE PAYID = $payid;"
exit 1
fi

echo "Received from $file: $amount"
a1=$(mysql --batch \
--user=sysadmin \
--password=mypassword \
-e "SELECT (amount) FROM payDB.payments WHERE PAYID = $payid;" | tail -n1)
if [ "$amount" = "$a1" ]; then
echo "amount is equal."
mysql --user=sysadmin \
--password=mypassword \
-e "UPDATE payDB.payments SET STATUS = 'COMPLETED' WHERE PAYID = $payid;"
else
echo "amount is not equal."
mysql --user=sysadmin \
--password=mypassword \
-e "UPDATE payDB.payments SET STATUS = 'FAILED' WHERE PAYID = $payid;"
fi
}

# Trap SIGINT to clean up child processes
trap 'kill $(jobs -p); exit' SIGINT

# Watch for new pipes using inotifywait
inotifywait -m /tmp/mywallet -e create -r |
while read dir action file; do
# Check if the created file is a named pipe
if [ -p "${dir}/${file}" ]; then
echo "New pipe detected: $file"
# Call function to read from pipe in a background process
read_pipe "$dir" "$file" &
fi
done

0 comments on commit 9ba533f

Please sign in to comment.