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

Push data to Iroh #54

Closed
wants to merge 1 commit into from
Closed
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
67 changes: 67 additions & 0 deletions .github/workflows/upload_folder_to_iroh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash
set -e

if [ -z "$IROH_DOT_NETWORK_API_KEY" ]; then
echo "IROH_DOT_NETWORK_API_KEY is not set. Exiting."
exit 1
fi

# Project and Document ID
PROJECT="davidgasquez/gitcoin-grants-data-portal"
DOC_ID="m55mn6ej57fblwhtdawdlrukob6f3pmhjsge5h2n6bqsym3miaqq"

# Install sendme
curl -fsSL https://iroh.computer/sendme.sh | sh
mv sendme ~/.local/bin

# Directory containing the files
DIRECTORY="data/tables"

# Loop through each file in the directory
for FILE in "$DIRECTORY"/*; do
echo "Processing $FILE..."

# Add files, get ticket, and save process id
nohup sendme send "$FILE" > ticket 2>&1 &
echo $! > save_pid.txt

# need to sleep long enough for the ticket to be generated
# (bad! this won't be an issue when working with iroh as a library)
sleep 5

# extract hash & size from sendme output
HASH=$(grep "hash" ticket | awk '{print $7}')
echo "Hash: ${HASH}"

# get file size
SIZE=$(wc -c < "$FILE")

# extract ticket from sendme output
TICKET=$(grep "sendme receive" ticket | awk '{print $3}')
echo "Ticket: ${TICKET}"

# intiate sendme transfer to iroh.network iroh node
echo "Uploading $FILE to iroh.network..."
curl "https://api.iroh.network/blobs/$PROJECT" \
-X POST \
-H "Authorization: Bearer ${IROH_DOT_NETWORK_API_KEY}" \
-H "Content-Type: application/json" \
-d "{\"ticket\": \"${TICKET}\", \"tag\": \"latest\"}"

# tell iroh.network to update the document entry
echo "Updating document entry for $FILE..."
curl "https://api.iroh.network/docs/$PROJECT/${DOC_ID}/set-hash" \
-X POST \
-H "Authorization: Bearer ${IROH_DOT_NETWORK_API_KEY}" \
-H "Content-Type: application/json" \
-d "{ \"key\": \"data\", \"hash\": \"${HASH}\", \"size\": ${SIZE} }"

# cleanup
kill -9 "$(cat save_pid.txt)"
rm save_pid.txt
rm ticket

echo "Processed $FILE"
done

echo "All files processed"