Last active
October 2, 2021 23:16
-
-
Save davaymne/f33e1098f400f8e9dc6eefa5de9e0750 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
# apt-get -y install python3-pip | |
# pip3 install base58 | |
import base58 | |
import argparse | |
import sys | |
import requests | |
import json | |
import os | |
from string import Template | |
import argparse | |
start_block = 11446768 | |
end_block = 13307648 | |
step = 6646 | |
local_index_node_endpoint = 'http://index-node-0:8030/graphql' | |
ethereum = 'https://eth-mainnet.alchemyapi.io/v2/demo' | |
subgraph_ipfs_hash = 'Qmf5XXWA8zhHbdvWqtPcR3jFkmb5FLR4MAefEYx8E3pHfr' | |
indexer_id = '0x0000000000000000000000000000000000000000' | |
#start_block_hash = get_start_block_hash(start_block) | |
#my_poi = generate_poi(i["indexer_id"], start_block, start_block_hash, subgraph_ipfs_hash) | |
def generate_poi(indexer_id, block_number, block_hash, subgraph_ipfs_hash): | |
t = Template("""query MyQuery { | |
proofOfIndexing( | |
subgraph: "$subgraph_ipfs_hash", | |
blockNumber: $block_number, | |
blockHash: "$block_hash", | |
indexer: "$indexer_id") | |
}""") | |
query_data = t.substitute(subgraph_ipfs_hash=subgraph_ipfs_hash, | |
block_number=block_number, | |
block_hash=block_hash, | |
indexer_id=indexer_id) | |
request = requests.post(local_index_node_endpoint, json={'query': query_data}) | |
if request.status_code != 200: | |
print("error in generate_poi") | |
print(request.text) | |
os._exit(1) | |
json_response = json.loads(request.text) | |
if "errors" in json_response: | |
print("error in generate_poi") | |
print(json_response["errors"]) | |
os._exit(1) | |
return json_response["data"]["proofOfIndexing"] | |
def get_start_block_hash(block): | |
payload = { | |
"method": "eth_getBlockByNumber", | |
"params": ['{}'.format(hex(block)), False], | |
"jsonrpc": "2.0", | |
"id": 1, | |
} | |
response = requests.post(ethereum, json=payload).json() | |
if "error" in response: | |
print("error in get_start_block_hash") | |
print(response["error"]) | |
os._exit(1) | |
return response["result"]["hash"] | |
for block in range(start_block, end_block, step): | |
block_hash = get_start_block_hash(block) | |
print('Block: ', block, 'Hash: ', block_hash, 'POI: ', generate_poi(indexer_id, block, block_hash, subgraph_ipfs_hash)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment