Action to update edge database.
This commit is contained in:
parent
a28e24e48c
commit
4aace2a6a0
2 changed files with 85 additions and 0 deletions
42
.github/workflows/edges.yml
vendored
Normal file
42
.github/workflows/edges.yml
vendored
Normal file
|
@ -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
|
43
download_safes.py
Executable file
43
download_safes.py
Executable file
|
@ -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'))
|
Loading…
Reference in a new issue