Skip to content

Commit

Permalink
Updated pool.py
Browse files Browse the repository at this point in the history
QuixoteSystems committed Oct 12, 2022
1 parent 74e5352 commit f7d7750
Showing 6 changed files with 56 additions and 22 deletions.
Binary file modified koios_python/__pycache__/network.cpython-310.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/pool.cpython-310.pyc
Binary file not shown.
Binary file modified koios_python/__pycache__/urls.cpython-310.pyc
Binary file not shown.
72 changes: 51 additions & 21 deletions koios_python/pool.py
Original file line number Diff line number Diff line change
@@ -4,8 +4,9 @@
"""
import json
import requests
from .urls import POOL_BLOCKS_URL, POOL_DELEGATORS_URL, POOL_HISTORY_URL, POOL_INFO_URL, \
POOL_LIST_URL, POOL_METADATA_URL, POOL_RELAYS_URL, POOL_UPDATES_URL
from .urls import POOL_BLOCKS_URL, POOL_DELEGATORS_URL, POOL_STAKE_SNAPSHOT, POOL_HISTORY_URL, \
POOL_DELEGATORS_HISTORY_URL, POOL_INFO_URL, POOL_LIST_URL, POOL_METADATA_URL, POOL_RELAYS_URL, \
POOL_UPDATES_URL


def get_pool_list(content_range="0-999"):
@@ -22,49 +23,78 @@ def get_pool_list(content_range="0-999"):
return pool_list


def get_pool_info(pool_bech32):
def get_pool_info(*args):
"""
Get current pool status and details for a specified pool.
:param str pool_bech32: pool IDs in bech32 format (pool1...)
:param str args: pool IDs in bech32 format (pool1...)
:return: list of pool information.
:rtype: list.
"""
get_format = {"_pool_bech32_ids": [pool_bech32] }
get_format = {"_pool_bech32_ids": [args] }
pool_list = requests.post(POOL_INFO_URL, json = get_format, timeout=10)
pool_list = json.loads(pool_list.content)
return pool_list


def get_pool_delegators(pool_bech32, epoch_no="current"):
def get_pool_stake_snapshot(pool_bech32):
"""
Get information about delegators by a given pool and optional epoch (current if omitted).
Returns Mark, Set and Go stake snapshots for the selected pool, useful for leaderlog calculation
:param str pool_bech32: Pool IDs in bech32 format (pool1...)
:return: Array of pool stake information for 3 snapshots
:rtype: list.
"""

snapshot = requests.get(POOL_STAKE_SNAPSHOT + pool_bech32, timeout=10)
snapshot = json.loads(snapshot.content)
return snapshot


def get_pool_delegators(pool_bech32):
"""
Return information about live delegators for a given pool.
:param str pool_bech32: pool IDs in bech32 format (pool1...).
:param str epoch_no: epoch number to get info (current if omitted).
:return: list of pool delegators information.
:rtype: list.
"""
if epoch_no == "current":
info = requests.get(POOL_DELEGATORS_URL + pool_bech32, timeout=10)
info = requests.get(POOL_DELEGATORS_URL + pool_bech32, timeout=10)
info = json.loads(info.content)
return info


def get_pool_delegators_history(pool_bech32, epoch_no=None):
"""
Return information about active delegators (incl. history) for a given pool and epoch number \
(all epochs if not specified).
:param str pool_bech32: pool IDs in bech32 format (pool1...).
:param str epoch_no: epoch number to get info (current if omitted).
:return: list of pool delegators information.
:rtype: list.
"""
if epoch_no is None:
info = requests.get(POOL_DELEGATORS_HISTORY_URL + pool_bech32, timeout=10)
info = json.loads(info.content)
else:
info = requests.get(POOL_DELEGATORS_URL + pool_bech32 + "&_epoch_no=" + str(epoch_no), timeout=10)
info = requests.get(POOL_DELEGATORS_HISTORY_URL + pool_bech32 + "&_epoch_no=" + str(epoch_no), timeout=10)
info = json.loads(info.content)
return info


def get_pool_blocks(pool_bech32, epoch_no="beginning"):

def get_pool_blocks(pool_bech32, epoch_no=None):
"""
Get information about pool stake, block and reward history in a given epoch _epoch_no
(or all epochs that pool existed for, in descending order if no _epoch_no was provided)
Return information about blocks minted by a given pool for all epochs (or _epoch_no if provided)
:param str pool_bech32: pool IDs in bech32 format (pool1...).
:param str epoch_no: epoch number to get info (from the beginning if omitted).
:return: list of blocks created by pool.
:rtype: list.s
"""
if epoch_no == "beginning":
if epoch_no is None:
info = requests.get(POOL_BLOCKS_URL + pool_bech32, timeout=10)
info = json.loads(info.content)
else:
@@ -75,8 +105,8 @@ def get_pool_blocks(pool_bech32, epoch_no="beginning"):

def get_pool_history(pool_bech32, epoch_no="history"):
"""
Get information about all blocks minted by a given pool from the beginning (or specific epoch
if provided).
Return information about pool stake, block and reward history in a given epoch _epoch_no \
(or all epochs that pool existed for, in descending order if no _epoch_no was provided)
:param str pool_bech32: pool IDs in bech32 format (pool1...).
:param str epoch_no: epoch number to get info (from the beginning if omitted).
@@ -104,7 +134,7 @@ def get_pool_updates(pool_bech32=None):
pool_list = requests.get(POOL_UPDATES_URL, timeout=10)
pool_list = json.loads(pool_list.content)
else:
pool_list = requests.get(POOL_UPDATES_URL + pool_bech32, timeout=10)
pool_list = requests.get(POOL_UPDATES_URL + "?_pool_bech32=" + pool_bech32, timeout=10)
pool_list = json.loads(pool_list.content)
return pool_list

