From 9bddce55ca69ee853e31addf3cc122f748d9a1f0 Mon Sep 17 00:00:00 2001 From: DhananjayPurohit Date: Wed, 17 Apr 2024 21:53:02 +0530 Subject: [PATCH] feat: add dockerfile and script for keylist cronjob --- .github/workflows/ci.yaml | 14 +++++++++--- keylistCron/Dockerfile | 9 ++++++++ keylistCron/crontab.txt | 1 + keylistCron/send_commitment.sh | 39 ++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 keylistCron/Dockerfile create mode 100644 keylistCron/crontab.txt create mode 100644 keylistCron/send_commitment.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 93727452..b7e30758 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,7 +25,7 @@ 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: . @@ -33,7 +33,7 @@ jobs: 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: . @@ -41,10 +41,18 @@ jobs: 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 diff --git a/keylistCron/Dockerfile b/keylistCron/Dockerfile new file mode 100644 index 00000000..32ecfed4 --- /dev/null +++ b/keylistCron/Dockerfile @@ -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"] diff --git a/keylistCron/crontab.txt b/keylistCron/crontab.txt new file mode 100644 index 00000000..ccff9d6e --- /dev/null +++ b/keylistCron/crontab.txt @@ -0,0 +1 @@ +0 0 * * * /app/send_commitment.sh diff --git a/keylistCron/send_commitment.sh b/keylistCron/send_commitment.sh new file mode 100644 index 00000000..ceb899ae --- /dev/null +++ b/keylistCron/send_commitment.sh @@ -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!"