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

New indexer API helpers #369

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
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
40 changes: 40 additions & 0 deletions client/dump_drips.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import requests
import pandas as pd

# Define the URL and the data for the POST request
url = "https://api.encointer.org/v1/indexer2/query"
data = {
"collection": "extrinsics",
"query": {
"section": "encointerFaucet",
"method": "drip",
"success": True,
},
"options": {
"limit": 999,
"skip": 0,
"sort": {
"blockNumber": -1
}
}
}

# Send the POST request
response = requests.post(url, json=data)

# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response into a pandas DataFrame
json_response = response.json()
data = []
for item in json_response:
signer = item['signer']['Id']
extrinsic_id = item['_id']
block_hash = item['blockHash']
faucet = item['args']['faucet_account']
cid = item['args']['cid']
cindex = item['args']['cindex']
print(f"{extrinsic_id}, {block_hash}, {signer}, {faucet}, {cid}, {cindex}")
# Print the DataFrame
else:
print(f"Request failed with status code {response.status_code}")
51 changes: 51 additions & 0 deletions client/dump_teleports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import requests
import pandas as pd

# Define the URL and the data for the POST request
url = "https://api.encointer.org/v1/indexer2/query"
data = {
"collection": "extrinsics",
"query": {
"section": "polkadotXcm",
"method": "limitedTeleportAssets"
},
"options": {
"limit": 100,
"skip": 0,
"sort": {
"blockNumber": -1
}
}
}

# Send the POST request
response = requests.post(url, json=data)

# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response into a pandas DataFrame
json_response = response.json()
data = []
for item in json_response:
signer = item['signer']['Id']
extrinsic_id = item['_id']
block_hash = item['blockHash']
beneficiary = ''
if 'V1' in item['args']['beneficiary']:
beneficiary = item['args']['beneficiary']['V1']['interior']['X1']['AccountId32']['id']
elif 'V3' in item['args']['beneficiary']:
beneficiary = item['args']['beneficiary']['V3']['interior']['X1']['AccountId32']['id']
elif 'V4' in item['args']['beneficiary']:
beneficiary = item['args']['beneficiary']['V4']['interior']['X1'][0]['AccountId32']['id']

amount = 0
if 'V1' in item['args']['assets']:
amount = int(item['args']['assets']['V1'][0]['fun']['Fungible'].replace(',', ''))
elif 'V3' in item['args']['beneficiary']:
amount = int(item['args']['assets']['V3'][0]['fun']['Fungible'].replace(',', ''))
elif 'V4' in item['args']['beneficiary']:
amount = int(item['args']['assets']['V4'][0]['fun']['Fungible'].replace(',', ''))
print(f"{extrinsic_id}, {block_hash}, {signer}, {beneficiary}, {amount}")
# Print the DataFrame
else:
print(f"Request failed with status code {response.status_code}")
Loading