@@ -123,19 +153,19 @@ def get_pool_relays(content_range="0-999"):
return pool_list


def get_pool_metadata(pool_bech32=None):
def get_pool_metadata(*args):
"""
Get Metadata (on & off-chain) for all currently registered/retiring (not retired) pools.
:param str pool_bech32: pool IDs in bech32 format (pool1...).
:param str args: pool IDs in bech32 format (pool1...).
:return: list of pool metadata.
:rtype: list.
"""
if pool_bech32 is None:
if len(args) == 0:
pool_list = requests.post(POOL_METADATA_URL, timeout=10)
pool_list = json.loads(pool_list.content)
else:
get_format = {"_pool_bech32_ids": [pool_bech32]}
get_format = {"_pool_bech32_ids": [args]}
pool_list = requests.post(POOL_METADATA_URL, json = get_format, timeout=10)
pool_list = json.loads(pool_list.content)
return pool_list
2 changes: 2 additions & 0 deletions koios_python/urls.py
Original file line number Diff line number Diff line change
@@ -55,7 +55,9 @@
# Pool URLs
POOL_LIST_URL = KOIOS_URL + "pool_list"
POOL_INFO_URL = KOIOS_URL + "pool_info"
POOL_STAKE_SNAPSHOT = KOIOS_URL + "pool_stake_snapshot?_pool_bech32="
POOL_DELEGATORS_URL = KOIOS_URL + "pool_delegators?_pool_bech32="
POOL_DELEGATORS_HISTORY_URL = KOIOS_URL + "pool_delegators_history?_pool_bech32="
POOL_BLOCKS_URL = KOIOS_URL + "pool_blocks?_pool_bech32="
POOL_HISTORY_URL = KOIOS_URL + "pool_history?_pool_bech32="
POOL_UPDATES_URL = KOIOS_URL + "pool_updates"
4 changes: 3 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
@@ -71,4 +71,6 @@
# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy", 350))


pprint.pp(koios_python.get_totals())
pprint.pp(koios_python.get_pool_info("pool100wj94uzf54vup2hdzk0afng4dhjaqggt7j434mtgm8v2gfvfgp",
"pool102s2nqtea2hf5q0s4amj0evysmfnhrn4apyyhd4azcmsclzm96m",
"pool102vsulhfx8ua2j9fwl2u7gv57fhhutc3tp6juzaefgrn7ae35wm"))

0 comments on commit f7d7750

Please sign in to comment.