Skip to content

Commit

Permalink
main
Browse files Browse the repository at this point in the history
  • Loading branch information
Quixote committed Dec 10, 2022
1 parent 50fdde0 commit 372f163
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14 deletions.
Binary file modified koios_python/__pycache__/account.cpython-310.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/asset.cpython-310.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/epoch.cpython-310.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/pool.cpython-310.pyc
Binary file not shown.
5 changes: 3 additions & 2 deletions koios_python/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import json
import requests

def get_account_list(self):
def get_account_list(self, content_range="0-999"):
"""
Get a list of all accounts.
:return: string list of account (stake address: stake1... bech32 format) IDs.
:rtype: list.
"""
address_list = requests.get(self.ACCOUNT_LIST_URL, timeout=20)
custom_headers = {"Range": str(content_range)}
address_list = requests.get(self.ACCOUNT_LIST_URL, headers = custom_headers, timeout=20)
address_list = json.loads(address_list.content)
return address_list

Expand Down
12 changes: 6 additions & 6 deletions koios_python/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
import json
import requests

def get_asset_list(self):
def get_asset_list(self, content_range="0-999"):
"""
Get the list of all native assets (paginated)
:return: list with all asset list.
:rtype: list.
"""

asset_list = requests.get(self.ASSET_LIST_URL, timeout=10)
custom_headers = {"Range": str(content_range)}
asset_list = requests.get(self.ASSET_LIST_URL, headers = custom_headers, timeout=10)
asset_list = json.loads(asset_list.content)
return asset_list


def get_asset_address_list(self, asset_policy, asset_name):
def get_asset_address_list(self, asset_policy, asset_name, content_range="0-999"):
"""
Get the list of all addresses holding a given asset.
Expand All @@ -27,8 +27,8 @@ def get_asset_address_list(self, asset_policy, asset_name):
:return: list of all addresses.
:rtype: list.
"""

info = requests.get(f"{self.ASSET_ADDRESS_LIST_URL}{asset_policy}&_asset_name={asset_name}", timeout=10)
custom_headers = {"Range": str(content_range)}
info = requests.get(f"{self.ASSET_ADDRESS_LIST_URL}{asset_policy}&_asset_name={asset_name}", headers = custom_headers, timeout=10)
info = json.loads(info.content)
return info

Expand Down
5 changes: 3 additions & 2 deletions koios_python/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_pool_stake_snapshot(self, pool_bech32):
return snapshot


def get_pool_delegators(self, pool_bech32):
def get_pool_delegators(self, pool_bech32, content_range="0-999"):
"""
Return information about live delegators for a given pool.
Expand All @@ -56,7 +56,8 @@ def get_pool_delegators(self, pool_bech32):
:return: list of pool delegators information.
:rtype: list.
"""
info = requests.get(self.POOL_DELEGATORS_URL + pool_bech32, timeout=10)
custom_headers = {"Range": str(content_range)}
info = requests.get(self.POOL_DELEGATORS_URL + pool_bech32, headers = custom_headers, timeout=10)
info = json.loads(info.content)
return info

Expand Down
18 changes: 14 additions & 4 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
# Example of yout Custom Endpoint
#kp = koios_python.URLs(url="https://koios-otg.tosidrop.io/api/v0/", network='mainnet') # We need to create an instance of the class URLs

# Get Native Script List, first 11 scripts
#print(kp.get_native_script_list('0-10'))
print(len(kp.get_native_script_list('0-10')))
#print(kp.get_account_list()) # We can use the methods of the class URLs
#print(len(kp.get_native_script_list('0-10')))

pprint.pp(kp.get_account_list("2000-2999")) # We can use the methods of the class URLs
# print(kp.url)

# kp_mainnet = koios_python.URLs()
Expand All @@ -57,8 +59,8 @@
# pprint.pp(kp.get_asset_txs("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b",63487))

# Get Datum information for given datum hashes of a Plutus Contracts
pprint.pp(kp.get_datum_info('818ee3db3bbbd04f9f2ce21778cac3ac605802a4fcb00c8b3a58ee2dafc17d46',
"45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0"))
#pprint.pp(kp.get_datum_info('818ee3db3bbbd04f9f2ce21778cac3ac605802a4fcb00c8b3a58ee2dafc17d46',
# "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0"))

# pprint.pp(kp_mainnet.get_pool_stake_snapshot("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc"))

Expand Down Expand Up @@ -108,6 +110,14 @@
# Get the Pool List from the record 2001 to 3000
#pprint.pp(koios_python.get_pool_list("2001-3000"))

# Get the Asset List from the record 2001 to 3000
#pprint.pp(kp.get_asset_list("2001-3000"))

# Get Delegator List from a Pool
#pprint.pp(kp.get_pool_delegators("pool1x5dfpgp987e4jhxvgczr3wv50nv2pwd873tlx3uthvcasm422q6", "1000-2000"))

#pprint.pp(kp.get_asset_address_list("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b", "10-20"))

# Get all the information for a specified Stake Pool
#pprint.pp(koios_python.get_pool_info("pool100wj94uzf54vup2hdzk0afng4dhjaqggt7j434mtgm8v2gfvfgp"))

Expand Down

0 comments on commit 372f163

Please sign in to comment.