Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update entrypoint.sh #78

Open
wants to merge 1 commit into
base: Release-0.0.7
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ getinfo_request() {
EOF
}

createrune_request() {
commando_rune_request() {
cat <<EOF
{
"jsonrpc": "2.0",
"id": 2,
"method": "createrune",
"method": "commando-rune",
"params": [null, [["For Application#"]]]
}
EOF
Expand All @@ -40,11 +40,11 @@ generate_new_rune() {
COUNTER=0
RUNE=""
while { [ "$RUNE" = "" ] || [ "$RUNE" = "null" ]; } && [ $COUNTER -lt 10 ]; do
# Send 'createrune' request
# Send 'commando-rune' request
echo "Generating rune attempt: $COUNTER"
COUNTER=$((COUNTER+1))

RUNE_RESPONSE=$( (echo "$(createrune_request)"; sleep 2) | socat - UNIX-CONNECT:"$LIGHTNING_RPC")
RUNE_RESPONSE=$( (echo "$(commando_rune_request)"; sleep 2) | socat - UNIX-CONNECT:"$LIGHTNING_RPC")

RUNE=$(echo "$RUNE_RESPONSE" | jq -r '.result.rune')
UNIQUE_ID=$(echo "$RUNE_RESPONSE" | jq -r '.result.unique_id')
Expand Down Expand Up @@ -90,18 +90,34 @@ done
LIGHTNING_PUBKEY="$(jq -n "$GETINFO_RESPONSE" | jq -r '.result.id')"
echo "$LIGHTNING_PUBKEY"

# Compare existing pubkey with current
# Check if the existing rune is blacklisted
is_blacklisted=false
if [ "$EXISTING_RUNE" != "" ] && [ "$EXISTING_RUNE" != "LIGHTNING_RUNE=\"\"" ] && [ "$EXISTING_RUNE" != "LIGHTNING_RUNE=\"null\"" ]; then
EXISTING_RUNE_VALUE=$(echo "$EXISTING_RUNE" | sed 's/LIGHTNING_RUNE="//' | sed 's/"//')
echo "Checking if rune is blacklisted: $EXISTING_RUNE_VALUE"

RUNES_RESPONSE=$(lightning-cli showrunes)
echo "RUNES_RESPONSE: $RUNES_RESPONSE"

is_blacklisted=$(echo "$RUNES_RESPONSE" | jq -r ".runes[] | select(.rune == \"$EXISTING_RUNE_VALUE\") | .blacklisted")
is_blacklisted=${is_blacklisted:-false}

echo "Is Blacklisted: $is_blacklisted"
fi

# Compare existing pubkey with current and check if rune is blacklisted
if [ "$EXISTING_PUBKEY" != "LIGHTNING_PUBKEY=\"$LIGHTNING_PUBKEY\"" ] ||
[ "$EXISTING_RUNE" = "" ] ||
[ "$EXISTING_RUNE" = "LIGHTNING_RUNE=\"\"" ] ||
[ "$EXISTING_RUNE" = "LIGHTNING_RUNE=\"null\"" ]; then
# Pubkey changed or missing rune; rewrite new data on the file.
echo "Pubkey mismatched or missing rune; Rewriting the data."
[ "$EXISTING_RUNE" = "LIGHTNING_RUNE=\"null\"" ] ||
[ "$is_blacklisted" = "true" ]; then
# Pubkey mismatched, rune missing, or blacklisted; rewrite new data on the file.
echo "Pubkey mismatched, missing rune, or blacklisted rune; Rewriting the data."
cat /dev/null > "$COMMANDO_CONFIG"
echo "LIGHTNING_PUBKEY=\"$LIGHTNING_PUBKEY\"" >> "$COMMANDO_CONFIG"
generate_new_rune
else
echo "Pubkey matches with existing pubkey."
echo "Pubkey matches with existing pubkey and rune is valid."
fi

exec "$@"