-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUniqueAddy.py
49 lines (36 loc) · 1.39 KB
/
UniqueAddy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import json
import requests
def get_stake_address(cardano_address):
api_key = "blockfrost_project_id"
base_url = "https://cardano-mainnet.blockfrost.io/api/v0"
address_endpoint = f"{base_url}/addresses/{cardano_address}"
headers = {
"project_id": api_key
}
try:
response = requests.get(address_endpoint, headers=headers)
response.raise_for_status()
data = json.loads(response.text)
stake_address = data["stake_address"]
return stake_address
except requests.exceptions.RequestException as e:
print("Error occurred:", e)
return None
with open('addresses.json', 'r') as f:
addresses = json.load(f)
stake_address_counts = {}
for address in addresses:
cardano_address = address['address']
stake_address = get_stake_address(cardano_address)
if stake_address:
if stake_address not in stake_address_counts:
stake_address_counts[stake_address] = {
"address": cardano_address,
"count": 1
}
else:
stake_address_counts[stake_address]["count"] += 1
unique_stake_addresses = list(stake_address_counts.values())
with open('uAddress.json', 'w') as f:
json.dump(unique_stake_addresses, f, indent=2)
print("JSON file with address, stake address, and count created successfully.")