diff --git a/.github/workflows/edges.yml b/.github/workflows/edges.yml new file mode 100644 index 0000000..d564a63 --- /dev/null +++ b/.github/workflows/edges.yml @@ -0,0 +1,42 @@ +name: Edges + +on: + workflow_dispatch: + schedule: + - cron: '7 */5 * * *' + +jobs: + updateEdges: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Build + run: cargo build --verbose --release + - name: Download safes + run: ./download_safes.py + - name: Convert to binary + run: | + cargo run --release --bin convert -- --safes-json safes.json --edges-bin edges.dat + mv edges.dat /tmp/ + - name: Push to gh-pages + env: + DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} + run: | + git config --local user.email "chris@ethereum.org" + git config --local user.name "chriseth_automation" + git remote set-url origin "$(git config --get remote.origin.url | sed 's#http.*com/#git@github.com:#g')" + eval `ssh-agent -t 60 -s` + ssh-add - <<< "${{ secrets.DEPLOY_KEY }}" + mkdir -p ~/.ssh/ + ssh-keyscan github.com >> ~/.ssh/known_hosts + + git fetch + git checkout -B gh-pages origin/main + git clean -f -d + mv /tmp/edges.dat ./ + git add edges.dat + git commit -m "Add edges." + + git push -f origin gh-pages + ssh-agent -k \ No newline at end of file diff --git a/download_safes.py b/download_safes.py new file mode 100755 index 0000000..3862838 --- /dev/null +++ b/download_safes.py @@ -0,0 +1,43 @@ +#!/usr/bin/python3 + +import sys +import requests +import json + +blockNumber =requests.get('https://blockscout.com/poa/xdai/api?module=block&action=eth_block_number').json()['result'] + +query="""{ + id + organization + outgoing { limit limitPercentage canSendToAddress userAddress } + incoming { limit limitPercentage canSendToAddress userAddress } + balances { amount token { id owner { id } } } +}""".replace('\n', ' ') + +#API='https://graph.circles.garden/subgraphs/name/CirclesUBI/circles-subgraph' +API='https://api.thegraph.com/subgraphs/name/circlesubi/circles' + + +lastID = 0 +count = 1000 +safes = [] +success = False +for totalTries in range(500): + print("ID: %s" % lastID) + result = requests.post(API, data='{"query":"{ safes( orderBy: id, first: %d, where: { id_gt: \\"%s\\" } ) %s }"}' % (count, lastID, query)).json() + if 'errors' in result: + continue + if 'data' not in result or 'safes' not in result['data'] or len(result['data']['safes']) == 0: + print("Last response:") + print(result) + success = True + break + print("Got %d safes..." % len(result['data']['safes'])) + safes += result['data']['safes'] + lastID = result['data']['safes'][-1]['id'] +if not success: + print("Too many failures or requests.") + sys.exit(1) + + +json.dump({'blockNumber': blockNumber, 'safes': safes}, open('safes.json', 'w'))