62 lines
2.3 KiB
Bash
Executable File
62 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -xue
|
|
|
|
. ./config.sh
|
|
|
|
mkdir -p "$DEALS_LAST_BALANCE"
|
|
|
|
MESSAGE_TXT="${DEALS_BASE}/message.txt"
|
|
PAID_REQUESTS="${DEALS_BASE}/paid_requests.json"
|
|
PENDING_REQUESTS="${DEALS_BASE}/pending_requests.json"
|
|
|
|
$ELECTRUM listrequests --pending > "$PENDING_REQUESTS"
|
|
|
|
for deal in $(grep 'deposit for deal' "$PENDING_REQUESTS" | egrep -o '[0-9a-f]{64}'); do
|
|
DEPOSIT_ADDRESS=$(grep "$deal" -B 5 "$PENDING_REQUESTS" | grep '"address":' | sed 's/"address": //' | sed 's/[ ",]//g')
|
|
BALANCE=$($ELECTRUM getaddressbalance "$DEPOSIT_ADDRESS" | grep '"confirmed"' | sed 's/"confirmed": "//' | sed 's/[" ,]//g')
|
|
BALANCE_FILE="${DEALS_LAST_BALANCE}/${deal}"
|
|
PREV_BALANCE=$(cat "$BALANCE_FILE" || echo '')
|
|
if [ "$BALANCE" = "$PREV_BALANCE" ]; then
|
|
echo "No changes for balance of deal ${deal}, address ${DEPOSIT_ADDRESS}"
|
|
continue
|
|
fi
|
|
if [ "$BALANCE" = "0" ]; then
|
|
echo "Balance is 0 for deal ${deal}, address ${DEPOSIT_ADDRESS}"
|
|
continue
|
|
fi
|
|
echo "$BALANCE" > "$BALANCE_FILE"
|
|
SENDER_FILE="${DEALS_DEAL_SENDERS}/${deal}"
|
|
echo "Balance of deal ${deal} updated: ${BALANCE}" > "$MESSAGE_TXT"
|
|
python send_bm_message.py \
|
|
--from-address "$DEALS_BM_TO_NOTIFY_BALANCE_UPDATES" \
|
|
--to-address "$(cat "$SENDER_FILE" )" \
|
|
--subject "" \
|
|
--message-file "$MESSAGE_TXT"
|
|
done
|
|
|
|
mkdir -p "$DEALS_FILLED"
|
|
|
|
$ELECTRUM listrequests --paid > "$PAID_REQUESTS"
|
|
|
|
for deal in $(grep 'deposit for deal' "$PAID_REQUESTS" | egrep -o '[0-9a-f]{64}'); do
|
|
FILLED_FILE="${DEALS_FILLED}/${deal}"
|
|
if [ -f "$FILLED_FILE" ] ; then
|
|
continue
|
|
fi
|
|
DEPOSIT_ADDRESS=$(grep "$deal" -B 6 "$PAID_REQUESTS" | grep '"address":' | sed 's/"address": //' | sed 's/[ ",]//g')
|
|
BALANCE=$($ELECTRUM getaddressbalance "$DEPOSIT_ADDRESS" | grep '"unconfirmed"' | sed 's/"unconfirmed": "//' | sed 's/[" ,]//g')
|
|
if [ "$BALANCE" != "0" ]; then
|
|
echo "There is unconfirmed money on deal ${deal}, address ${DEPOSIT_ADDRESS}"
|
|
continue
|
|
fi
|
|
touch "$FILLED_FILE"
|
|
SENDER_FILE="${DEALS_DEAL_SENDERS}/${deal}"
|
|
echo "Deal ${deal} is filled" > "$MESSAGE_TXT"
|
|
python send_bm_message.py \
|
|
--from-address "$DEALS_BM_TO_NOTIFY_BALANCE_UPDATES" \
|
|
--to-address "$(cat "$SENDER_FILE" )" \
|
|
--subject "" \
|
|
--message-file "$MESSAGE_TXT"
|
|
done
|