Skip to content

Commit

Permalink
New indexer API helpers (#369)
Browse files Browse the repository at this point in the history
* dump teleports

* add script to dump drips
  • Loading branch information
brenzi authored Jun 22, 2024
1 parent 25fd802 commit 2208ffc
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
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}")

0 comments on commit 2208ffc

Please sign in to comment.