From a91a9802784aad8c886adbb57c03dc6be3bf2884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Mon, 3 Feb 2025 17:31:03 -0800 Subject: [PATCH] Add more utility scripts to identify and ping incomplete checkouts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel D’Aquino --- scripts/filter_incomplete_sessions.sh | 16 +++++++++++ scripts/ping_checkouts.sh | 40 +++++++++++++++++++++++++++ shell.nix | 2 +- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 scripts/filter_incomplete_sessions.sh create mode 100755 scripts/ping_checkouts.sh diff --git a/scripts/filter_incomplete_sessions.sh b/scripts/filter_incomplete_sessions.sh new file mode 100644 index 0000000..95840dd --- /dev/null +++ b/scripts/filter_incomplete_sessions.sh @@ -0,0 +1,16 @@ +if [[ -z "$1" ]]; then + echo "Usage: $0 " + echo "Description: This script outputs checkout sessions from the JSON where the invoice is not null and completed is false." + exit 1 +fi + +if [[ ! -f "$1" ]]; then + echo "Error: File does not exist." + echo "Usage: $0 " + exit 1 +fi + +jq '.checkout_sessions | + to_entries | + map(select(.value.invoice != null and .value.completed == false)) | + from_entries' "$1" diff --git a/scripts/ping_checkouts.sh b/scripts/ping_checkouts.sh new file mode 100755 index 0000000..b3cabb0 --- /dev/null +++ b/scripts/ping_checkouts.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Check if exactly one argument is given (the filename) +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + echo "Description: This script pings the Damus API to check the status of each checkout session UUID in the file." + exit 1 +fi + +# Assign the first command-line argument to FILE +FILE=$1 + +# Check if file exists +if [ ! -f "$FILE" ]; then + echo "Error: File does not exist." + exit 1 +fi + +# Loop through each line in the file +while IFS= read -r uuid +do + # URL where UUID is passed as part of the path + URL="https://api.damus.io/ln-checkout/${uuid}/check-invoice" + + # Make the CURL call and capture the HTTP response code + RESPONSE=$(curl -s -o response.txt -w "%{http_code}" -X POST "$URL") + + # Read server response from the file + SERVER_RESPONSE=$( {} }: with pkgs; mkShell { - buildInputs = [ node2nix ] ++ (with python3Packages; [ pandas matplotlib plotly ]); + buildInputs = [ node2nix jq ] ++ (with python3Packages; [ pandas matplotlib plotly ]); }