Skip to content

Commit

Permalink
feat: add dockerfile and script for keylist cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
DhananjayPurohit committed Apr 17, 2024
1 parent 732d98b commit 9bddce5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,34 @@ jobs:
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build and push
name: Build and push for mercury-server
uses: docker/build-push-action@v5
with:
context: .
file: ./server/Dockerfile
push: true
tags: commerceblockx/mercury-server:latest
-
name: Build and push
name: Build and push for token-server
uses: docker/build-push-action@v5
with:
context: .
file: ./token-server/Dockerfile
push: true
tags: commerceblockx/token-server:latest
-
name: Build and push
name: Build and push for mercury-explorer
uses: docker/build-push-action@v5
with:
context: .
file: ./explorer/Dockerfile
push: true
tags: commerceblockx/mercury-explorer:latest
-
name: Build and push for keylist-cronjob
uses: docker/build-push-action@v5
with:
context: .
file: ./keylistCron/Dockerfile
push: true
tags: commerceblockx/keylist-cronjob:latest
9 changes: 9 additions & 0 deletions keylistCron/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine:latest

WORKDIR /app

COPY ../keylistCron/send_commitment.sh .
COPY ../keylistCron/crontab.txt .

# CMD to run cron and keep container running
CMD ["sh", "-c", "crontab ./crontab.txt && tail -f /dev/null"]
1 change: 1 addition & 0 deletions keylistCron/crontab.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0 * * * /app/send_commitment.sh
39 changes: 39 additions & 0 deletions keylistCron/send_commitment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Fetch keylist JSON from the provided URL
KEYLIST_URL="https://api.mercurywallet.io/info/keylist"
KEYLIST_JSON=$(curl -sSL "$KEYLIST_URL")

# Check if the GET request was successful
if [[ $? -ne 0 ]]; then
echo "Error: Failed to retrieve keylist JSON from $KEYLIST_URL"
exit 1
fi

# Calculate SHA256 hash of the keylist JSON
KEYLIST_HASH=$(echo "$KEYLIST_JSON" | sha256sum | awk '{print $1}')

# Define mainstay slot URL
MAINSTAY_URL="https://testnet.mainstay.xyz/ctrl/sendcommitment"

# Attestation data
POSITION="3"
TOKEN="0972e199-6cf8-4164-8445-235528b6afa5"

# Construct the POST request body
PAYLOAD="{
\"position\": \"$POSITION\",
\"token\": \"$TOKEN\",
\"commitment\": \"$KEYLIST_HASH\"
}"

# Send POST request to mainstay slot
curl --header "Content-Type: application/json" --request POST --data "$PAYLOAD" "$MAINSTAY_URL"

# Check if the POST request was successful
if [[ $? -ne 0 ]]; then
echo "Error: Failed to send attestation data to $MAINSTAY_URL"
exit 1
fi

echo "Keylist $KEYLIST_HASH attestation completed successfully!"

0 comments on commit 9bddce5

Please sign in to comment.