Provision account #3627
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Provision account | |
on: | |
schedule: | |
- cron: "17,47 * * * *" | |
workflow_dispatch: | |
inputs: | |
empty: | |
description: "Empty" | |
required: true | |
default: "10" | |
jobs: | |
provision-account: | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- id: 0 | |
timeout-minutes: 30 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check how many accounts are provisioned | |
id: check_count # Create an ID for the step so we can refer to its output | |
run: | | |
COUNT=$(curl -sSL -H "Authorization: Bearer ${{ secrets.PRIVATE_KEY_SERVER_KEY }}" https://polygongas.org/keys/count/unused_accounts) | |
echo "Provisioned accounts count: $COUNT" | |
if [ "$COUNT" -gt 400 ]; then | |
echo "Too many accounts provisioned ($COUNT). Skipping remaining steps." | |
echo "should_continue=false" >> $GITHUB_ENV | |
else | |
echo "should_continue=true" >> $GITHUB_ENV | |
fi | |
- name: Prepare funding | |
if: env.should_continue == 'true' | |
run: | | |
wget https://github.com/golemfactory/erc20_payment_lib/releases/download/pre-rel-v0.4.8-nightly/erc20_processor-linux-x86_64.tar.xz | |
tar -xf erc20_processor-linux-x86_64.tar.xz | |
sudo cp erc20_processor /usr/bin/erc20_processor | |
erc20_processor --version | |
- name: Give back up to 10 ethereum from used accounts | |
continue-on-error: true | |
run: | | |
set -x | |
for i in {1..10}; do | |
mkdir -p back_$i && cd back_$i | |
curl -sSL -H "Authorization: Bearer ${{ secrets.PRIVATE_KEY_SERVER_KEY }}" https://polygongas.org/keys/get/used_accounts > used_private_key.key | |
echo "Used keys left $(curl -sSL -H "Authorization: Bearer ${{ secrets.PRIVATE_KEY_SERVER_KEY }}" https://polygongas.org/keys/count/unused_accounts)" | |
# Check if the downloaded key is a valid private key | |
grep -qE '^[a-fA-F0-9]{64}$' used_private_key.key || { echo "Error: File contents do not match expected format: $(cat downloaded_private_key_1.key)"; exit 1; } | |
echo "ETH_PRIVATE_KEYS=$(cat used_private_key.key)" >> .env | |
erc20_processor transfer --recipient 0x5b984629E2Cc7570cBa7dD745b83c3dD23Ba6d0f --token eth --all | |
erc20_processor run | |
cd .. | |
done | |
- name: Provision 10 ethereum accounts | |
if: env.should_continue == 'true' | |
run: | | |
for i in {1..10}; do | |
mkdir -p funding_$i && cd funding_$i | |
erc20_processor generate-key -n 1 > .env | |
erc20_processor get-dev-eth | |
erc20_processor mint-test-tokens | |
erc20_processor run | |
erc20_processor transfer --recipient 0x5b984629E2Cc7570cBa7dD745b83c3dD23Ba6d0f --token glm --amount 900 | |
erc20_processor run | |
erc20_processor balance | |
# Extract the private key | |
ETH_PRIVATE_KEY=$(cat .env | grep ETH_PRIVATE_KEY_0 | sed "s/#\s//g" | sed "s/ETH_PRIVATE_KEY_0:\s//g") | |
# Upload the account to the server | |
curl -sSL -X POST -H "Authorization: Bearer ${{ secrets.PRIVATE_KEY_SERVER_KEY }}" -d $ETH_PRIVATE_KEY https://polygongas.org/keys/add/unused_accounts | |
cd .. | |
done | |