diff --git a/.gitignore b/.gitignore
index ab096e8..f6656bd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
test_koios_nets.py
+test_koios.py
build
dist
koios_python.egg-info
.DS_Store
+.env
\ No newline at end of file
diff --git a/__pycache__/test_koios.cpython-310-pytest-7.2.0.pyc b/__pycache__/test_koios.cpython-310-pytest-7.2.0.pyc
index 7fb14f2..8adebc6 100644
Binary files a/__pycache__/test_koios.cpython-310-pytest-7.2.0.pyc and b/__pycache__/test_koios.cpython-310-pytest-7.2.0.pyc differ
diff --git a/__pycache__/test_koios.cpython-311-pytest-7.2.2.pyc b/__pycache__/test_koios.cpython-311-pytest-7.2.2.pyc
new file mode 100644
index 0000000..5f6790d
Binary files /dev/null and b/__pycache__/test_koios.cpython-311-pytest-7.2.2.pyc differ
diff --git a/koios_python.egg-info/PKG-INFO b/koios_python.egg-info/PKG-INFO
deleted file mode 100644
index 8486b2f..0000000
--- a/koios_python.egg-info/PKG-INFO
+++ /dev/null
@@ -1,133 +0,0 @@
-Metadata-Version: 2.1
-Name: koios-python
-Version: 1.3.1
-Summary: Python wrapper Library using Koios API for accessing information stored on the Cardano Blockchain
-Home-page: https://github.com/QuixoteSystems
-Author: Quixote Stake Pool
-Author-email: quixotepool@proton.me
-License: MIT
-Keywords: koios,blockchain,cardano,API,REST,RESTful
-Classifier: Development Status :: 4 - Beta
-Classifier: Intended Audience :: Developers
-Classifier: Topic :: Software Development :: Build Tools
-Classifier: License :: OSI Approved :: MIT License
-Classifier: Programming Language :: Python :: 3.8
-Classifier: Programming Language :: Python :: 3.9
-Classifier: Programming Language :: Python :: 3.10
-Classifier: Programming Language :: Python :: 3.11
-Classifier: Programming Language :: Python :: 3 :: Only
-Description-Content-Type: text/markdown
-License-File: LICENSE.md
-
-![koios-python](https://user-images.githubusercontent.com/82296005/194378368-6d2de904-8eec-48bf-a0d9-37118f299470.png)
-
-# Koios Python ![PyPI - Python Version](https://img.shields.io/badge/python-%3E%3D3.8-blue) [![PyPI - Python Version](https://img.shields.io/badge/pypi%20package-v1.3.0-green)](https://pypi.org/project/koios-python/)
-
-## Overview
-**Koios Python** is Python wrapper which allow interacting with all information and parameters stored on the Cardano blockchain using [Koios REST API](https://api.koios.rest/)
-
-
-## What is Koios Python?
-**Koios Python** is a library based on [Koios](https://www.koios.rest/) Elastic Query Layer for [Cardano Node](https://github.com/input-output-hk/cardano-node/) by [Cardano Community Guild Operators](https://github.com/cardano-community).
-**Koios** is best described as a Decentralized and Elastic RESTful query layer for exploring data on Cardano blockchain to consume within applications/wallets/explorers/etc.
-**Koios** is really useful for developers because resource and maintenance requirements for Cardano blockchain components (e.g. cardano-node, cardano-db-sync) are ever-growing. It also simplifies how to query complex information from the blockchain. - -This library allows getting data from the Cardano Blockchain using a simple syntaxis in your Python code. All the querys follow Koios API REST operations. - -Required Python Modules --------------- -* https://pypi.python.org/pypi/requests - -## Installation [![PyPI Latest Release](https://img.shields.io/pypi/v/koios-python.svg)](https://pypi.org/project/koios-python/) -```python -pip install koios_python -``` - -## Upgrade to the last Version -```python -pip install --upgrade koios_python -``` - -## Usage -Import to your python file this library: - -```python -import koios_python -``` - -You can read all info about how works this library in our [Wiki](https://github.com/cardano-community/koios-python/wiki) - -## TODO - -- [ ] Adding Pagination for all queries where makes sense (At the moment, there are a bunch with this feature) -- [x] Managing errors - - [x] Inside functions - - [ ] Pagination - - [x] User Inputs - - [x] Timeouts -- [ ] Adding Vertical Filtering -- [ ] Adding Async methods - - - - - -## Features -- Supported REST Services: - - [x] Network - - Chain Tip - - Genesis Info - - Historical Tokenomic Statistics - - [x] Epoch - - Epoch Information - - Epoch's Protocol Parameters - - Epoch Blocks Protocol - - [x] Block - - Block List - - Block Information - - Block Transactions - - [x] Transactions - - Transaction Information - - Transaction UTxOs - - Transaction Metadata - - Transaction Metadata Labels - - Transaction Submission - - Transaction Status (Block Confirmations) - - [x] Address - - Address Information - - Address Transactions - - Transactions from Payment Credentials - - Address Assets - - [x] Account - - Account List - - Account Information - - Account Information Cached - - Account Rewards - - Account Updates (History) - - Account Addresses - - Account Assets - - Account History - - [x] Asset - - Asset List - - Asset Address List - - Asset Information - - Asset History - - Asset Policy Information - - Asset Summary - - Asset Transaction History - - [x] Pool - - Pool List - - Pool Information - - Stake Snapshot - - Pool Delegators List - - Pool Blocks - - Pool Stake, Block and Reward History - - Pool Updates (History) - - Pool Relays - - Pool Metadata - - [x] Script - - Native Script List - - Plutus Script List - - Script Redeemers - - Datum Information - diff --git a/koios_python.egg-info/SOURCES.txt b/koios_python.egg-info/SOURCES.txt deleted file mode 100644 index 67f7d1f..0000000 --- a/koios_python.egg-info/SOURCES.txt +++ /dev/null @@ -1,19 +0,0 @@ -LICENSE.md -README.md -setup.py -koios_python/__init__.py -koios_python/account.py -koios_python/address.py -koios_python/asset.py -koios_python/block.py -koios_python/environment.py -koios_python/epoch.py -koios_python/network.py -koios_python/pool.py -koios_python/scripts.py -koios_python/transactions.py -koios_python/urls.py -koios_python.egg-info/PKG-INFO -koios_python.egg-info/SOURCES.txt -koios_python.egg-info/dependency_links.txt -koios_python.egg-info/top_level.txt \ No newline at end of file diff --git a/koios_python.egg-info/dependency_links.txt b/koios_python.egg-info/dependency_links.txt deleted file mode 100644 index 8b13789..0000000 --- a/koios_python.egg-info/dependency_links.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/koios_python.egg-info/top_level.txt b/koios_python.egg-info/top_level.txt deleted file mode 100644 index 5073aeb..0000000 --- a/koios_python.egg-info/top_level.txt +++ /dev/null @@ -1 +0,0 @@ -koios_python diff --git a/koios_python/__pycache__/__init__.cpython-310.pyc b/koios_python/__pycache__/__init__.cpython-310.pyc index ec8b0a4..21a5741 100644 Binary files a/koios_python/__pycache__/__init__.cpython-310.pyc and b/koios_python/__pycache__/__init__.cpython-310.pyc differ diff --git a/koios_python/__pycache__/__init__.cpython-311.pyc b/koios_python/__pycache__/__init__.cpython-311.pyc index 9318bd1..409b12d 100644 Binary files a/koios_python/__pycache__/__init__.cpython-311.pyc and b/koios_python/__pycache__/__init__.cpython-311.pyc differ diff --git a/koios_python/__pycache__/__init__.cpython-312.pyc b/koios_python/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..8d91bf2 Binary files /dev/null and b/koios_python/__pycache__/__init__.cpython-312.pyc differ diff --git a/koios_python/__pycache__/account.cpython-310.pyc b/koios_python/__pycache__/account.cpython-310.pyc index cb6cec7..3ba8ebc 100644 Binary files a/koios_python/__pycache__/account.cpython-310.pyc and b/koios_python/__pycache__/account.cpython-310.pyc differ diff --git a/koios_python/__pycache__/account.cpython-311.pyc b/koios_python/__pycache__/account.cpython-311.pyc index cb2a565..92f9a68 100644 Binary files a/koios_python/__pycache__/account.cpython-311.pyc and b/koios_python/__pycache__/account.cpython-311.pyc differ diff --git a/koios_python/__pycache__/account.cpython-312.pyc b/koios_python/__pycache__/account.cpython-312.pyc new file mode 100644 index 0000000..e59b42d Binary files /dev/null and b/koios_python/__pycache__/account.cpython-312.pyc differ diff --git a/koios_python/__pycache__/address.cpython-310.pyc b/koios_python/__pycache__/address.cpython-310.pyc index 2f53a8c..47cb90e 100644 Binary files a/koios_python/__pycache__/address.cpython-310.pyc and b/koios_python/__pycache__/address.cpython-310.pyc differ diff --git a/koios_python/__pycache__/address.cpython-311.pyc b/koios_python/__pycache__/address.cpython-311.pyc index 1a7b2f5..df656e7 100644 Binary files a/koios_python/__pycache__/address.cpython-311.pyc and b/koios_python/__pycache__/address.cpython-311.pyc differ diff --git a/koios_python/__pycache__/address.cpython-312.pyc b/koios_python/__pycache__/address.cpython-312.pyc new file mode 100644 index 0000000..9f4c73e Binary files /dev/null and b/koios_python/__pycache__/address.cpython-312.pyc differ diff --git a/koios_python/__pycache__/asset.cpython-310.pyc b/koios_python/__pycache__/asset.cpython-310.pyc index 759de78..f4a2248 100644 Binary files a/koios_python/__pycache__/asset.cpython-310.pyc and b/koios_python/__pycache__/asset.cpython-310.pyc differ diff --git a/koios_python/__pycache__/asset.cpython-311.pyc b/koios_python/__pycache__/asset.cpython-311.pyc index 553fa01..809d4bf 100644 Binary files a/koios_python/__pycache__/asset.cpython-311.pyc and b/koios_python/__pycache__/asset.cpython-311.pyc differ diff --git a/koios_python/__pycache__/asset.cpython-312.pyc b/koios_python/__pycache__/asset.cpython-312.pyc new file mode 100644 index 0000000..a05cf4f Binary files /dev/null and b/koios_python/__pycache__/asset.cpython-312.pyc differ diff --git a/koios_python/__pycache__/block.cpython-310.pyc b/koios_python/__pycache__/block.cpython-310.pyc index aa273e7..6a4df30 100644 Binary files a/koios_python/__pycache__/block.cpython-310.pyc and b/koios_python/__pycache__/block.cpython-310.pyc differ diff --git a/koios_python/__pycache__/block.cpython-311.pyc b/koios_python/__pycache__/block.cpython-311.pyc index 9be73ab..c069f96 100644 Binary files a/koios_python/__pycache__/block.cpython-311.pyc and b/koios_python/__pycache__/block.cpython-311.pyc differ diff --git a/koios_python/__pycache__/block.cpython-312.pyc b/koios_python/__pycache__/block.cpython-312.pyc new file mode 100644 index 0000000..3b8d828 Binary files /dev/null and b/koios_python/__pycache__/block.cpython-312.pyc differ diff --git a/koios_python/__pycache__/environment.cpython-310.pyc b/koios_python/__pycache__/environment.cpython-310.pyc index c0758c2..140c7ac 100644 Binary files a/koios_python/__pycache__/environment.cpython-310.pyc and b/koios_python/__pycache__/environment.cpython-310.pyc differ diff --git a/koios_python/__pycache__/environment.cpython-311.pyc b/koios_python/__pycache__/environment.cpython-311.pyc index af4a4bd..cfe00d3 100644 Binary files a/koios_python/__pycache__/environment.cpython-311.pyc and b/koios_python/__pycache__/environment.cpython-311.pyc differ diff --git a/koios_python/__pycache__/environment.cpython-312.pyc b/koios_python/__pycache__/environment.cpython-312.pyc new file mode 100644 index 0000000..ccdb5e8 Binary files /dev/null and b/koios_python/__pycache__/environment.cpython-312.pyc differ diff --git a/koios_python/__pycache__/epoch.cpython-310.pyc b/koios_python/__pycache__/epoch.cpython-310.pyc index 8a9d12e..7ce880c 100644 Binary files a/koios_python/__pycache__/epoch.cpython-310.pyc and b/koios_python/__pycache__/epoch.cpython-310.pyc differ diff --git a/koios_python/__pycache__/epoch.cpython-311.pyc b/koios_python/__pycache__/epoch.cpython-311.pyc index 622cacd..30a4145 100644 Binary files a/koios_python/__pycache__/epoch.cpython-311.pyc and b/koios_python/__pycache__/epoch.cpython-311.pyc differ diff --git a/koios_python/__pycache__/epoch.cpython-312.pyc b/koios_python/__pycache__/epoch.cpython-312.pyc new file mode 100644 index 0000000..bf3ad7e Binary files /dev/null and b/koios_python/__pycache__/epoch.cpython-312.pyc differ diff --git a/koios_python/__pycache__/network.cpython-310.pyc b/koios_python/__pycache__/network.cpython-310.pyc index 8b692ff..33251ab 100644 Binary files a/koios_python/__pycache__/network.cpython-310.pyc and b/koios_python/__pycache__/network.cpython-310.pyc differ diff --git a/koios_python/__pycache__/network.cpython-311.pyc b/koios_python/__pycache__/network.cpython-311.pyc index fe6b7c6..af827f7 100644 Binary files a/koios_python/__pycache__/network.cpython-311.pyc and b/koios_python/__pycache__/network.cpython-311.pyc differ diff --git a/koios_python/__pycache__/network.cpython-312.pyc b/koios_python/__pycache__/network.cpython-312.pyc new file mode 100644 index 0000000..82c041e Binary files /dev/null and b/koios_python/__pycache__/network.cpython-312.pyc differ diff --git a/koios_python/__pycache__/ogmios.cpython-310.pyc b/koios_python/__pycache__/ogmios.cpython-310.pyc new file mode 100644 index 0000000..3e8fa27 Binary files /dev/null and b/koios_python/__pycache__/ogmios.cpython-310.pyc differ diff --git a/koios_python/__pycache__/ogmios.cpython-311.pyc b/koios_python/__pycache__/ogmios.cpython-311.pyc new file mode 100644 index 0000000..4e5c628 Binary files /dev/null and b/koios_python/__pycache__/ogmios.cpython-311.pyc differ diff --git a/koios_python/__pycache__/ogmios.cpython-312.pyc b/koios_python/__pycache__/ogmios.cpython-312.pyc new file mode 100644 index 0000000..340c4b2 Binary files /dev/null and b/koios_python/__pycache__/ogmios.cpython-312.pyc differ diff --git a/koios_python/__pycache__/pool.cpython-310.pyc b/koios_python/__pycache__/pool.cpython-310.pyc index eaa14bf..941799e 100644 Binary files a/koios_python/__pycache__/pool.cpython-310.pyc and b/koios_python/__pycache__/pool.cpython-310.pyc differ diff --git a/koios_python/__pycache__/pool.cpython-311.pyc b/koios_python/__pycache__/pool.cpython-311.pyc index df08067..c96a0cc 100644 Binary files a/koios_python/__pycache__/pool.cpython-311.pyc and b/koios_python/__pycache__/pool.cpython-311.pyc differ diff --git a/koios_python/__pycache__/pool.cpython-312.pyc b/koios_python/__pycache__/pool.cpython-312.pyc new file mode 100644 index 0000000..82ec477 Binary files /dev/null and b/koios_python/__pycache__/pool.cpython-312.pyc differ diff --git a/koios_python/__pycache__/scripts.cpython-310.pyc b/koios_python/__pycache__/scripts.cpython-310.pyc index 43f22d8..abb3b29 100644 Binary files a/koios_python/__pycache__/scripts.cpython-310.pyc and b/koios_python/__pycache__/scripts.cpython-310.pyc differ diff --git a/koios_python/__pycache__/scripts.cpython-311.pyc b/koios_python/__pycache__/scripts.cpython-311.pyc index 757e053..0e3353d 100644 Binary files a/koios_python/__pycache__/scripts.cpython-311.pyc and b/koios_python/__pycache__/scripts.cpython-311.pyc differ diff --git a/koios_python/__pycache__/scripts.cpython-312.pyc b/koios_python/__pycache__/scripts.cpython-312.pyc new file mode 100644 index 0000000..620f26a Binary files /dev/null and b/koios_python/__pycache__/scripts.cpython-312.pyc differ diff --git a/koios_python/__pycache__/transactions.cpython-310.pyc b/koios_python/__pycache__/transactions.cpython-310.pyc index 2fd9e15..2542cfb 100644 Binary files a/koios_python/__pycache__/transactions.cpython-310.pyc and b/koios_python/__pycache__/transactions.cpython-310.pyc differ diff --git a/koios_python/__pycache__/transactions.cpython-311.pyc b/koios_python/__pycache__/transactions.cpython-311.pyc index 253d287..5888d7c 100644 Binary files a/koios_python/__pycache__/transactions.cpython-311.pyc and b/koios_python/__pycache__/transactions.cpython-311.pyc differ diff --git a/koios_python/__pycache__/transactions.cpython-312.pyc b/koios_python/__pycache__/transactions.cpython-312.pyc new file mode 100644 index 0000000..006a574 Binary files /dev/null and b/koios_python/__pycache__/transactions.cpython-312.pyc differ diff --git a/koios_python/__pycache__/urls.cpython-310.pyc b/koios_python/__pycache__/urls.cpython-310.pyc index 4b04e05..336ecfd 100644 Binary files a/koios_python/__pycache__/urls.cpython-310.pyc and b/koios_python/__pycache__/urls.cpython-310.pyc differ diff --git a/koios_python/__pycache__/urls.cpython-311.pyc b/koios_python/__pycache__/urls.cpython-311.pyc index 670c40e..0d64766 100644 Binary files a/koios_python/__pycache__/urls.cpython-311.pyc and b/koios_python/__pycache__/urls.cpython-311.pyc differ diff --git a/koios_python/__pycache__/urls.cpython-312.pyc b/koios_python/__pycache__/urls.cpython-312.pyc new file mode 100644 index 0000000..9f6f1fc Binary files /dev/null and b/koios_python/__pycache__/urls.cpython-312.pyc differ diff --git a/koios_python/account.py b/koios_python/account.py index f524e86..b2757e7 100644 --- a/koios_python/account.py +++ b/koios_python/account.py @@ -17,9 +17,16 @@ def get_account_list(self, content_range="0-999"): :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - account_list = requests.get(self.ACCOUNT_LIST_URL, headers = custom_headers, timeout=timeout) - account_list = json.loads(account_list.content) + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + account_list = requests.get(self.ACCOUNT_LIST_URL, headers = custom_headers, timeout=timeout) + account_list = json.loads(account_list.content) + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + account_list = requests.get(self.ACCOUNT_LIST_URL, headers = custom_headers, timeout=timeout) + account_list = json.loads(account_list.content) + return account_list @@ -33,14 +40,46 @@ def get_account_info(self, *args): :rtype: list. """ timeout = get_timeout() - get_format = {"_stake_addresses": [args] } - accounts_info = requests.post(self.ACCOUNT_INFO_URL, json= get_format, timeout=timeout ) - accounts_info = json.loads(accounts_info.content) + + if self.BEARER is None: + get_format = {"_stake_addresses": [args] } + accounts_info = requests.post(self.ACCOUNT_INFO_URL, json= get_format, timeout=timeout ) + accounts_info = json.loads(accounts_info.content) + else: + get_format = {"_stake_addresses": [args] } + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + accounts_info = requests.post(self.ACCOUNT_INFO_URL, json= get_format, headers = custom_headers, timeout=timeout ) + accounts_info = json.loads(accounts_info.content) + + return accounts_info + + +@Exception_Handler +def get_account_info_cached(self, *args): + """ + Get the account information for given stake addresses (accounts). + + :param str args: staking address/es in bech32 format (stake1...). + :return: list with all address data. + :rtype: list. + """ + timeout = get_timeout() + + if self.BEARER is None: + get_format = {"_stake_addresses": [args] } + accounts_info = requests.post(self.ACCOUNT_INFO_CACHED_URL, json=get_format, timeout=timeout) + accounts_info = json.loads(accounts_info.content) + else: + get_format = {"_stake_addresses": [args] } + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + accounts_info = requests.post(self.ACCOUNT_INFO_CACHED_URL, json=get_format, headers = custom_headers, timeout=timeout) + accounts_info = json.loads(accounts_info.content) + return accounts_info @Exception_Handler -def get_account_utxos(self, stake): +def get_account_utxos(self, *args, content_range="0-999", extended=False): """ Get a list of all UTxOs for a given stake address (account) @@ -48,29 +87,74 @@ def get_account_utxos(self, stake): :rtype: list. """ timeout = get_timeout() - account_utxos = requests.get(f"{self.ACCOUNT_UTXOS_URL}{stake}", timeout=timeout) - account_utxos = json.loads(account_utxos.content) + + if self.BEARER is None and extended is False: + custom_headers = {"Range": str(content_range)} + get_format = {"_stake_addresses": [args], "_extended": "false"} + account_utxos = requests.post(f"{self.ACCOUNT_UTXOS_URL}", timeout=timeout, json=get_format, headers=custom_headers) + account_utxos = json.loads(account_utxos.content) + + if self.BEARER is None and extended is True: + custom_headers = {"Range": str(content_range)} + get_format = {"_stake_addresses": [args], "_extended": "true"} + account_utxos = requests.post(f"{self.ACCOUNT_UTXOS_URL}", timeout=timeout, json=get_format, headers=custom_headers) + account_utxos = json.loads(account_utxos.content) + + if self.BEARER is not None and extended is False: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}" } + get_format = {"_stake_addresses": [args], "_extended": "false"} + account_utxos = requests.post(f"{self.ACCOUNT_UTXOS_URL}", headers = custom_headers, timeout=timeout, json=get_format) + account_utxos = json.loads(account_utxos.content) + + if self.BEARER is not None and extended is True: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}" } + get_format = {"_stake_addresses": [args], "_extended": "true"} + account_utxos = requests.post(f"{self.ACCOUNT_UTXOS_URL}", headers = custom_headers, timeout=timeout, json=get_format) + account_utxos = json.loads(account_utxos.content) + return account_utxos @Exception_Handler -def get_account_info_cached(self, *args): +def get_account_txs(self, stake_address, after_block=None): """ - Get the account information for given stake addresses (accounts). + Get the transaction hash list of input payment credential array (stake key), optionally + filtering after specified block height (inclusive). - :param str args: staking address/es in bech32 format (stake1...). - :return: list with all address data. + :param str stake_address: str stake address (stake1...) + :param int after_block: filtering after block (inclusive) defaul is None, from the beginning + :return: list of address transactions. :rtype: list. """ timeout = get_timeout() - get_format = {"_stake_addresses": [args] } - accounts_info = requests.post(self.ACCOUNT_INFO_CACHED_URL, json=get_format, timeout=timeout) - accounts_info = json.loads(accounts_info.content) - return accounts_info + + if self.BEARER is None and after_block is None: + get_format = {"_stake_address": stake_address} + txs_list = requests.post(self.ACCOUNT_TX_URL, json = get_format, timeout=timeout) + txs_list = json.loads(txs_list.content) + + if self.BEARER is None and after_block is not None: + get_format = {"_stake_address": stake_address, "_after_block_height": after_block} + txs_list = requests.post(self.ACCOUNT_TXS_URL, json = get_format, timeout=timeout) + txs_list = json.loads(txs_list.content) + + if self.BEARER is not None and after_block is None: + get_format = {"_stake_address": stake_address} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + txs_list = requests.post(self.ACCOUNT_TX_URL, json = get_format, headers = custom_headers, timeout=timeout) + txs_list = json.loads(txs_list.content) + + if self.BEARER is not None and after_block is not None: + get_format = {"_stake_address": stake_address, "_after_block_height": after_block} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + txs_list = requests.post(self.ACCOUNT_TXS_URL, json = get_format, headers = custom_headers, timeout=timeout) + txs_list = json.loads(txs_list.content) + + return txs_list @Exception_Handler -def get_account_rewards(self, *args): +def get_account_rewards(self, *args, epoch_no=None): """ Get the full rewards history (including MIR) for given stake addresses (accounts). @@ -80,15 +164,29 @@ def get_account_rewards(self, *args): :rtype: list. """ timeout = get_timeout() - epoch = args[len(args)-1] - if not isinstance(epoch, int): + + if self.BEARER is None and epoch_no is None: get_format = {"_stake_addresses": [args] } rewards = requests.post(self.ACCOUNT_REWARDS_URL, json= get_format, timeout=timeout) rewards = json.loads(rewards.content) - else: - get_format = {"_stake_addresses": [args], "_epoch_no": epoch} + + if self.BEARER is None and epoch_no is not None: + get_format = {"_stake_addresses": [args], "_epoch_no": str(epoch_no)} rewards = requests.post(self.ACCOUNT_REWARDS_URL, json= get_format, timeout=timeout) rewards = json.loads(rewards.content) + + if self.BEARER is not None and epoch_no is None: + get_format = {"_stake_addresses": [args] } + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + rewards = requests.post(self.ACCOUNT_REWARDS_URL, json= get_format, headers = custom_headers, timeout=timeout) + rewards = json.loads(rewards.content) + + if self.BEARER is not None and epoch_no is not None: + get_format = {"_stake_addresses": [args], "_epoch_no": str(epoch_no)} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + rewards = requests.post(self.ACCOUNT_REWARDS_URL, json= get_format, headers = custom_headers, timeout=timeout) + rewards = json.loads(rewards.content) + return rewards @@ -103,14 +201,22 @@ def get_account_updates(self, *args): :rtype: list. """ timeout = get_timeout() - get_format = {"_stake_addresses": [args]} - updates = requests.post(self.ACCOUNT_UPDATES_URL, json= get_format, timeout=timeout) - updates = json.loads(updates.content) + + if self.BEARER is None: + get_format = {"_stake_addresses": [args]} + updates = requests.post(self.ACCOUNT_UPDATES_URL, json= get_format, timeout=timeout) + updates = json.loads(updates.content) + else: + get_format = {"_stake_addresses": [args]} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + updates = requests.post(self.ACCOUNT_UPDATES_URL, json= get_format, headers = custom_headers, timeout=timeout) + updates = json.loads(updates.content) + return updates @Exception_Handler -def get_account_addresses(self, *args): +def get_account_addresses(self, *args, content_range="0-999", first_only=False, empty=False): """ Get all addresses associated with given staking accounts. :param str args: staking address/es in bech32 format (stake1...) @@ -118,9 +224,55 @@ def get_account_addresses(self, *args): :rtype: list. """ timeout = get_timeout() - get_format = {"_stake_addresses": [args]} - addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, timeout=timeout) - addresses = json.loads(addresses.content) + + if self.BEARER is None and first_only is False and empty is False: + custom_headers = {"Range": str(content_range)} + get_format = {"_stake_addresses": [args], "_first_only": "false", "_empty": "false"} + addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, timeout=timeout, headers=custom_headers) + addresses = json.loads(addresses.content) + + if self.BEARER is None and first_only is True and empty is False: + custom_headers = {"Range": str(content_range)} + get_format = {"_stake_addresses": [args], "_first_only": "true", "_empty": "false"} + addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, timeout=timeout, headers=custom_headers) + addresses = json.loads(addresses.content) + + if self.BEARER is None and first_only is False and empty is True: + custom_headers = {"Range": str(content_range)} + get_format = {"_stake_addresses": [args], "_first_only": "false", "_empty": "true"} + addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, timeout=timeout, headers=custom_headers) + addresses = json.loads(addresses.content) + + if self.BEARER is None and first_only is True and empty is True: + custom_headers = {"Range": str(content_range)} + get_format = {"_stake_addresses": [args], "_first_only": "true", "_empty": "true"} + addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, timeout=timeout, headers=custom_headers) + addresses = json.loads(addresses.content) + + if self.BEARER is not None and first_only is False and empty is False: + get_format = {"_stake_addresses": [args], "_first_only": "false", "_empty": "false"} + custom_headers = {"Range": str(content_range) ,"Authorization": f"Bearer {self.BEARER}"} + addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, headers = custom_headers, timeout=timeout) + addresses = json.loads(addresses.content) + + if self.BEARER is not None and first_only is True and empty is False: + get_format = {"_stake_addresses": [args], "_first_only": "true", "_empty": "false"} + custom_headers = {"Range": str(content_range) ,"Authorization": f"Bearer {self.BEARER}"} + addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, headers = custom_headers, timeout=timeout) + addresses = json.loads(addresses.content) + + if self.BEARER is not None and first_only is False and empty is True: + get_format = {"_stake_addresses": [args], "_first_only": "false", "_empty": "true"} + custom_headers = {"Range": str(content_range) ,"Authorization": f"Bearer {self.BEARER}"} + addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, headers = custom_headers, timeout=timeout) + addresses = json.loads(addresses.content) + + if self.BEARER is not None and first_only is True and empty is True: + get_format = {"_stake_addresses": [args], "_first_only": "true", "_empty": "true"} + custom_headers = {"Range": str(content_range) ,"Authorization": f"Bearer {self.BEARER}"} + addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, headers = custom_headers, timeout=timeout) + addresses = json.loads(addresses.content) + return addresses @@ -133,9 +285,17 @@ def get_account_assets(self, *args): :rtype: list. """ timeout = get_timeout() - get_format = {"_stake_addresses": [args]} - assets = requests.post(self.ACCOUNT_ASSETS_URL, json= get_format, timeout=timeout) - assets = json.loads(assets.content) + + if self.BEARER is None: + get_format = {"_stake_addresses": [args]} + assets = requests.post(self.ACCOUNT_ASSETS_URL, json= get_format, timeout=timeout) + assets = json.loads(assets.content) + else: + get_format = {"_stake_addresses": [args]} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + assets = requests.post(self.ACCOUNT_ASSETS_URL, json= get_format, headers = custom_headers, timeout=timeout) + assets = json.loads(assets.content) + return assets @@ -185,8 +345,9 @@ def get_account_assets_paginated(self, *args): return total_assets + @Exception_Handler -def get_account_history(self, *args): +def get_account_history(self, *args, epoch_no=None, content_range="0-999"): """ Get the staking history of given stake addresses (accounts). :param str address: staking address in bech32 format (stake1...) @@ -194,13 +355,30 @@ def get_account_history(self, *args): :rtype: list. """ timeout = get_timeout() - epoch = args[len(args)-1] - if not isinstance(epoch, int): + + if self.BEARER is None and epoch_no is None: get_format = {"_stake_addresses": [args] } - history = requests.post(self.ACCOUNT_HISTORY_URL, json= get_format, timeout=timeout) + custom_headers = {"Range": str(content_range)} + history = requests.post(self.ACCOUNT_HISTORY_URL, json= get_format, timeout=timeout, headers=custom_headers) history = json.loads(history.content) - else: - get_format = {"_stake_addresses": [args], "_epoch_no": epoch} - history = requests.post(self.ACCOUNT_HISTORY_URL, json= get_format, timeout=timeout) + + if self.BEARER is None and epoch_no is not None: + get_format = {"_stake_addresses": [args], "_epoch_no": str(epoch_no)} + custom_headers = {"Range": str(content_range)} + history = requests.post(self.ACCOUNT_HISTORY_URL, json= get_format, timeout=timeout, headers=custom_headers) + history = json.loads(history.content) + + if self.BEARER is not None and epoch_no is None: + get_format = {"_stake_addresses": [args] } + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + history = requests.post(self.ACCOUNT_HISTORY_URL, json= get_format, headers = custom_headers, timeout=timeout) + history = json.loads(history.content) + + if self.BEARER is not None and epoch_no is not None: + get_format = {"_stake_addresses": [args], "_epoch_no": str(epoch_no)} + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + history = requests.post(self.ACCOUNT_HISTORY_URL, json= get_format, headers = custom_headers, timeout=timeout) history = json.loads(history.content) - return history \ No newline at end of file + + return history + diff --git a/koios_python/address.py b/koios_python/address.py index 81fd9e9..f9a20a2 100644 --- a/koios_python/address.py +++ b/koios_python/address.py @@ -17,32 +17,68 @@ def get_address_info(self, *args): :rtype: list. """ timeout = get_timeout() - get_format = {"_addresses": [args] } - addresses = requests.post(self.ADDRESS_INFO_URL, json= get_format, timeout=timeout) - addresses = json.loads(addresses.content) + + if self.BEARER is None: + get_format = {"_addresses": [args] } + addresses = requests.post(self.ADDRESS_INFO_URL, json= get_format, timeout=timeout) + addresses = json.loads(addresses.content) + else: + get_format = {"_addresses": [args] } + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + addresses = requests.post(self.ADDRESS_INFO_URL, json= get_format, timeout=timeout, headers=custom_headers) + addresses = json.loads(addresses.content) return addresses @Exception_Handler -def get_address_txs(self, *address_tx, after_block=0): +def get_address_utxos(self, *addresses, extended=False, content_range="0-999"): """ - Get the transaction hash list of input address array, optionally filtering after specified - block height (inclusive) + Get the UTxO set for a given address. - :param tx_hash: list or single transaction hash to search and read utxos data - :param after_block: filtering after block (inclusive) defaul is 0, from the beginning - :return: hash list of address transactions + :param list address: Array of Cardano payment address(es) + :param bool extended: extended flag to toggle additional fields (optional, default is False) + return: list of utxos + :rtype: list. """ - timeout = get_timeout() - get_format = {"_addresses": [address_tx], "_after_block_height": str(after_block)} - hash_list = requests.post(self.ADDRESS_TXS_URL, json = get_format, timeout=timeout) - hash_list = json.loads(hash_list.content) - return hash_list + if self.BEARER is None and extended is True: + extended = "true" + timeout = get_timeout() + custom_headers = {"Range": str(content_range)} + get_format = {"_addresses": [addresses], "_extended": extended} + utxos = requests.post(self.ADDRESS_UTXOS_URL, json = get_format, headers=custom_headers, timeout=timeout) + utxos = json.loads(utxos.content) + + if self.BEARER is None and extended is False: + extended = "false" + timeout = get_timeout() + custom_headers = {"Range": str(content_range)} + get_format = {"_addresses": [addresses], "_extended": extended} + utxos = requests.post(self.ADDRESS_UTXOS_URL, json = get_format, headers=custom_headers, timeout=timeout) + utxos = json.loads(utxos.content) + + if self.BEARER is not None and extended is True: + extended = "true" + timeout = get_timeout() + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + get_format = {"_addresses": [addresses], "_extended": extended} + utxos = requests.post(self.ADDRESS_UTXOS_URL, json = get_format, headers=custom_headers, timeout=timeout) + utxos = json.loads(utxos.content) + + if self.BEARER is not None and extended is False: + extended = "false" + timeout = get_timeout() + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + get_format = {"_addresses": [addresses], "_extended": extended} + utxos = requests.post(self.ADDRESS_UTXOS_URL, json = get_format, headers=custom_headers, timeout=timeout) + utxos = json.loads(utxos.content) + + return utxos + @Exception_Handler -def get_credential_utxos(self, *payment_credentials, content_range="0-5"): +def get_credential_utxos(self, *payment_credentials, extended=False, content_range="0-999"): """ Get a list of UTxO against input payment credential array including their balances. @@ -51,33 +87,66 @@ def get_credential_utxos(self, *payment_credentials, content_range="0-5"): :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - get_format = {"_payment_credentials":[payment_credentials]} - utxos = requests.post(self.ADDRESS_CREDENTIAL_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) - utxos = json.loads(utxos.content) + + if self.BEARER is None and extended is True: + extended = "true" + custom_headers = {"Range": str(content_range)} + get_format = {"_payment_credentials":[payment_credentials], "_extended": extended} + utxos = requests.post(self.ADDRESS_CREDENTIAL_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) + utxos = json.loads(utxos.content) + + if self.BEARER is not None and extended is True: + extended = "true" + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + get_format = {"_payment_credentials":[payment_credentials], "_extended": extended} + utxos = requests.post(self.ADDRESS_CREDENTIAL_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) + utxos = json.loads(utxos.content) + + if self.BEARER is None and extended is False: + extended = "false" + custom_headers = {"Range": str(content_range)} + get_format = {"_payment_credentials":[payment_credentials], "_extended": extended} + utxos = requests.post(self.ADDRESS_CREDENTIAL_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) + utxos = json.loads(utxos.content) + + if self.BEARER is not None and extended is False: + extended = "false" + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + get_format = {"_payment_credentials":[payment_credentials], "_extended": extended} + utxos = requests.post(self.ADDRESS_CREDENTIAL_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) + utxos = json.loads(utxos.content) return utxos @Exception_Handler -def get_address_assets(self, *args): +def get_address_txs(self, *address_tx, after_block=0): """ - Get the list of all the assets (policy, name and quantity) for a given address. + Get the transaction hash list of input address array, optionally filtering after specified + block height (inclusive) - :param str address: wallet used public address - return: list of all the assets - :rtype: list. + :param tx_hash: list or single transaction hash to search and read utxos data + :param after_block: filtering after block (inclusive) defaul is 0, from the beginning + :return: hash list of address transactions """ timeout = get_timeout() - get_format = {"_addresses": [args] } - addresses = requests.post(self.ADDRESS_ASSETS_URL, json= get_format, timeout=timeout) - addresses = json.loads(addresses.content) - return addresses + if self.BEARER is None: + get_format = {"_addresses": [address_tx], "_after_block_height": str(after_block)} + hash_list = requests.post(self.ADDRESS_TXS_URL, json = get_format, timeout=timeout) + hash_list = json.loads(hash_list.content) + + if self.BEARER is not None: + get_format = {"_addresses": [address_tx], "_after_block_height": str(after_block)} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + hash_list = requests.post(self.ADDRESS_TXS_URL, json = get_format, headers=custom_headers, timeout=timeout) + hash_list = json.loads(hash_list.content) + + return hash_list @Exception_Handler -def get_credential_txs(self, *payment_credentials, after_block_height=0, content_range="0-15"): +def get_credential_txs(self, *payment_credentials, after_block_height=0, content_range="0-999"): """ Get the transaction hash list of input payment credential array (stake key), optionally filtering after specified block height (inclusive). @@ -88,9 +157,42 @@ def get_credential_txs(self, *payment_credentials, after_block_height=0, content :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - get_format = {"_payment_credentials": [payment_credentials], "_after_block_height": after_block_height} - txs_list = requests.post(self.ADDRESS_CREDENTIAL_TXS_URL, json = get_format, headers=custom_headers, timeout=timeout) - txs_list = json.loads(txs_list.content) - return txs_list \ No newline at end of file + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + get_format = {"_payment_credentials": [payment_credentials], "_after_block_height": str(after_block_height)} + txs_list = requests.post(self.ADDRESS_CREDENTIAL_TXS_URL, json = get_format, headers = custom_headers, timeout=timeout) + txs_list = json.loads(txs_list.content) + + if self.BEARER is not None: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + get_format = {"_payment_credentials": [payment_credentials], "_after_block_height": str(after_block_height)} + txs_list = requests.post(self.ADDRESS_CREDENTIAL_TXS_URL, json = get_format, headers = custom_headers, timeout=timeout) + txs_list = json.loads(txs_list.content) + + return txs_list + + +@Exception_Handler +def get_address_assets(self, *args): + """ + Get the list of all the assets (policy, name and quantity) for a given address. + + :param str address: wallet used public address + return: list of all the assets + :rtype: list. + """ + timeout = get_timeout() + + if self.BEARER is None: + get_format = {"_addresses": [args]} + assets = requests.post(self.ADDRESS_ASSETS_URL, json = get_format, timeout=timeout) + assets = json.loads(assets.content) + + if self.BEARER is not None: + get_format = {"_addresses": [args]} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + assets = requests.post(self.ADDRESS_ASSETS_URL, json = get_format, headers=custom_headers, timeout=timeout) + assets = json.loads(assets.content) + + return assets \ No newline at end of file diff --git a/koios_python/asset.py b/koios_python/asset.py index 4bfed59..82a5745 100644 --- a/koios_python/asset.py +++ b/koios_python/asset.py @@ -17,67 +17,70 @@ def get_asset_list(self, content_range="0-999"): :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - custom_params = {"order": "asset_name.asc"} - asset_list = requests.get(self.ASSET_LIST_URL, headers = custom_headers, params = custom_params, timeout=timeout) - asset_list = json.loads(asset_list.content) + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + custom_params = {"order": "asset_name.asc"} + asset_list = requests.get(self.ASSET_LIST_URL, headers = custom_headers, params = custom_params, timeout=timeout) + asset_list = json.loads(asset_list.content) + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + custom_params = {"order": "asset_name.asc"} + asset_list = requests.get(self.ASSET_LIST_URL, headers = custom_headers, params = custom_params, timeout=timeout) + asset_list = json.loads(asset_list.content) + return asset_list @Exception_Handler -def get_asset_token_registry(self, content_range="0-999"): - """ - Get a list of assets registered via token registry on Github - - :return: list of all asset token registry. - :param str content_range: number of selected elements to return - :rtype: list. - """ - timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - token_registry = requests.get(self.ASSET_TOKEN_REGISTRY_URL, headers = custom_headers, timeout=timeout) - token_registry = json.loads(token_registry.content) - - return token_registry - - -@Exception_Handler -def get_asset_addresses(self, asset_policy, asset_name, content_range="0-999"): +def get_policy_asset_list(self, asset_policy, content_range="0-999"): """ - Get the list of all addresses holding a given asset. + Get the list of asset under the given policy (including balances) :param str asset_policy: asset Policy ID in hexadecimal format (hex). - :param str asset_name: string with Asset Name in hexadecimal format (hex). :param str content_range: number of selected elements to return - :return: list of all addresses. + :return: list of all assets under the same policy. :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - custom_params = {"order": "payment_address.asc"} - info = requests.get(f"{self.ASSET_ADDRESSES_URL}{asset_policy}&_asset_name={asset_name}", \ - headers = custom_headers, params = custom_params, timeout=timeout) - info = json.loads(info.content) + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + custom_params = {"order": "asset_name.asc"} + info = requests.get(f"{self.POLICY_ASSET_LIST_URL}{asset_policy}", + headers = custom_headers, params = custom_params, timeout = timeout) + info = json.loads(info.content) + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + custom_params = {"order": "asset_name.asc"} + info = requests.get(f"{self.POLICY_ASSET_LIST_URL}{asset_policy}", + headers = custom_headers, params = custom_params, timeout = timeout) + info = json.loads(info.content) + return info @Exception_Handler -def get_asset_nft_address(self, asset_policy, asset_name): +def get_asset_token_registry(self, content_range="0-999"): """ - Get the address where specified NFT currently reside on. + Get a list of assets registered via token registry on Github - :param str asset_policy: asset Policy ID in hexadecimal format (hex). - :param str asset_name: string with Asset Name in hexadecimal format (hex). - :return: list with payment addresses. - :rtype: list. + :return: list of all asset token registry. + :param str content_range: number of selected elements to return + :rtype: list. """ timeout = get_timeout() - info = requests.get(f"{self.ASSET_NFT_ADDRESS_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout) - info = json.loads(info.content) - return info + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + token_registry = requests.get(self.ASSET_TOKEN_REGISTRY_URL, headers = custom_headers, timeout=timeout) + token_registry = json.loads(token_registry.content) + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + token_registry = requests.get(self.ASSET_TOKEN_REGISTRY_URL, headers = custom_headers, timeout=timeout) + token_registry = json.loads(token_registry.content) + + return token_registry @Exception_Handler @@ -91,8 +94,15 @@ def get_asset_info(self, asset_policy, asset_name): :rtype: list. """ timeout = get_timeout() - info = requests.get(f"{self.ASSET_INFO_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout) - info = json.loads(info.content) + + if self.BEARER is None: + info = requests.get(f"{self.ASSET_INFO_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout) + info = json.loads(info.content) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(f"{self.ASSET_INFO_URL}{asset_policy}&_asset_name={asset_name}", \ + headers = custom_headers, timeout=timeout) + info = json.loads(info.content) return info @@ -106,15 +116,67 @@ def get_asset_info_bulk(self, *asset_list): :rtype: list. """ timeout = get_timeout() - get_format = {"_asset_list": asset_list} - asset_info = requests.post(self.ASSET_INFO_BULK_URL, json= get_format, timeout=timeout) - asset_info = json.loads(asset_info.content) + + if self.BEARER is None: + get_format = {"_asset_list": asset_list} + asset_info = requests.post(self.ASSET_INFO_BULK_URL, json= get_format, timeout=timeout) + asset_info = json.loads(asset_info.content) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + get_format = {"_asset_list": asset_list} + asset_info = requests.post(self.ASSET_INFO_BULK_URL, json= get_format, headers=custom_headers, timeout=timeout) + asset_info = json.loads(asset_info.content) return asset_info @Exception_Handler -def get_asset_history(self, asset_policy, asset_name): +def get_asset_utxos(self, *asset_list, extended=False, content_range="0-999"): + """ + Get the UTXO information of a list of assets including + + :param list of assets + :param bool extended: extended UTXO information + :return: list of utxos + :rtype: list. + """ + if self.BEARER is None and extended is True: + extended = "true" + timeout = get_timeout() + custom_headers = {"Range": str(content_range),} + get_format = {"_asset_list": asset_list, "_extended": extended} + utxos = requests.post(self.ASSET_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) + utxos = json.loads(utxos.content) + + if self.BEARER is None and extended is False: + extended = "false" + timeout = get_timeout() + custom_headers = {"Range": str(content_range),} + get_format = {"_asset_list": asset_list, "_extended": extended} + utxos = requests.post(self.ASSET_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) + utxos = json.loads(utxos.content) + + if self.BEARER is not None and extended is True: + extended = "true" + timeout = get_timeout() + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + get_format = {"_asset_list": asset_list, "_extended": extended} + utxos = requests.post(self.ASSET_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) + utxos = json.loads(utxos.content) + + if self.BEARER is not None and extended is False: + extended = "false" + timeout = get_timeout() + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + get_format = {"_asset_list": asset_list, "_extended": extended} + utxos = requests.post(self.ASSET_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) + utxos = json.loads(utxos.content) + + return utxos + + +@Exception_Handler +def get_asset_history(self, asset_policy, asset_name, content_range="0-999"): """ Get the mint/burn history of an asset. @@ -124,64 +186,121 @@ def get_asset_history(self, asset_policy, asset_name): :rtype: list. """ timeout = get_timeout() - history = requests.get(f"{self.ASSET_HISTORY_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout) - history = json.loads(history.content) + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + history = requests.get(f"{self.ASSET_HISTORY_URL}{asset_policy}&_asset_name={asset_name}", + headers=custom_headers, timeout=timeout) + history = json.loads(history.content) + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + history = requests.get(f"{self.ASSET_HISTORY_URL}{asset_policy}&_asset_name={asset_name}", + headers=custom_headers, timeout=timeout) + history = json.loads(history.content) return history @Exception_Handler -def get_policy_asset_addresses(self, asset_policy, content_range="0-500"): +def get_asset_addresses(self, asset_policy, asset_name, content_range="0-999"): """ - Get the list of addresses with quantity for each asset on the given policy + Get the list of all addresses holding a given asset. :param str asset_policy: asset Policy ID in hexadecimal format (hex). + :param str asset_name: string with Asset Name in hexadecimal format (hex). :param str content_range: number of selected elements to return :return: list of all addresses. :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - custom_params = {"order": "asset_name.asc"} - info = requests.get(f"{self.POLICY_ASSET_ADDRESSES_LIST_URL}{asset_policy}", - headers = custom_headers, params = custom_params, timeout = timeout) - info = json.loads(info.content) + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + custom_params = {"order": "payment_address.asc"} + info = requests.get(f"{self.ASSET_ADDRESSES_URL}{asset_policy}&_asset_name={asset_name}", \ + headers = custom_headers, params = custom_params, timeout=timeout) + info = json.loads(info.content) + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + custom_params = {"order": "payment_address.asc"} + info = requests.get(f"{self.ASSET_ADDRESSES_URL}{asset_policy}&_asset_name={asset_name}", \ + headers = custom_headers, params = custom_params, timeout=timeout) + info = json.loads(info.content) return info @Exception_Handler -def get_policy_asset_info(self, asset_policy): +def get_asset_nft_address(self, asset_policy, asset_name): """ - Get the information for all assets under the same policy. + Get the address where specified NFT currently reside on. :param str asset_policy: asset Policy ID in hexadecimal format (hex). - :return: list of all mint/burn transactions for an asset + :param str asset_name: string with Asset Name in hexadecimal format (hex). + :return: list with payment addresses. :rtype: list. """ timeout = get_timeout() - info = requests.get(f"{self.POLICY_ASSET_INFO_URL}{asset_policy}", timeout=timeout) - info = json.loads(info.content) + + if self.BEARER is None: + info = requests.get(f"{self.ASSET_NFT_ADDRESS_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout) + info = json.loads(info.content) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(f"{self.ASSET_NFT_ADDRESS_URL}{asset_policy}&_asset_name={asset_name}", \ + headers = custom_headers, timeout=timeout) + info = json.loads(info.content) return info @Exception_Handler -def get_policy_asset_list(self, asset_policy, content_range="0-999"): +def get_policy_asset_addresses(self, asset_policy, content_range="0-999"): """ - Get the list of asset under the given policy (including balances) + Get the list of addresses with quantity for each asset on the given policy :param str asset_policy: asset Policy ID in hexadecimal format (hex). :param str content_range: number of selected elements to return - :return: list of all assets under the same policy. + :return: list of all addresses. :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - custom_params = {"order": "asset_name.asc"} - info = requests.get(f"{self.POLICY_ASSET_LIST_URL}{asset_policy}", - headers = custom_headers, params = custom_params, timeout = timeout) - info = json.loads(info.content) + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + custom_params = {"order": "asset_name.asc"} + info = requests.get(f"{self.POLICY_ASSET_ADDRESSES_LIST_URL}{asset_policy}", + headers = custom_headers, params = custom_params, timeout = timeout) + info = json.loads(info.content) + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + custom_params = {"order": "asset_name.asc"} + info = requests.get(f"{self.POLICY_ASSET_ADDRESSES_LIST_URL}{asset_policy}", + headers = custom_headers, params = custom_params, timeout = timeout) + info = json.loads(info.content) + + return info + + +@Exception_Handler +def get_policy_asset_info(self, asset_policy): + """ + Get the information for all assets under the same policy. + + :param str asset_policy: asset Policy ID in hexadecimal format (hex). + :return: list of all mint/burn transactions for an asset + :rtype: list. + """ + timeout = get_timeout() + + if self.BEARER is None: + info = requests.get(f"{self.POLICY_ASSET_INFO_URL}{asset_policy}", timeout=timeout) + info = json.loads(info.content) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(f"{self.POLICY_ASSET_INFO_URL}{asset_policy}", \ + headers = custom_headers, timeout=timeout) + info = json.loads(info.content) return info @@ -198,14 +317,21 @@ def get_asset_summary(self, asset_policy, asset_name): :rtype: list. """ timeout = get_timeout() - summary = requests.get(f"{self.ASSET_SUMMARY_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout) - summary = json.loads(summary.content) + + if self.BEARER is None: + summary = requests.get(f"{self.ASSET_SUMMARY_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout) + summary = json.loads(summary.content) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + summary = requests.get(f"{self.ASSET_SUMMARY_URL}{asset_policy}&_asset_name={asset_name}", \ + headers = custom_headers, timeout=timeout) + summary = json.loads(summary.content) return summary @Exception_Handler -def get_asset_txs(self, asset_policy, asset_name, after_block_height=0, history=False, content_range="0-999"): +def get_asset_txs(self, asset_policy, asset_name, after_block=0, history=False, content_range="0-999"): """ Get the list of current or all asset transaction hashes (newest first) @@ -218,19 +344,37 @@ def get_asset_txs(self, asset_policy, asset_name, after_block_height=0, history= :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - if history is True: + if self.BEARER is None and history is True: history = "true" + custom_headers = {"Range": str(content_range)} txs = requests.get(f"{self.ASSET_TXS_URL}{asset_policy}&_asset_name={asset_name} \ - &_after_block_height={after_block_height}&_history={history}", + &_after_block_height={after_block}&_history={history}", headers=custom_headers, timeout=timeout) txs = json.loads(txs.content) - if history is False: + + if self.BEARER is None and history is False: history = "false" + custom_headers = {"Range": str(content_range)} txs = requests.get(f"{self.ASSET_TXS_URL}{asset_policy}&_asset_name={asset_name} \ - &_after_block_height={after_block_height}&_history={history}", + &_after_block_height={after_block}&_history={history}", headers=custom_headers, timeout=timeout) txs = json.loads(txs.content) + if self.BEARER is not None and history is True: + history = "true" + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + txs = requests.get(f"{self.ASSET_TXS_URL}{asset_policy}&_asset_name={asset_name} \ + &_after_block_height={after_block}&_history={history}", + headers=custom_headers, timeout=timeout) + txs = json.loads(txs.content) + + if self.BEARER is not None and history is False: + history = "false" + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + txs = requests.get(f"{self.ASSET_TXS_URL}{asset_policy}&_asset_name={asset_name} \ + &_after_block_height={after_block}&_history={history}", + headers=custom_headers, timeout=timeout) + txs = json.loads(txs.content) + return txs diff --git a/koios_python/block.py b/koios_python/block.py index 9e5a42a..2dacf86 100644 --- a/koios_python/block.py +++ b/koios_python/block.py @@ -17,9 +17,16 @@ def get_blocks(self,content_range="0-999"): :rtype: list """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - blocks = requests.get(self.BLOCKS_URL, headers = custom_headers, timeout=timeout) - blocks = json.loads(blocks.content) + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + blocks = requests.get(self.BLOCKS_URL, headers = custom_headers, timeout=timeout) + blocks = json.loads(blocks.content) + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + blocks = requests.get(self.BLOCKS_URL, headers = custom_headers, timeout=timeout) + blocks = json.loads(blocks.content) + return blocks @@ -33,9 +40,17 @@ def get_block_info(self,*block_hash): :rtype: list """ timeout = get_timeout() - get_format = {"_block_hashes":[block_hash]} - block = requests.post(self.BLOCK_INFO_URL, json = get_format, timeout=timeout) - block = json.loads(block.content) + + if self.BEARER is None: + get_format = {"_block_hashes":[block_hash]} + block = requests.post(self.BLOCK_INFO_URL, json = get_format, timeout=timeout) + block = json.loads(block.content) + else: + get_format = {"_block_hashes":[block_hash]} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + block = requests.post(self.BLOCK_INFO_URL, json = get_format, timeout=timeout, headers=custom_headers) + block = json.loads(block.content) + return block @@ -49,7 +64,15 @@ def get_block_txs(self,*block_hash): :rtype: list """ timeout = get_timeout() - get_format = {"_block_hashes":[block_hash]} - txs = requests.post(self.BLOCK_TXS_URL, json = get_format, timeout=timeout) - txs = json.loads(txs.content) + + if self.BEARER is None: + get_format = {"_block_hashes":[block_hash]} + txs = requests.post(self.BLOCK_TXS_URL, json = get_format, timeout=timeout) + txs = json.loads(txs.content) + else: + get_format = {"_block_hashes":[block_hash]} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + txs = requests.post(self.BLOCK_TXS_URL, json = get_format, timeout=timeout, headers=custom_headers) + txs = json.loads(txs.content) + return txs \ No newline at end of file diff --git a/koios_python/environment.py b/koios_python/environment.py index c94b22b..fcf6c73 100644 --- a/koios_python/environment.py +++ b/koios_python/environment.py @@ -17,7 +17,6 @@ LIMIT_RETRYING_TIMES= 10 - def init_timeout(): ''' Function to initialize timeout diff --git a/koios_python/epoch.py b/koios_python/epoch.py index 92ff35d..cfe42b3 100644 --- a/koios_python/epoch.py +++ b/koios_python/epoch.py @@ -16,20 +16,45 @@ def get_epoch_info(self, epoch_no=None, include_next_epoch=False): :rtype: list """ timeout = get_timeout() - if epoch_no is None and include_next_epoch is False: - info = requests.get(f"{self.EPOCH_INFO_URL}?_include_next_epoch=false", timeout=timeout) - info = json.loads(info.content) - if epoch_no is None and include_next_epoch is True: - info = requests.get(f"{self.EPOCH_INFO_URL}?_include_next_epoch=true", timeout=timeout) - info = json.loads(info.content) - if epoch_no is not None and include_next_epoch is False: - info = requests.get(f"{self.EPOCH_INFO_URL}?_epoch_no={epoch_no}&_include_next_epoch=false",\ - timeout=timeout) - info = json.loads(info.content) - if epoch_no is not None and include_next_epoch is True: - info = requests.get(f"{self.EPOCH_INFO_URL}?_epoch_no={epoch_no}&_include_next_epoch=true",\ - timeout=timeout) - info = json.loads(info.content) + + if self.BEARER is None: + + if epoch_no is None and include_next_epoch is False: + info = requests.get(f"{self.EPOCH_INFO_URL}?_include_next_epoch=false", timeout=timeout) + info = json.loads(info.content) + if epoch_no is None and include_next_epoch is True: + info = requests.get(f"{self.EPOCH_INFO_URL}?_include_next_epoch=true", timeout=timeout) + info = json.loads(info.content) + if epoch_no is not None and include_next_epoch is False: + info = requests.get(f"{self.EPOCH_INFO_URL}?_epoch_no={epoch_no}&_include_next_epoch=false",\ + timeout=timeout) + info = json.loads(info.content) + if epoch_no is not None and include_next_epoch is True: + info = requests.get(f"{self.EPOCH_INFO_URL}?_epoch_no={epoch_no}&_include_next_epoch=true",\ + timeout=timeout) + info = json.loads(info.content) + + else: + + if epoch_no is None and include_next_epoch is False: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(f"{self.EPOCH_INFO_URL}?_include_next_epoch=false", timeout=timeout, headers=custom_headers) + info = json.loads(info.content) + if epoch_no is None and include_next_epoch is True: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(f"{self.EPOCH_INFO_URL}?_include_next_epoch=true", timeout=timeout, headers=custom_headers) + info = json.loads(info.content) + if epoch_no is not None and include_next_epoch is False: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(f"{self.EPOCH_INFO_URL}?_epoch_no={epoch_no}&_include_next_epoch=false",\ + timeout=timeout, headers=custom_headers) + info = json.loads(info.content) + if epoch_no is not None and include_next_epoch is True: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(f"{self.EPOCH_INFO_URL}?_epoch_no={epoch_no}&_include_next_epoch=true",\ + timeout=timeout, headers=custom_headers) + info = json.loads(info.content) + return info @@ -44,12 +69,23 @@ def get_epoch_params(self, epoch_no=None): :rtype: list """ timeout = get_timeout() - if epoch_no is None: - info = requests.get(self.EPOCH_PARAMS_URL, timeout=timeout) - info = json.loads(info.content) + if self.BEARER is None: + if epoch_no is None: + info = requests.get(self.EPOCH_PARAMS_URL, timeout=timeout) + info = json.loads(info.content) + else: + info = requests.get(f"{self.EPOCH_PARAMS_URL}?_epoch_no={epoch_no}", timeout=timeout) + info = json.loads(info.content) else: - info = requests.get(f"{self.EPOCH_PARAMS_URL}?_epoch_no={epoch_no}", timeout=timeout) - info = json.loads(info.content) + if epoch_no is None: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(self.EPOCH_PARAMS_URL, timeout=timeout, headers=custom_headers) + info = json.loads(info.content) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(f"{self.EPOCH_PARAMS_URL}?_epoch_no={epoch_no}", timeout=timeout, headers=custom_headers) + info = json.loads(info.content) + return info @@ -63,10 +99,22 @@ def get_epoch_block_protocols(self, epoch_no=None): :rtype: list """ timeout = get_timeout() - if epoch_no is None: - info = requests.get(self.EPOCH_BLOCKS_URL, timeout=timeout) - info = json.loads(info.content) + + if self.BEARER is None: + if epoch_no is None: + info = requests.get(self.EPOCH_BLOCKS_URL, timeout=timeout) + info = json.loads(info.content) + else: + info = requests.get(f"{self.EPOCH_BLOCKS_URL}?_epoch_no={epoch_no}", timeout=timeout) + info = json.loads(info.content) else: - info = requests.get(f"{self.EPOCH_BLOCKS_URL}?_epoch_no={epoch_no}", timeout=timeout) - info = json.loads(info.content) + if epoch_no is None: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(self.EPOCH_BLOCKS_URL, timeout=timeout, headers=custom_headers) + info = json.loads(info.content) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(f"{self.EPOCH_BLOCKS_URL}?_epoch_no={epoch_no}", timeout=timeout, headers=custom_headers) + info = json.loads(info.content) + return info \ No newline at end of file diff --git a/koios_python/network.py b/koios_python/network.py index 4b047fe..0133a8f 100644 --- a/koios_python/network.py +++ b/koios_python/network.py @@ -15,8 +15,14 @@ def get_tip(self): :rtype: list. """ timeout = get_timeout() - tip = requests.get(self.TIP_URL, timeout=timeout) - tip = json.loads(tip.content) + if self.BEARER is None: + tip = requests.get(self.TIP_URL, timeout=timeout) + tip = json.loads(tip.content) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + tip = requests.get(self.TIP_URL, timeout=timeout, headers=custom_headers) + tip = json.loads(tip.content) + return tip @@ -29,7 +35,13 @@ def get_genesis(self): :rtype: list. """ timeout = get_timeout() - genesis = requests.get(self.GENESIS_URL, timeout=timeout) + + if self.BEARER is None: + genesis = requests.get(self.GENESIS_URL, timeout=timeout) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + genesis = requests.get(self.GENESIS_URL, timeout=timeout, headers=custom_headers) + genesis = json.loads(genesis.content) return genesis @@ -45,16 +57,27 @@ def get_totals(self, epoch_no=None): :rtype: list. """ timeout = get_timeout() - if epoch_no is None: - totals = requests.get(self.TOTALS_URL, timeout=timeout) - totals = json.loads(totals.content) + + if self.BEARER is None: + if epoch_no is None: + totals = requests.get(self.TOTALS_URL, timeout=timeout) + totals = json.loads(totals.content) + else: + totals = requests.get(f"{self.TOTALS_URL}?_epoch_no={epoch_no}", timeout=timeout) + totals = json.loads(totals.content) else: - totals = requests.get(f"{self.TOTALS_URL}?_epoch_no={epoch_no}", timeout=timeout) - totals = json.loads(totals.content) + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + if epoch_no is None: + totals = requests.get(self.TOTALS_URL, timeout=timeout, headers=custom_headers) + totals = json.loads(totals.content) + else: + totals = requests.get(f"{self.TOTALS_URL}?_epoch_no={epoch_no}", timeout=timeout, headers=custom_headers) + totals = json.loads(totals.content) + return totals @Exception_Handler -def get_param_updates(self, content_range="0-57"): +def get_param_updates(self, content_range="0-999"): """ Get all parameter update proposals submitted to the chain starting Shelley era @@ -62,8 +85,59 @@ def get_param_updates(self, content_range="0-57"): :rtype: list """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - network_params = requests.get(self.NETWORK_PARAM_UPDATES_URL, headers=custom_headers, timeout=timeout) - network_params = json.loads(network_params.content) + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + network_params = requests.get(self.NETWORK_PARAM_UPDATES_URL, headers=custom_headers, timeout=timeout) + network_params = json.loads(network_params.content) + else: + custom_headers = {"Range": str(content_range), "Authorizatoin": f"Bearer {self.BEARER}"} + network_params = requests.get(self.NETWORK_PARAM_UPDATES_URL, headers=custom_headers, timeout=timeout) + network_params = json.loads(network_params.content) + return network_params + + +@Exception_Handler +def get_reserve_withdrawals(self, content_range="0-999"): + """ + Get all reserve withdrawals from the chain starting Shelley era + + :return: list of reserve withdrawals starting from Shelley era. + :rtype: list + """ + timeout = get_timeout() + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + reserve_withdrawals = requests.get(self.RESERVE_WITHDRAWALS_URL, headers=custom_headers, timeout=timeout) + reserve_withdrawals = json.loads(reserve_withdrawals.content) + else: + custom_headers = {"Range": str(content_range), "Authorizatoin": f"Bearer {self.BEARER}"} + reserve_withdrawals = requests.get(self.RESERVE_WITHDRAWALS_URL, timeout=timeout, headers=custom_headers) + reserve_withdrawals = json.loads(reserve_withdrawals.content) + return reserve_withdrawals + + +@Exception_Handler +def get_treasury_withdrawals(self, content_range="0-999"): + """ + Get all treasury withdrawals from the chain starting Shelley era + + :return: list of treasury withdrawals starting from Shelley era. + :rtype: list + """ + timeout = get_timeout() + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + treasury_withdrawals = requests.get(self.TREASURY_WITHDRAWALS_URL, headers=custom_headers, timeout=timeout) + treasury_withdrawals = json.loads(treasury_withdrawals.content) + else: + custom_headers = {"Range": str(content_range), "Authorizatoin": f"Bearer {self.BEARER}"} + treasury_withdrawals = requests.get(self.TREASURY_WITHDRAWALS_URL, headers=custom_headers, timeout=timeout) + treasury_withdrawals = json.loads(treasury_withdrawals.content) + + return treasury_withdrawals + diff --git a/koios_python/ogmios.py b/koios_python/ogmios.py new file mode 100644 index 0000000..8ee759e --- /dev/null +++ b/koios_python/ogmios.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +""" +Provides all address functions +""" +import json +import requests +from .environment import * + + +@Exception_Handler +def query(self, query, *params): + """ + Query the current tip of the Network. + + :param str query: query to search and read data from Ogmios. + :param dict params: parameters to search and read data. + :return: list of all info about query. + :rtype: list. + """ + print(f"Querying {self.url}...") + timeout = get_timeout() + + if self.BEARER is None: + get_format = {"jsonrpc": "2.0", "method": query} + tip = requests.post(self.url, json = get_format, timeout=timeout) + tip = json.loads(tip.content) + else: + get_format = {"jsonrpc": "2.0", "method": query} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + tip = requests.post(self.url, json = get_format, timeout=timeout, headers=custom_headers) + + return tip \ No newline at end of file diff --git a/koios_python/pool.py b/koios_python/pool.py index 5a1e69f..29b7e38 100644 --- a/koios_python/pool.py +++ b/koios_python/pool.py @@ -16,9 +16,17 @@ def get_pool_list(self, content_range="0-999"): :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - pool_list = requests.get(self.POOL_LIST_URL, headers = custom_headers, timeout=timeout) - pool_list = json.loads(pool_list.content) + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + pool_list = requests.get(self.POOL_LIST_URL, headers = custom_headers, timeout=timeout) + pool_list = json.loads(pool_list.content) + + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + pool_list = requests.get(self.POOL_LIST_URL, headers = custom_headers, timeout=timeout) + pool_list = json.loads(pool_list.content) + return pool_list @@ -32,9 +40,17 @@ def get_pool_info(self, *args): :rtype: list. """ timeout = get_timeout() - get_format = {"_pool_bech32_ids": [args] } - pool_list = requests.post(self.POOL_INFO_URL, json = get_format, timeout=timeout) - pool_list = json.loads(pool_list.content) + + if self.BEARER is None: + get_format = {"_pool_bech32_ids": [args] } + pool_list = requests.post(self.POOL_INFO_URL, json = get_format, timeout=timeout) + pool_list = json.loads(pool_list.content) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + get_format = {"_pool_bech32_ids": [args] } + pool_list = requests.post(self.POOL_INFO_URL, json = get_format, headers = custom_headers, timeout=timeout) + pool_list = json.loads(pool_list.content) + return pool_list @@ -48,8 +64,15 @@ def get_pool_stake_snapshot(self, pool_bech32): :rtype: list. """ timeout = get_timeout() - snapshot = requests.get(self.POOL_STAKE_SNAPSHOT + pool_bech32, timeout=timeout) - snapshot = json.loads(snapshot.content) + + if self.BEARER is None: + snapshot = requests.get(self.POOL_STAKE_SNAPSHOT + pool_bech32, timeout=timeout) + snapshot = json.loads(snapshot.content) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + snapshot = requests.get(self.POOL_STAKE_SNAPSHOT + pool_bech32, headers = custom_headers, timeout=timeout) + snapshot = json.loads(snapshot.content) + return snapshot @@ -64,9 +87,16 @@ def get_pool_delegators(self, pool_bech32, content_range="0-999"): :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - info = requests.get(self.POOL_DELEGATORS_URL + pool_bech32, headers = custom_headers, timeout=timeout) - info = json.loads(info.content) + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + info = requests.get(self.POOL_DELEGATORS_URL + pool_bech32, headers = custom_headers, timeout=timeout) + info = json.loads(info.content) + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + info = requests.get(self.POOL_DELEGATORS_URL + pool_bech32, headers = custom_headers, timeout=timeout) + info = json.loads(info.content) + return info @@ -83,17 +113,30 @@ def get_pool_delegators_history(self, pool_bech32, epoch_no=None, content_range= """ timeout = get_timeout() custom_headers = {"Range": str(content_range)} - if epoch_no is None: + + if self.BEARER is None and epoch_no is None: info = requests.get(self.POOL_DELEGATORS_HISTORY_URL + pool_bech32, headers=custom_headers, timeout=timeout) info = json.loads(info.content) - else: + + if self.BEARER is None and epoch_no is not None: info = requests.get(f"{self.POOL_DELEGATORS_HISTORY_URL}{pool_bech32}&_epoch_no={epoch_no}", headers=custom_headers, timeout=timeout) info = json.loads(info.content) + + if self.BEARER is not None and epoch_no is None: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + info = requests.get(self.POOL_DELEGATORS_HISTORY_URL + pool_bech32, headers=custom_headers, timeout=timeout) + info = json.loads(info.content) + + if self.BEARER is not None and epoch_no is not None: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + info = requests.get(f"{self.POOL_DELEGATORS_HISTORY_URL}{pool_bech32}&_epoch_no={epoch_no}", headers=custom_headers, timeout=timeout) + info = json.loads(info.content) + return info @Exception_Handler -def get_pool_blocks(self, pool_bech32, epoch_no=None): +def get_pool_blocks(self, pool_bech32, epoch_no=None, content_range="0-999"): """ Return information about blocks minted by a given pool for all epochs (or _epoch_no if provided) @@ -103,17 +146,32 @@ def get_pool_blocks(self, pool_bech32, epoch_no=None): :rtype: list.s """ timeout = get_timeout() - if epoch_no is None: - info = requests.get(self.POOL_BLOCKS_URL + pool_bech32, timeout=timeout) + + if self.BEARER is None and epoch_no is None: + custom_headers = {"Range": str(content_range)} + info = requests.get(self.POOL_BLOCKS_URL + pool_bech32, timeout=timeout, headers=custom_headers) info = json.loads(info.content) - else: - info = requests.get(f"{self.POOL_BLOCKS_URL}{pool_bech32}&_epoch_no={epoch_no}", timeout=timeout) + + if self.BEARER is None and epoch_no is not None: + custom_headers = {"Range": str(content_range)} + info = requests.get(f"{self.POOL_BLOCKS_URL}{pool_bech32}&_epoch_no={epoch_no}", timeout=timeout, headers=custom_headers) + info = json.loads(info.content) + + if self.BEARER is not None and epoch_no is None: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + info = requests.get(self.POOL_BLOCKS_URL + pool_bech32, headers=custom_headers, timeout=timeout) info = json.loads(info.content) + + if self.BEARER is not None and epoch_no is not None: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + info = requests.get(f"{self.POOL_BLOCKS_URL}{pool_bech32}&_epoch_no={epoch_no}", headers=custom_headers, timeout=timeout) + info = json.loads(info.content) + return info @Exception_Handler -def get_pool_history(self, pool_bech32, epoch_no="history"): +def get_pool_history(self, pool_bech32, epoch_no=None): """ 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) @@ -124,12 +182,25 @@ def get_pool_history(self, pool_bech32, epoch_no="history"): :rtype: list. """ timeout = get_timeout() - if epoch_no == "history": + + if self.BEARER is None and epoch_no == None: info = requests.get(self.POOL_HISTORY_URL + pool_bech32, timeout=timeout) info = json.loads(info.content) - else: + + if self.BEARER is None and epoch_no is not None: info = requests.get(f"{self.POOL_HISTORY_URL}{pool_bech32}&_epoch_no={epoch_no}", timeout=timeout) info = json.loads(info.content) + + if self.BEARER is not None and epoch_no is None: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(self.POOL_HISTORY_URL + pool_bech32, headers=custom_headers, timeout=timeout) + info = json.loads(info.content) + + if self.BEARER is not None and epoch_no is not None: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + info = requests.get(f"{self.POOL_HISTORY_URL}{pool_bech32}&_epoch_no={epoch_no}", headers=custom_headers, timeout=timeout) + info = json.loads(info.content) + return info @@ -143,12 +214,25 @@ def get_pool_updates(self, pool_bech32=None): :rtype: list. """ timeout = get_timeout() - if pool_bech32 is None: + + if self.BEARER is None and pool_bech32 is None: pool_list = requests.get(self.POOL_UPDATES_URL, timeout=timeout) pool_list = json.loads(pool_list.content) - else: + + if self.BEARER is None and pool_bech32 is not None: pool_list = requests.get(f"{self.POOL_UPDATES_URL}?_pool_bech32={pool_bech32}", timeout=timeout) pool_list = json.loads(pool_list.content) + + if self.BEARER is not None and pool_bech32 is None: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + pool_list = requests.get(self.POOL_UPDATES_URL, headers=custom_headers, timeout=timeout) + pool_list = json.loads(pool_list.content) + + if self.BEARER is not None and pool_bech32 is not None: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + pool_list = requests.get(f"{self.POOL_UPDATES_URL}?_pool_bech32={pool_bech32}", headers=custom_headers, timeout=timeout) + pool_list = json.loads(pool_list.content) + return pool_list @@ -162,9 +246,16 @@ def get_pool_relays(self, content_range="0-999"): :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - pool_list = requests.get(self.POOL_RELAYS_URL, headers = custom_headers, timeout=timeout) - pool_list = json.loads(pool_list.content) + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + pool_list = requests.get(self.POOL_RELAYS_URL, headers = custom_headers, timeout=timeout) + pool_list = json.loads(pool_list.content) + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + pool_list = requests.get(self.POOL_RELAYS_URL, headers = custom_headers, timeout=timeout) + pool_list = json.loads(pool_list.content) + return pool_list @@ -178,11 +269,66 @@ def get_pool_metadata(self, *args): :rtype: list. """ timeout = get_timeout() - if len(args) == 0: - pool_list = requests.post(self.POOL_METADATA_URL, timeout=timeout) + + if self.BEARER is None and len(args) != 0: + get_format = {"_pool_bech32_ids": [args] } + pool_list = requests.post(self.POOL_METADATA_URL, json = get_format, timeout=timeout) + pool_list = json.loads(pool_list.content) + + if self.BEARER is not None and len(args) != 0: + get_format = {"_pool_bech32_ids": [args] } + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + pool_list = requests.get(self.POOL_METADATA_URL, headers = custom_headers, json = get_format, timeout=timeout) pool_list = json.loads(pool_list.content) else: - get_format = {"_pool_bech32_ids": [args]} - pool_list = requests.post(self.POOL_METADATA_URL, json = get_format, timeout=timeout) + pool_list = None + + return pool_list + +@Exception_Handler +def get_pool_registrations(self, epoch_no=None): + """ + Get all pool registrations for all epochs (or _epoch_no if provided) + + :param str epoch_no: epoch number to get info (from the beginning if omitted). + :return: list of pool registrations. + :rtype: list. + """ + timeout = get_timeout() + if epoch_no is None: + print(f"WARNING: epoch_no is required") + return + + if self.BEARER is None: + pool_list = requests.get(f"{self.POOL_REGISTRATIONS_URL}{epoch_no}", timeout=timeout) + pool_list = json.loads(pool_list.content) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + pool_list = requests.get(f"{self.POOL_REGISTRATIONS_URL}{epoch_no}", headers = custom_headers, timeout=timeout) + pool_list = json.loads(pool_list.content) + + return pool_list + +@Exception_Handler +def get_pool_retirements(self, epoch_no=None): + """ + Get all pool retirements for all epochs (or _epoch_no if provided) + + :param str epoch_no: epoch number to get info (from the beginning if omitted). + :return: list of pool retirements. + :rtype: list. + """ + timeout = get_timeout() + if epoch_no is None: + print(f"WARNING: epoch_no is required") + return + + if self.BEARER is None: + pool_list = requests.get(f"{self.POOL_RETIREMENTS_URL}{epoch_no}", timeout=timeout) + pool_list = json.loads(pool_list.content) + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + pool_list = requests.get(f"{self.POOL_RETIREMENTS_URL}{epoch_no}", headers = custom_headers, timeout=timeout) pool_list = json.loads(pool_list.content) + return pool_list \ No newline at end of file diff --git a/koios_python/scripts.py b/koios_python/scripts.py index 1872e1b..3fe25c8 100644 --- a/koios_python/scripts.py +++ b/koios_python/scripts.py @@ -7,6 +7,33 @@ import requests from .environment import * + +@Exception_Handler +def get_script_info(self, *script_hashes, content_range="0-999"): + """ + Get list of script information for given script hashes + + :params list script_hashes: Array of script hashes in hexadecimal format (hex) to search and read data. + :return: list of script information for given script hashes. + :rtype: list. + """ + timeout = get_timeout() + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + get_format = {"_script_hashes": [script_hashes]} + script_info = requests.post(self.SCRIPT_INFO_URL, json = get_format, timeout=timeout, headers=custom_headers) + script_info = json.loads(script_info.content) + + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + get_format = {"_script_hashes": [script_hashes]} + script_info = requests.post(self.SCRIPT_INFO_URL, json = get_format, headers = custom_headers, timeout=timeout) + script_info = json.loads(script_info.content) + + return script_info + + @Exception_Handler def get_native_script_list(self, content_range="0-999"): """ @@ -17,10 +44,18 @@ def get_native_script_list(self, content_range="0-999"): :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - get_format = requests.post(self.NATIVE_SCRIPT_LIST_URL, headers = custom_headers, timeout=timeout) - get_format = json.loads(get_format.content) - return get_format + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + script_list = requests.post(self.NATIVE_SCRIPT_LIST_URL, headers = custom_headers, timeout=timeout) + script_list = json.loads(script_list.content) + + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + script_list = requests.post(self.NATIVE_SCRIPT_LIST_URL, headers = custom_headers, timeout=timeout) + script_list = json.loads(script_list.content) + + return script_list @Exception_Handler @@ -33,14 +68,22 @@ def get_plutus_script_list(self, content_range="0-999"): :rtype: list. """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - get_format = requests.post(self.PLUTUS_SCRIPT_LIST_URL, headers = custom_headers, timeout=timeout) - get_format = json.loads(get_format.content) - return get_format + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + script_list = requests.post(self.PLUTUS_SCRIPT_LIST_URL, headers = custom_headers, timeout=timeout) + script_list = json.loads(script_list.content) + + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + script_list = requests.post(self.PLUTUS_SCRIPT_LIST_URL, headers = custom_headers, timeout=timeout) + script_list = json.loads(script_list.content) + + return script_list @Exception_Handler -def get_script_redeemers(self, script_hash): +def get_script_redeemers(self, script_hash, content_range="0-999"): """ Get list of all redeemers for a given script hash. @@ -49,9 +92,61 @@ def get_script_redeemers(self, script_hash): :rtype: list. """ timeout = get_timeout() - query = requests.get(self.SCRIPT_REDEEMERS_URL + script_hash, timeout=timeout) - query = json.loads(query.content) - return query + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + script_redeemers = requests.get(self.SCRIPT_REDEEMERS_URL + script_hash, timeout=timeout, headers = custom_headers) + script_redeemers = json.loads(script_redeemers.content) + + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + script_redeemers = requests.get(self.SCRIPT_REDEEMERS_URL + script_hash, headers = custom_headers, timeout=timeout) + script_redeemers = json.loads(script_redeemers.content) + + return script_redeemers + + +@Exception_Handler +def get_script_utxos(self, script_hash, extended=False, content_range="0-999"): + """ + Get list of all UTxOs for a given script hash + + :params string script_hash: script hash in hexadecimal format (hex) to search and read data. + :params bool extended: extended output format, default is False. + :return: list of all UTxOs for a given script hash. + :rtype: list. + """ + + if self.BEARER is None and extended is False: + extended = "false" + timeout = get_timeout() + custom_headers = {"Range": str(content_range)} + utxos_list = requests.get(f"{self.SCRIPT_UTXOS_URL}{script_hash}&_extended={extended}", timeout=timeout, headers = custom_headers) + utxos_list = json.loads(utxos_list.content) + + if self.BEARER is None and extended is True: + extended = "true" + timeout = get_timeout() + custom_headers = {"Range": str(content_range)} + utxos_list = requests.get(f"{self.SCRIPT_UTXOS_URL}{script_hash}&_extended={extended}", timeout=timeout, headers = custom_headers) + utxos_list = json.loads(utxos_list.content) + + if self.BEARER is not None and extended is False: + extended = "false" + timeout = get_timeout() + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + utxos_list = requests.get(f"{self.SCRIPT_UTXOS_URL}{script_hash}&_extended={extended}", timeout=timeout, headers = custom_headers) + utxos_list = json.loads(utxos_list.content) + + if self.BEARER is not None and extended is True: + extended = "true" + timeout = get_timeout() + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + utxos_list = requests.get(f"{self.SCRIPT_UTXOS_URL}{script_hash}&_extended={extended}", timeout=timeout, headers = custom_headers) + utxos_list = json.loads(utxos_list.content) + + return utxos_list + @Exception_Handler @@ -64,7 +159,16 @@ def get_datum_info(self, *datum_hash): :rtype: list. ''' timeout = get_timeout() - custom_headers = {"_datum_hashes": [datum_hash]} - get_format = requests.post(self.DATUM_INFO_URL, json = custom_headers, timeout=timeout) - get_format = json.loads(get_format.content) - return get_format \ No newline at end of file + + if self.BEARER is None: + get_format = {"_datum_hashes": [datum_hash]} + datum_info = requests.post(self.DATUM_INFO_URL, json = get_format, timeout=timeout) + datum_info = json.loads(datum_info.content) + + else: + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + get_format = {"_datum_hashes": [datum_hash]} + datum_info = requests.post(self.DATUM_INFO_URL, json = get_format, headers = custom_headers, timeout=timeout) + datum_info = json.loads(datum_info.content) + + return datum_info diff --git a/koios_python/transactions.py b/koios_python/transactions.py index dff72e1..5016215 100644 --- a/koios_python/transactions.py +++ b/koios_python/transactions.py @@ -6,6 +6,46 @@ import requests from .environment import * + +@Exception_Handler +def get_utxo_info(self, *args, extended=False, content_range="0-999"): + """ + Get UTxO set for requested UTxO references. + + :param list utxo_hash: Array of Cardano utxo references in the form "hash#index" + :return: list of all info about UTxO(s). + :rtype: list. + """ + timeout = get_timeout() + + if self.BEARER is None and extended is False: + custom_headers = {"Range": str(content_range)} + get_format = {"_utxo_refs": [args], "_extended": "false"} + utxo_info = requests.post(self.UTXO_INFO_URL, json = get_format, timeout=timeout, headers = custom_headers) + utxo_info = json.loads(utxo_info.content) + + if self.BEARER is None and extended is True: + custom_headers = {"Range": str(content_range)} + get_format = {"_utxo_refs": [args], "_extended": "true"} + utxo_info = requests.post(self.UTXO_INFO_URL, json = get_format, timeout=timeout, headers = custom_headers) + utxo_info = json.loads(utxo_info.content) + + if self.BEARER is not None and extended is False: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + get_format = {"_utxo_refs": [args], "_extended": "false"} + utxo_info = requests.post(self.UTXO_INFO_URL, json = get_format, timeout=timeout, headers = custom_headers) + utxo_info = json.loads(utxo_info.content) + print('LOL') + + if self.BEARER is not None and extended is True: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + get_format = {"_utxo_refs": [args], "_extended": "true"} + utxo_info = requests.post(self.UTXO_INFO_URL, json = get_format, timeout=timeout, headers = custom_headers) + utxo_info = json.loads(utxo_info.content) + + return utxo_info + + @Exception_Handler def get_tx_info(self, *args): """ @@ -16,12 +56,21 @@ def get_tx_info(self, *args): :rtype: list. """ timeout = get_timeout() - get_format = {"_tx_hashes": [args]} - tx_info = requests.post(self.TX_INFO_URL, json = get_format, timeout=timeout) - tx_info = json.loads(tx_info.content) + + if self.BEARER is None: + get_format = {"_tx_hashes": [args]} + tx_info = requests.post(self.TX_INFO_URL, json = get_format, timeout=timeout) + tx_info = json.loads(tx_info.content) + else: + get_format = {"_tx_hashes": [args]} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + tx_info = requests.post(self.TX_INFO_URL, json = get_format, timeout=timeout, headers=custom_headers) + tx_info = json.loads(tx_info.content) + return tx_info +## [DEPRECATED - Use /utxo_info instead] @Exception_Handler def get_tx_utxos(self, *args): """ @@ -32,9 +81,17 @@ def get_tx_utxos(self, *args): :rtype: list. """ timeout = get_timeout() - get_format = {"_tx_hashes": [args]} - tx_utxos = requests.post(self.TX_UTXOS_URL, json = get_format, timeout=timeout) - tx_utxos = json.loads(tx_utxos.content) + + if self.BEARER is None: + get_format = {"_tx_hashes": [args]} + tx_utxos = requests.post(self.TX_UTXOS_URL, json = get_format, timeout=timeout) + tx_utxos = json.loads(tx_utxos.content) + else: + get_format = {"_tx_hashes": [args]} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + tx_utxos = requests.post(self.TX_UTXOS_URL, json = get_format, timeout=timeout, headers=custom_headers) + tx_utxos = json.loads(tx_utxos.content) + return tx_utxos @@ -48,9 +105,17 @@ def get_tx_metadata(self, *args): :rtype: list. """ timeout = get_timeout() - get_format = {"_tx_hashes": [args]} - tx_metadata = requests.post(self.TX_METADATA_URL, json = get_format, timeout=timeout) - tx_metadata = json.loads(tx_metadata.content) + + if self.BEARER is None: + get_format = {"_tx_hashes": [args]} + tx_metadata = requests.post(self.TX_METADATA_URL, json = get_format, timeout=timeout) + tx_metadata = json.loads(tx_metadata.content) + else: + get_format = {"_tx_hashes": [args]} + custom_headers = {"Authorization": f"Bearer {self.BEARER}"} + tx_metadata = requests.post(self.TX_METADATA_URL, json = get_format, timeout=timeout, headers=custom_headers) + tx_metadata = json.loads(tx_metadata.content) + return tx_metadata @@ -63,10 +128,18 @@ def get_tx_metalabels(self, content_range="0-999"): :return: list of metalabels transactions """ timeout = get_timeout() - custom_headers = {"Range": str(content_range)} - tx_metalabels = requests.get(self.TX_METALABELS_URL, headers \ - = custom_headers, timeout=timeout) - tx_metalabels = json.loads(tx_metalabels.content) + + if self.BEARER is None: + custom_headers = {"Range": str(content_range)} + tx_metalabels = requests.get(self.TX_METALABELS_URL, headers \ + = custom_headers, timeout=timeout) + tx_metalabels = json.loads(tx_metalabels.content) + else: + custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} + tx_metalabels = requests.get(self.TX_METALABELS_URL, headers \ + = custom_headers, timeout=timeout) + tx_metalabels = json.loads(tx_metalabels.content) + return tx_metalabels @@ -80,12 +153,22 @@ def submit_tx(self, file): :return: hex transaction ID (if is successful ) """ timeout = get_timeout() - with open(file, "rb") as cbor_tx: - cbor_tx = cbor_tx.read() - cbor_header = {'Content-Type': 'application/cbor'} - submit = requests.post(self.SUBMIT_TX_URL, headers = cbor_header, \ - data = cbor_tx, timeout=timeout) - submit = json.loads(submit.content) + + if self.BEARER is None: + with open(file, "rb") as cbor_tx: + cbor_tx = cbor_tx.read() + cbor_header = {'Content-Type': 'application/cbor'} + submit = requests.post(self.SUBMIT_TX_URL, headers = cbor_header, \ + data = cbor_tx, timeout=timeout) + submit = json.loads(submit.content) + else: + with open(file, "rb") as cbor_tx: + cbor_tx = cbor_tx.read() + cbor_header = {'Content-Type': 'application/cbor', "Authorization": f"Bearer {self.BEARER}"} + submit = requests.post(self.SUBMIT_TX_URL, headers = cbor_header, \ + data = cbor_tx, timeout=timeout) + submit = json.loads(submit.content) + return submit @@ -102,4 +185,4 @@ def get_tx_status(self, *args): get_format = {"_tx_hashes": [args]} tx_status = requests.post(self.TX_STATUS_URL, json = get_format, timeout=timeout) tx_status = json.loads(tx_status.content) - return tx_status \ No newline at end of file + return tx_status diff --git a/koios_python/urls.py b/koios_python/urls.py index 8dbb187..2277aad 100644 --- a/koios_python/urls.py +++ b/koios_python/urls.py @@ -6,24 +6,29 @@ class URLs: # imported like class methods from .epoch import get_epoch_info, get_epoch_params, get_epoch_block_protocols - from .network import get_tip, get_genesis, get_totals, get_param_updates + from .network import get_tip, get_genesis, get_totals, get_param_updates, get_treasury_withdrawals, get_reserve_withdrawals from .block import get_blocks, get_block_info, get_block_txs - from .address import get_address_info, get_address_txs, get_address_assets, get_credential_txs, get_credential_utxos + from .address import get_address_info, get_address_txs, get_address_assets, get_credential_txs, get_credential_utxos,\ + get_address_utxos from .account import get_account_info, get_account_info_cached, get_account_list, get_account_rewards, get_account_utxos,\ - get_account_updates, get_account_addresses, get_account_assets, get_account_history, get_account_assets_paginated + get_account_updates, get_account_addresses, get_account_assets, get_account_history, get_account_assets_paginated, get_account_txs from .asset import get_asset_list, get_asset_addresses, get_asset_info, get_asset_history, get_policy_asset_info, \ get_asset_summary, get_asset_txs, get_asset_info_bulk, get_asset_token_registry, get_asset_nft_address,\ - get_policy_asset_addresses, get_policy_asset_list - from .pool import get_pool_list, get_pool_info, get_pool_stake_snapshot, get_pool_delegators, get_pool_delegators_history, get_pool_blocks, get_pool_history, get_pool_updates, get_pool_relays, get_pool_metadata - from .scripts import get_native_script_list, get_plutus_script_list, get_script_redeemers, get_datum_info - from .transactions import get_tx_info, get_tx_utxos, get_tx_metadata, get_tx_metalabels, submit_tx, get_tx_status + get_policy_asset_addresses, get_policy_asset_list, get_asset_utxos + from .pool import get_pool_list, get_pool_info, get_pool_stake_snapshot, get_pool_delegators, get_pool_delegators_history, get_pool_blocks, \ + get_pool_history, get_pool_updates, get_pool_relays, get_pool_metadata, get_pool_registrations, get_pool_retirements + from .scripts import get_native_script_list, get_plutus_script_list, get_script_redeemers, get_datum_info, get_script_utxos, get_script_info + from .transactions import get_tx_info, get_tx_utxos, get_tx_metadata, get_tx_metalabels, submit_tx, get_tx_status, get_utxo_info + from .ogmios import query - def __init__(self, url='https://api.koios.rest/api/v0/', network='mainnet'): + def __init__(self, url='https://api.koios.rest/api/v1/', network='mainnet', server='koios', bearer=None): - self.version = 'koios-python v1.3.1' + self.version = 'koios-python v2.0.0' self.url = url self.network = network + self.server = server + self.BEARER = bearer # change subdomain to network name then change the rest of urls to use the new subdomain if self.network == 'preview' or self.network == 'preprod': @@ -33,6 +38,13 @@ def __init__(self, url='https://api.koios.rest/api/v0/', network='mainnet'): self.url = 'https://' + self.url elif self.network == 'mainnet': self.url = url + + if self.server == "ogmios": + self.url = url + "ogmios/" + + if self.server == "koios": + self.url = url + # Network URLs @@ -40,6 +52,8 @@ def __init__(self, url='https://api.koios.rest/api/v0/', network='mainnet'): self.GENESIS_URL = self.url + "genesis" self.TOTALS_URL = self.url + "totals" self.NETWORK_PARAM_UPDATES_URL = self.url + "param_updates" + self.RESERVE_WITHDRAWALS_URL = self.url + "reserve_withdrawals" + self.TREASURY_WITHDRAWALS_URL = self.url + "treasury_withdrawals" # Epoch URLs self.EPOCH_INFO_URL = self.url + "epoch_info" @@ -52,6 +66,7 @@ def __init__(self, url='https://api.koios.rest/api/v0/', network='mainnet'): self.BLOCK_TXS_URL = self.url + "block_txs" # Transaction URLs + self.UTXO_INFO_URL = self.url + "utxo_info" self.TX_INFO_URL = self.url + "tx_info" self.TX_UTXOS_URL = self.url + "tx_utxos" self.TX_METADATA_URL = self.url + "tx_metadata" @@ -59,17 +74,19 @@ def __init__(self, url='https://api.koios.rest/api/v0/', network='mainnet'): self.SUBMIT_TX_URL = self.url + "submittx" self.TX_STATUS_URL = self.url + "tx_status" + # Address URLs self.ADDRESS_INFO_URL = self.url + "address_info" self.ADDRESS_TXS_URL = self.url + "address_txs" self.ADDRESS_ASSETS_URL = self.url + "address_assets" self.ADDRESS_CREDENTIAL_TXS_URL = self.url + "credential_txs" self.ADDRESS_CREDENTIAL_UTXOS_URL = self.url + "credential_utxos" + self.ADDRESS_UTXOS_URL = self.url + "address_utxos" # Stake Account URLs self.ACCOUNT_LIST_URL = self.url + "account_list?offset=" self.ACCOUNT_INFO_URL = self.url + "account_info" - self.ACCOUNT_UTXOS_URL = self.url + "account_utxos?_stake_address=" + self.ACCOUNT_UTXOS_URL = self.url + "account_utxos?" self.ACCOUNT_INFO_CACHED_URL = self.url + "account_info_cached" self.ACCOUNT_REWARDS_URL = self.url + "account_rewards" self.ACCOUNT_UPDATES_URL = self.url + "account_updates" @@ -77,11 +94,12 @@ def __init__(self, url='https://api.koios.rest/api/v0/', network='mainnet'): #self.ACCOUNT_ASSETS_URL = self.url + "account_assets?offset=" self.ACCOUNT_ASSETS_URL = self.url + "account_assets" self.ACCOUNT_HISTORY_URL = self.url + "account_history" + self.ACCOUNT_TXS_URL = self.url + "account_txs" # Asset URLs self.ASSET_LIST_URL = self.url + "asset_list" self.ASSET_ADDRESSES_URL = self.url + "asset_addresses?_asset_policy=" - self.ASSET_INFO_URL = self.url + "asset_info?_asset_policy=" + self.ASSET_INFO_URL = self.url + "asset_info?_asset_policy=" #DEPRECATED self.ASSET_HISTORY_URL = self.url + "asset_history?_asset_policy=" self.POLICY_ASSET_INFO_URL = self.url + "policy_asset_info?_asset_policy=" self.ASSET_SUMMARY_URL = self.url + "asset_summary?_asset_policy=" @@ -91,6 +109,7 @@ def __init__(self, url='https://api.koios.rest/api/v0/', network='mainnet'): self.ASSET_TOKEN_REGISTRY_URL = self.url + "asset_token_registry" self.POLICY_ASSET_ADDRESSES_LIST_URL = self.url + "policy_asset_addresses?_asset_policy=" self.POLICY_ASSET_LIST_URL = self.url + "policy_asset_list?_asset_policy=" + self.ASSET_UTXOS_URL = self.url + "asset_utxos" # Pool URLs self.POOL_LIST_URL = self.url + "pool_list" @@ -103,9 +122,13 @@ def __init__(self, url='https://api.koios.rest/api/v0/', network='mainnet'): self.POOL_UPDATES_URL = self.url + "pool_updates" self.POOL_RELAYS_URL = self.url + "pool_relays" self.POOL_METADATA_URL = self.url + "pool_metadata" + self.POOL_REGISTRATIONS_URL = self.url + "pool_registrations?_epoch_no=" + self.POOL_RETIREMENTS_URL = self.url + "pool_retirements?_epoch_no=" # Scripts URLs self.NATIVE_SCRIPT_LIST_URL = self.url + "native_script_list" self.PLUTUS_SCRIPT_LIST_URL = self.url + "plutus_script_list" self.SCRIPT_REDEEMERS_URL = self.url + "script_redeemers?_script_hash=" self.DATUM_INFO_URL = self.url + "datum_info" + self.SCRIPT_UTXOS_URL = self.url + "script_utxos?_script_hash=" + self.SCRIPT_INFO_URL = self.url + "script_info" \ No newline at end of file diff --git a/test_koios.py b/test_koios.py deleted file mode 100644 index 8d7151c..0000000 --- a/test_koios.py +++ /dev/null @@ -1,507 +0,0 @@ -#!/usr/bin/env python -""" -TESTING SCRIPT FOR KOIOS_PYTHON USING PYTEST - -Main purpose of this script is to ensure basic functionality of the koios-python library and -its features are working with the current version of the Koios REST API. - -It will help test basic edge cases and ensure that the library is working as expected. - -To use this script, you must have pytest installed. - -You can install pytest using pip: -pip install pytest - -After you have downloaded/cloned this repo and installed pytest, you can run this script -First change directory to the folder containing this repo and script then simply run the -following command in your terminal: - -pytest test_koios.py - - -Watch the terminal for the results of the tests. :) - -""" - -import pytest -import koios_python - -# create a new url object with your own url or use koios.rest url by default -kp = koios_python.URLs() - - -# START OF TESTS FOR KOIOS_PYTHON - -############################################################################## -# STAKE ACCOUNT FUNCTIONS -############################################################################## - -# get account list -def test_get_account_list(): - - # get account list from mainnet server - account_list_mainnet = kp.get_account_list() - assert len(account_list_mainnet) > 0 - assert 'code' not in account_list_mainnet[0] - -# get account info -def test_get_account_info(): - - # get account info from mainnet server - account_info_mainnet = kp.get_account_info("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250") - if len(account_info_mainnet) > 0: - assert 'code' not in account_info_mainnet[0] - assert len(account_info_mainnet) > 0 - -# get account utxos -def test_get_account_utxos(): - - account_utxos_mainnet = kp.get_account_utxos("stake1u8yxtugdv63wxafy9d00nuz6hjyyp4qnggvc9a3vxh8yl0ckml2uz") - if len(account_utxos_mainnet) > 0: - assert 'code' not in account_utxos_mainnet[0] - assert len(account_utxos_mainnet) > 0 - -# get account info -def test_get_account_info_cached(): - - # get account info from mainnet server - account_info_cached_mainnet = kp.get_account_info_cached("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250") - if len(account_info_cached_mainnet) > 0: - assert 'code' not in account_info_cached_mainnet[0] - assert len(account_info_cached_mainnet) > 0 - -# get account rewards -def test_get_account_rewards(): - - # get account rewards from mainnet server - account_rewards_mainnet = kp.get_account_rewards("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250") - # get account rewards by epoch - account_rewards_mainnet_epoch = kp.get_account_rewards("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", 350) - # Check for error code in response and empty list - if len(account_rewards_mainnet) > 0 and len(account_rewards_mainnet_epoch) > 0: - assert 'code' not in account_rewards_mainnet[0] and 'code' not in account_rewards_mainnet_epoch[0] - assert len(account_rewards_mainnet) > 0 and len(account_rewards_mainnet_epoch) > 0 - -# get account updates -def test_get_account_updates(): - - account_updates_mainnet = kp.get_account_updates("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250") - if len(account_updates_mainnet) > 0: - assert 'code' not in account_updates_mainnet[0] - assert len(account_updates_mainnet) > 0 - -# get account addresses -def get_account_addresses(): - - account_addresses_mainnet = kp.get_account_updates(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"]) - if len(account_addresses_mainnet) > 0: - assert 'code' not in account_addresses_mainnet[0] - assert len(account_addresses_mainnet) > 0 - -# get account assets -def test_get_account_assets(): - - account_assets_mainnet = kp.get_account_assets("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250") - if len(account_assets_mainnet) > 0: - assert 'code' not in account_assets_mainnet[0] - -# get account history -def test_get_account_history(): - - account_history_mainnet = kp.get_account_history(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"]) - if len(account_history_mainnet) > 0: - assert 'code' not in account_history_mainnet[0] - - -############################################################################## -# ADDRESS FUNCTIONS -############################################################################## - -# get address info -def test_get_address_info(): - - address_info_mainnet = kp.get_address_info("addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g") - if len(address_info_mainnet) > 0: - assert 'code' not in address_info_mainnet[0] - -# get address transactions -def test_get_address_transactions(): - - address_txs_mainnet = kp.get_address_txs(["addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g", - "addr1qyfldpcvte8nkfpyv0jdc8e026cz5qedx7tajvupdu2724tlj8sypsq6p90hl40ya97xamkm9fwsppus2ru8zf6j8g9sm578cu"]) - if len(address_txs_mainnet) > 0: - assert 'code' not in address_txs_mainnet[0] - - address_txs_after_block = kp.get_address_txs("addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g",1) - if len(address_txs_after_block) > 0: - assert 'code' not in address_txs_after_block[0] - -# get address assets -def test_get_address_assets(): - - address_assets_mainnet = kp.get_address_assets("addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g") - if len(address_assets_mainnet) >0: - assert 'code' not in address_assets_mainnet[0] - -# Get a list of UTxO against input payment credential -def test_get_credential_utxos(): - - credentials_utxos_mainnet = kp.get_credential_utxos(["025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52",\ - "13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555"]) - if len(credentials_utxos_mainnet) > 0: - assert 'code' not in credentials_utxos_mainnet[0] - -# get payment credentials hash -def test_get_credentials(): - - credentials_mainnet = kp.get_credential_txs(['025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52','13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555']) - if len(credentials_mainnet) > 0: - assert 'code' not in credentials_mainnet[0] - - credentials_after_block_height = kp.get_credential_txs('025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52','13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555',after_block_height=6238675) - if len(credentials_after_block_height) > 0: - assert 'code' not in credentials_after_block_height[0] - - -############################################################################## -# ASSET FUNCTIONS -############################################################################## - -# get asset list of all native tokens -def test_get_asset_list(): - - asset_list_mainnet = kp.get_asset_list() - if len(asset_list_mainnet) > 0: - assert 'code' not in asset_list_mainnet[0] - -# Get a list of assets registered via token registry on Github -def test_get_asset_token_registry(): - - asset_token_registry = kp.get_asset_token_registry() - if len(asset_token_registry) > 0: - assert 'code' not in asset_token_registry[0] - -# get asset address list -def test_get_asset_address_list(): - - asset_addr_list_mainnet = kp.get_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b") - if len(asset_addr_list_mainnet) > 0: - assert 'code' not in asset_addr_list_mainnet[0] - -# get asset address nft address -def test_get_asset_nft_address(): - - asset_nft_address_mainnet = kp.get_asset_nft_address("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b") - if len(asset_nft_address_mainnet) > 0: - assert 'code' not in asset_nft_address_mainnet[0] - -# get asset info -def test_get_asset_info(): - - asset_info_mainnet = kp.get_asset_info("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b") - if len(asset_info_mainnet) > 0: - assert 'code' not in asset_info_mainnet[0] - -# get asset info list of assets (bulk) -def test_get_asset_info_bulk(): - - asset_info_bulk_mainnet = kp.get_asset_info_bulk(["750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b"],["1d7f33bd23d85e1a25d87d86fac4f199c3197a2f7afeb662a0f34e1e","776f726c646d6f62696c65746f6b656e"]) - if len(asset_info_bulk_mainnet) > 0: - assert 'code' not in asset_info_bulk_mainnet[0] - - asset_info_bulk_mainnet = kp.get_asset_info_bulk("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b") - if len(asset_info_bulk_mainnet) > 0: - assert 'code' not in asset_info_bulk_mainnet[0] - -# get asset history -def test_get_asset_history(): - - asset_history_mainnet = kp.get_asset_history("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b") - if len(asset_history_mainnet) > 0: - assert 'code' not in asset_history_mainnet[0] - -# get policy asset addresses -def test_get_policy_asset_addresses(): - - asset_policy_asset_addresses_mainnet = kp.get_policy_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "0-50") - if len(asset_policy_asset_addresses_mainnet) > 0: - assert 'code' not in asset_policy_asset_addresses_mainnet[0] - -# get policy asset information -def test_get_policy_asset_info(): - - asset_policy_asset_info_mainnet = kp.get_policy_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501") - if len(asset_policy_asset_info_mainnet) > 0: - assert 'code' not in asset_policy_asset_info_mainnet[0] - -def test_get_policy_asset_list(): - - asset_policy_asset_list_mainnet = kp.get_policy_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "0-99") - if len(asset_policy_asset_list_mainnet) > 0: - assert 'code' not in asset_policy_asset_list_mainnet[0] - -# get asset summary -def test_get_asset_summary(): - - asset_summary_mainnet = kp.get_asset_summary('750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', '424f4f4b') - if len(asset_summary_mainnet) > 0: - assert 'code' not in asset_summary_mainnet[0] - -# get asset transaction history -def test_get_asset_txs(): - - asset_txs_history_mainnet = kp.get_asset_txs('750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', '424f4f4b', 5000000, True, "0-99") - if len(asset_txs_history_mainnet) > 0: - assert 'code' not in asset_txs_history_mainnet[0] - - -############################################################################## -# BLOCK FUNCTIONS -############################################################################## - -# get list of blocks -def test_get_blocks(): - - blocks_mainnet_server = kp.get_blocks() - assert 'code' not in blocks_mainnet_server[0] - -# get block info -def test_get_block_info(): - - block_info_mainnet = kp.get_block_info(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30", - "60188a8dcb6db0d80628815be2cf626c4d17cb3e826cebfca84adaff93ad492a", - "c6646214a1f377aa461a0163c213fc6b86a559a2d6ebd647d54c4eb00aaab015"]) - if len(block_info_mainnet) > 0: - assert 'code' not in block_info_mainnet[0] - -# get block transactions -def test_get_block_txs(): - - block_txs_mainnet = kp.get_block_txs(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30"]) - if len(block_txs_mainnet) > 0: - assert 'code' not in block_txs_mainnet[0] - - -############################################################################## -# EPOCH FUNCTIONS -############################################################################## - -# get epoch info -def test_get_epoch_info(): - - epoch_info_mainnet = kp.get_epoch_info() - assert 'code' not in epoch_info_mainnet[0] - -# get epoch params -def test_get_epoch_params(): - - epoch_params_mainnet = kp.get_epoch_params() - assert 'code' not in epoch_params_mainnet[0] - -def test_get_epoch_block_protocols(): - - epoch_block_protocols_mainnet = kp.get_epoch_block_protocols() - assert 'code' not in epoch_block_protocols_mainnet[0] - - -############################################################################## -# NETWORK FUNCTIONS -############################################################################## - -# check tip -def test_get_tip(): - - tip_mainnet = kp.get_tip() - assert 'code' not in tip_mainnet[0] - -# check genesis info -def test_get_genesis(): - - genesis_mainnet = kp.get_genesis() - assert 'code' not in genesis_mainnet[0] - -def test_get_totals(): - - epoch_totals_mainnet = kp.get_totals() - assert 'code' not in epoch_totals_mainnet[0] - - -############################################################################## -# POOL FUNCTIONS -############################################################################## - -# get list of pools on the network -def test_get_pool_list(): - - pool_list_mainnet = kp.get_pool_list() - pool_list_mainnet_range = kp.get_pool_list('0-10') - if len(pool_list_mainnet) > 0 and len(pool_list_mainnet_range) > 0: - assert 'code' not in pool_list_mainnet[0] and 'code' not in pool_list_mainnet_range[0] - -# get pool info -def test_get_pool_info(): - - pool_info_mainnet = kp.get_pool_info(["pool100wj94uzf54vup2hdzk0afng4dhjaqggt7j434mtgm8v2gfvfgp", - "pool102s2nqtea2hf5q0s4amj0evysmfnhrn4apyyhd4azcmsclzm96m", - "pool102vsulhfx8ua2j9fwl2u7gv57fhhutc3tp6juzaefgrn7ae35wm"]) - if len(pool_info_mainnet) > 0: - assert 'code' not in pool_info_mainnet[0] - assert 'code' not in pool_info_mainnet[0] - -# get pool stake snapshot -def test_get_pool_stake_snapshot(): - - stake_snapshot_mainnet = kp.get_pool_stake_snapshot("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - if len(stake_snapshot_mainnet) > 0: - assert 'code' not in stake_snapshot_mainnet[0] - -# get pool delegator information -def test_get_pool_delegators(): - - delegator_info_mainnet = kp.get_pool_delegators("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - if len(delegator_info_mainnet) > 0: - assert 'code' not in delegator_info_mainnet[0] - -# get pool delegator history -def test_get_pool_delegators_history(): - - delegator_history_mainnet = kp.get_pool_delegators_history("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - if len(delegator_history_mainnet) > 0: - assert 'code' not in delegator_history_mainnet[0] - -# get pool blocks -def test_get_pool_blocks(): - - pool_blocks_mainnet = kp.get_pool_blocks("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - pool_blocks_mainnet_epoch = kp.get_pool_blocks("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc", 350) - if len(pool_blocks_mainnet) > 0 and len(pool_blocks_mainnet_epoch) > 0: - assert 'code' not in pool_blocks_mainnet[0] and 'code' not in pool_blocks_mainnet_epoch[0] - -# get pool history -def test_get_pool_history(): - - pool_history_mainnet = kp.get_pool_history("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - pool_history_mainnet_epoch = kp.get_pool_history("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc", 350) - if len(pool_history_mainnet) > 0 and len(pool_history_mainnet_epoch) > 0: - assert 'code' not in pool_history_mainnet[0] and 'code' not in pool_history_mainnet_epoch[0] - -# get pool updates -def test_get_pool_updates(): - - pool_updates_mainnet = kp.get_pool_updates() - pool_updates_mainnet_pool = kp.get_pool_updates("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - if len(pool_updates_mainnet) > 0 and len(pool_updates_mainnet_pool) > 0: - assert 'code' not in pool_updates_mainnet[0] and 'code' not in pool_updates_mainnet_pool[0] - -# get pool relays -def test_get_pool_relays(): - - pool_relays_mainnet = kp.get_pool_relays() - pool_relays_mainnet_range = kp.get_pool_relays('0-70') - if len(pool_relays_mainnet) > 0 and len(pool_relays_mainnet_range) > 0: - assert 'code' not in pool_relays_mainnet[0] and 'code' not in pool_relays_mainnet_range[0] - -# get pool metadata -def test_get_pool_metadata(): - - pool_metadata_mainnet = kp.get_pool_metadata() - pool_metadata_mainnet_pool = kp.get_pool_metadata("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - pool_metadata_mainnet_pool_list = kp.get_pool_metadata(["pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc", - "pool102s2nqtea2hf5q0s4amj0evysmfnhrn4apyyhd4azcmsclzm96m"]) - if len(pool_metadata_mainnet) > 0 and len(pool_metadata_mainnet_pool) > 0 and len(pool_metadata_mainnet_pool_list) > 0: - assert 'code' not in pool_metadata_mainnet[0] and 'code' not in pool_metadata_mainnet_pool[0] and 'code' not in pool_metadata_mainnet_pool_list[0] - - -############################################################################## -# SCRIPT FUNCTIONS -############################################################################## - -# get list of native scripts on the network -def test_get_native_script_list(): - - script_list_mainnet = kp.get_native_script_list() - script_list_mainnet_range = kp.get_native_script_list('0-10') - if len(script_list_mainnet) > 0 and len(script_list_mainnet_range) > 0: - assert 'code' not in script_list_mainnet[0] and 'code' not in script_list_mainnet_range[0] - -# get plutus script list -def test_get_plutus_script_list(): - - script_list_mainnet = kp.get_plutus_script_list() - script_list_mainnet_range = kp.get_plutus_script_list('0-10') - if len(script_list_mainnet) > 0 and len(script_list_mainnet_range) > 0: - assert 'code' not in script_list_mainnet[0] and 'code' not in script_list_mainnet_range[0] - -# get list of all redeemers for a given script hash -def test_get_script_redeemers(): - - script_redeemers_mainnet = kp.get_script_redeemers('d8480dc869b94b80e81ec91b0abe307279311fe0e7001a9488f61ff8') - if len(script_redeemers_mainnet) > 0: - assert 'code' not in script_redeemers_mainnet[0] - -def test_get_datum_info(): - - datum_info = kp.get_datum_info('818ee3db3bbbd04f9f2ce21778cac3ac605802a4fcb00c8b3a58ee2dafc17d46', - "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0") - if len(datum_info) > 0: - assert 'code' not in datum_info[0] - - -############################################################################## -# TRANSACTION FUNCTIONS -############################################################################## - -# get transaction(s) info -def test_tx_info(): - - tx_info_mainnet = kp.get_tx_info('0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94') - tx_info_mainnet_list = kp.get_tx_info(['0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94', - 'f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e']) - if len(tx_info_mainnet) > 0 and len(tx_info_mainnet_list) > 0: - assert 'code' not in tx_info_mainnet[0] and 'code' not in tx_info_mainnet_list[0] - -# get transaction(s) utxos -def test_get_tx_utxos(): - - tx_utxo_mainnet = kp.get_tx_utxos('0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94') - tx_utxo_mainnet_list = kp.get_tx_utxos(['0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94', - 'f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e']) - if len(tx_utxo_mainnet) > 0 and len(tx_utxo_mainnet_list) > 0: - assert 'code' not in tx_utxo_mainnet[0] and 'code' not in tx_utxo_mainnet_list[0] - -# get transaction(s) metadata -def test_get_tx_metadata(): - - tx_metadata_mainnet = kp.get_tx_metadata('0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94') - tx_metadata_mainnet_list = kp.get_tx_metadata(['0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94', - 'f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e']) - if len(tx_metadata_mainnet) > 0 and len(tx_metadata_mainnet_list) > 0: - assert 'code' not in tx_metadata_mainnet[0] and 'code' not in tx_metadata_mainnet_list[0] - -# get transaction(s) metadata labels -def test_get_tx_metalabels(): - - tx_metalables_mainnet = kp.get_tx_metalabels('0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94') - tx_metalables_mainnet_list = kp.get_tx_metalabels(['0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94', - 'f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e']) - if len(tx_metalables_mainnet) > 0 and len(tx_metalables_mainnet_list) > 0: - assert 'code' not in tx_metalables_mainnet[0] and 'code' not in tx_metalables_mainnet_list[0] - -# # NOT FINISHED -# # submit_tx signed cbor -# # def test_submit_tx(): - -# # tx_submit = koios_python.submit_tx("file") -# # assert 'code' not in tx_submit[0] - -# get tx status -def test_get_tx_status(): - - tx_status_mainnet = kp.get_tx_status('0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94') - tx_status_mainnet_list = kp.get_tx_status(['0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94', - 'f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e']) - if len(tx_status_mainnet) > 0 and len(tx_status_mainnet_list) > 0: - assert 'code' not in tx_status_mainnet[0] and 'code' not in tx_status_mainnet_list[0] - diff --git a/test_koios_nets.py b/test_koios_nets.py deleted file mode 100644 index ab549e8..0000000 --- a/test_koios_nets.py +++ /dev/null @@ -1,665 +0,0 @@ -#!/usr/bin/env python -""" -TESTING SCRIPT FOR KOIOS_PYTHON USING PYTEST (MAINNET & TESTNET) - -Main purpose of this script is to ensure basic functionality of the koios-python library and -its features are working with the current version of the Koios REST API. - -It will help test basic edge cases and ensure that the library is working as expected. - -To use this script, you must have pytest installed. - -You can install pytest using pip: -pip install pytest - -After you have downloaded/cloned this repo and installed pytest, you can run this script -First change directory to the folder containing this repo and script then simply run the -following command in your terminal: - -pytest test_koios_nets.py - -Watch the terminal for the results of the tests. :) - -""" - -import pytest -import koios_python as kp - -# create a new url object with your own url or use koios.rest url by default -kp_mainnet_server = kp.URLs() - -# Koios server switching to testnet default is mainnet and this feature only works for standard Koios rest api server api.koios.rest/api/v0 -kp_testnet_server = kp.URLs( network='testnet') - - -# test network switching by trying to switch back to mainnet -def test_network_switch(): - - kp_test = kp.URLs(network='testnet') - genesis_info_testnet = kp_test.get_genesis() - # check if we are on testnet - assert genesis_info_testnet[0]['networkid'] == 'Testnet' - # switch back to mainnet - kp_test = kp.URLs(network='mainnet') - genesis_info_mainnet = kp_test.get_genesis() - # check if we are on mainnet - assert genesis_info_mainnet[0]['networkid'] == 'Mainnet' - - -############################################################################## -# ACCOUNT FUNCTIONS - -# 1- get account list -def test_get_account_list(): - - # get account list from mainnet server - account_list_mainnet = kp_mainnet_server.get_account_list() - assert len(account_list_mainnet) > 0 - assert 'code' not in account_list_mainnet[0] - - # get account list from testnet server - account_list_testnet = kp_testnet_server.get_account_list() - assert len(account_list_testnet) > 0 - assert 'code' not in account_list_testnet[0] - -# 2- get account info -def test_get_account_info(): - - # get account info from mainnet server - account_info_mainnet = kp_mainnet_server.get_account_info("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250") - if len(account_info_mainnet) > 0: - assert 'code' not in account_info_mainnet[0] - assert len(account_info_mainnet) > 0 - - # get account info from testnet server - account_info_testnet = kp_testnet_server.get_account_info("stake_test1uqrw9tjymlm8wrwq7jk68n6v7fs9qz8z0tkdkve26dylmfc2ux2hj") - if len(account_info_testnet) > 0: - assert 'code' not in account_info_testnet[0] - assert len(account_info_testnet) > 0 - -# 3- get account rewards -def test_get_account_rewards(): - - # get account rewards from mainnet server - account_rewards_mainnet = kp_mainnet_server.get_account_rewards("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250") - # get account rewards by epoch - account_rewards_mainnet_epoch = kp_mainnet_server.get_account_rewards("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", 350) - # Check for error code in response and empty list - if len(account_rewards_mainnet) > 0 and len(account_rewards_mainnet_epoch) > 0: - assert 'code' not in account_rewards_mainnet[0] and 'code' not in account_rewards_mainnet_epoch[0] - assert len(account_rewards_mainnet) > 0 and len(account_rewards_mainnet_epoch) > 0 - - # get account rewards from testnet server - account_rewards_testnet = kp_testnet_server.get_account_rewards("stake_test1uqrw9tjymlm8wrwq7jk68n6v7fs9qz8z0tkdkve26dylmfc2ux2hj") - # get account rewards by epoch - account_rewards_testnet_epoch = kp_testnet_server.get_account_rewards("stake_test1uqrw9tjymlm8wrwq7jk68n6v7fs9qz8z0tkdkve26dylmfc2ux2hj", 200) - # Check for error code in response and empty list - if len(account_rewards_testnet) > 0 and len(account_rewards_testnet_epoch) > 0: - assert 'code' not in account_rewards_testnet[0] and 'code' not in account_rewards_testnet_epoch[0] - -# 4- get account updates -def test_get_account_updates(): - - account_updates_mainnet = kp_mainnet_server.get_account_updates("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250") - if len(account_updates_mainnet) > 0: - assert 'code' not in account_updates_mainnet[0] - assert len(account_updates_mainnet) > 0 - - account_updates_testnet = kp_testnet_server.get_account_updates("stake_test1uqrw9tjymlm8wrwq7jk68n6v7fs9qz8z0tkdkve26dylmfc2ux2hj") - if len(account_updates_testnet) > 0: - assert 'code' not in account_updates_testnet[0] - -# 5- get account addresses -def test_get_account_addresses(): - - account_assets_mainnet = kp_mainnet_server.get_account_addresses("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250") - if len(account_assets_mainnet) > 0: - assert 'code' not in account_assets_mainnet[0] - - account_assets_testnet = kp_testnet_server.get_account_addresses(["stake_test1uqrw9tjymlm8wrwq7jk68n6v7fs9qz8z0tkdkve26dylmfc2ux2hj", - "stake_test1uq7g7kqeucnqfweqzgxk3dw34e8zg4swnc7nagysug2mm4cm77jrx"]) - if len(account_assets_testnet) > 0: - assert 'code' not in account_assets_testnet[0] - - -# 6- get account assets -def test_get_account_assets(): - - account_assets_mainnet = kp_mainnet_server.get_account_assets("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250") - if len(account_assets_mainnet) > 0: - assert 'code' not in account_assets_mainnet[0] - - account_assets_testnet = kp_testnet_server.get_account_assets(["stake_test1uqrw9tjymlm8wrwq7jk68n6v7fs9qz8z0tkdkve26dylmfc2ux2hj", - "stake_test1uq7g7kqeucnqfweqzgxk3dw34e8zg4swnc7nagysug2mm4cm77jrx"]) - if len(account_assets_testnet) > 0: - assert 'code' not in account_assets_testnet[0] - - -# 7- get account history -def test_get_account_history(): - - account_history_mainnet = kp_mainnet_server.get_account_history(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", - "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"]) - if len(account_history_mainnet) > 0: - assert 'code' not in account_history_mainnet[0] - - account_history_testnet = kp_testnet_server.get_account_history(["stake_test1uqrw9tjymlm8wrwq7jk68n6v7fs9qz8z0tkdkve26dylmfc2ux2hj", - "stake_test1uq7g7kqeucnqfweqzgxk3dw34e8zg4swnc7nagysug2mm4cm77jrx"]) - if len(account_history_testnet) > 0: - assert 'code' not in account_history_testnet[0] - -############################################################################## -# ADDRESS FUNCTIONS - -# 1- get address info -def test_get_address_info(): - - address_info_mainnet = kp_mainnet_server.get_address_info("addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g") - if len(address_info_mainnet) > 0: - assert 'code' not in address_info_mainnet[0] - - address_info_testnet = kp_testnet_server.get_address_info("addr_test1qzx9hu8j4ah3auytk0mwcupd69hpc52t0cw39a65ndrah86djs784u92a3m5w475w3w35tyd6v3qumkze80j8a6h5tuqq5xe8y") - if len(address_info_testnet) > 0: - assert 'code' not in address_info_testnet[0] - -# 2- get address transactions -def test_get_address_transactions(): - - address_txs_mainnet = kp_mainnet_server.get_address_txs(["addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g", - "addr1qyfldpcvte8nkfpyv0jdc8e026cz5qedx7tajvupdu2724tlj8sypsq6p90hl40ya97xamkm9fwsppus2ru8zf6j8g9sm578cu"]) - if len(address_txs_mainnet) > 0: - assert 'code' not in address_txs_mainnet[0] - - address_txs_testnet = kp_testnet_server.get_address_txs(["addr_test1qzx9hu8j4ah3auytk0mwcupd69hpc52t0cw39a65ndrah86djs784u92a3m5w475w3w35tyd6v3qumkze80j8a6h5tuqq5xe8y", - "addr_test1qrk7920v35zukhcch4kyydy6rxnhqdcvetkvngeqrvtgavw8tpzdklse3kwer7urhrlfg962m9fc8cznfcdpka5pd07sgf8n0w"]) - if len(address_txs_testnet) > 0: - assert 'code' not in address_txs_testnet[0] - - address_txs_after_block = kp_mainnet_server.get_address_txs("addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g",1) - if len(address_txs_after_block) > 0: - assert 'code' not in address_txs_after_block[0] - -# 3- get address assets -def test_get_address_assets(): - - - address_assets_mainnet = kp_mainnet_server.get_address_assets("addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g") - if len(address_assets_mainnet) >0: - assert 'code' not in address_assets_mainnet[0] - - address_assets_testnet = kp_testnet_server.get_address_assets("addr_test1qrk7920v35zukhcch4kyydy6rxnhqdcvetkvngeqrvtgavw8tpzdklse3kwer7urhrlfg962m9fc8cznfcdpka5pd07sgf8n0w") - if len(address_assets_testnet) >0: - assert 'code' not in address_assets_testnet[0] - -# 4- get payment credentials hash -def test_get_credentials(): - - - credentials_mainnet = kp_mainnet_server.get_credential_txs('025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52') - if len(credentials_mainnet) > 0: - assert 'code' not in credentials_mainnet[0] - - credentials_testnet = kp_testnet_server.get_credential_txs('00003fac863dc2267d0cd90768c4af653572d719a79ca3b01957fa79') - if len(credentials_testnet) > 0: - assert 'code' not in credentials_testnet[0] - - credentials_after_block = kp_mainnet_server.get_credential_txs('025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52',6238675) - if len(credentials_after_block) > 0: - assert 'code' not in credentials_after_block[0] - - credentials_after_block_testnet = kp_testnet_server.get_credential_txs('00003fac863dc2267d0cd90768c4af653572d719a79ca3b01957fa79',2342661) - if len(credentials_after_block_testnet) > 0: - assert 'code' not in credentials_after_block_testnet[0] - -############################################################################## -# ASSET FUNCTIONS - -# 1- get asset list of all native tokens -def test_get_asset_list(): - - - asset_list_mainnet = kp_mainnet_server.get_asset_list() - if len(asset_list_mainnet) > 0: - assert 'code' not in asset_list_mainnet[0] - - asset_list_testnet = kp_testnet_server.get_asset_list() - if len(asset_list_testnet) > 0: - assert 'code' not in asset_list_testnet[0] - - -# 2- get asset address list -def test_get_asset_address_list(): - - - asset_addr_list_mainnet = kp_mainnet_server.get_asset_address_list("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b") - if len(asset_addr_list_mainnet) > 0: - assert 'code' not in asset_addr_list_mainnet[0] - - asset_addr_list_testnet = kp_testnet_server.get_asset_address_list("000327a9e427a3a3256eb6212ae26b7f53f7969b8e62d37ea9138a7b",54735465737431) - if len(asset_addr_list_testnet) > 0: - assert 'code' not in asset_addr_list_testnet[0] - - -# 3- get asset info -def test_get_asset_info(): - - - asset_info_mainnet = kp_mainnet_server.get_asset_info("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b") - if len(asset_info_mainnet) > 0: - assert 'code' not in asset_info_mainnet[0] - - asset_info_testnet = kp_testnet_server.get_asset_info("000327a9e427a3a3256eb6212ae26b7f53f7969b8e62d37ea9138a7b",54735465737431) - if len(asset_info_testnet) > 0: - assert 'code' not in asset_info_testnet[0] - -# 4- get asset history -def test_get_asset_history(): - - asset_history_mainnet = kp_mainnet_server.get_asset_history("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b") - if len(asset_history_mainnet) > 0: - assert 'code' not in asset_history_mainnet[0] - - asset_history_testnet = kp_testnet_server.get_asset_history("000327a9e427a3a3256eb6212ae26b7f53f7969b8e62d37ea9138a7b",54735465737431) - if len(asset_history_testnet) > 0: - assert 'code' not in asset_history_testnet[0] - -# 5- get asset policy info -def test_get_asset_policy_info(): - - - asset_policy_info_mainnet = kp_mainnet_server.get_asset_policy_info("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501") - if len(asset_policy_info_mainnet) > 0: - assert 'code' not in asset_policy_info_mainnet[0] - - asset_policy_info_testnet = kp_testnet_server.get_asset_policy_info("000327a9e427a3a3256eb6212ae26b7f53f7969b8e62d37ea9138a7b") - if len(asset_policy_info_testnet) > 0: - assert 'code' not in asset_policy_info_testnet[0] - -# 6- get asset summary -def test_get_asset_summary(): - - - asset_summary_mainnet = kp_mainnet_server.get_asset_summary('750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', '424f4f4b') - if len(asset_summary_mainnet) > 0: - assert 'code' not in asset_summary_mainnet[0] - - asset_summary_testnet = kp_testnet_server.get_asset_summary("000327a9e427a3a3256eb6212ae26b7f53f7969b8e62d37ea9138a7b",54735465737431) - if len(asset_summary_testnet) > 0: - assert 'code' not in asset_summary_testnet[0] - -# 7- get asset transaction history -def test_get_asset_txs_history(): - - - asset_txs_history_mainnet = kp_mainnet_server.get_asset_txs('750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501','424f4f4b') - if len(asset_txs_history_mainnet) > 0: - assert 'code' not in asset_txs_history_mainnet[0] - - asset_txs_history_testnet = kp_testnet_server.get_asset_txs('000327a9e427a3a3256eb6212ae26b7f53f7969b8e62d37ea9138a7b',54735465737431) - if len(asset_txs_history_testnet) > 0: - assert 'code' not in asset_txs_history_testnet[0] - -############################################################################## - -# BLOCK FUNCTIONS - -# 1- get list of blocks -def test_get_blocks(): - - blocks_mainnet_server = kp_mainnet_server.get_blocks() - assert 'code' not in blocks_mainnet_server[0] - - blocks_testnet_server = kp_testnet_server.get_blocks() - assert 'code' not in blocks_testnet_server[0] - -# 2- get block info -def test_get_block_info(): - - - block_info_mainnet = kp_mainnet_server.get_block_info(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30", - "60188a8dcb6db0d80628815be2cf626c4d17cb3e826cebfca84adaff93ad492a", - "c6646214a1f377aa461a0163c213fc6b86a559a2d6ebd647d54c4eb00aaab015"]) - if len(block_info_mainnet) > 0: - assert 'code' not in block_info_mainnet[0] - - block_info_testnet = kp_testnet_server.get_block_info(["f75fea40852ed7d7f539d008e45255725daef8553ae7162750836f279570813a", - "ff9f0c7fb1136de2cd6f10c9a140af2887f1d3614cc949bfeb262266d4c202b7", - "5ef645ee519cde94a82f0aa880048c37978374f248f11e408ac0571a9054d9d3"]) - if len(block_info_testnet) > 0: - assert 'code' not in block_info_testnet[0] - - -# 3- get block transactions -def test_get_block_txs(): - - - block_txs_mainnet = kp_mainnet_server.get_block_txs(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30"]) - if len(block_txs_mainnet) > 0: - assert 'code' not in block_txs_mainnet[0] - - block_txs_testnet = kp_testnet_server.get_block_txs(["f75fea40852ed7d7f539d008e45255725daef8553ae7162750836f279570813a", - "ff9f0c7fb1136de2cd6f10c9a140af2887f1d3614cc949bfeb262266d4c202b7", - "5ef645ee519cde94a82f0aa880048c37978374f248f11e408ac0571a9054d9d3"]) - if len(block_txs_testnet) > 0: - assert 'code' not in block_txs_testnet[0] - -############################################################################## -# EPOCH FUNCTIONS - -# 1- get epoch info -def test_get_epoch_info(): - - epoch_info_mainnet = kp_mainnet_server.get_epoch_info() - assert 'code' not in epoch_info_mainnet[0] - - epoch_info_testnet = kp_testnet_server.get_epoch_info() - assert 'code' not in epoch_info_testnet[0] - -# 2- get epoch params -def test_get_epoch_params(): - - epoch_params_mainnet = kp_mainnet_server.get_epoch_params() - assert 'code' not in epoch_params_mainnet[0] - - epoch_params_testnet = kp_testnet_server.get_epoch_params() - assert 'code' not in epoch_params_testnet[0] - - - -############################################################################## -# NETWORK FUNCTIONS - -# 1- check tip -def test_get_tip(): - - tip_mainnet = kp_mainnet_server.get_tip() - assert 'code' not in tip_mainnet[0] - - tip_testnet = kp_testnet_server.get_tip() - assert 'code' not in tip_testnet[0] - - -# 2- check genesis info -def test_get_genesis(): - - genesis_mainnet = kp_mainnet_server.get_genesis() - assert 'code' not in genesis_mainnet[0] - - genesis_testnet = kp_testnet_server.get_genesis() - assert 'code' not in genesis_testnet[0] - -# 3- check total info -def test_get_totals(): - - epoch_totals_mainnet = kp_mainnet_server.get_totals() - assert 'code' not in epoch_totals_mainnet[0] - - epoch_totals_testnet = kp_testnet_server.get_totals() - assert 'code' not in epoch_totals_testnet[0] - - -############################################################################## -# POOL FUNCTIONS - -# 1- get list of pools on the network -def test_get_pool_list(): - - pool_list_mainnet = kp_mainnet_server.get_pool_list() - pool_list_mainnet_range = kp_mainnet_server.get_pool_list('0-10') - if len(pool_list_mainnet) > 0 and len(pool_list_mainnet_range) > 0: - assert 'code' not in pool_list_mainnet[0] and 'code' not in pool_list_mainnet_range[0] - - pool_list_testnet = kp_testnet_server.get_pool_list() - pool_list_testnet_range = kp_testnet_server.get_pool_list('0-10') - if len(pool_list_testnet) > 0 and len(pool_list_testnet_range) > 0: - assert 'code' not in pool_list_testnet[0] and 'code' not in pool_list_testnet_range[0] - - -# 2- get pool info -def test_get_pool_info(): - - pool_info_mainnet = kp_mainnet_server.get_pool_info(["pool100wj94uzf54vup2hdzk0afng4dhjaqggt7j434mtgm8v2gfvfgp", - "pool102s2nqtea2hf5q0s4amj0evysmfnhrn4apyyhd4azcmsclzm96m", - "pool102vsulhfx8ua2j9fwl2u7gv57fhhutc3tp6juzaefgrn7ae35wm"]) - if len(pool_info_mainnet) > 0: - assert 'code' not in pool_info_mainnet[0] - assert 'code' not in pool_info_mainnet[0] - - pool_info_testnet = kp_testnet_server.get_pool_info(["pool102llj7e7a0mmxssjvjkv2d6lppuh6cz6q9xwc3tsksn0jqwz9eh", - "pool102x86jz7uus6p6mlw02fdw2s805kng7g6ujs6s342t5msk36tch", - "pool103qt58f9xlsr7y9anz3lnyq6cph4xh2yr4qrrtc356ldzz6ktqz"]) - if len(pool_info_testnet) > 0: - assert 'code' not in pool_info_testnet[0] - - -# 3- get pool stake snapshot -def test_get_pool_stake_snapshot(): - - stake_snapshot_mainnet = kp_mainnet_server.get_pool_stake_snapshot("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - if len(stake_snapshot_mainnet) > 0: - assert 'code' not in stake_snapshot_mainnet[0] - - stake_snapshot_testnet = kp_testnet_server.get_pool_stake_snapshot("pool102llj7e7a0mmxssjvjkv2d6lppuh6cz6q9xwc3tsksn0jqwz9eh") - if len(stake_snapshot_testnet) > 0: - assert 'code' not in stake_snapshot_testnet[0] - -# 4- get pool delegator information -def test_get_pool_delegators(): - - delegator_info_mainnet = kp_mainnet_server.get_pool_delegators("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - if len(delegator_info_mainnet) > 0: - assert 'code' not in delegator_info_mainnet[0] - - delegator_info_testnet = kp_testnet_server.get_pool_delegators("pool102llj7e7a0mmxssjvjkv2d6lppuh6cz6q9xwc3tsksn0jqwz9eh") - if len(delegator_info_testnet) > 0: - assert 'code' not in delegator_info_testnet[0] - - -# 5- get pool delegator history -def test_get_pool_delegators_history(): - - delegator_history_mainnet = kp_mainnet_server.get_pool_delegators_history("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - if len(delegator_history_mainnet) > 0: - assert 'code' not in delegator_history_mainnet[0] - - delegator_history_testnet = kp_testnet_server.get_pool_delegators_history("pool102llj7e7a0mmxssjvjkv2d6lppuh6cz6q9xwc3tsksn0jqwz9eh") - if len(delegator_history_testnet) > 0: - assert 'code' not in delegator_history_testnet[0] - -# 6- get pool blocks -def test_get_pool_blocks(): - - pool_blocks_mainnet = kp_mainnet_server.get_pool_blocks("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - pool_blocks_mainnet_epoch = kp_mainnet_server.get_pool_blocks("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc", 350) - if len(pool_blocks_mainnet) > 0 and len(pool_blocks_mainnet_epoch) > 0: - assert 'code' not in pool_blocks_mainnet[0] and 'code' not in pool_blocks_mainnet_epoch[0] - - pool_blocks_testnet = kp_testnet_server.get_pool_blocks("pool102llj7e7a0mmxssjvjkv2d6lppuh6cz6q9xwc3tsksn0jqwz9eh") - pool_blocks_testnet_epoch = kp_testnet_server.get_pool_blocks("pool102llj7e7a0mmxssjvjkv2d6lppuh6cz6q9xwc3tsksn0jqwz9eh", 185) - if len(pool_blocks_testnet) > 0 and len(pool_blocks_testnet_epoch) > 0: - assert 'code' not in pool_blocks_testnet[0] - -# 7- get pool history -def test_get_pool_history(): - - pool_history_mainnet = kp_mainnet_server.get_pool_history("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - pool_history_mainnet_epoch = kp_mainnet_server.get_pool_history("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc", 350) - if len(pool_history_mainnet) > 0 and len(pool_history_mainnet_epoch) > 0: - assert 'code' not in pool_history_mainnet[0] and 'code' not in pool_history_mainnet_epoch[0] - - pool_history_testnet = kp_testnet_server.get_pool_history("pool102llj7e7a0mmxssjvjkv2d6lppuh6cz6q9xwc3tsksn0jqwz9eh") - pool_history_testnet_epoch = kp_testnet_server.get_pool_history("pool102llj7e7a0mmxssjvjkv2d6lppuh6cz6q9xwc3tsksn0jqwz9eh", 185) - if len(pool_history_testnet) > 0 and len(pool_history_testnet_epoch) > 0: - assert 'code' not in pool_history_testnet[0] and 'code' not in pool_history_testnet_epoch[0] - -# 8- get pool updates -def test_get_pool_updates(): - - pool_updates_mainnet = kp_mainnet_server.get_pool_updates() - pool_updates_mainnet_pool = kp_mainnet_server.get_pool_updates("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - if len(pool_updates_mainnet) > 0 and len(pool_updates_mainnet_pool) > 0: - assert 'code' not in pool_updates_mainnet[0] and 'code' not in pool_updates_mainnet_pool[0] - - pool_updates_testnet = kp_testnet_server.get_pool_updates() - pool_updates_testnet_pool = kp_testnet_server.get_pool_updates("pool102llj7e7a0mmxssjvjkv2d6lppuh6cz6q9xwc3tsksn0jqwz9eh") - if len(pool_updates_testnet) > 0 and len(pool_updates_testnet_pool) > 0: - assert 'code' not in pool_updates_testnet[0] and 'code' not in pool_updates_testnet_pool[0] - -# 9- get pool relays -def test_get_pool_relays(): - - pool_relays_mainnet = kp_mainnet_server.get_pool_relays() - pool_relays_mainnet_range = kp_mainnet_server.get_pool_relays('0-70') - if len(pool_relays_mainnet) > 0 and len(pool_relays_mainnet_range) > 0: - assert 'code' not in pool_relays_mainnet[0] and 'code' not in pool_relays_mainnet_range[0] - - pool_relays_testnet = kp_testnet_server.get_pool_relays() - pool_relays_testnet_range = kp_testnet_server.get_pool_relays('0-70') - if len(pool_relays_testnet) > 0 and len(pool_relays_testnet_range) > 0: - assert 'code' not in pool_relays_testnet[0] and 'code' not in pool_relays_testnet_range[0] - -# 10- get pool metadata -def test_get_pool_metadata(): - - pool_metadata_mainnet = kp_mainnet_server.get_pool_metadata() - pool_metadata_mainnet_pool = kp_mainnet_server.get_pool_metadata("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc") - pool_metadata_mainnet_pool_list = kp_mainnet_server.get_pool_metadata(["pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc", - "pool102s2nqtea2hf5q0s4amj0evysmfnhrn4apyyhd4azcmsclzm96m"]) - if len(pool_metadata_mainnet) > 0 and len(pool_metadata_mainnet_pool) > 0 and len(pool_metadata_mainnet_pool_list) > 0: - assert 'code' not in pool_metadata_mainnet[0] and 'code' not in pool_metadata_mainnet_pool[0] and 'code' not in pool_metadata_mainnet_pool_list[0] - - pool_metadata_testnet = kp_testnet_server.get_pool_metadata() - pool_metadata_testnet_pool = kp_testnet_server.get_pool_metadata("pool102llj7e7a0mmxssjvjkv2d6lppuh6cz6q9xwc3tsksn0jqwz9eh") - pool_metadata_testnet_pool_list = kp_testnet_server.get_pool_metadata(["pool102llj7e7a0mmxssjvjkv2d6lppuh6cz6q9xwc3tsksn0jqwz9eh", - "pool102x86jz7uus6p6mlw02fdw2s805kng7g6ujs6s342t5msk36tch"]) - if len(pool_metadata_testnet) > 0 and len(pool_metadata_testnet_pool) > 0 and len(pool_metadata_testnet_pool_list) > 0: - assert 'code' not in pool_metadata_testnet[0] and 'code' not in pool_metadata_testnet_pool[0] and 'code' not in pool_metadata_testnet_pool_list[0] - - -############################################################################## -# SCRIPT FUNCTIONS - -# 1- get list of native scripts on the network -def test_get_native_script_list(): - - script_list_mainnet = kp_mainnet_server.get_native_script_list() - script_list_mainnet_range = kp_mainnet_server.get_native_script_list('0-10') - if len(script_list_mainnet) > 0 and len(script_list_mainnet_range) > 0: - assert 'code' not in script_list_mainnet[0] and 'code' not in script_list_mainnet_range[0] - - script_list_testnet = kp_testnet_server.get_native_script_list() - script_list_testnet_range = kp_testnet_server.get_native_script_list('0-10') - if len(script_list_testnet) > 0 and len(script_list_testnet_range) > 0: - assert 'code' not in script_list_testnet[0] and 'code' not in script_list_testnet_range[0] - -# 2- get plutus script list -def test_get_plutus_script_list(): - - script_list_mainnet = kp_mainnet_server.get_plutus_script_list() - script_list_mainnet_range = kp_mainnet_server.get_plutus_script_list('0-10') - if len(script_list_mainnet) > 0 and len(script_list_mainnet_range) > 0: - assert 'code' not in script_list_mainnet[0] and 'code' not in script_list_mainnet_range[0] - - script_list_testnet = kp_testnet_server.get_plutus_script_list() - script_list_testnet_range = kp_testnet_server.get_plutus_script_list('0-10') - if len(script_list_testnet) > 0 and len(script_list_testnet_range) > 0: - assert 'code' not in script_list_testnet[0] and 'code' not in script_list_testnet_range[0] - - -# 3- get list of all redeemers for a given script hash -def test_get_script_redeemers(): - - script_redeemers_mainnet = kp_mainnet_server.get_script_redeemers('d8480dc869b94b80e81ec91b0abe307279311fe0e7001a9488f61ff8') - if len(script_redeemers_mainnet) > 0: - assert 'code' not in script_redeemers_mainnet[0] - - script_redeemers_testnet = kp_testnet_server.get_script_redeemers('9a3910acc1e1d49a25eb5798d987739a63f65eb48a78462ffae21e6f') - if len(script_redeemers_testnet) > 0: - assert 'code' not in script_redeemers_testnet[0] - - -############################################################################## -# TRANSACTION FUNCTIONS - -# 1- get transaction(s) info -def test_tx_info(): - - tx_info_mainnet = kp_mainnet_server.get_tx_info('0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94') - tx_info_mainnet_list = kp_mainnet_server.get_tx_info(['0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94', - 'f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e']) - if len(tx_info_mainnet) > 0 and len(tx_info_mainnet_list) > 0: - assert 'code' not in tx_info_mainnet[0] and 'code' not in tx_info_mainnet_list[0] - - tx_info_testnet = kp_testnet_server.get_tx_info('928052b80bfc23801da525a6bf8f805da36f22fa0fd5fec2198b0746eb82b72b') - tx_info_testnet_list = kp_testnet_server.get_tx_info(['928052b80bfc23801da525a6bf8f805da36f22fa0fd5fec2198b0746eb82b72b', - 'c7e96e4cd6aa9e3afbc7b32d1e8023daf4197931f1ea61d2bdfc7a2e5e017cf1']) - if len(tx_info_testnet) > 0 and len(tx_info_testnet_list) > 0: - assert 'code' not in tx_info_testnet[0] and 'code' not in tx_info_testnet_list[0] - -# 2- get transaction(s) utxos -def test_get_tx_utxos(): - - tx_utxo_mainnet = kp_mainnet_server.get_tx_utxos('0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94') - tx_utxo_mainnet_list = kp_mainnet_server.get_tx_utxos(['0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94', - 'f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e']) - if len(tx_utxo_mainnet) > 0 and len(tx_utxo_mainnet_list) > 0: - assert 'code' not in tx_utxo_mainnet[0] and 'code' not in tx_utxo_mainnet_list[0] - - tx_utxo_testnet = kp_testnet_server.get_tx_utxos('928052b80bfc23801da525a6bf8f805da36f22fa0fd5fec2198b0746eb82b72b') - tx_utxo_testnet_list = kp_testnet_server.get_tx_utxos(['928052b80bfc23801da525a6bf8f805da36f22fa0fd5fec2198b0746eb82b72b', - 'c7e96e4cd6aa9e3afbc7b32d1e8023daf4197931f1ea61d2bdfc7a2e5e017cf1']) - if len(tx_utxo_testnet) > 0 and len(tx_utxo_testnet_list) > 0: - assert 'code' not in tx_utxo_testnet[0] and 'code' not in tx_utxo_testnet_list[0] - -# 3- get transaction(s) metadata -def test_get_tx_metadata(): - - tx_metadata_mainnet = kp_mainnet_server.get_tx_metadata('0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94') - tx_metadata_mainnet_list = kp_mainnet_server.get_tx_metadata(['0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94', - 'f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e']) - if len(tx_metadata_mainnet) > 0 and len(tx_metadata_mainnet_list) > 0: - assert 'code' not in tx_metadata_mainnet[0] and 'code' not in tx_metadata_mainnet_list[0] - - tx_metadata_testnet = kp_testnet_server.get_tx_metadata('928052b80bfc23801da525a6bf8f805da36f22fa0fd5fec2198b0746eb82b72b') - tx_metadata_testnet_list = kp_testnet_server.get_tx_metadata(['928052b80bfc23801da525a6bf8f805da36f22fa0fd5fec2198b0746eb82b72b', - 'c7e96e4cd6aa9e3afbc7b32d1e8023daf4197931f1ea61d2bdfc7a2e5e017cf1']) - if len(tx_metadata_testnet) > 0 and len(tx_metadata_testnet_list) > 0: - assert 'code' not in tx_metadata_testnet[0] and 'code' not in tx_metadata_testnet_list[0] - -# 4- get transaction(s) metadata labels -def test_get_tx_metalabels(): - - tx_metalables_mainnet = kp_mainnet_server.get_tx_metalabels('0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94') - tx_metalables_mainnet_list = kp_mainnet_server.get_tx_metalabels(['0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94', - 'f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e']) - if len(tx_metalables_mainnet) > 0 and len(tx_metalables_mainnet_list) > 0: - assert 'code' not in tx_metalables_mainnet[0] and 'code' not in tx_metalables_mainnet_list[0] - - tx_metalables_testnet = kp_testnet_server.get_tx_metalabels('928052b80bfc23801da525a6bf8f805da36f22fa0fd5fec2198b0746eb82b72b') - tx_metalables_testnet_list = kp_testnet_server.get_tx_metalabels(['928052b80bfc23801da525a6bf8f805da36f22fa0fd5fec2198b0746eb82b72b', - 'c7e96e4cd6aa9e3afbc7b32d1e8023daf4197931f1ea61d2bdfc7a2e5e017cf1']) - if len(tx_metalables_testnet) > 0 and len(tx_metalables_testnet_list) > 0: - assert 'code' not in tx_metalables_testnet[0] and 'code' not in tx_metalables_testnet_list[0] - -# 5- get submit signed transaction -# # NOT FINISHED -# # submit_tx signed cbor -# # def test_submit_tx(): - -# # tx_submit = koios_python.submit_tx("file") -# # assert 'code' not in tx_submit[0] - -# 6- get tx status -def test_get_tx_status(): - - tx_status_mainnet = kp_mainnet_server.get_tx_status('0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94') - tx_status_mainnet_list = kp_mainnet_server.get_tx_status(['0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94', - 'f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e']) - if len(tx_status_mainnet) > 0 and len(tx_status_mainnet_list) > 0: - assert 'code' not in tx_status_mainnet[0] and 'code' not in tx_status_mainnet_list[0] - - tx_status_testnet = kp_testnet_server.get_tx_status('928052b80bfc23801da525a6bf8f805da36f22fa0fd5fec2198b0746eb82b72b') - tx_status_testnet_list = kp_testnet_server.get_tx_status(['928052b80bfc23801da525a6bf8f805da36f22fa0fd5fec2198b0746eb82b72b', - 'c7e96e4cd6aa9e3afbc7b32d1e8023daf4197931f1ea61d2bdfc7a2e5e017cf1']) - if len(tx_status_testnet) > 0 and len(tx_status_testnet_list) > 0: - assert 'code' not in tx_status_testnet[0] and 'code' not in tx_status_testnet_list[0] diff --git a/tests.py b/tests.py index 6698c6a..b3e7961 100644 --- a/tests.py +++ b/tests.py @@ -3,128 +3,506 @@ Examples to check how works Koios-Python Library """ import pprint as pp # We recommend use pprint library to show your outputs -import koios_python # We need to install and import koios_python library +from koios_python import * # We need to install and import koios_python library +# from koios_python import block, epochs # alternative if we just need some functions import time +import os +#from dotenv import load_dotenv +# load the environment variables +#load_dotenv() +# Get api token +token = os.getenv("TOKEN") -#alternative if we just need some functions -#from koios_python import block, epochs -# Some examples: +########################################################################################## +## MAINNET PARAMETERS (simple TESTS) +# Public Tier with Default Koios Endpoint +#kp = URLs() # We need to create an instance of the class URLs (no bearer token) FREE TIER -## TESTENET PARAMETERS -# kp_test = koios_python.URLs(network="testnet") -# print(kp_test.url, kp_test.network) -# print(kp_test.get_account_info("stake_test1uqrw9tjymlm8wrwq7jk68n6v7fs9qz8z0tkdkve26dylmfc2ux2hj")) -# print(kp_test.get_native_script_list()) +# Select this if you are usinf Bearer Token. We need to create an instance of the class URLs (with bearer token) +#kp = URLs(bearer=token) +#pp.pprint(kp.BEARER) +########################################################################################## +# Network Endpoint Tests +########################################################################################## +# # Get tip (no bearer token) +#pp.pprint(kp.get_tip()) -# kp_test = koios_python.URLs(network="mainnet") -# print(kp_test.GENESIS_URL) -# print(kp_test.url, kp_test.network) -# print(kp_test.get_tip_test_version()) +# # Get tip (with bearer token) +# pp.pprint(kp_token.get_tip()) +# # Get Genesis (no bearer token) +# pp.pprint(kp.get_genesis()) -############################################################ -## MAINNET PARAMETERS -# Default Koios Endpoint -kp = koios_python.URLs() # We need to create an instance of the class URLs +# # Get Genesis (with bearer token) +# pp.pprint(kp_token.get_genesis()) -print('------------------------------------------------------------------------------------------') +# # Get Totals (no bearer token) +# pp.pprint(kp.get_totals()) +# pp.pprint(kp.get_totals(epoch_no=320)) -print(kp.version) +# # Get Totals (with bearer token) +# pp.pprint(kp_token.get_totals()) +# pp.pprint(kp_token.get_totals(epoch_no=320)) -print('------------------------------------------------------------------------------------------') +# Get Network Param Updates (no bearer token) +# pp.pprint(kp.get_param_updates()) -''' -pp.pp(kp.get_tip()) +# # Get Network Param Updates (with bearer token) +# pp.pprint(kp_token.get_param_updates()) -pp.pp(kp.get_genesis()) +# # Get Reserve Withdrawals (no bearer token) +# pp.pprint(kp.get_reserve_withdrawals()) -pp.pp(kp.get_totals()) -pp.pp(kp.get_pool_delegators_history("pool1hrv8gtrm0dgjg6zyss5uwa4nkruzfnh5vrdkr2sayj7x2nw6mjc", 391)) +# # Get Reserve Withdrawals (with bearer token) +# pp.pprint(kp_token.get_reserve_withdrawals()) -# print('----------------------------------------------------------------------------------------') -# check_big_account = kp.get_account_addresses(["stake1uxqh9rn76n8nynsnyvf4ulndjv0srcc8jtvumut3989cqmgjt49h6"]) -# pp.pp(check_big_account) +# # Get Treasury Withdrawals (no bearer token) +# pp.pprint(kp.get_treasury_withdrawals()) -print('------------------------------------------------------------------------------------------') +# # Get Treasury Withdrawals (with bearer token) +# pp.pprint(kp_token.get_treasury_withdrawals()) -get_asset_list = kp.get_asset_list(content_range="999-1999") -print(get_asset_list) +########################################################################################## +# Epoch Endpoint Tests +########################################################################################## -print('------------------------------------------------------------------------------------------') -get_asset_token_registry = kp.get_asset_token_registry("0-5") -pp.pp(get_asset_token_registry) +# # Get Epoch Info (no bearer token) +# get_epoch_320_info = kp.get_epoch_info(epoch_no=320, include_next_epoch=True) +# pp.pprint(get_epoch_320_info) -print('------------------------------------------------------------------------------------------') -get_asset_addresses = kp.get_asset_addresses(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501',asset_name='424f4f4b',content_range="999-1999") -pp.pprint(get_asset_addresses) +# get_epoch_320_info_false = kp.get_epoch_info(epoch_no=320, include_next_epoch=False) +# pp.pprint(get_epoch_320_info_false) +# # Get Epoch Info (with bearer token) +# get_epoch_320_info = kp_token.get_epoch_info(epoch_no=320, include_next_epoch=True) +# pp.pprint(get_epoch_320_info) -print('------------------------------------------------------------------------------------------------------------------------------------------------------') -get_asset_nft_address = kp.get_asset_nft_address(asset_policy='f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a', - asset_name='68616e646c65') -pp.pprint(get_asset_nft_address) +# get_epoch_320_info_false = kp_token.get_epoch_info(epoch_no=320, include_next_epoch=False) +# pp.pprint(get_epoch_320_info_false) -print('------------------------------------------------------------------------------------------') -get_asset_info_bulk = kp.get_asset_info_bulk(["750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b"],["1d7f33bd23d85e1a25d87d86fac4f199c3197a2f7afeb662a0f34e1e","776f726c646d6f62696c65746f6b656e"]) -pp.pprint(get_asset_info_bulk) +# # Get Epoch Params (no bearer token) +# pp.pprint(kp.get_epoch_params(320)) -print('------------------------------------------------------------------------------------------') -get_policy_asset_addresses = kp.get_policy_asset_addresses(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', content_range="0-500") -pp.pprint(get_policy_asset_addresses) +# # Get Epoch Params (with bearer token) +# pp.pprint(kp_token.get_epoch_params(320)) -print('------------------------------------------------------------------------------------------') -get_policy_asset_info = kp.get_policy_asset_info(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501') -pp.pprint(get_policy_asset_info) +# # Get Epoch Block Protocols (no bearer token) +# pp.pprint(kp.get_epoch_block_protocols(320)) -print('------------------------------------------------------------------------------------------') -get_policy_asset_list = kp.get_policy_asset_list(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', content_range="0-99") -pp.pprint(get_policy_asset_list) +# # Get Epoch Block Protocols (with bearer token) +# pp.pprint(kp_token.get_epoch_block_protocols(320)) -print('------------------------------------------------------------------------------------------') -get_asset_summary = kp.get_asset_summary(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', asset_name='424f4f4b') -pp.pprint(get_asset_summary) +########################################################################################## +# Block Endpoint Tests +########################################################################################## -print('------------------------------------------------------------------------------------------') -get_asset_txs = kp.get_asset_txs(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', asset_name='424f4f4b', after_block_height=500000, history=False, content_range="0-99") -pp.pprint(get_asset_txs) +# Get Block List (no bearer token) +# pp.pprint(kp.get_blocks("0-10")) -print('------------------------------------------------------------------------------------------') -get_asset_txs_hist_true = kp.get_asset_txs(asset_policy='750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', asset_name='424f4f4b', after_block_height=50000, history=True, content_range="0-99") -pp.pprint(get_asset_txs_hist_true) +# # Get Block List (with bearer token) +# pp.pprint(kp_token.get_blocks("0-10")) -print('------------------------------------------------------------------------------------------') -get_address_info = kp.get_address_info("addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv","addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y") -pp.pprint(get_address_info) +# # Get Block Info (no bearer token) +# pp.pprint(kp.get_block_info(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30", \ +# "60188a8dcb6db0d80628815be2cf626c4d17cb3e826cebfca84adaff93ad492a", \ +# "c6646214a1f377aa461a0163c213fc6b86a559a2d6ebd647d54c4eb00aaab015"])) -print('------------------------------------------------------------------------------------------') -get_address_txs = kp.get_address_txs("addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv","addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y",after_block=6238675) -pp.pprint(get_address_txs) +# # Get Block Info (with bearer token) +# pp.pprint(kp_token.get_block_info(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30", \ +# "60188a8dcb6db0d80628815be2cf626c4d17cb3e826cebfca84adaff93ad492a", \ +# "c6646214a1f377aa461a0163c213fc6b86a559a2d6ebd647d54c4eb00aaab015"])) -print('------------------------------------------------------------------------------------------') -get_address_credential_utxos = kp.get_credential_utxos("025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52","025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52") -pp.pprint(get_address_credential_utxos) +# # Get Block Txs (no bearer token) +# pp.pprint(kp.get_block_txs(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30", \ +# "60188a8dcb6db0d80628815be2cf626c4d17cb3e826cebfca84adaff93ad492a", \ +# "c6646214a1f377aa461a0163c213fc6b86a559a2d6ebd647d54c4eb00aaab015"])) -print('------------------------------------------------------------------------------------------') -get_address_assets = kp.get_address_assets("addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv","addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y") -pp.pprint(get_address_assets) +# # Get Block Txs (with bearer token) +# pp.pprint(kp_token.get_block_txs(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30", \ +# "60188a8dcb6db0d80628815be2cf626c4d17cb3e826cebfca84adaff93ad492a", \ +# "c6646214a1f377aa461a0163c213fc6b86a559a2d6ebd647d54c4eb00aaab015"])) -print('------------------------------------------------------------------------------------------') -get_address_credential_txs = kp.get_credential_txs("025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52", "13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555", after_block_height=6238675) -pp.pprint(get_address_credential_txs) -print('------------------------------------------------------------------------------------------') -get_network_params = kp.get_param_updates() -pp.pprint(get_network_params) -print('------------------------------------------------------------------------------------------') -get_epoch_320_info = kp.get_epoch_info(epoch_no=320, include_next_epoch=True) -pp.pprint(get_epoch_320_info) +########################################################################################## +# Transaction Endpoint Tests +########################################################################################## + +# # Get UTxO info +# pp.pprint(kp.get_utxo_info(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e#0"])) + +# pp.pprint(kp.get_utxo_info(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e#0", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94#0"])) + +# # Get UTxO info ( extended) +# pp.pprint(kp.get_utxo_info(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e#0", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94#0"], extended=True, content_range="0-9")) +# pp.pprint(kp.get_utxo_info(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e#0", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94#0"], extended=False, content_range="0-9")) + +# # Get Tx Info (no bearer token) +# pp.pprint(kp.get_tx_info(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) + +# # Get Tx Info (with bearer token) +# pp.pprint(kp_token.get_tx_info(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) + +# # Get Tx Metadata (no bearer token) +# pp.pprint(kp.get_tx_metadata(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) + +# # Get Tx Metadata (with bearer token) +# pp.pprint(kp_token.get_tx_metadata(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) + +# # Get Tx Metalabels (no bearer token) +# pp.pprint(kp.get_tx_metalabels(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) + +# # Get Tx Metalabels (with bearer token) +# pp.pprint(kp_token.get_tx_metalabels(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) + +# # Submit Tx (no bearer token) +# Testing soon + +# # Submit Tx (with bearer token) +# Testing soon + +# # Get Tx Status (no bearer token) +# pp.pprint(kp.get_tx_status(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) + +# # Get Tx Status (with bearer token) +# pp.pprint(kp_token.get_tx_status(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) + +# # Get Tx Utxos (no bearer token) +# pp.pprint(kp.get_tx_utxos("f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94")) + +# # Get Tx Utxos (with bearer token) +# pp.pprint(kp_token.get_tx_utxos("f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ +# "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94")) + +########################################################################################## +# Address Endpoint Tests +########################################################################################## + +# # Get Address Info (no bearer token) +# pp.pprint(kp.get_address_info(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ +# "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"])) + +# # Get Address Info (with bearer token) +# pp.pprint(kp_token.get_address_info(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ +# "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"])) + +# # Get Address UTxOs (no bearer token) +# pp.pprint(kp.get_address_utxos(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ +# "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"])) + +# # Get Address UTxOs (no bearer token, extended) +# pp.pprint(kp.get_address_utxos(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ +# "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"], extended=True, content_range="0-9")) +# pp.pprint(kp.get_address_utxos(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ +# "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"], extended=False, content_range="0-9")) + +# # Get Address UTxOs (with bearer token) +# pp.pprint(kp_token.get_address_utxos(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ +# "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"])) + +# # Get Address UTxOs (with bearer token, extended) +# pp.pprint(kp_token.get_address_utxos(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ +# "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"], extended=True, content_range="0-9")) +# pp.pprint(kp_token.get_address_utxos(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ +# "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"], extended=False, content_range="0-9")) + +# # Get Address Txs (no bearer token) +# pp.pprint(kp.get_address_txs(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ +# "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"], +# after_block=6238675)) + +# # Get Address Txs (with bearer token) +# pp.pprint(kp_token.get_address_txs(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ +# "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"], +# after_block=6238675)) + +# # Get Address Assets (no bearer token) +# pp.pprint(kp.get_address_assets(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv", \ +# "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"])) + +# # Get Address Assets (with bearer token) +# pp.pprint(kp_token.get_address_assets(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv", \ +# "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"])) + +# # Get UTxOs from payment credentials (no bearer token) +# pp.pprint(kp.get_credential_utxos(["025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52", \ +# "13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555"], extended=True, content_range="0-9")) + +# # Get UTxOs from payment credentials (with bearer token) +# pp.pprint(kp_token.get_credential_utxos(["025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52", +# "13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555"], extended=False, content_range="0-9")) + +# # Get Credential TXs (no bearer token) +# pp.pprint(kp.get_credential_txs("025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52", \ +# "13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555", after_block=6238675)) + +# # Get Credential TXs (with bearer token) +# pp.pprint(kp_token.get_credential_txs("025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52", \ +# "13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555", after_block=6238675)) + +########################################################################################## +# Pool Endpoint Tests +########################################################################################## + +# # Get Pool List +# pp.pprint(kp.get_pool_list('0-10')) + +# # Get Pool Info +# pp.pprint(kp.get_pool_info(["pool100wj94uzf54vup2hdzk0afng4dhjaqggt7j434mtgm8v2gfvfgp", +# "pool102s2nqtea2hf5q0s4amj0evysmfnhrn4apyyhd4azcmsclzm96m", +# "pool102vsulhfx8ua2j9fwl2u7gv57fhhutc3tp6juzaefgrn7ae35wm"])) + +# # Get Pool Stake Snapshot +# pp.pprint(kp.get_pool_stake_snapshot("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc")) + +# # Get Pool Delegators +# pp.pprint(kp.get_pool_delegators("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc", content_range="0-9")) + +# # Get Pool Delegators History +# pp.pprint(kp.get_pool_delegators_history("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc", epoch_no=320)) + +# # Get Pool Metadata +# pp.pprint(kp.get_pool_metadata()) +# pp.pprint(kp.get_pool_metadata("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc")) + +# # Get Pool Relays +# pp.pprint(kp.get_pool_relays()) +# pp.pprint(kp.get_pool_relays('0-70')) + +# # Get Pool Updates +# pp.pprint(kp.get_pool_updates("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc")) + +########################################################################################## +# Asset Endpoint Tests +########################################################################################## + +# # Get Asset List (no bearer token) +# pp.pprint(kp.get_asset_list(content_range="0-9")) + +# # Get Asset List (with bearer token) +# pp.pprint(kp_token.get_asset_list(content_range="0-9")) + +# # Get Policy Asset List (no bearer token) +# pp.pprint(kp.get_policy_asset_list("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","0-9")) + +# # Get Policy Asset List (with bearer token) +# pp.pprint(kp_token.get_policy_asset_list("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","0-9")) + +# # Get Asset Token Registry (no bearer token) +# pp.pprint(kp.get_asset_token_registry("0-9")) + +# # Get Asset Token Registry (with bearer token) +# pp.pprint(kp_token.get_asset_token_registry("0-9")) + +# # Get Asset Information (Bulk) (no bearer token) +# pp.pprint(kp.get_asset_info_bulk(["750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b"], \ +# ["f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a","6b6f696f732e72657374"])) + +# # Get Asset Information (Bulk) (with bearer token) +# pp.pprint(kp_token.get_asset_info_bulk(["750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b"], \ +# ["f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a","6b6f696f732e72657374"])) + +# # Get Asset UTxOs (no bearer token, extended=False) +# pp.pprint(kp.get_asset_utxos(["750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b"], \ +# ["f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a","6b6f696f732e72657374"], extended=False)) + +# # Get Asset UTxOs (no bearer token, extended=True) +# pp.pprint(kp.get_asset_utxos(["750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b"], \ +# ["f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a","6b6f696f732e72657374"], extended=True, content_range="0-9")) + +# # Get Asset History (no bearer token) +# pp.pprint(kp.get_asset_history("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b" \ +# , content_range="0-9")) + +# # Get Asset History (with bearer token) +# pp.pprint(kp_token.get_asset_history("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b" \ +# , content_range="0-9")) + +# # Get Asset Addresses (no bearer token) +# pp.pprint(kp.get_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b" \ +# , content_range="0-9")) + +# # Get Asset Addresses (with bearer token) +# pp.pprint(kp_token.get_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b" \ +# , content_range="0-9")) + +# # Get Asset NFT Address (no bearer token) +# pp.pprint(kp.get_asset_nft_address("f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a", "68616e646c65")) + +# # Get Asset NFT Address (with bearer token) +# pp.pprint(kp_token.get_asset_nft_address("f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a", "68616e646c65")) + +# # Get Policy Asset Adress List (no bearer token) +# pp.pprint(kp.get_policy_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", content_range="0-9")) + +# # Get Policy Asset Adress List (with bearer token) +# pp.pprint(kp_token.get_policy_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", content_range="0-9")) + +# # Get Policy Asset Info (no bearer token) +# pp.pprint(kp.get_policy_asset_info("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501")) + +# # Get Policy Asset Info (with bearer token) +# pp.pprint(kp_token.get_policy_asset_info("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501")) + +# # Get Asset Summary (no bearer token) +# pp.pprint(kp.get_asset_summary("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b")) + +# # Get Asset Summary (with bearer token) +# pp.pprint(kp_token.get_asset_summary("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b")) + +# # Get Asset Transactions (no bearer token) +# pp.pprint(kp.get_asset_txs("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b", after_block=50000,\ +# content_range="0-9")) + +# # Get Asset Transactions (with bearer token) +# pp.pprint(kp_token.get_asset_txs("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b", after_block=50000,\ +# content_range="0-9")) + +########################################################################################## +# Account Endpoint Tests +########################################################################################## + +# # Get Account List (no bearer token) +# pp.pprint(kp.get_account_list(content_range="0-9")) + +# # Get Account List (with bearer token) +# pp.pprint(kp_token.get_account_list(content_range="0-9")) + +# # Get Account Info (no bearer token) +# pp.pprint(kp.get_account_info(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) + +# # Get Account Info (with bearer token) +# pp.pprint(kp_token.get_account_info(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) + +# # Get Account Info Cached (no bearer token) +# pp.pprint(kp.get_account_info_cached(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) + +# # Get Account Info Cached (with bearer token) +# pp.pprint(kp_token.get_account_info_cached(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) + +# # Get UTxOs from Stake Addresses/Accounts (no bearer token) +# pp.pprint(kp.get_account_utxos(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"], extended=False, content_range="0-9")) + +# # Get UTxOs from Stake Addresses/Accounts (with bearer token) +# pp.pprint(kp_token.get_account_utxos(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"], extended=True, content_range="0-9")) + +# # Get Account Txs (no bearer token) +# pp.pprint(kp.get_account_txs("stake1u8yxtugdv63wxafy9d00nuz6hjyyp4qnggvc9a3vxh8yl0ckml2uz", after_block=50000)) + +# # Get Account Txs (with bearer token) +# pp.pprint(kp_token.get_account_txs("stake1u8yxtugdv63wxafy9d00nuz6hjyyp4qnggvc9a3vxh8yl0ckml2uz", after_block=50000)) + +# # Get Account Rewards (no bearer token) +# pp.pprint(kp.get_account_rewards(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"], epoch_no=409)) + +# # Get Account Rewards (with bearer token) +# pp.pprint(kp_token.get_account_rewards(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"], epoch_no=409)) + +# # Get Account Updates (no bearer token) +# pp.pprint(kp.get_account_updates(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) + +# # Get Account Updates (with bearer token) +# pp.pprint(kp_token.get_account_updates(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", \ +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) + +# # Get Account Addresses (no bearer token) +# pp.pprint(kp.get_account_addresses(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", \ +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"], content_range="0-9", first_only=False, +# empty=False)) + +# # Get Account Addresses (with bearer token) +# pp.pprint(kp_token.get_account_addresses(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", \ +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"], content_range="0-9", first_only=False, +# empty=False)) + +# # Get Account Assets (no bearer token) +# pp.pprint(kp.get_account_assets(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) + +# # Get Account Assets (with bearer token) +# pp.pprint(kp_token.get_account_assets(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ +# "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) + +# # Get Account History (no bearer token) +# pp.pprint(kp.get_account_history("stake1u8yxtugdv63wxafy9d00nuz6hjyyp4qnggvc9a3vxh8yl0ckml2uz", \ +# content_range="0-9", epoch_no=409)) + +# # Get Account History (with bearer token) +# pp.pprint(kp_token.get_account_history("stake1u8yxtugdv63wxafy9d00nuz6hjyyp4qnggvc9a3vxh8yl0ckml2uz", \ +# content_range="0-9", epoch_no=409)) + +########################################################################################## +# Script Endpoint Tests +########################################################################################## + +# # Get Script Info (no bearer token) +# pp.pprint(kp.get_script_info(["bd2119ee2bfb8c8d7c427e8af3c35d537534281e09e23013bca5b138", \ +# "c0c671fba483641a71bb92d3a8b7c52c90bf1c01e2b83116ad7d4536"])) + +# # Get Script Info (with bearer token) +# pp.pprint(kp_token.get_script_info(["bd2119ee2bfb8c8d7c427e8af3c35d537534281e09e23013bca5b138", \ +# "c0c671fba483641a71bb92d3a8b7c52c90bf1c01e2b83116ad7d4536"])) + +# # Get Native Script List (no bearer token) +# pp.pprint(kp.get_native_script_list(content_range="0-9")) + +# # Get Native Script List (with bearer token) +# pp.pprint(kp_token.get_native_script_list(content_range="0-9")) + +# # Get Plutus Script List (no bearer token) +# pp.pprint(kp.get_plutus_script_list(content_range="0-9")) + +# # Get Plutus Script List (with bearer token) +# pp.pprint(kp_token.get_plutus_script_list(content_range="0-9")) + +# # Get Script UTxOs (no bearer token) +# pp.pprint(kp.get_script_utxos(script_hash="d8480dc869b94b80e81ec91b0abe307279311fe0e7001a9488f61ff8", extended=False)) + +# # Get Script UTxOs (with bearer token) +# pp.pprint(kp_token.get_script_utxos(script_hash="d8480dc869b94b80e81ec91b0abe307279311fe0e7001a9488f61ff8", extended=True)) + +# # Get Script Redeemers (no bearer token) +# pp.pprint(kp.get_script_redeemers(script_hash="d8480dc869b94b80e81ec91b0abe307279311fe0e7001a9488f61ff8")) + +# # Get Script Redeemers (with bearer token) +# pp.pprint(kp_token.get_script_redeemers(script_hash="d8480dc869b94b80e81ec91b0abe307279311fe0e7001a9488f61ff8")) + +# # Get Datum Info (no bearer token) +# pp.pprint(kp.get_datum_info(["818ee3db3bbbd04f9f2ce21778cac3ac605802a4fcb00c8b3a58ee2dafc17d46", \ +# "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0"])) + +# # Get Datum Info (with bearer token) +# pp.pprint(kp_token.get_datum_info(["818ee3db3bbbd04f9f2ce21778cac3ac605802a4fcb00c8b3a58ee2dafc17d46", \ +# "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0"])) + +########################################################################################## +# End of Simple Testing +########################################################################################## + -get_epoch_320_info_false = kp.get_epoch_info(epoch_no=320, include_next_epoch=False) -pp.pprint(get_epoch_320_info_false) -''' ############################################################ @@ -159,7 +537,8 @@ ############################################################ - +# Heavy/Large data tests +############################################################ #pprint.pp(kp.get_account_assets_2("stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz", "0-999")) # pprint.pp(kp.get_account_assets("stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz"))