├── .gitignore
├── LICENSE.md
├── README.md
├── __pycache__
├── test_koios.cpython-310-pytest-7.2.0.pyc
├── test_koios.cpython-311-pytest-7.2.2.pyc
├── test_koios.cpython-39-pytest-6.2.4.pyc
└── test_koios_nets.cpython-39-pytest-6.2.4.pyc
├── koios_1_0_10_changes.md
├── koios_python
├── __init__.py
├── __pycache__
│ ├── __init__.cpython-310.pyc
│ ├── __init__.cpython-311.pyc
│ ├── __init__.cpython-312.pyc
│ ├── __init__.cpython-39.pyc
│ ├── account.cpython-310.pyc
│ ├── account.cpython-311.pyc
│ ├── account.cpython-312.pyc
│ ├── account.cpython-39.pyc
│ ├── address.cpython-310.pyc
│ ├── address.cpython-311.pyc
│ ├── address.cpython-312.pyc
│ ├── address.cpython-39.pyc
│ ├── asset.cpython-310.pyc
│ ├── asset.cpython-311.pyc
│ ├── asset.cpython-312.pyc
│ ├── asset.cpython-39.pyc
│ ├── block.cpython-310.pyc
│ ├── block.cpython-311.pyc
│ ├── block.cpython-312.pyc
│ ├── block.cpython-39.pyc
│ ├── enviroment.cpython-310.pyc
│ ├── enviroment.cpython-311.pyc
│ ├── environment.cpython-310.pyc
│ ├── environment.cpython-311.pyc
│ ├── environment.cpython-312.pyc
│ ├── environment.cpython-39.pyc
│ ├── epoch.cpython-310.pyc
│ ├── epoch.cpython-311.pyc
│ ├── epoch.cpython-312.pyc
│ ├── epoch.cpython-39.pyc
│ ├── epochs.cpython-310.pyc
│ ├── exceptions.cpython-310.pyc
│ ├── network.cpython-310.pyc
│ ├── network.cpython-311.pyc
│ ├── network.cpython-312.pyc
│ ├── network.cpython-39.pyc
│ ├── ogmios.cpython-310.pyc
│ ├── ogmios.cpython-311.pyc
│ ├── ogmios.cpython-312.pyc
│ ├── pool.cpython-310.pyc
│ ├── pool.cpython-311.pyc
│ ├── pool.cpython-312.pyc
│ ├── pool.cpython-39.pyc
│ ├── scripts.cpython-310.pyc
│ ├── scripts.cpython-311.pyc
│ ├── scripts.cpython-312.pyc
│ ├── scripts.cpython-39.pyc
│ ├── transactions.cpython-310.pyc
│ ├── transactions.cpython-311.pyc
│ ├── transactions.cpython-312.pyc
│ ├── transactions.cpython-39.pyc
│ ├── url.cpython-310.pyc
│ ├── urls.cpython-310.pyc
│ ├── urls.cpython-311.pyc
│ ├── urls.cpython-312.pyc
│ └── urls.cpython-39.pyc
├── account.py
├── address.py
├── asset.py
├── block.py
├── environment.py
├── epoch.py
├── network.py
├── ogmios.py
├── pool.py
├── scripts.py
├── transactions.py
└── urls.py
├── setup.py
└── tests.py
/.gitignore:
--------------------------------------------------------------------------------
1 | test_koios_nets.py
2 | test_koios.py
3 | build
4 | dist
5 | koios_python.egg-info
6 | .DS_Store
7 | .env
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Quixote Systems
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | 
3 |
4 |
5 | # Koios Python  [](https://pypi.org/project/koios-python/)
6 |
7 | ## Overview
8 | **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/)
9 |
10 |
11 | ## What is Koios Python?
12 | **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).
13 | **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.
14 | **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. 15 | 16 | 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. 17 | 18 | Required Python Modules 19 | -------------- 20 | * https://pypi.python.org/pypi/requests 21 | 22 | ## Installation [](https://pypi.org/project/koios-python/) 23 | ```python 24 | pip install koios_python 25 | ``` 26 | 27 | ## Upgrade to the last Version 28 | ```python 29 | pip install --upgrade koios_python 30 | ``` 31 | 32 | ## Usage 33 | Import to your python file this library: 34 | 35 | ```python 36 | import koios_python 37 | ``` 38 | 39 | You can read all info about how works this library in our [Wiki](https://github.com/cardano-community/koios-python/wiki) 40 | 41 | ## TODO 42 | - [x] Managing errors 43 | - [x] Inside functions 44 | - [x] Pagination (most functions have it added) 45 | - [x] User Inputs 46 | - [x] Timeouts 47 | - [x] Ordering 48 | - [ ] Adding Vertical Filtering 49 | - [ ] Adding Async methods 50 | 51 | 52 | 53 | ## Features 54 | - Supported REST Services: 55 | - [x] Network 56 | - Chain Tip 57 | - Genesis Info 58 | - Historical Tokenomic Statistics 59 | - Param Update Proposals 60 | - Reserve Withdrawals 61 | - Treasury Withdrawals 62 | 63 | - [x] Epoch 64 | - Epoch Information 65 | - Epoch's Protocol Parameters 66 | - Epoch Blocks Protocol 67 | 68 | - [x] Block 69 | - Block List 70 | - Block Information 71 | - Block Transactions 72 | 73 | - [x] Transactions 74 | - UTxO Information 75 | - Transaction Information 76 | - Transaction UTxOs [Deprecated] 77 | - Transaction Metadata 78 | - Transaction Metadata Labels 79 | - Transaction Submit 80 | - Transaction Status (Block Confirmations) 81 | 82 | - [x] Stake Account 83 | - Account List 84 | - Account Information 85 | - Account Information Cached 86 | - UTxOs for Stake Addresses (accounts) 87 | - Account Transactions 88 | - Account Rewards 89 | - Account Updates (History) 90 | - Account Addresses 91 | - Account Assets 92 | - Account History 93 | 94 | - [x] Address 95 | - Address Information 96 | - Address UTxOs 97 | - Address Transactions 98 | - Transactions from Payment Credentials 99 | - Address Assets 100 | 101 | - [x] Asset 102 | - Asset List 103 | - Policy Asset List 104 | - Asset Token Registry 105 | - Asset Information (Bulk) 106 | - Asset Information 107 | - Asset UTxOs 108 | - Asset History 109 | - Asset Addresses 110 | - NFT Address 111 | - Policy Asset Address List 112 | - Policy Asset Information 113 | - Asset Summary 114 | - Asset Transactions 115 | - Asset Policy Information [DEPRECATED] 116 | - Asset Address List [DEPRECATED] 117 | 118 | - [x] Pool 119 | - Pool List 120 | - Pool Information 121 | - Pool Stake Snapshot 122 | - Pool Delegators List 123 | - Pool Delegators History 124 | - Pool Blocks 125 | - Pool Stake, Block and Reward History 126 | - Pool Updates (History) 127 | - Pool Registrations 128 | - Pool Retirements 129 | - Pool Relays 130 | - Pool Metadata 131 | 132 | - [x] Script 133 | - Script Information 134 | - Native Script List 135 | - Plutus Script List 136 | - Script Redeemers 137 | - Script UTxOs 138 | - Datum Information 139 | 140 | - [x] Ogmios 141 | - Query 142 | 143 | -------------------------------------------------------------------------------- /__pycache__/test_koios.cpython-310-pytest-7.2.0.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/__pycache__/test_koios.cpython-310-pytest-7.2.0.pyc -------------------------------------------------------------------------------- /__pycache__/test_koios.cpython-311-pytest-7.2.2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/__pycache__/test_koios.cpython-311-pytest-7.2.2.pyc -------------------------------------------------------------------------------- /__pycache__/test_koios.cpython-39-pytest-6.2.4.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/__pycache__/test_koios.cpython-39-pytest-6.2.4.pyc -------------------------------------------------------------------------------- /__pycache__/test_koios_nets.cpython-39-pytest-6.2.4.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/__pycache__/test_koios_nets.cpython-39-pytest-6.2.4.pyc -------------------------------------------------------------------------------- /koios_1_0_10_changes.md: -------------------------------------------------------------------------------- 1 | ## Changes for KOIOS API 2 | 3 | - In this file you will find the changes we need to complete to koios_python before next release to match the current version of KOIOS API. All tasks that have been completed are the ones crossed out by a line. 4 | 5 | ### Deprecations 6 | 7 | - ~~`/asset_address_list` - Renamed to asset_addresses keeping naming line with other endpoints (old endpoint will be retired in future release) #149~~ 8 | - ~~`/asset_policy_info` - Renamed to policy_asset_info keeping naming line with other endpoints (old endpoint will be retired in future release) #149~~ 9 | 10 | ### New endpoints added 11 | 12 | - ~~`/asset_addresses` - Equivalent of deprecated /asset_address_list #149~~ 13 | - ~~`/asset_nft_address` - Returns address where the specified NFT sits on #149~~ 14 | - ~~`/account_utxos` - Returns brief details on non-empty UTxOs associated with a given stake address #149~~ 15 | - ~~`/asset_info_bulk` - Bulk version of /asset_info #142~~ 16 | - ~~`/asset_token_registry` - Returns assets registered via token registry on github #145~~ 17 | - ~~`/credential_utxos` - Returns UTxOs associated with a payment credential #149~~ 18 | - ~~`/param_updates` - Returns list of parameter update proposals applied to the network #149~~ 19 | - ~~`/policy_asset_addresses` - Returns addresses with quantity for each asset on a given policy #149~~ 20 | - ~~`/policy_asset_info` - Equivalent of deprecated /asset_policy_info but with more details in output #149~~ 21 | - ~~`/policy_asset_list` - Returns list of asset under the given policy (including supply) #142, #149~~ 22 | 23 | 24 | ## Data Input/Output Changes 25 | - Input - `/account_addresses` - Add optional _first_only and _empty flags to show only first address with tx or to include empty addresses to output #149 26 | - Input - `/epoch_info` - Add optional _include_next_epoch field to show next epoch stats if available (eg: nonce, active stake) #143 27 | - Output (addition) - `/account_assets` , `/address_assets` , `/address_info`, `/tx_info`, `/tx_utxos` - Add decimals to output #142 28 | - Output (addition) - `/policy_asset_info` - Add `minting_tx_hash`, `total_supply`, `mint_cnt`, `burn_cnt` and `creation_time` fields to the output #149 29 | - Output (breaking) - `/tx_info` - Change `_invalid_before` and `_invalid_after` to text field #141 30 | - Output (breaking/removal) - `tx_info` - Remove the field `plutus_contracts` > [array] > `outputs` as there is no logic to connect it to inputs spending #163 31 | 32 | ## Chores/epoch_info, /epoch_params - Restrict output to current epoch #149 33 | - `/block_info` - Use `/previous_id` field to show previous/next blocks (previously was using block_id/height) #145 34 | - `/asset_info/asset_policy_info` - Fix mint tx data to be latest #141 35 | - Support new guild scripts revamp #1572 36 | - Add asset token registry check 1606 37 | - New cache table `grest.asset_info_cache` to hold mint/burn counts alongwith first/last mint tx/keys #142 38 | - Bump to Koios 1.0.10rc #149 39 | - Fix typo in specs for `/pool_delegators` output column `latest_delegation_tx_hash` #149 40 | - Add indexes for ones missing after configuring cardano-db-sync 13.1.0.0 #149 41 | - Update PostgREST to be run as `authenticator` user, whose default `statement_timeout` is set to 65s and update configs accordingly #1606 42 | - Replace all RPC references for JSON endpoints with JSONB, this allows filtering child members of array elements using `cs.[{"key":"value"}]` in PostgREST #172 43 | - Fix Asset Info Cache to not rely on being able to decode policy ID (bad data on IO repo) #173 44 | - Handle Pool_list to check metadata entries that have not been populated in pool_offline_data #173 45 | - Fix pool_updates to use pmr_id instead of pool_offline_data.id #173 46 | - Update account_info_cached description to clarify it is effective for registered accounts #173 47 | -------------------------------------------------------------------------------- /koios_python/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Provides all modules 3 | """ 4 | from .block import * 5 | from .epoch import * 6 | from .network import * 7 | from .transactions import * 8 | from .address import * 9 | from .account import * 10 | from .asset import * 11 | from .pool import * 12 | from .scripts import * 13 | from .urls import * 14 | from .environment import * 15 | -------------------------------------------------------------------------------- /koios_python/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/__init__.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/__init__.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/__init__.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/__init__.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/account.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/account.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/account.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/account.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/account.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/account.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/account.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/account.cpython-39.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/address.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/address.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/address.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/address.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/address.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/address.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/address.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/address.cpython-39.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/asset.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/asset.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/asset.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/asset.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/asset.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/asset.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/asset.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/asset.cpython-39.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/block.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/block.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/block.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/block.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/block.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/block.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/block.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/block.cpython-39.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/enviroment.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/enviroment.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/enviroment.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/enviroment.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/environment.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/environment.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/environment.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/environment.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/environment.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/environment.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/environment.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/environment.cpython-39.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/epoch.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/epoch.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/epoch.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/epoch.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/epoch.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/epoch.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/epoch.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/epoch.cpython-39.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/epochs.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/epochs.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/exceptions.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/exceptions.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/network.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/network.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/network.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/network.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/network.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/network.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/network.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/network.cpython-39.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/ogmios.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/ogmios.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/ogmios.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/ogmios.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/ogmios.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/ogmios.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/pool.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/pool.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/pool.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/pool.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/pool.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/pool.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/pool.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/pool.cpython-39.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/scripts.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/scripts.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/scripts.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/scripts.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/scripts.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/scripts.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/scripts.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/scripts.cpython-39.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/transactions.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/transactions.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/transactions.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/transactions.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/transactions.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/transactions.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/transactions.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/transactions.cpython-39.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/url.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/url.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/urls.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/urls.cpython-310.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/urls.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/urls.cpython-311.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/urls.cpython-312.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/urls.cpython-312.pyc -------------------------------------------------------------------------------- /koios_python/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cardano-community/koios-python/d70fa74a0a6aefba9bd5c2d3d6ce5ffe95ccf769/koios_python/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /koios_python/account.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Provides all account functions 4 | """ 5 | import json 6 | from time import sleep 7 | import requests 8 | from .environment import * 9 | 10 | 11 | @Exception_Handler 12 | def get_account_list(self, content_range="0-999"): 13 | """ 14 | Get a list of all accounts. 15 | 16 | :return: string list of account (stake address: stake1... bech32 format) IDs. 17 | :rtype: list. 18 | """ 19 | timeout = get_timeout() 20 | 21 | if self.BEARER is None: 22 | custom_headers = {"Range": str(content_range)} 23 | account_list = requests.get(self.ACCOUNT_LIST_URL, headers = custom_headers, timeout=timeout) 24 | account_list = json.loads(account_list.content) 25 | else: 26 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 27 | account_list = requests.get(self.ACCOUNT_LIST_URL, headers = custom_headers, timeout=timeout) 28 | account_list = json.loads(account_list.content) 29 | 30 | return account_list 31 | 32 | 33 | @Exception_Handler 34 | def get_account_info(self, *args): 35 | """ 36 | Get the account information for given stake addresses (accounts). 37 | 38 | :param str args: staking address/es in bech32 format (stake1...). 39 | :return: list with all address data. 40 | :rtype: list. 41 | """ 42 | timeout = get_timeout() 43 | 44 | if self.BEARER is None: 45 | get_format = {"_stake_addresses": [args] } 46 | accounts_info = requests.post(self.ACCOUNT_INFO_URL, json= get_format, timeout=timeout ) 47 | accounts_info = json.loads(accounts_info.content) 48 | else: 49 | get_format = {"_stake_addresses": [args] } 50 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 51 | accounts_info = requests.post(self.ACCOUNT_INFO_URL, json= get_format, headers = custom_headers, timeout=timeout ) 52 | accounts_info = json.loads(accounts_info.content) 53 | 54 | return accounts_info 55 | 56 | 57 | @Exception_Handler 58 | def get_account_info_cached(self, *args): 59 | """ 60 | Get the account information for given stake addresses (accounts). 61 | 62 | :param str args: staking address/es in bech32 format (stake1...). 63 | :return: list with all address data. 64 | :rtype: list. 65 | """ 66 | timeout = get_timeout() 67 | 68 | if self.BEARER is None: 69 | get_format = {"_stake_addresses": [args] } 70 | accounts_info = requests.post(self.ACCOUNT_INFO_CACHED_URL, json=get_format, timeout=timeout) 71 | accounts_info = json.loads(accounts_info.content) 72 | else: 73 | get_format = {"_stake_addresses": [args] } 74 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 75 | accounts_info = requests.post(self.ACCOUNT_INFO_CACHED_URL, json=get_format, headers = custom_headers, timeout=timeout) 76 | accounts_info = json.loads(accounts_info.content) 77 | 78 | return accounts_info 79 | 80 | 81 | @Exception_Handler 82 | def get_account_utxos(self, *args, content_range="0-999", extended=False): 83 | """ 84 | Get a list of all UTxOs for a given stake address (account) 85 | 86 | :return: string list Array of account UTxOs associated with stake address. 87 | :rtype: list. 88 | """ 89 | timeout = get_timeout() 90 | 91 | if self.BEARER is None and extended is False: 92 | custom_headers = {"Range": str(content_range)} 93 | get_format = {"_stake_addresses": [args], "_extended": "false"} 94 | account_utxos = requests.post(f"{self.ACCOUNT_UTXOS_URL}", timeout=timeout, json=get_format, headers=custom_headers) 95 | account_utxos = json.loads(account_utxos.content) 96 | 97 | if self.BEARER is None and extended is True: 98 | custom_headers = {"Range": str(content_range)} 99 | get_format = {"_stake_addresses": [args], "_extended": "true"} 100 | account_utxos = requests.post(f"{self.ACCOUNT_UTXOS_URL}", timeout=timeout, json=get_format, headers=custom_headers) 101 | account_utxos = json.loads(account_utxos.content) 102 | 103 | if self.BEARER is not None and extended is False: 104 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}" } 105 | get_format = {"_stake_addresses": [args], "_extended": "false"} 106 | account_utxos = requests.post(f"{self.ACCOUNT_UTXOS_URL}", headers = custom_headers, timeout=timeout, json=get_format) 107 | account_utxos = json.loads(account_utxos.content) 108 | 109 | if self.BEARER is not None and extended is True: 110 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}" } 111 | get_format = {"_stake_addresses": [args], "_extended": "true"} 112 | account_utxos = requests.post(f"{self.ACCOUNT_UTXOS_URL}", headers = custom_headers, timeout=timeout, json=get_format) 113 | account_utxos = json.loads(account_utxos.content) 114 | 115 | return account_utxos 116 | 117 | 118 | @Exception_Handler 119 | def get_account_txs(self, stake_address, after_block=None): 120 | """ 121 | Get the transaction hash list of input payment credential array (stake key), optionally 122 | filtering after specified block height (inclusive). 123 | 124 | :param str stake_address: str stake address (stake1...) 125 | :param int after_block: filtering after block (inclusive) defaul is None, from the beginning 126 | :return: list of address transactions. 127 | :rtype: list. 128 | """ 129 | timeout = get_timeout() 130 | 131 | if self.BEARER is None and after_block is None: 132 | get_format = {"_stake_address": stake_address} 133 | txs_list = requests.post(self.ACCOUNT_TX_URL, json = get_format, timeout=timeout) 134 | txs_list = json.loads(txs_list.content) 135 | 136 | if self.BEARER is None and after_block is not None: 137 | get_format = {"_stake_address": stake_address, "_after_block_height": after_block} 138 | txs_list = requests.post(self.ACCOUNT_TXS_URL, json = get_format, timeout=timeout) 139 | txs_list = json.loads(txs_list.content) 140 | 141 | if self.BEARER is not None and after_block is None: 142 | get_format = {"_stake_address": stake_address} 143 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 144 | txs_list = requests.post(self.ACCOUNT_TX_URL, json = get_format, headers = custom_headers, timeout=timeout) 145 | txs_list = json.loads(txs_list.content) 146 | 147 | if self.BEARER is not None and after_block is not None: 148 | get_format = {"_stake_address": stake_address, "_after_block_height": after_block} 149 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 150 | txs_list = requests.post(self.ACCOUNT_TXS_URL, json = get_format, headers = custom_headers, timeout=timeout) 151 | txs_list = json.loads(txs_list.content) 152 | 153 | return txs_list 154 | 155 | 156 | @Exception_Handler 157 | def get_account_rewards(self, *args, epoch_no=None): 158 | """ 159 | Get the full rewards history (including MIR) for given stake addresses (accounts). 160 | 161 | :param str args: Cardano staking address (reward account) in bech32 format (stake1...) 162 | :param int args: Epoch Number, has to be last parameter (optional). 163 | return: list with all account rewards. 164 | :rtype: list. 165 | """ 166 | timeout = get_timeout() 167 | 168 | if self.BEARER is None and epoch_no is None: 169 | get_format = {"_stake_addresses": [args] } 170 | rewards = requests.post(self.ACCOUNT_REWARDS_URL, json= get_format, timeout=timeout) 171 | rewards = json.loads(rewards.content) 172 | 173 | if self.BEARER is None and epoch_no is not None: 174 | get_format = {"_stake_addresses": [args], "_epoch_no": str(epoch_no)} 175 | rewards = requests.post(self.ACCOUNT_REWARDS_URL, json= get_format, timeout=timeout) 176 | rewards = json.loads(rewards.content) 177 | 178 | if self.BEARER is not None and epoch_no is None: 179 | get_format = {"_stake_addresses": [args] } 180 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 181 | rewards = requests.post(self.ACCOUNT_REWARDS_URL, json= get_format, headers = custom_headers, timeout=timeout) 182 | rewards = json.loads(rewards.content) 183 | 184 | if self.BEARER is not None and epoch_no is not None: 185 | get_format = {"_stake_addresses": [args], "_epoch_no": str(epoch_no)} 186 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 187 | rewards = requests.post(self.ACCOUNT_REWARDS_URL, json= get_format, headers = custom_headers, timeout=timeout) 188 | rewards = json.loads(rewards.content) 189 | 190 | return rewards 191 | 192 | 193 | @Exception_Handler 194 | def get_account_updates(self, *args): 195 | """ 196 | Get the account updates (registration, deregistration, delegation and withdrawals) for given \ 197 | stake addresses (accounts) 198 | 199 | :param str args: staking address/es in bech32 format (stake1...) 200 | :return: list with all account updates. 201 | :rtype: list. 202 | """ 203 | timeout = get_timeout() 204 | 205 | if self.BEARER is None: 206 | get_format = {"_stake_addresses": [args]} 207 | updates = requests.post(self.ACCOUNT_UPDATES_URL, json= get_format, timeout=timeout) 208 | updates = json.loads(updates.content) 209 | else: 210 | get_format = {"_stake_addresses": [args]} 211 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 212 | updates = requests.post(self.ACCOUNT_UPDATES_URL, json= get_format, headers = custom_headers, timeout=timeout) 213 | updates = json.loads(updates.content) 214 | 215 | return updates 216 | 217 | 218 | @Exception_Handler 219 | def get_account_addresses(self, *args, content_range="0-999", first_only=False, empty=False): 220 | """ 221 | Get all addresses associated with given staking accounts. 222 | :param str args: staking address/es in bech32 format (stake1...) 223 | :return: list with all account addresses. 224 | :rtype: list. 225 | """ 226 | timeout = get_timeout() 227 | 228 | if self.BEARER is None and first_only is False and empty is False: 229 | custom_headers = {"Range": str(content_range)} 230 | get_format = {"_stake_addresses": [args], "_first_only": "false", "_empty": "false"} 231 | addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, timeout=timeout, headers=custom_headers) 232 | addresses = json.loads(addresses.content) 233 | 234 | if self.BEARER is None and first_only is True and empty is False: 235 | custom_headers = {"Range": str(content_range)} 236 | get_format = {"_stake_addresses": [args], "_first_only": "true", "_empty": "false"} 237 | addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, timeout=timeout, headers=custom_headers) 238 | addresses = json.loads(addresses.content) 239 | 240 | if self.BEARER is None and first_only is False and empty is True: 241 | custom_headers = {"Range": str(content_range)} 242 | get_format = {"_stake_addresses": [args], "_first_only": "false", "_empty": "true"} 243 | addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, timeout=timeout, headers=custom_headers) 244 | addresses = json.loads(addresses.content) 245 | 246 | if self.BEARER is None and first_only is True and empty is True: 247 | custom_headers = {"Range": str(content_range)} 248 | get_format = {"_stake_addresses": [args], "_first_only": "true", "_empty": "true"} 249 | addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, timeout=timeout, headers=custom_headers) 250 | addresses = json.loads(addresses.content) 251 | 252 | if self.BEARER is not None and first_only is False and empty is False: 253 | get_format = {"_stake_addresses": [args], "_first_only": "false", "_empty": "false"} 254 | custom_headers = {"Range": str(content_range) ,"Authorization": f"Bearer {self.BEARER}"} 255 | addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, headers = custom_headers, timeout=timeout) 256 | addresses = json.loads(addresses.content) 257 | 258 | if self.BEARER is not None and first_only is True and empty is False: 259 | get_format = {"_stake_addresses": [args], "_first_only": "true", "_empty": "false"} 260 | custom_headers = {"Range": str(content_range) ,"Authorization": f"Bearer {self.BEARER}"} 261 | addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, headers = custom_headers, timeout=timeout) 262 | addresses = json.loads(addresses.content) 263 | 264 | if self.BEARER is not None and first_only is False and empty is True: 265 | get_format = {"_stake_addresses": [args], "_first_only": "false", "_empty": "true"} 266 | custom_headers = {"Range": str(content_range) ,"Authorization": f"Bearer {self.BEARER}"} 267 | addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, headers = custom_headers, timeout=timeout) 268 | addresses = json.loads(addresses.content) 269 | 270 | if self.BEARER is not None and first_only is True and empty is True: 271 | get_format = {"_stake_addresses": [args], "_first_only": "true", "_empty": "true"} 272 | custom_headers = {"Range": str(content_range) ,"Authorization": f"Bearer {self.BEARER}"} 273 | addresses = requests.post(self.ACCOUNT_ADDRESSES_URL, json= get_format, headers = custom_headers, timeout=timeout) 274 | addresses = json.loads(addresses.content) 275 | 276 | return addresses 277 | 278 | 279 | @Exception_Handler 280 | def get_account_assets(self, *args): 281 | """ 282 | Get the native asset balance of given accounts. 283 | :param str args: staking address/es in bech32 format (stake1...) 284 | :return: list with all account assets. 285 | :rtype: list. 286 | """ 287 | timeout = get_timeout() 288 | 289 | if self.BEARER is None: 290 | get_format = {"_stake_addresses": [args]} 291 | assets = requests.post(self.ACCOUNT_ASSETS_URL, json= get_format, timeout=timeout) 292 | assets = json.loads(assets.content) 293 | else: 294 | get_format = {"_stake_addresses": [args]} 295 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 296 | assets = requests.post(self.ACCOUNT_ASSETS_URL, json= get_format, headers = custom_headers, timeout=timeout) 297 | assets = json.loads(assets.content) 298 | 299 | return assets 300 | 301 | 302 | ## Alternative to Paginate all list automatically 303 | def get_account_assets_paginated(self, *args): 304 | """ 305 | Get the native asset balance of given accounts. 306 | :param str args: staking address/es in bech32 format (stake1...) 307 | :return: list with all account assets. 308 | :rtype: list. 309 | """ 310 | timeout = BASE_TIMEOUT 311 | offset= OFFSET 312 | retriyng_time = RETRYING_TIME 313 | total_assets= [] 314 | 315 | while True: 316 | while True: 317 | try: 318 | get_format = {"_stake_addresses": [args]} 319 | assets = requests.post(self.ACCOUNT_ASSETS_URL + str(offset), json= get_format, timeout=timeout) 320 | assets = json.loads(assets.content) 321 | break 322 | 323 | except requests.exceptions.ReadTimeout as timeout_error: 324 | print(f"Exception: {timeout_error}") 325 | if timeout < LIMIT_TIMEOUT: 326 | timeout= timeout + 10 327 | else: 328 | print(f"Reach Limit Timeout= {LIMIT_TIMEOUT} seconds") 329 | break 330 | print(f"Retriyng with longer timeout: Total Timeout= {timeout}s") 331 | 332 | except json.decoder.JSONDecodeError as decode_error: 333 | print(f"Exception Decode: Payload too heavy. {decode_error}") 334 | sleep(SLEEP_TIME) 335 | retriyng_time += 1 336 | print(f"Retriyng one more time...({retriyng_time} times)") 337 | if retriyng_time >= LIMIT_RETRYING_TIMES: 338 | print("Reached limit of attempts") 339 | break 340 | 341 | total_assets += assets 342 | if len(total_assets) < 1000: 343 | break 344 | offset += len(total_assets) 345 | 346 | return total_assets 347 | 348 | 349 | @Exception_Handler 350 | def get_account_history(self, *args, epoch_no=None, content_range="0-999"): 351 | """ 352 | Get the staking history of given stake addresses (accounts). 353 | :param str address: staking address in bech32 format (stake1...) 354 | return: list with all account history. 355 | :rtype: list. 356 | """ 357 | timeout = get_timeout() 358 | 359 | if self.BEARER is None and epoch_no is None: 360 | get_format = {"_stake_addresses": [args] } 361 | custom_headers = {"Range": str(content_range)} 362 | history = requests.post(self.ACCOUNT_HISTORY_URL, json= get_format, timeout=timeout, headers=custom_headers) 363 | history = json.loads(history.content) 364 | 365 | if self.BEARER is None and epoch_no is not None: 366 | get_format = {"_stake_addresses": [args], "_epoch_no": str(epoch_no)} 367 | custom_headers = {"Range": str(content_range)} 368 | history = requests.post(self.ACCOUNT_HISTORY_URL, json= get_format, timeout=timeout, headers=custom_headers) 369 | history = json.loads(history.content) 370 | 371 | if self.BEARER is not None and epoch_no is None: 372 | get_format = {"_stake_addresses": [args] } 373 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 374 | history = requests.post(self.ACCOUNT_HISTORY_URL, json= get_format, headers = custom_headers, timeout=timeout) 375 | history = json.loads(history.content) 376 | 377 | if self.BEARER is not None and epoch_no is not None: 378 | get_format = {"_stake_addresses": [args], "_epoch_no": str(epoch_no)} 379 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 380 | history = requests.post(self.ACCOUNT_HISTORY_URL, json= get_format, headers = custom_headers, timeout=timeout) 381 | history = json.loads(history.content) 382 | 383 | return history 384 | 385 | -------------------------------------------------------------------------------- /koios_python/address.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Provides all address functions 4 | """ 5 | import json 6 | import requests 7 | from .environment import * 8 | 9 | 10 | @Exception_Handler 11 | def get_address_info(self, *args): 12 | """ 13 | Get address info - balance, associated stake address (if any) and UTxO set. 14 | 15 | :param str address: wallet used public address(es). 16 | return: list with data of this used public address. 17 | :rtype: list. 18 | """ 19 | timeout = get_timeout() 20 | 21 | if self.BEARER is None: 22 | get_format = {"_addresses": [args] } 23 | addresses = requests.post(self.ADDRESS_INFO_URL, json= get_format, timeout=timeout) 24 | addresses = json.loads(addresses.content) 25 | else: 26 | get_format = {"_addresses": [args] } 27 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 28 | addresses = requests.post(self.ADDRESS_INFO_URL, json= get_format, timeout=timeout, headers=custom_headers) 29 | addresses = json.loads(addresses.content) 30 | 31 | return addresses 32 | 33 | 34 | @Exception_Handler 35 | def get_address_utxos(self, *addresses, extended=False, content_range="0-999"): 36 | """ 37 | Get the UTxO set for a given address. 38 | 39 | :param list address: Array of Cardano payment address(es) 40 | :param bool extended: extended flag to toggle additional fields (optional, default is False) 41 | return: list of utxos 42 | :rtype: list. 43 | """ 44 | 45 | if self.BEARER is None and extended is True: 46 | extended = "true" 47 | timeout = get_timeout() 48 | custom_headers = {"Range": str(content_range)} 49 | get_format = {"_addresses": [addresses], "_extended": extended} 50 | utxos = requests.post(self.ADDRESS_UTXOS_URL, json = get_format, headers=custom_headers, timeout=timeout) 51 | utxos = json.loads(utxos.content) 52 | 53 | if self.BEARER is None and extended is False: 54 | extended = "false" 55 | timeout = get_timeout() 56 | custom_headers = {"Range": str(content_range)} 57 | get_format = {"_addresses": [addresses], "_extended": extended} 58 | utxos = requests.post(self.ADDRESS_UTXOS_URL, json = get_format, headers=custom_headers, timeout=timeout) 59 | utxos = json.loads(utxos.content) 60 | 61 | if self.BEARER is not None and extended is True: 62 | extended = "true" 63 | timeout = get_timeout() 64 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 65 | get_format = {"_addresses": [addresses], "_extended": extended} 66 | utxos = requests.post(self.ADDRESS_UTXOS_URL, json = get_format, headers=custom_headers, timeout=timeout) 67 | utxos = json.loads(utxos.content) 68 | 69 | if self.BEARER is not None and extended is False: 70 | extended = "false" 71 | timeout = get_timeout() 72 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 73 | get_format = {"_addresses": [addresses], "_extended": extended} 74 | utxos = requests.post(self.ADDRESS_UTXOS_URL, json = get_format, headers=custom_headers, timeout=timeout) 75 | utxos = json.loads(utxos.content) 76 | 77 | return utxos 78 | 79 | 80 | @Exception_Handler 81 | def get_credential_utxos(self, *payment_credentials, extended=False, content_range="0-999"): 82 | """ 83 | Get a list of UTxO against input payment credential array including their balances. 84 | 85 | :param str payment_credentials 86 | :return: list of utxos 87 | :rtype: list. 88 | """ 89 | timeout = get_timeout() 90 | 91 | if self.BEARER is None and extended is True: 92 | extended = "true" 93 | custom_headers = {"Range": str(content_range)} 94 | get_format = {"_payment_credentials":[payment_credentials], "_extended": extended} 95 | utxos = requests.post(self.ADDRESS_CREDENTIAL_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) 96 | utxos = json.loads(utxos.content) 97 | 98 | if self.BEARER is not None and extended is True: 99 | extended = "true" 100 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 101 | get_format = {"_payment_credentials":[payment_credentials], "_extended": extended} 102 | utxos = requests.post(self.ADDRESS_CREDENTIAL_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) 103 | utxos = json.loads(utxos.content) 104 | 105 | if self.BEARER is None and extended is False: 106 | extended = "false" 107 | custom_headers = {"Range": str(content_range)} 108 | get_format = {"_payment_credentials":[payment_credentials], "_extended": extended} 109 | utxos = requests.post(self.ADDRESS_CREDENTIAL_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) 110 | utxos = json.loads(utxos.content) 111 | 112 | if self.BEARER is not None and extended is False: 113 | extended = "false" 114 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 115 | get_format = {"_payment_credentials":[payment_credentials], "_extended": extended} 116 | utxos = requests.post(self.ADDRESS_CREDENTIAL_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) 117 | utxos = json.loads(utxos.content) 118 | 119 | return utxos 120 | 121 | 122 | @Exception_Handler 123 | def get_address_txs(self, *address_tx, after_block=0): 124 | """ 125 | Get the transaction hash list of input address array, optionally filtering after specified 126 | block height (inclusive) 127 | 128 | :param tx_hash: list or single transaction hash to search and read utxos data 129 | :param after_block: filtering after block (inclusive) defaul is 0, from the beginning 130 | :return: hash list of address transactions 131 | """ 132 | timeout = get_timeout() 133 | 134 | if self.BEARER is None: 135 | get_format = {"_addresses": [address_tx], "_after_block_height": str(after_block)} 136 | hash_list = requests.post(self.ADDRESS_TXS_URL, json = get_format, timeout=timeout) 137 | hash_list = json.loads(hash_list.content) 138 | 139 | if self.BEARER is not None: 140 | get_format = {"_addresses": [address_tx], "_after_block_height": str(after_block)} 141 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 142 | hash_list = requests.post(self.ADDRESS_TXS_URL, json = get_format, headers=custom_headers, timeout=timeout) 143 | hash_list = json.loads(hash_list.content) 144 | 145 | return hash_list 146 | 147 | 148 | @Exception_Handler 149 | def get_credential_txs(self, *payment_credentials, after_block_height=0, content_range="0-999"): 150 | """ 151 | Get the transaction hash list of input payment credential array (stake key), optionally 152 | filtering after specified block height (inclusive). 153 | 154 | :param str payment_credentials: list address payment credential array (stake key) 155 | :param int after_block: filtering after block (inclusive) defaul is 0, from the beginning 156 | :return: hash list of address transactions. 157 | :rtype: list. 158 | """ 159 | timeout = get_timeout() 160 | 161 | if self.BEARER is None: 162 | custom_headers = {"Range": str(content_range)} 163 | get_format = {"_payment_credentials": [payment_credentials], "_after_block_height": str(after_block_height)} 164 | txs_list = requests.post(self.ADDRESS_CREDENTIAL_TXS_URL, json = get_format, headers = custom_headers, timeout=timeout) 165 | txs_list = json.loads(txs_list.content) 166 | 167 | if self.BEARER is not None: 168 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 169 | get_format = {"_payment_credentials": [payment_credentials], "_after_block_height": str(after_block_height)} 170 | txs_list = requests.post(self.ADDRESS_CREDENTIAL_TXS_URL, json = get_format, headers = custom_headers, timeout=timeout) 171 | txs_list = json.loads(txs_list.content) 172 | 173 | return txs_list 174 | 175 | 176 | @Exception_Handler 177 | def get_address_assets(self, *args): 178 | """ 179 | Get the list of all the assets (policy, name and quantity) for a given address. 180 | 181 | :param str address: wallet used public address 182 | return: list of all the assets 183 | :rtype: list. 184 | """ 185 | timeout = get_timeout() 186 | 187 | if self.BEARER is None: 188 | get_format = {"_addresses": [args]} 189 | assets = requests.post(self.ADDRESS_ASSETS_URL, json = get_format, timeout=timeout) 190 | assets = json.loads(assets.content) 191 | 192 | if self.BEARER is not None: 193 | get_format = {"_addresses": [args]} 194 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 195 | assets = requests.post(self.ADDRESS_ASSETS_URL, json = get_format, headers=custom_headers, timeout=timeout) 196 | assets = json.loads(assets.content) 197 | 198 | return assets -------------------------------------------------------------------------------- /koios_python/asset.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Provides all asset functions 4 | """ 5 | import json 6 | import requests 7 | from .environment import * 8 | 9 | 10 | @Exception_Handler 11 | def get_asset_list(self, content_range="0-999"): 12 | """ 13 | Get the list of all native assets (paginated, sorted) 14 | 15 | :return: list with all asset list. 16 | :param str content_range: number of selected elements to return 17 | :rtype: list. 18 | """ 19 | timeout = get_timeout() 20 | 21 | if self.BEARER is None: 22 | custom_headers = {"Range": str(content_range)} 23 | custom_params = {"order": "asset_name.asc"} 24 | asset_list = requests.get(self.ASSET_LIST_URL, headers = custom_headers, params = custom_params, timeout=timeout) 25 | asset_list = json.loads(asset_list.content) 26 | else: 27 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 28 | custom_params = {"order": "asset_name.asc"} 29 | asset_list = requests.get(self.ASSET_LIST_URL, headers = custom_headers, params = custom_params, timeout=timeout) 30 | asset_list = json.loads(asset_list.content) 31 | 32 | return asset_list 33 | 34 | 35 | @Exception_Handler 36 | def get_policy_asset_list(self, asset_policy, content_range="0-999"): 37 | """ 38 | Get the list of asset under the given policy (including balances) 39 | 40 | :param str asset_policy: asset Policy ID in hexadecimal format (hex). 41 | :param str content_range: number of selected elements to return 42 | :return: list of all assets under the same policy. 43 | :rtype: list. 44 | """ 45 | timeout = get_timeout() 46 | 47 | if self.BEARER is None: 48 | custom_headers = {"Range": str(content_range)} 49 | custom_params = {"order": "asset_name.asc"} 50 | info = requests.get(f"{self.POLICY_ASSET_LIST_URL}{asset_policy}", 51 | headers = custom_headers, params = custom_params, timeout = timeout) 52 | info = json.loads(info.content) 53 | else: 54 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 55 | custom_params = {"order": "asset_name.asc"} 56 | info = requests.get(f"{self.POLICY_ASSET_LIST_URL}{asset_policy}", 57 | headers = custom_headers, params = custom_params, timeout = timeout) 58 | info = json.loads(info.content) 59 | 60 | return info 61 | 62 | 63 | @Exception_Handler 64 | def get_asset_token_registry(self, content_range="0-999"): 65 | """ 66 | Get a list of assets registered via token registry on Github 67 | 68 | :return: list of all asset token registry. 69 | :param str content_range: number of selected elements to return 70 | :rtype: list. 71 | """ 72 | timeout = get_timeout() 73 | 74 | if self.BEARER is None: 75 | custom_headers = {"Range": str(content_range)} 76 | token_registry = requests.get(self.ASSET_TOKEN_REGISTRY_URL, headers = custom_headers, timeout=timeout) 77 | token_registry = json.loads(token_registry.content) 78 | else: 79 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 80 | token_registry = requests.get(self.ASSET_TOKEN_REGISTRY_URL, headers = custom_headers, timeout=timeout) 81 | token_registry = json.loads(token_registry.content) 82 | 83 | return token_registry 84 | 85 | 86 | @Exception_Handler 87 | def get_asset_info(self, asset_policy, asset_name): 88 | """ 89 | Get the information of an asset including first minting & token registry metadata. 90 | 91 | :param str asset_policy: asset Policy ID in hexadecimal format (hex). 92 | :param str asset_name: string with Asset Name in hexadecimal format (hex). 93 | :return: list of all asset info. 94 | :rtype: list. 95 | """ 96 | timeout = get_timeout() 97 | 98 | if self.BEARER is None: 99 | info = requests.get(f"{self.ASSET_INFO_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout) 100 | info = json.loads(info.content) 101 | else: 102 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 103 | info = requests.get(f"{self.ASSET_INFO_URL}{asset_policy}&_asset_name={asset_name}", \ 104 | headers = custom_headers, timeout=timeout) 105 | info = json.loads(info.content) 106 | 107 | return info 108 | 109 | 110 | @Exception_Handler 111 | def get_asset_info_bulk(self, *asset_list): 112 | """ 113 | Get the information of a list of assets including first minting & token registry metadata. 114 | :param list asset_list: list of assets to query. 115 | :return: list of all asset info. 116 | :rtype: list. 117 | """ 118 | timeout = get_timeout() 119 | 120 | if self.BEARER is None: 121 | get_format = {"_asset_list": asset_list} 122 | asset_info = requests.post(self.ASSET_INFO_BULK_URL, json= get_format, timeout=timeout) 123 | asset_info = json.loads(asset_info.content) 124 | else: 125 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 126 | get_format = {"_asset_list": asset_list} 127 | asset_info = requests.post(self.ASSET_INFO_BULK_URL, json= get_format, headers=custom_headers, timeout=timeout) 128 | asset_info = json.loads(asset_info.content) 129 | 130 | return asset_info 131 | 132 | 133 | @Exception_Handler 134 | def get_asset_utxos(self, *asset_list, extended=False, content_range="0-999"): 135 | """ 136 | Get the UTXO information of a list of assets including 137 | 138 | :param list of assets 139 | :param bool extended: extended UTXO information 140 | :return: list of utxos 141 | :rtype: list. 142 | """ 143 | if self.BEARER is None and extended is True: 144 | extended = "true" 145 | timeout = get_timeout() 146 | custom_headers = {"Range": str(content_range),} 147 | get_format = {"_asset_list": asset_list, "_extended": extended} 148 | utxos = requests.post(self.ASSET_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) 149 | utxos = json.loads(utxos.content) 150 | 151 | if self.BEARER is None and extended is False: 152 | extended = "false" 153 | timeout = get_timeout() 154 | custom_headers = {"Range": str(content_range),} 155 | get_format = {"_asset_list": asset_list, "_extended": extended} 156 | utxos = requests.post(self.ASSET_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) 157 | utxos = json.loads(utxos.content) 158 | 159 | if self.BEARER is not None and extended is True: 160 | extended = "true" 161 | timeout = get_timeout() 162 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 163 | get_format = {"_asset_list": asset_list, "_extended": extended} 164 | utxos = requests.post(self.ASSET_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) 165 | utxos = json.loads(utxos.content) 166 | 167 | if self.BEARER is not None and extended is False: 168 | extended = "false" 169 | timeout = get_timeout() 170 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 171 | get_format = {"_asset_list": asset_list, "_extended": extended} 172 | utxos = requests.post(self.ASSET_UTXOS_URL, json = get_format, headers = custom_headers, timeout=timeout) 173 | utxos = json.loads(utxos.content) 174 | 175 | return utxos 176 | 177 | 178 | @Exception_Handler 179 | def get_asset_history(self, asset_policy, asset_name, content_range="0-999"): 180 | """ 181 | Get the mint/burn history of an asset. 182 | 183 | :param str asset_policy: asset Policy ID in hexadecimal format (hex). 184 | :param str asset_name: string with Asset Name in hexadecimal format (hex). 185 | :return: list of asset mint/burn history. 186 | :rtype: list. 187 | """ 188 | timeout = get_timeout() 189 | 190 | if self.BEARER is None: 191 | custom_headers = {"Range": str(content_range)} 192 | history = requests.get(f"{self.ASSET_HISTORY_URL}{asset_policy}&_asset_name={asset_name}", 193 | headers=custom_headers, timeout=timeout) 194 | history = json.loads(history.content) 195 | else: 196 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 197 | history = requests.get(f"{self.ASSET_HISTORY_URL}{asset_policy}&_asset_name={asset_name}", 198 | headers=custom_headers, timeout=timeout) 199 | history = json.loads(history.content) 200 | 201 | return history 202 | 203 | 204 | @Exception_Handler 205 | def get_asset_addresses(self, asset_policy, asset_name, content_range="0-999"): 206 | """ 207 | Get the list of all addresses holding a given asset. 208 | 209 | :param str asset_policy: asset Policy ID in hexadecimal format (hex). 210 | :param str asset_name: string with Asset Name in hexadecimal format (hex). 211 | :param str content_range: number of selected elements to return 212 | :return: list of all addresses. 213 | :rtype: list. 214 | """ 215 | timeout = get_timeout() 216 | 217 | if self.BEARER is None: 218 | custom_headers = {"Range": str(content_range)} 219 | custom_params = {"order": "payment_address.asc"} 220 | info = requests.get(f"{self.ASSET_ADDRESSES_URL}{asset_policy}&_asset_name={asset_name}", \ 221 | headers = custom_headers, params = custom_params, timeout=timeout) 222 | info = json.loads(info.content) 223 | else: 224 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 225 | custom_params = {"order": "payment_address.asc"} 226 | info = requests.get(f"{self.ASSET_ADDRESSES_URL}{asset_policy}&_asset_name={asset_name}", \ 227 | headers = custom_headers, params = custom_params, timeout=timeout) 228 | info = json.loads(info.content) 229 | 230 | return info 231 | 232 | 233 | @Exception_Handler 234 | def get_asset_nft_address(self, asset_policy, asset_name): 235 | """ 236 | Get the address where specified NFT currently reside on. 237 | 238 | :param str asset_policy: asset Policy ID in hexadecimal format (hex). 239 | :param str asset_name: string with Asset Name in hexadecimal format (hex). 240 | :return: list with payment addresses. 241 | :rtype: list. 242 | """ 243 | timeout = get_timeout() 244 | 245 | if self.BEARER is None: 246 | info = requests.get(f"{self.ASSET_NFT_ADDRESS_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout) 247 | info = json.loads(info.content) 248 | else: 249 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 250 | info = requests.get(f"{self.ASSET_NFT_ADDRESS_URL}{asset_policy}&_asset_name={asset_name}", \ 251 | headers = custom_headers, timeout=timeout) 252 | info = json.loads(info.content) 253 | 254 | return info 255 | 256 | 257 | @Exception_Handler 258 | def get_policy_asset_addresses(self, asset_policy, content_range="0-999"): 259 | """ 260 | Get the list of addresses with quantity for each asset on the given policy 261 | 262 | :param str asset_policy: asset Policy ID in hexadecimal format (hex). 263 | :param str content_range: number of selected elements to return 264 | :return: list of all addresses. 265 | :rtype: list. 266 | """ 267 | timeout = get_timeout() 268 | 269 | if self.BEARER is None: 270 | custom_headers = {"Range": str(content_range)} 271 | custom_params = {"order": "asset_name.asc"} 272 | info = requests.get(f"{self.POLICY_ASSET_ADDRESSES_LIST_URL}{asset_policy}", 273 | headers = custom_headers, params = custom_params, timeout = timeout) 274 | info = json.loads(info.content) 275 | else: 276 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 277 | custom_params = {"order": "asset_name.asc"} 278 | info = requests.get(f"{self.POLICY_ASSET_ADDRESSES_LIST_URL}{asset_policy}", 279 | headers = custom_headers, params = custom_params, timeout = timeout) 280 | info = json.loads(info.content) 281 | 282 | return info 283 | 284 | 285 | @Exception_Handler 286 | def get_policy_asset_info(self, asset_policy): 287 | """ 288 | Get the information for all assets under the same policy. 289 | 290 | :param str asset_policy: asset Policy ID in hexadecimal format (hex). 291 | :return: list of all mint/burn transactions for an asset 292 | :rtype: list. 293 | """ 294 | timeout = get_timeout() 295 | 296 | if self.BEARER is None: 297 | info = requests.get(f"{self.POLICY_ASSET_INFO_URL}{asset_policy}", timeout=timeout) 298 | info = json.loads(info.content) 299 | else: 300 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 301 | info = requests.get(f"{self.POLICY_ASSET_INFO_URL}{asset_policy}", \ 302 | headers = custom_headers, timeout=timeout) 303 | info = json.loads(info.content) 304 | 305 | return info 306 | 307 | 308 | @Exception_Handler 309 | def get_asset_summary(self, asset_policy, asset_name): 310 | """ 311 | Get the summary of an asset (total transactions exclude minting/total wallets include only 312 | wallets with asset balance). 313 | 314 | :param str asset_policy: asset Policy ID in hexadecimal format (hex). 315 | :param str asset_name: string with Asset Name in hexadecimal format (hex). 316 | :return: list of asset summary information. 317 | :rtype: list. 318 | """ 319 | timeout = get_timeout() 320 | 321 | if self.BEARER is None: 322 | summary = requests.get(f"{self.ASSET_SUMMARY_URL}{asset_policy}&_asset_name={asset_name}", timeout=timeout) 323 | summary = json.loads(summary.content) 324 | else: 325 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 326 | summary = requests.get(f"{self.ASSET_SUMMARY_URL}{asset_policy}&_asset_name={asset_name}", \ 327 | headers = custom_headers, timeout=timeout) 328 | summary = json.loads(summary.content) 329 | 330 | return summary 331 | 332 | 333 | @Exception_Handler 334 | def get_asset_txs(self, asset_policy, asset_name, after_block=0, history=False, content_range="0-999"): 335 | """ 336 | Get the list of current or all asset transaction hashes (newest first) 337 | 338 | :param str asset_policy: asset Policy ID in hexadecimal format (hex). 339 | :param str asset name: Asset Name in hexadecimal format (hex), empty asset name returns royalties 340 | :param int after_block_height: Block height for specifying time delta 341 | :param bool history: Include all historical transactions, setting to false includes only the non-empty ones 342 | :param str content_range: number of selected elements to return 343 | :return: list of all assets under the same policy. 344 | :rtype: list. 345 | """ 346 | timeout = get_timeout() 347 | 348 | if self.BEARER is None and history is True: 349 | history = "true" 350 | custom_headers = {"Range": str(content_range)} 351 | txs = requests.get(f"{self.ASSET_TXS_URL}{asset_policy}&_asset_name={asset_name} \ 352 | &_after_block_height={after_block}&_history={history}", 353 | headers=custom_headers, timeout=timeout) 354 | txs = json.loads(txs.content) 355 | 356 | if self.BEARER is None and history is False: 357 | history = "false" 358 | custom_headers = {"Range": str(content_range)} 359 | txs = requests.get(f"{self.ASSET_TXS_URL}{asset_policy}&_asset_name={asset_name} \ 360 | &_after_block_height={after_block}&_history={history}", 361 | headers=custom_headers, timeout=timeout) 362 | txs = json.loads(txs.content) 363 | 364 | if self.BEARER is not None and history is True: 365 | history = "true" 366 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 367 | txs = requests.get(f"{self.ASSET_TXS_URL}{asset_policy}&_asset_name={asset_name} \ 368 | &_after_block_height={after_block}&_history={history}", 369 | headers=custom_headers, timeout=timeout) 370 | txs = json.loads(txs.content) 371 | 372 | if self.BEARER is not None and history is False: 373 | history = "false" 374 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 375 | txs = requests.get(f"{self.ASSET_TXS_URL}{asset_policy}&_asset_name={asset_name} \ 376 | &_after_block_height={after_block}&_history={history}", 377 | headers=custom_headers, timeout=timeout) 378 | txs = json.loads(txs.content) 379 | 380 | return txs 381 | -------------------------------------------------------------------------------- /koios_python/block.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Provides all block functions 4 | """ 5 | import json 6 | import requests 7 | from .environment import * 8 | 9 | 10 | @Exception_Handler 11 | def get_blocks(self,content_range="0-999"): 12 | """ 13 | Get summarised details about all blocks (paginated - latest first). 14 | 15 | :param str range: paginated content range, up to 1000 records. 16 | :return: list of all blocks. 17 | :rtype: list 18 | """ 19 | timeout = get_timeout() 20 | 21 | if self.BEARER is None: 22 | custom_headers = {"Range": str(content_range)} 23 | blocks = requests.get(self.BLOCKS_URL, headers = custom_headers, timeout=timeout) 24 | blocks = json.loads(blocks.content) 25 | else: 26 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 27 | blocks = requests.get(self.BLOCKS_URL, headers = custom_headers, timeout=timeout) 28 | blocks = json.loads(blocks.content) 29 | 30 | return blocks 31 | 32 | 33 | @Exception_Handler 34 | def get_block_info(self,*block_hash): 35 | """ 36 | Get detailed information about a specific block or blocks 37 | 38 | :param str block_hash: block/s hash ID. 39 | :return: list of detailed block information. 40 | :rtype: list 41 | """ 42 | timeout = get_timeout() 43 | 44 | if self.BEARER is None: 45 | get_format = {"_block_hashes":[block_hash]} 46 | block = requests.post(self.BLOCK_INFO_URL, json = get_format, timeout=timeout) 47 | block = json.loads(block.content) 48 | else: 49 | get_format = {"_block_hashes":[block_hash]} 50 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 51 | block = requests.post(self.BLOCK_INFO_URL, json = get_format, timeout=timeout, headers=custom_headers) 52 | block = json.loads(block.content) 53 | 54 | return block 55 | 56 | 57 | @Exception_Handler 58 | def get_block_txs(self,*block_hash): 59 | """ 60 | Get a list of all transactions included in a provided block. 61 | 62 | :param str block_hash: block hash ID. 63 | :return: list of transactions hashes. 64 | :rtype: list 65 | """ 66 | timeout = get_timeout() 67 | 68 | if self.BEARER is None: 69 | get_format = {"_block_hashes":[block_hash]} 70 | txs = requests.post(self.BLOCK_TXS_URL, json = get_format, timeout=timeout) 71 | txs = json.loads(txs.content) 72 | else: 73 | get_format = {"_block_hashes":[block_hash]} 74 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 75 | txs = requests.post(self.BLOCK_TXS_URL, json = get_format, timeout=timeout, headers=custom_headers) 76 | txs = json.loads(txs.content) 77 | 78 | return txs -------------------------------------------------------------------------------- /koios_python/environment.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Provides all enviroment variables and constants used in the library 4 | """ 5 | from time import sleep 6 | import json 7 | import requests 8 | 9 | 10 | # Timing 11 | BASE_TIMEOUT= 10 12 | LIMIT_TIMEOUT= 60 13 | BASE_TIMEOUT= 10 14 | SLEEP_TIME= 10 15 | OFFSET= 0 16 | RETRYING_TIME= 1 17 | LIMIT_RETRYING_TIMES= 10 18 | 19 | 20 | def init_timeout(): 21 | ''' 22 | Function to initialize timeout 23 | ''' 24 | global timeout 25 | timeout = BASE_TIMEOUT 26 | 27 | 28 | def get_timeout(): 29 | ''' 30 | Function to Get alive timeout 31 | ''' 32 | return timeout 33 | 34 | 35 | def set_timeout(new_timeout): 36 | ''' 37 | Function to update a new timeout dynamically 38 | ''' 39 | global timeout 40 | timeout = new_timeout 41 | 42 | 43 | def Exception_Handler(func): 44 | ''' 45 | Exceptions Functions to use as Decorator 46 | ''' 47 | 48 | def inner_function(*args, **kwargs): 49 | ''' 50 | Inner function handles exceptions 51 | ''' 52 | retrying_time = RETRYING_TIME 53 | init_timeout() 54 | timeout = get_timeout() 55 | while True: 56 | 57 | try: 58 | return func(*args, **kwargs) 59 | 60 | # Bad URL/Invalid URL 61 | except requests.exceptions.InvalidURL as url_error: 62 | print(f"Exception: {url_error} ! PLEASE CHECK YOUR URL ENDPOINT OR NETWORK ARE CORRECT BEFORE LOOKING INTO OTHER ERRORS !") 63 | break 64 | 65 | # Bad server connection error 66 | except requests.exceptions.ConnectionError as connection_error: 67 | print(f"Exception: {connection_error} ! PLEASE CHECK YOUR URL ENDPOINT OR NETWORK ARE CORRECT BEFORE LOOKING INTO OTHER ERRORS !") 68 | break 69 | 70 | # Timeout error 71 | except requests.exceptions.ReadTimeout as timeout_error: 72 | print(f"Exception: {timeout_error}") 73 | if timeout < LIMIT_TIMEOUT: 74 | timeout= timeout + 10 75 | # Updating the new Timeout for the function 76 | set_timeout(timeout) 77 | 78 | else: 79 | print(f"Reach Limit Timeout= {LIMIT_TIMEOUT} seconds") 80 | break 81 | print(f"Retrying with longer timeout: Total Timeout= {timeout}s") 82 | 83 | # Bad JSON error 84 | except json.decoder.JSONDecodeError as decode_error: 85 | print(f"Exception Decode: Payload too heavy....bad JSON returned. {decode_error}") 86 | sleep(SLEEP_TIME) 87 | try: 88 | retrying_time += 1 89 | except UnboundLocalError as unbound_error: 90 | print(f"Something went wrong XD: {unbound_error}") 91 | 92 | print(f"Retrying one more time...({retrying_time} times)") 93 | if retrying_time >= LIMIT_RETRYING_TIMES: 94 | print("Reached limit of attempts") 95 | break 96 | 97 | # UnboundLocalError 98 | except UnboundLocalError as unbound_error: 99 | print(f"Exception: {unbound_error}") 100 | 101 | # All other exceptions 102 | except Exception as general_error: 103 | print(f"Exception: {general_error}") 104 | 105 | return inner_function 106 | -------------------------------------------------------------------------------- /koios_python/epoch.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Provides all epoch functions 4 | """ 5 | import json 6 | import requests 7 | from .environment import * 8 | 9 | @Exception_Handler 10 | def get_epoch_info(self, epoch_no=None, include_next_epoch=False): 11 | """ 12 | Get the epoch information, all epochs if no epoch specified. 13 | 14 | :param int epoch_no: epoch number to fetch details for. 15 | :return: list of detailed summary for each epoch. 16 | :rtype: list 17 | """ 18 | timeout = get_timeout() 19 | 20 | if self.BEARER is None: 21 | 22 | if epoch_no is None and include_next_epoch is False: 23 | info = requests.get(f"{self.EPOCH_INFO_URL}?_include_next_epoch=false", timeout=timeout) 24 | info = json.loads(info.content) 25 | if epoch_no is None and include_next_epoch is True: 26 | info = requests.get(f"{self.EPOCH_INFO_URL}?_include_next_epoch=true", timeout=timeout) 27 | info = json.loads(info.content) 28 | if epoch_no is not None and include_next_epoch is False: 29 | info = requests.get(f"{self.EPOCH_INFO_URL}?_epoch_no={epoch_no}&_include_next_epoch=false",\ 30 | timeout=timeout) 31 | info = json.loads(info.content) 32 | if epoch_no is not None and include_next_epoch is True: 33 | info = requests.get(f"{self.EPOCH_INFO_URL}?_epoch_no={epoch_no}&_include_next_epoch=true",\ 34 | timeout=timeout) 35 | info = json.loads(info.content) 36 | 37 | else: 38 | 39 | if epoch_no is None and include_next_epoch is False: 40 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 41 | info = requests.get(f"{self.EPOCH_INFO_URL}?_include_next_epoch=false", timeout=timeout, headers=custom_headers) 42 | info = json.loads(info.content) 43 | if epoch_no is None and include_next_epoch is True: 44 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 45 | info = requests.get(f"{self.EPOCH_INFO_URL}?_include_next_epoch=true", timeout=timeout, headers=custom_headers) 46 | info = json.loads(info.content) 47 | if epoch_no is not None and include_next_epoch is False: 48 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 49 | info = requests.get(f"{self.EPOCH_INFO_URL}?_epoch_no={epoch_no}&_include_next_epoch=false",\ 50 | timeout=timeout, headers=custom_headers) 51 | info = json.loads(info.content) 52 | if epoch_no is not None and include_next_epoch is True: 53 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 54 | info = requests.get(f"{self.EPOCH_INFO_URL}?_epoch_no={epoch_no}&_include_next_epoch=true",\ 55 | timeout=timeout, headers=custom_headers) 56 | info = json.loads(info.content) 57 | 58 | return info 59 | 60 | 61 | @Exception_Handler 62 | def get_epoch_params(self, epoch_no=None): 63 | """ 64 | Get the protocol parameters for specific epoch, returns information about all epochs 65 | if no epoch specified. 66 | 67 | :param int epoch_no: epoch number to fetch details for. 68 | :return: list of protocol parameters for each epoch. 69 | :rtype: list 70 | """ 71 | timeout = get_timeout() 72 | if self.BEARER is None: 73 | if epoch_no is None: 74 | info = requests.get(self.EPOCH_PARAMS_URL, timeout=timeout) 75 | info = json.loads(info.content) 76 | else: 77 | info = requests.get(f"{self.EPOCH_PARAMS_URL}?_epoch_no={epoch_no}", timeout=timeout) 78 | info = json.loads(info.content) 79 | else: 80 | if epoch_no is None: 81 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 82 | info = requests.get(self.EPOCH_PARAMS_URL, timeout=timeout, headers=custom_headers) 83 | info = json.loads(info.content) 84 | else: 85 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 86 | info = requests.get(f"{self.EPOCH_PARAMS_URL}?_epoch_no={epoch_no}", timeout=timeout, headers=custom_headers) 87 | info = json.loads(info.content) 88 | 89 | return info 90 | 91 | 92 | @Exception_Handler 93 | def get_epoch_block_protocols(self, epoch_no=None): 94 | """ 95 | Get the information about block protocol distribution in epoch 96 | 97 | :param int epoch_no: epoch number to fetch details for. 98 | :return: list of distinct block protocol versions counts in epoch 99 | :rtype: list 100 | """ 101 | timeout = get_timeout() 102 | 103 | if self.BEARER is None: 104 | if epoch_no is None: 105 | info = requests.get(self.EPOCH_BLOCKS_URL, timeout=timeout) 106 | info = json.loads(info.content) 107 | else: 108 | info = requests.get(f"{self.EPOCH_BLOCKS_URL}?_epoch_no={epoch_no}", timeout=timeout) 109 | info = json.loads(info.content) 110 | else: 111 | if epoch_no is None: 112 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 113 | info = requests.get(self.EPOCH_BLOCKS_URL, timeout=timeout, headers=custom_headers) 114 | info = json.loads(info.content) 115 | else: 116 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 117 | info = requests.get(f"{self.EPOCH_BLOCKS_URL}?_epoch_no={epoch_no}", timeout=timeout, headers=custom_headers) 118 | info = json.loads(info.content) 119 | 120 | return info -------------------------------------------------------------------------------- /koios_python/network.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Provides all network functions 4 | """ 5 | import json 6 | import requests 7 | from .environment import * 8 | 9 | @Exception_Handler 10 | def get_tip(self): 11 | """ 12 | Get the tip info about the latest block seen by chain. 13 | 14 | :return: list of block summary (limit+paginated). 15 | :rtype: list. 16 | """ 17 | timeout = get_timeout() 18 | if self.BEARER is None: 19 | tip = requests.get(self.TIP_URL, timeout=timeout) 20 | tip = json.loads(tip.content) 21 | else: 22 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 23 | tip = requests.get(self.TIP_URL, timeout=timeout, headers=custom_headers) 24 | tip = json.loads(tip.content) 25 | 26 | return tip 27 | 28 | 29 | @Exception_Handler 30 | def get_genesis(self): 31 | """ 32 | Get the Genesis parameters used to start specific era on chain. 33 | 34 | :return: list of genesis parameters used to start each era on chain. 35 | :rtype: list. 36 | """ 37 | timeout = get_timeout() 38 | 39 | if self.BEARER is None: 40 | genesis = requests.get(self.GENESIS_URL, timeout=timeout) 41 | else: 42 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 43 | genesis = requests.get(self.GENESIS_URL, timeout=timeout, headers=custom_headers) 44 | 45 | genesis = json.loads(genesis.content) 46 | return genesis 47 | 48 | 49 | @Exception_Handler 50 | def get_totals(self, epoch_no=None): 51 | """ 52 | Get the circulating utxo, treasury, rewards, supply and reserves in lovelace for specified 53 | epoch, all epochs if empty. 54 | 55 | :param int epoch_no: Epoch Number to fetch details for. 56 | :return: list of of supply/reserves/utxo/fees/treasury stats. 57 | :rtype: list. 58 | """ 59 | timeout = get_timeout() 60 | 61 | if self.BEARER is None: 62 | if epoch_no is None: 63 | totals = requests.get(self.TOTALS_URL, timeout=timeout) 64 | totals = json.loads(totals.content) 65 | else: 66 | totals = requests.get(f"{self.TOTALS_URL}?_epoch_no={epoch_no}", timeout=timeout) 67 | totals = json.loads(totals.content) 68 | else: 69 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 70 | if epoch_no is None: 71 | totals = requests.get(self.TOTALS_URL, timeout=timeout, headers=custom_headers) 72 | totals = json.loads(totals.content) 73 | else: 74 | totals = requests.get(f"{self.TOTALS_URL}?_epoch_no={epoch_no}", timeout=timeout, headers=custom_headers) 75 | totals = json.loads(totals.content) 76 | 77 | return totals 78 | 79 | @Exception_Handler 80 | def get_param_updates(self, content_range="0-999"): 81 | """ 82 | Get all parameter update proposals submitted to the chain starting Shelley era 83 | 84 | :return: list of protocol parameters starting from Shelley era. 85 | :rtype: list 86 | """ 87 | timeout = get_timeout() 88 | 89 | if self.BEARER is None: 90 | custom_headers = {"Range": str(content_range)} 91 | network_params = requests.get(self.NETWORK_PARAM_UPDATES_URL, headers=custom_headers, timeout=timeout) 92 | network_params = json.loads(network_params.content) 93 | else: 94 | custom_headers = {"Range": str(content_range), "Authorizatoin": f"Bearer {self.BEARER}"} 95 | network_params = requests.get(self.NETWORK_PARAM_UPDATES_URL, headers=custom_headers, timeout=timeout) 96 | network_params = json.loads(network_params.content) 97 | 98 | return network_params 99 | 100 | 101 | @Exception_Handler 102 | def get_reserve_withdrawals(self, content_range="0-999"): 103 | """ 104 | Get all reserve withdrawals from the chain starting Shelley era 105 | 106 | :return: list of reserve withdrawals starting from Shelley era. 107 | :rtype: list 108 | """ 109 | timeout = get_timeout() 110 | 111 | if self.BEARER is None: 112 | custom_headers = {"Range": str(content_range)} 113 | reserve_withdrawals = requests.get(self.RESERVE_WITHDRAWALS_URL, headers=custom_headers, timeout=timeout) 114 | reserve_withdrawals = json.loads(reserve_withdrawals.content) 115 | else: 116 | custom_headers = {"Range": str(content_range), "Authorizatoin": f"Bearer {self.BEARER}"} 117 | reserve_withdrawals = requests.get(self.RESERVE_WITHDRAWALS_URL, timeout=timeout, headers=custom_headers) 118 | reserve_withdrawals = json.loads(reserve_withdrawals.content) 119 | 120 | return reserve_withdrawals 121 | 122 | 123 | @Exception_Handler 124 | def get_treasury_withdrawals(self, content_range="0-999"): 125 | """ 126 | Get all treasury withdrawals from the chain starting Shelley era 127 | 128 | :return: list of treasury withdrawals starting from Shelley era. 129 | :rtype: list 130 | """ 131 | timeout = get_timeout() 132 | 133 | if self.BEARER is None: 134 | custom_headers = {"Range": str(content_range)} 135 | treasury_withdrawals = requests.get(self.TREASURY_WITHDRAWALS_URL, headers=custom_headers, timeout=timeout) 136 | treasury_withdrawals = json.loads(treasury_withdrawals.content) 137 | else: 138 | custom_headers = {"Range": str(content_range), "Authorizatoin": f"Bearer {self.BEARER}"} 139 | treasury_withdrawals = requests.get(self.TREASURY_WITHDRAWALS_URL, headers=custom_headers, timeout=timeout) 140 | treasury_withdrawals = json.loads(treasury_withdrawals.content) 141 | 142 | return treasury_withdrawals 143 | 144 | -------------------------------------------------------------------------------- /koios_python/ogmios.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Provides all address functions 4 | """ 5 | import json 6 | import requests 7 | from .environment import * 8 | 9 | 10 | @Exception_Handler 11 | def query(self, query, *params): 12 | """ 13 | Query the current tip of the Network. 14 | 15 | :param str query: query to search and read data from Ogmios. 16 | :param dict params: parameters to search and read data. 17 | :return: list of all info about query. 18 | :rtype: list. 19 | """ 20 | print(f"Querying {self.url}...") 21 | timeout = get_timeout() 22 | 23 | if self.BEARER is None: 24 | get_format = {"jsonrpc": "2.0", "method": query} 25 | tip = requests.post(self.url, json = get_format, timeout=timeout) 26 | tip = json.loads(tip.content) 27 | else: 28 | get_format = {"jsonrpc": "2.0", "method": query} 29 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 30 | tip = requests.post(self.url, json = get_format, timeout=timeout, headers=custom_headers) 31 | 32 | return tip -------------------------------------------------------------------------------- /koios_python/pool.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Provides all pool functions 4 | """ 5 | import json 6 | import requests 7 | from .environment import * 8 | 9 | @Exception_Handler 10 | def get_pool_list(self, content_range="0-999"): 11 | """ 12 | Get a list of all currently registered/retiring (not retired) pools. 13 | 14 | :param str range: paginated content range, up to 1000 records. 15 | :return: list of all registered/retiring pools. 16 | :rtype: list. 17 | """ 18 | timeout = get_timeout() 19 | 20 | if self.BEARER is None: 21 | custom_headers = {"Range": str(content_range)} 22 | pool_list = requests.get(self.POOL_LIST_URL, headers = custom_headers, timeout=timeout) 23 | pool_list = json.loads(pool_list.content) 24 | 25 | else: 26 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 27 | pool_list = requests.get(self.POOL_LIST_URL, headers = custom_headers, timeout=timeout) 28 | pool_list = json.loads(pool_list.content) 29 | 30 | return pool_list 31 | 32 | 33 | @Exception_Handler 34 | def get_pool_info(self, *args): 35 | """ 36 | Get current pool status and details for a specified pool. 37 | 38 | :param str args: pool IDs in bech32 format (pool1...) 39 | :return: list of pool information. 40 | :rtype: list. 41 | """ 42 | timeout = get_timeout() 43 | 44 | if self.BEARER is None: 45 | get_format = {"_pool_bech32_ids": [args] } 46 | pool_list = requests.post(self.POOL_INFO_URL, json = get_format, timeout=timeout) 47 | pool_list = json.loads(pool_list.content) 48 | else: 49 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 50 | get_format = {"_pool_bech32_ids": [args] } 51 | pool_list = requests.post(self.POOL_INFO_URL, json = get_format, headers = custom_headers, timeout=timeout) 52 | pool_list = json.loads(pool_list.content) 53 | 54 | return pool_list 55 | 56 | 57 | @Exception_Handler 58 | def get_pool_stake_snapshot(self, pool_bech32): 59 | """ 60 | Returns Mark, Set and Go stake snapshots for the selected pool, useful for leaderlog calculation 61 | 62 | :param str pool_bech32: Pool IDs in bech32 format (pool1...) 63 | :return: Array of pool stake information for 3 snapshots 64 | :rtype: list. 65 | """ 66 | timeout = get_timeout() 67 | 68 | if self.BEARER is None: 69 | snapshot = requests.get(self.POOL_STAKE_SNAPSHOT + pool_bech32, timeout=timeout) 70 | snapshot = json.loads(snapshot.content) 71 | else: 72 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 73 | snapshot = requests.get(self.POOL_STAKE_SNAPSHOT + pool_bech32, headers = custom_headers, timeout=timeout) 74 | snapshot = json.loads(snapshot.content) 75 | 76 | return snapshot 77 | 78 | 79 | @Exception_Handler 80 | def get_pool_delegators(self, pool_bech32, content_range="0-999"): 81 | """ 82 | Return information about live delegators for a given pool. 83 | 84 | :param str pool_bech32: pool IDs in bech32 format (pool1...). 85 | :param str epoch_no: epoch number to get info (current if omitted). 86 | :return: list of pool delegators information. 87 | :rtype: list. 88 | """ 89 | timeout = get_timeout() 90 | 91 | if self.BEARER is None: 92 | custom_headers = {"Range": str(content_range)} 93 | info = requests.get(self.POOL_DELEGATORS_URL + pool_bech32, headers = custom_headers, timeout=timeout) 94 | info = json.loads(info.content) 95 | else: 96 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 97 | info = requests.get(self.POOL_DELEGATORS_URL + pool_bech32, headers = custom_headers, timeout=timeout) 98 | info = json.loads(info.content) 99 | 100 | return info 101 | 102 | 103 | @Exception_Handler 104 | def get_pool_delegators_history(self, pool_bech32, epoch_no=None, content_range="0-999"): 105 | """ 106 | Return information about active delegators (incl. history) for a given pool and epoch number \ 107 | (all epochs if not specified). 108 | 109 | :param str pool_bech32: pool IDs in bech32 format (pool1...). 110 | :param str epoch_no: epoch number to get info (current if omitted). 111 | :return: list of pool delegators information. 112 | :rtype: list. 113 | """ 114 | timeout = get_timeout() 115 | custom_headers = {"Range": str(content_range)} 116 | 117 | if self.BEARER is None and epoch_no is None: 118 | info = requests.get(self.POOL_DELEGATORS_HISTORY_URL + pool_bech32, headers=custom_headers, timeout=timeout) 119 | info = json.loads(info.content) 120 | 121 | if self.BEARER is None and epoch_no is not None: 122 | info = requests.get(f"{self.POOL_DELEGATORS_HISTORY_URL}{pool_bech32}&_epoch_no={epoch_no}", headers=custom_headers, timeout=timeout) 123 | info = json.loads(info.content) 124 | 125 | if self.BEARER is not None and epoch_no is None: 126 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 127 | info = requests.get(self.POOL_DELEGATORS_HISTORY_URL + pool_bech32, headers=custom_headers, timeout=timeout) 128 | info = json.loads(info.content) 129 | 130 | if self.BEARER is not None and epoch_no is not None: 131 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 132 | info = requests.get(f"{self.POOL_DELEGATORS_HISTORY_URL}{pool_bech32}&_epoch_no={epoch_no}", headers=custom_headers, timeout=timeout) 133 | info = json.loads(info.content) 134 | 135 | return info 136 | 137 | 138 | @Exception_Handler 139 | def get_pool_blocks(self, pool_bech32, epoch_no=None, content_range="0-999"): 140 | """ 141 | Return information about blocks minted by a given pool for all epochs (or _epoch_no if provided) 142 | 143 | :param str pool_bech32: pool IDs in bech32 format (pool1...). 144 | :param str epoch_no: epoch number to get info (from the beginning if omitted). 145 | :return: list of blocks created by pool. 146 | :rtype: list.s 147 | """ 148 | timeout = get_timeout() 149 | 150 | if self.BEARER is None and epoch_no is None: 151 | custom_headers = {"Range": str(content_range)} 152 | info = requests.get(self.POOL_BLOCKS_URL + pool_bech32, timeout=timeout, headers=custom_headers) 153 | info = json.loads(info.content) 154 | 155 | if self.BEARER is None and epoch_no is not None: 156 | custom_headers = {"Range": str(content_range)} 157 | info = requests.get(f"{self.POOL_BLOCKS_URL}{pool_bech32}&_epoch_no={epoch_no}", timeout=timeout, headers=custom_headers) 158 | info = json.loads(info.content) 159 | 160 | if self.BEARER is not None and epoch_no is None: 161 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 162 | info = requests.get(self.POOL_BLOCKS_URL + pool_bech32, headers=custom_headers, timeout=timeout) 163 | info = json.loads(info.content) 164 | 165 | if self.BEARER is not None and epoch_no is not None: 166 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 167 | info = requests.get(f"{self.POOL_BLOCKS_URL}{pool_bech32}&_epoch_no={epoch_no}", headers=custom_headers, timeout=timeout) 168 | info = json.loads(info.content) 169 | 170 | return info 171 | 172 | 173 | @Exception_Handler 174 | def get_pool_history(self, pool_bech32, epoch_no=None): 175 | """ 176 | Return information about pool stake, block and reward history in a given epoch _epoch_no \ 177 | (or all epochs that pool existed for, in descending order if no _epoch_no was provided) 178 | 179 | :param str pool_bech32: pool IDs in bech32 format (pool1...). 180 | :param str epoch_no: epoch number to get info (from the beginning if omitted). 181 | :return: list of blocks created by pool. 182 | :rtype: list. 183 | """ 184 | timeout = get_timeout() 185 | 186 | if self.BEARER is None and epoch_no == None: 187 | info = requests.get(self.POOL_HISTORY_URL + pool_bech32, timeout=timeout) 188 | info = json.loads(info.content) 189 | 190 | if self.BEARER is None and epoch_no is not None: 191 | info = requests.get(f"{self.POOL_HISTORY_URL}{pool_bech32}&_epoch_no={epoch_no}", timeout=timeout) 192 | info = json.loads(info.content) 193 | 194 | if self.BEARER is not None and epoch_no is None: 195 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 196 | info = requests.get(self.POOL_HISTORY_URL + pool_bech32, headers=custom_headers, timeout=timeout) 197 | info = json.loads(info.content) 198 | 199 | if self.BEARER is not None and epoch_no is not None: 200 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 201 | info = requests.get(f"{self.POOL_HISTORY_URL}{pool_bech32}&_epoch_no={epoch_no}", headers=custom_headers, timeout=timeout) 202 | info = json.loads(info.content) 203 | 204 | return info 205 | 206 | 207 | @Exception_Handler 208 | def get_pool_updates(self, pool_bech32=None): 209 | """ 210 | Get all pool updates for all pools or only updates for specific pool if specified. 211 | 212 | :param str pool_bech32: pool IDs in bech32 format (pool1...). 213 | :return: list of historical pool updates. 214 | :rtype: list. 215 | """ 216 | timeout = get_timeout() 217 | 218 | if self.BEARER is None and pool_bech32 is None: 219 | pool_list = requests.get(self.POOL_UPDATES_URL, timeout=timeout) 220 | pool_list = json.loads(pool_list.content) 221 | 222 | if self.BEARER is None and pool_bech32 is not None: 223 | pool_list = requests.get(f"{self.POOL_UPDATES_URL}?_pool_bech32={pool_bech32}", timeout=timeout) 224 | pool_list = json.loads(pool_list.content) 225 | 226 | if self.BEARER is not None and pool_bech32 is None: 227 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 228 | pool_list = requests.get(self.POOL_UPDATES_URL, headers=custom_headers, timeout=timeout) 229 | pool_list = json.loads(pool_list.content) 230 | 231 | if self.BEARER is not None and pool_bech32 is not None: 232 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 233 | pool_list = requests.get(f"{self.POOL_UPDATES_URL}?_pool_bech32={pool_bech32}", headers=custom_headers, timeout=timeout) 234 | pool_list = json.loads(pool_list.content) 235 | 236 | return pool_list 237 | 238 | 239 | @Exception_Handler 240 | def get_pool_relays(self, content_range="0-999"): 241 | """ 242 | Get a list of registered relays for all currently registered/retiring (not retired) pools. 243 | 244 | :param str range: paginated content range, up to 1000 records. 245 | :return: list of pool relay information. 246 | :rtype: list. 247 | """ 248 | timeout = get_timeout() 249 | 250 | if self.BEARER is None: 251 | custom_headers = {"Range": str(content_range)} 252 | pool_list = requests.get(self.POOL_RELAYS_URL, headers = custom_headers, timeout=timeout) 253 | pool_list = json.loads(pool_list.content) 254 | else: 255 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 256 | pool_list = requests.get(self.POOL_RELAYS_URL, headers = custom_headers, timeout=timeout) 257 | pool_list = json.loads(pool_list.content) 258 | 259 | return pool_list 260 | 261 | 262 | @Exception_Handler 263 | def get_pool_metadata(self, *args): 264 | """ 265 | Get Metadata (on & off-chain) for all currently registered/retiring (not retired) pools. 266 | 267 | :param str args: pool IDs in bech32 format (pool1...). 268 | :return: list of pool metadata. 269 | :rtype: list. 270 | """ 271 | timeout = get_timeout() 272 | 273 | if self.BEARER is None and len(args) != 0: 274 | get_format = {"_pool_bech32_ids": [args] } 275 | pool_list = requests.post(self.POOL_METADATA_URL, json = get_format, timeout=timeout) 276 | pool_list = json.loads(pool_list.content) 277 | 278 | if self.BEARER is not None and len(args) != 0: 279 | get_format = {"_pool_bech32_ids": [args] } 280 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 281 | pool_list = requests.get(self.POOL_METADATA_URL, headers = custom_headers, json = get_format, timeout=timeout) 282 | pool_list = json.loads(pool_list.content) 283 | else: 284 | pool_list = None 285 | 286 | return pool_list 287 | 288 | @Exception_Handler 289 | def get_pool_registrations(self, epoch_no=None): 290 | """ 291 | Get all pool registrations for all epochs (or _epoch_no if provided) 292 | 293 | :param str epoch_no: epoch number to get info (from the beginning if omitted). 294 | :return: list of pool registrations. 295 | :rtype: list. 296 | """ 297 | timeout = get_timeout() 298 | if epoch_no is None: 299 | print(f"WARNING: epoch_no is required") 300 | return 301 | 302 | if self.BEARER is None: 303 | pool_list = requests.get(f"{self.POOL_REGISTRATIONS_URL}{epoch_no}", timeout=timeout) 304 | pool_list = json.loads(pool_list.content) 305 | else: 306 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 307 | pool_list = requests.get(f"{self.POOL_REGISTRATIONS_URL}{epoch_no}", headers = custom_headers, timeout=timeout) 308 | pool_list = json.loads(pool_list.content) 309 | 310 | return pool_list 311 | 312 | @Exception_Handler 313 | def get_pool_retirements(self, epoch_no=None): 314 | """ 315 | Get all pool retirements for all epochs (or _epoch_no if provided) 316 | 317 | :param str epoch_no: epoch number to get info (from the beginning if omitted). 318 | :return: list of pool retirements. 319 | :rtype: list. 320 | """ 321 | timeout = get_timeout() 322 | if epoch_no is None: 323 | print(f"WARNING: epoch_no is required") 324 | return 325 | 326 | if self.BEARER is None: 327 | pool_list = requests.get(f"{self.POOL_RETIREMENTS_URL}{epoch_no}", timeout=timeout) 328 | pool_list = json.loads(pool_list.content) 329 | else: 330 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 331 | pool_list = requests.get(f"{self.POOL_RETIREMENTS_URL}{epoch_no}", headers = custom_headers, timeout=timeout) 332 | pool_list = json.loads(pool_list.content) 333 | 334 | return pool_list -------------------------------------------------------------------------------- /koios_python/scripts.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Provides all scripts functions 4 | """ 5 | import json 6 | from time import sleep 7 | import requests 8 | from .environment import * 9 | 10 | 11 | @Exception_Handler 12 | def get_script_info(self, *script_hashes, content_range="0-999"): 13 | """ 14 | Get list of script information for given script hashes 15 | 16 | :params list script_hashes: Array of script hashes in hexadecimal format (hex) to search and read data. 17 | :return: list of script information for given script hashes. 18 | :rtype: list. 19 | """ 20 | timeout = get_timeout() 21 | 22 | if self.BEARER is None: 23 | custom_headers = {"Range": str(content_range)} 24 | get_format = {"_script_hashes": [script_hashes]} 25 | script_info = requests.post(self.SCRIPT_INFO_URL, json = get_format, timeout=timeout, headers=custom_headers) 26 | script_info = json.loads(script_info.content) 27 | 28 | else: 29 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 30 | get_format = {"_script_hashes": [script_hashes]} 31 | script_info = requests.post(self.SCRIPT_INFO_URL, json = get_format, headers = custom_headers, timeout=timeout) 32 | script_info = json.loads(script_info.content) 33 | 34 | return script_info 35 | 36 | 37 | @Exception_Handler 38 | def get_native_script_list(self, content_range="0-999"): 39 | """ 40 | Get list of all existing native script hashes along with their creation transaction hashes 41 | 42 | :param str range: paginated content range, up to 1000 records. 43 | return: list of native script and creation tx hash pairs. 44 | :rtype: list. 45 | """ 46 | timeout = get_timeout() 47 | 48 | if self.BEARER is None: 49 | custom_headers = {"Range": str(content_range)} 50 | script_list = requests.post(self.NATIVE_SCRIPT_LIST_URL, headers = custom_headers, timeout=timeout) 51 | script_list = json.loads(script_list.content) 52 | 53 | else: 54 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 55 | script_list = requests.post(self.NATIVE_SCRIPT_LIST_URL, headers = custom_headers, timeout=timeout) 56 | script_list = json.loads(script_list.content) 57 | 58 | return script_list 59 | 60 | 61 | @Exception_Handler 62 | def get_plutus_script_list(self, content_range="0-999"): 63 | """ 64 | Get list of all existing Plutus script hashes along with their creation transaction hashes. 65 | 66 | :param str range: paginated content range, up to 1000 records. 67 | return: list of Plutus script and creation tx hash pairs. 68 | :rtype: list. 69 | """ 70 | timeout = get_timeout() 71 | 72 | if self.BEARER is None: 73 | custom_headers = {"Range": str(content_range)} 74 | script_list = requests.post(self.PLUTUS_SCRIPT_LIST_URL, headers = custom_headers, timeout=timeout) 75 | script_list = json.loads(script_list.content) 76 | 77 | else: 78 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 79 | script_list = requests.post(self.PLUTUS_SCRIPT_LIST_URL, headers = custom_headers, timeout=timeout) 80 | script_list = json.loads(script_list.content) 81 | 82 | return script_list 83 | 84 | 85 | @Exception_Handler 86 | def get_script_redeemers(self, script_hash, content_range="0-999"): 87 | """ 88 | Get list of all redeemers for a given script hash. 89 | 90 | :params string script_hash: script hash in hexadecimal format (hex) to search and read data. 91 | :return: list of all redeemers for a given script hash. 92 | :rtype: list. 93 | """ 94 | timeout = get_timeout() 95 | 96 | if self.BEARER is None: 97 | custom_headers = {"Range": str(content_range)} 98 | script_redeemers = requests.get(self.SCRIPT_REDEEMERS_URL + script_hash, timeout=timeout, headers = custom_headers) 99 | script_redeemers = json.loads(script_redeemers.content) 100 | 101 | else: 102 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 103 | script_redeemers = requests.get(self.SCRIPT_REDEEMERS_URL + script_hash, headers = custom_headers, timeout=timeout) 104 | script_redeemers = json.loads(script_redeemers.content) 105 | 106 | return script_redeemers 107 | 108 | 109 | @Exception_Handler 110 | def get_script_utxos(self, script_hash, extended=False, content_range="0-999"): 111 | """ 112 | Get list of all UTxOs for a given script hash 113 | 114 | :params string script_hash: script hash in hexadecimal format (hex) to search and read data. 115 | :params bool extended: extended output format, default is False. 116 | :return: list of all UTxOs for a given script hash. 117 | :rtype: list. 118 | """ 119 | 120 | if self.BEARER is None and extended is False: 121 | extended = "false" 122 | timeout = get_timeout() 123 | custom_headers = {"Range": str(content_range)} 124 | utxos_list = requests.get(f"{self.SCRIPT_UTXOS_URL}{script_hash}&_extended={extended}", timeout=timeout, headers = custom_headers) 125 | utxos_list = json.loads(utxos_list.content) 126 | 127 | if self.BEARER is None and extended is True: 128 | extended = "true" 129 | timeout = get_timeout() 130 | custom_headers = {"Range": str(content_range)} 131 | utxos_list = requests.get(f"{self.SCRIPT_UTXOS_URL}{script_hash}&_extended={extended}", timeout=timeout, headers = custom_headers) 132 | utxos_list = json.loads(utxos_list.content) 133 | 134 | if self.BEARER is not None and extended is False: 135 | extended = "false" 136 | timeout = get_timeout() 137 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 138 | utxos_list = requests.get(f"{self.SCRIPT_UTXOS_URL}{script_hash}&_extended={extended}", timeout=timeout, headers = custom_headers) 139 | utxos_list = json.loads(utxos_list.content) 140 | 141 | if self.BEARER is not None and extended is True: 142 | extended = "true" 143 | timeout = get_timeout() 144 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 145 | utxos_list = requests.get(f"{self.SCRIPT_UTXOS_URL}{script_hash}&_extended={extended}", timeout=timeout, headers = custom_headers) 146 | utxos_list = json.loads(utxos_list.content) 147 | 148 | return utxos_list 149 | 150 | 151 | 152 | @Exception_Handler 153 | def get_datum_info(self, *datum_hash): 154 | ''' 155 | Get list of datum information for given datum hashes 156 | 157 | :params string datum_hash: The Hash of the Plutus Data. 158 | :return: the actual data in json form. 159 | :rtype: list. 160 | ''' 161 | timeout = get_timeout() 162 | 163 | if self.BEARER is None: 164 | get_format = {"_datum_hashes": [datum_hash]} 165 | datum_info = requests.post(self.DATUM_INFO_URL, json = get_format, timeout=timeout) 166 | datum_info = json.loads(datum_info.content) 167 | 168 | else: 169 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 170 | get_format = {"_datum_hashes": [datum_hash]} 171 | datum_info = requests.post(self.DATUM_INFO_URL, json = get_format, headers = custom_headers, timeout=timeout) 172 | datum_info = json.loads(datum_info.content) 173 | 174 | return datum_info 175 | -------------------------------------------------------------------------------- /koios_python/transactions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Provides all transactions functions 4 | """ 5 | import json 6 | import requests 7 | from .environment import * 8 | 9 | 10 | @Exception_Handler 11 | def get_utxo_info(self, *args, extended=False, content_range="0-999"): 12 | """ 13 | Get UTxO set for requested UTxO references. 14 | 15 | :param list utxo_hash: Array of Cardano utxo references in the form "hash#index" 16 | :return: list of all info about UTxO(s). 17 | :rtype: list. 18 | """ 19 | timeout = get_timeout() 20 | 21 | if self.BEARER is None and extended is False: 22 | custom_headers = {"Range": str(content_range)} 23 | get_format = {"_utxo_refs": [args], "_extended": "false"} 24 | utxo_info = requests.post(self.UTXO_INFO_URL, json = get_format, timeout=timeout, headers = custom_headers) 25 | utxo_info = json.loads(utxo_info.content) 26 | 27 | if self.BEARER is None and extended is True: 28 | custom_headers = {"Range": str(content_range)} 29 | get_format = {"_utxo_refs": [args], "_extended": "true"} 30 | utxo_info = requests.post(self.UTXO_INFO_URL, json = get_format, timeout=timeout, headers = custom_headers) 31 | utxo_info = json.loads(utxo_info.content) 32 | 33 | if self.BEARER is not None and extended is False: 34 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 35 | get_format = {"_utxo_refs": [args], "_extended": "false"} 36 | utxo_info = requests.post(self.UTXO_INFO_URL, json = get_format, timeout=timeout, headers = custom_headers) 37 | utxo_info = json.loads(utxo_info.content) 38 | print('LOL') 39 | 40 | if self.BEARER is not None and extended is True: 41 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 42 | get_format = {"_utxo_refs": [args], "_extended": "true"} 43 | utxo_info = requests.post(self.UTXO_INFO_URL, json = get_format, timeout=timeout, headers = custom_headers) 44 | utxo_info = json.loads(utxo_info.content) 45 | 46 | return utxo_info 47 | 48 | 49 | @Exception_Handler 50 | def get_tx_info(self, *args): 51 | """ 52 | Get detailed information about transaction(s). 53 | 54 | :param list tx_hash: list of transaction(s) hash to search and read data. 55 | :return: list of all info about transaction(s). 56 | :rtype: list. 57 | """ 58 | timeout = get_timeout() 59 | 60 | if self.BEARER is None: 61 | get_format = {"_tx_hashes": [args]} 62 | tx_info = requests.post(self.TX_INFO_URL, json = get_format, timeout=timeout) 63 | tx_info = json.loads(tx_info.content) 64 | else: 65 | get_format = {"_tx_hashes": [args]} 66 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 67 | tx_info = requests.post(self.TX_INFO_URL, json = get_format, timeout=timeout, headers=custom_headers) 68 | tx_info = json.loads(tx_info.content) 69 | 70 | return tx_info 71 | 72 | 73 | ## [DEPRECATED - Use /utxo_info instead] 74 | @Exception_Handler 75 | def get_tx_utxos(self, *args): 76 | """ 77 | Get UTxO set (inputs/outputs) of transactions. 78 | 79 | :param list tx_hash: list of transaction(s) hash to search and read utxos data. 80 | :return: all info about utxos in transaction(s) 81 | :rtype: list. 82 | """ 83 | timeout = get_timeout() 84 | 85 | if self.BEARER is None: 86 | get_format = {"_tx_hashes": [args]} 87 | tx_utxos = requests.post(self.TX_UTXOS_URL, json = get_format, timeout=timeout) 88 | tx_utxos = json.loads(tx_utxos.content) 89 | else: 90 | get_format = {"_tx_hashes": [args]} 91 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 92 | tx_utxos = requests.post(self.TX_UTXOS_URL, json = get_format, timeout=timeout, headers=custom_headers) 93 | tx_utxos = json.loads(tx_utxos.content) 94 | 95 | return tx_utxos 96 | 97 | 98 | @Exception_Handler 99 | def get_tx_metadata(self, *args): 100 | """ 101 | Get metadata information (if any) for given transaction(s). 102 | 103 | :param list tx_hash: list strings of transaction(s) hash to search and read utxos data. 104 | :return: list of all info about utxos in transaction(s) 105 | :rtype: list. 106 | """ 107 | timeout = get_timeout() 108 | 109 | if self.BEARER is None: 110 | get_format = {"_tx_hashes": [args]} 111 | tx_metadata = requests.post(self.TX_METADATA_URL, json = get_format, timeout=timeout) 112 | tx_metadata = json.loads(tx_metadata.content) 113 | else: 114 | get_format = {"_tx_hashes": [args]} 115 | custom_headers = {"Authorization": f"Bearer {self.BEARER}"} 116 | tx_metadata = requests.post(self.TX_METADATA_URL, json = get_format, timeout=timeout, headers=custom_headers) 117 | tx_metadata = json.loads(tx_metadata.content) 118 | 119 | return tx_metadata 120 | 121 | 122 | @Exception_Handler 123 | def get_tx_metalabels(self, content_range="0-999"): 124 | """ 125 | Get a list of all transaction metalabels. 126 | 127 | :param str range: paginated content range, up to 1000 records. 128 | :return: list of metalabels transactions 129 | """ 130 | timeout = get_timeout() 131 | 132 | if self.BEARER is None: 133 | custom_headers = {"Range": str(content_range)} 134 | tx_metalabels = requests.get(self.TX_METALABELS_URL, headers \ 135 | = custom_headers, timeout=timeout) 136 | tx_metalabels = json.loads(tx_metalabels.content) 137 | else: 138 | custom_headers = {"Range": str(content_range), "Authorization": f"Bearer {self.BEARER}"} 139 | tx_metalabels = requests.get(self.TX_METALABELS_URL, headers \ 140 | = custom_headers, timeout=timeout) 141 | tx_metalabels = json.loads(tx_metalabels.content) 142 | 143 | return tx_metalabels 144 | 145 | 146 | @Exception_Handler 147 | def submit_tx(self, file): 148 | """ 149 | Submit an already serialized transaction to the network. You have to serialized the transaction 150 | file with: xxd -r -p <<< $(jq .cborHex signed.txt) > signed.cbor 151 | 152 | :param file: a file with raw binary serialized transaction on the file-system. 153 | :return: hex transaction ID (if is successful ) 154 | """ 155 | timeout = get_timeout() 156 | 157 | if self.BEARER is None: 158 | with open(file, "rb") as cbor_tx: 159 | cbor_tx = cbor_tx.read() 160 | cbor_header = {'Content-Type': 'application/cbor'} 161 | submit = requests.post(self.SUBMIT_TX_URL, headers = cbor_header, \ 162 | data = cbor_tx, timeout=timeout) 163 | submit = json.loads(submit.content) 164 | else: 165 | with open(file, "rb") as cbor_tx: 166 | cbor_tx = cbor_tx.read() 167 | cbor_header = {'Content-Type': 'application/cbor', "Authorization": f"Bearer {self.BEARER}"} 168 | submit = requests.post(self.SUBMIT_TX_URL, headers = cbor_header, \ 169 | data = cbor_tx, timeout=timeout) 170 | submit = json.loads(submit.content) 171 | 172 | return submit 173 | 174 | 175 | @Exception_Handler 176 | def get_tx_status(self, *args): 177 | """ 178 | Get the number of block confirmations for a given transaction hash list. 179 | 180 | :param list tx_hash: list of transaction(s) hash to search and read utxos data. 181 | :return: list of all info about utxos in transaction(s) 182 | :rtype: list. 183 | """ 184 | timeout = get_timeout() 185 | get_format = {"_tx_hashes": [args]} 186 | tx_status = requests.post(self.TX_STATUS_URL, json = get_format, timeout=timeout) 187 | tx_status = json.loads(tx_status.content) 188 | return tx_status 189 | -------------------------------------------------------------------------------- /koios_python/urls.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Provides all urls used in the library 4 | """ 5 | 6 | class URLs: 7 | # imported like class methods 8 | from .epoch import get_epoch_info, get_epoch_params, get_epoch_block_protocols 9 | from .network import get_tip, get_genesis, get_totals, get_param_updates, get_treasury_withdrawals, get_reserve_withdrawals 10 | from .block import get_blocks, get_block_info, get_block_txs 11 | from .address import get_address_info, get_address_txs, get_address_assets, get_credential_txs, get_credential_utxos,\ 12 | get_address_utxos 13 | from .account import get_account_info, get_account_info_cached, get_account_list, get_account_rewards, get_account_utxos,\ 14 | get_account_updates, get_account_addresses, get_account_assets, get_account_history, get_account_assets_paginated, get_account_txs 15 | from .asset import get_asset_list, get_asset_addresses, get_asset_info, get_asset_history, get_policy_asset_info, \ 16 | get_asset_summary, get_asset_txs, get_asset_info_bulk, get_asset_token_registry, get_asset_nft_address,\ 17 | get_policy_asset_addresses, get_policy_asset_list, get_asset_utxos 18 | from .pool import get_pool_list, get_pool_info, get_pool_stake_snapshot, get_pool_delegators, get_pool_delegators_history, get_pool_blocks, \ 19 | get_pool_history, get_pool_updates, get_pool_relays, get_pool_metadata, get_pool_registrations, get_pool_retirements 20 | from .scripts import get_native_script_list, get_plutus_script_list, get_script_redeemers, get_datum_info, get_script_utxos, get_script_info 21 | from .transactions import get_tx_info, get_tx_utxos, get_tx_metadata, get_tx_metalabels, submit_tx, get_tx_status, get_utxo_info 22 | from .ogmios import query 23 | 24 | 25 | def __init__(self, url='https://api.koios.rest/api/v1/', network='mainnet', server='koios', bearer=None): 26 | 27 | self.version = 'koios-python v2.0.0' 28 | self.url = url 29 | self.network = network 30 | self.server = server 31 | self.BEARER = bearer 32 | 33 | # change subdomain to network name then change the rest of urls to use the new subdomain 34 | if self.network == 'preview' or self.network == 'preprod': 35 | # replace mainnet subdomain with "testnet" subdomain 36 | self.url = self.url.replace(self.url.split('.')[0], self.network) 37 | # add https:// to the url 38 | self.url = 'https://' + self.url 39 | elif self.network == 'mainnet': 40 | self.url = url 41 | 42 | if self.server == "ogmios": 43 | self.url = url + "ogmios/" 44 | 45 | if self.server == "koios": 46 | self.url = url 47 | 48 | 49 | 50 | # Network URLs 51 | self.TIP_URL = self.url + "tip" 52 | self.GENESIS_URL = self.url + "genesis" 53 | self.TOTALS_URL = self.url + "totals" 54 | self.NETWORK_PARAM_UPDATES_URL = self.url + "param_updates" 55 | self.RESERVE_WITHDRAWALS_URL = self.url + "reserve_withdrawals" 56 | self.TREASURY_WITHDRAWALS_URL = self.url + "treasury_withdrawals" 57 | 58 | # Epoch URLs 59 | self.EPOCH_INFO_URL = self.url + "epoch_info" 60 | self.EPOCH_PARAMS_URL = self.url + "epoch_params" 61 | self.EPOCH_BLOCKS_URL = self.url + "epoch_block_protocols" 62 | 63 | # Block URLs 64 | self.BLOCKS_URL = self.url + "blocks" 65 | self.BLOCK_INFO_URL = self.url + "block_info" 66 | self.BLOCK_TXS_URL = self.url + "block_txs" 67 | 68 | # Transaction URLs 69 | self.UTXO_INFO_URL = self.url + "utxo_info" 70 | self.TX_INFO_URL = self.url + "tx_info" 71 | self.TX_UTXOS_URL = self.url + "tx_utxos" 72 | self.TX_METADATA_URL = self.url + "tx_metadata" 73 | self.TX_METALABELS_URL = self.url + "tx_metalabels" 74 | self.SUBMIT_TX_URL = self.url + "submittx" 75 | self.TX_STATUS_URL = self.url + "tx_status" 76 | 77 | 78 | # Address URLs 79 | self.ADDRESS_INFO_URL = self.url + "address_info" 80 | self.ADDRESS_TXS_URL = self.url + "address_txs" 81 | self.ADDRESS_ASSETS_URL = self.url + "address_assets" 82 | self.ADDRESS_CREDENTIAL_TXS_URL = self.url + "credential_txs" 83 | self.ADDRESS_CREDENTIAL_UTXOS_URL = self.url + "credential_utxos" 84 | self.ADDRESS_UTXOS_URL = self.url + "address_utxos" 85 | 86 | # Stake Account URLs 87 | self.ACCOUNT_LIST_URL = self.url + "account_list?offset=" 88 | self.ACCOUNT_INFO_URL = self.url + "account_info" 89 | self.ACCOUNT_UTXOS_URL = self.url + "account_utxos?" 90 | self.ACCOUNT_INFO_CACHED_URL = self.url + "account_info_cached" 91 | self.ACCOUNT_REWARDS_URL = self.url + "account_rewards" 92 | self.ACCOUNT_UPDATES_URL = self.url + "account_updates" 93 | self.ACCOUNT_ADDRESSES_URL = self.url + "account_addresses" 94 | #self.ACCOUNT_ASSETS_URL = self.url + "account_assets?offset=" 95 | self.ACCOUNT_ASSETS_URL = self.url + "account_assets" 96 | self.ACCOUNT_HISTORY_URL = self.url + "account_history" 97 | self.ACCOUNT_TXS_URL = self.url + "account_txs" 98 | 99 | # Asset URLs 100 | self.ASSET_LIST_URL = self.url + "asset_list" 101 | self.ASSET_ADDRESSES_URL = self.url + "asset_addresses?_asset_policy=" 102 | self.ASSET_INFO_URL = self.url + "asset_info?_asset_policy=" #DEPRECATED 103 | self.ASSET_HISTORY_URL = self.url + "asset_history?_asset_policy=" 104 | self.POLICY_ASSET_INFO_URL = self.url + "policy_asset_info?_asset_policy=" 105 | self.ASSET_SUMMARY_URL = self.url + "asset_summary?_asset_policy=" 106 | self.ASSET_TXS_URL = self.url + "asset_txs?_asset_policy=" 107 | self.ASSET_NFT_ADDRESS_URL = self.url + "asset_nft_address?_asset_policy=" 108 | self.ASSET_INFO_BULK_URL = self.url + "asset_info" 109 | self.ASSET_TOKEN_REGISTRY_URL = self.url + "asset_token_registry" 110 | self.POLICY_ASSET_ADDRESSES_LIST_URL = self.url + "policy_asset_addresses?_asset_policy=" 111 | self.POLICY_ASSET_LIST_URL = self.url + "policy_asset_list?_asset_policy=" 112 | self.ASSET_UTXOS_URL = self.url + "asset_utxos" 113 | 114 | # Pool URLs 115 | self.POOL_LIST_URL = self.url + "pool_list" 116 | self.POOL_INFO_URL = self.url + "pool_info" 117 | self.POOL_STAKE_SNAPSHOT = self.url + "pool_stake_snapshot?_pool_bech32=" 118 | self.POOL_DELEGATORS_URL = self.url + "pool_delegators?_pool_bech32=" 119 | self.POOL_DELEGATORS_HISTORY_URL = self.url + "pool_delegators_history?_pool_bech32=" 120 | self.POOL_BLOCKS_URL = self.url + "pool_blocks?_pool_bech32=" 121 | self.POOL_HISTORY_URL = self.url + "pool_history?_pool_bech32=" 122 | self.POOL_UPDATES_URL = self.url + "pool_updates" 123 | self.POOL_RELAYS_URL = self.url + "pool_relays" 124 | self.POOL_METADATA_URL = self.url + "pool_metadata" 125 | self.POOL_REGISTRATIONS_URL = self.url + "pool_registrations?_epoch_no=" 126 | self.POOL_RETIREMENTS_URL = self.url + "pool_retirements?_epoch_no=" 127 | 128 | # Scripts URLs 129 | self.NATIVE_SCRIPT_LIST_URL = self.url + "native_script_list" 130 | self.PLUTUS_SCRIPT_LIST_URL = self.url + "plutus_script_list" 131 | self.SCRIPT_REDEEMERS_URL = self.url + "script_redeemers?_script_hash=" 132 | self.DATUM_INFO_URL = self.url + "datum_info" 133 | self.SCRIPT_UTXOS_URL = self.url + "script_utxos?_script_hash=" 134 | self.SCRIPT_INFO_URL = self.url + "script_info" -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pathlib 4 | from setuptools import setup, find_packages 5 | 6 | HERE = pathlib.Path(__file__).parent 7 | LONG_DESCRIPTION = (HERE / "README.md").read_text(encoding='utf-8') 8 | 9 | setup( 10 | version = '2.0.0', 11 | name = 'koios-python', 12 | author = 'Quixote Stake Pool', 13 | author_email = 'quixotepool@proton.me', 14 | url = 'https://github.com/QuixoteSystems', 15 | license = 'MIT', 16 | description = 'Python wrapper Library using Koios API for accessing information stored on the Cardano Blockchain', 17 | long_description= LONG_DESCRIPTION, 18 | long_description_content_type= 'text/markdown', 19 | keywords = ['koios', 'blockchain', 'cardano', 'API', 'REST', 'RESTful'], 20 | include_package_data = True, 21 | packages = find_packages(include=['koios_python']), 22 | install_requieres = ["requests"], 23 | classifiers=[ # Optional 24 | # How mature is this project? Common values are 25 | # 3 - Alpha 26 | # 4 - Beta 27 | # 5 - Production/Stable 28 | 'Development Status :: 4 - Beta', 29 | 30 | 'Intended Audience :: Developers', 31 | 32 | 'Topic :: Software Development :: Build Tools', 33 | 34 | 'License :: OSI Approved :: MIT License', 35 | 36 | 'Programming Language :: Python :: 3.8', 37 | 'Programming Language :: Python :: 3.9', 38 | 'Programming Language :: Python :: 3.10', 39 | 'Programming Language :: Python :: 3.11', 40 | 'Programming Language :: Python :: 3 :: Only', 41 | ], 42 | ) 43 | -------------------------------------------------------------------------------- /tests.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Examples to check how works Koios-Python Library 4 | """ 5 | import pprint as pp # We recommend use pprint library to show your outputs 6 | from koios_python import * # We need to install and import koios_python library 7 | # from koios_python import block, epochs # alternative if we just need some functions 8 | import time 9 | import os 10 | #from dotenv import load_dotenv 11 | # load the environment variables 12 | #load_dotenv() 13 | # Get api token 14 | token = os.getenv("TOKEN") 15 | 16 | 17 | ########################################################################################## 18 | ## MAINNET PARAMETERS (simple TESTS) 19 | # Public Tier with Default Koios Endpoint 20 | #kp = URLs() # We need to create an instance of the class URLs (no bearer token) FREE TIER 21 | 22 | # Select this if you are usinf Bearer Token. We need to create an instance of the class URLs (with bearer token) 23 | #kp = URLs(bearer=token) 24 | #pp.pprint(kp.BEARER) 25 | 26 | ########################################################################################## 27 | # Network Endpoint Tests 28 | ########################################################################################## 29 | # # Get tip (no bearer token) 30 | #pp.pprint(kp.get_tip()) 31 | 32 | # # Get tip (with bearer token) 33 | # pp.pprint(kp_token.get_tip()) 34 | 35 | # # Get Genesis (no bearer token) 36 | # pp.pprint(kp.get_genesis()) 37 | 38 | # # Get Genesis (with bearer token) 39 | # pp.pprint(kp_token.get_genesis()) 40 | 41 | # # Get Totals (no bearer token) 42 | # pp.pprint(kp.get_totals()) 43 | # pp.pprint(kp.get_totals(epoch_no=320)) 44 | 45 | # # Get Totals (with bearer token) 46 | # pp.pprint(kp_token.get_totals()) 47 | # pp.pprint(kp_token.get_totals(epoch_no=320)) 48 | 49 | # Get Network Param Updates (no bearer token) 50 | # pp.pprint(kp.get_param_updates()) 51 | 52 | # # Get Network Param Updates (with bearer token) 53 | # pp.pprint(kp_token.get_param_updates()) 54 | 55 | # # Get Reserve Withdrawals (no bearer token) 56 | # pp.pprint(kp.get_reserve_withdrawals()) 57 | 58 | # # Get Reserve Withdrawals (with bearer token) 59 | # pp.pprint(kp_token.get_reserve_withdrawals()) 60 | 61 | # # Get Treasury Withdrawals (no bearer token) 62 | # pp.pprint(kp.get_treasury_withdrawals()) 63 | 64 | # # Get Treasury Withdrawals (with bearer token) 65 | # pp.pprint(kp_token.get_treasury_withdrawals()) 66 | 67 | ########################################################################################## 68 | # Epoch Endpoint Tests 69 | ########################################################################################## 70 | 71 | # # Get Epoch Info (no bearer token) 72 | # get_epoch_320_info = kp.get_epoch_info(epoch_no=320, include_next_epoch=True) 73 | # pp.pprint(get_epoch_320_info) 74 | 75 | # get_epoch_320_info_false = kp.get_epoch_info(epoch_no=320, include_next_epoch=False) 76 | # pp.pprint(get_epoch_320_info_false) 77 | 78 | # # Get Epoch Info (with bearer token) 79 | # get_epoch_320_info = kp_token.get_epoch_info(epoch_no=320, include_next_epoch=True) 80 | # pp.pprint(get_epoch_320_info) 81 | 82 | # get_epoch_320_info_false = kp_token.get_epoch_info(epoch_no=320, include_next_epoch=False) 83 | # pp.pprint(get_epoch_320_info_false) 84 | 85 | # # Get Epoch Params (no bearer token) 86 | # pp.pprint(kp.get_epoch_params(320)) 87 | 88 | # # Get Epoch Params (with bearer token) 89 | # pp.pprint(kp_token.get_epoch_params(320)) 90 | 91 | # # Get Epoch Block Protocols (no bearer token) 92 | # pp.pprint(kp.get_epoch_block_protocols(320)) 93 | 94 | # # Get Epoch Block Protocols (with bearer token) 95 | # pp.pprint(kp_token.get_epoch_block_protocols(320)) 96 | 97 | ########################################################################################## 98 | # Block Endpoint Tests 99 | ########################################################################################## 100 | 101 | # Get Block List (no bearer token) 102 | # pp.pprint(kp.get_blocks("0-10")) 103 | 104 | # # Get Block List (with bearer token) 105 | # pp.pprint(kp_token.get_blocks("0-10")) 106 | 107 | # # Get Block Info (no bearer token) 108 | # pp.pprint(kp.get_block_info(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30", \ 109 | # "60188a8dcb6db0d80628815be2cf626c4d17cb3e826cebfca84adaff93ad492a", \ 110 | # "c6646214a1f377aa461a0163c213fc6b86a559a2d6ebd647d54c4eb00aaab015"])) 111 | 112 | # # Get Block Info (with bearer token) 113 | # pp.pprint(kp_token.get_block_info(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30", \ 114 | # "60188a8dcb6db0d80628815be2cf626c4d17cb3e826cebfca84adaff93ad492a", \ 115 | # "c6646214a1f377aa461a0163c213fc6b86a559a2d6ebd647d54c4eb00aaab015"])) 116 | 117 | # # Get Block Txs (no bearer token) 118 | # pp.pprint(kp.get_block_txs(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30", \ 119 | # "60188a8dcb6db0d80628815be2cf626c4d17cb3e826cebfca84adaff93ad492a", \ 120 | # "c6646214a1f377aa461a0163c213fc6b86a559a2d6ebd647d54c4eb00aaab015"])) 121 | 122 | # # Get Block Txs (with bearer token) 123 | # pp.pprint(kp_token.get_block_txs(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30", \ 124 | # "60188a8dcb6db0d80628815be2cf626c4d17cb3e826cebfca84adaff93ad492a", \ 125 | # "c6646214a1f377aa461a0163c213fc6b86a559a2d6ebd647d54c4eb00aaab015"])) 126 | 127 | 128 | 129 | ########################################################################################## 130 | # Transaction Endpoint Tests 131 | ########################################################################################## 132 | 133 | # # Get UTxO info 134 | # pp.pprint(kp.get_utxo_info(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e#0"])) 135 | 136 | # pp.pprint(kp.get_utxo_info(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e#0", \ 137 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94#0"])) 138 | 139 | # # Get UTxO info ( extended) 140 | # pp.pprint(kp.get_utxo_info(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e#0", \ 141 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94#0"], extended=True, content_range="0-9")) 142 | # pp.pprint(kp.get_utxo_info(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e#0", \ 143 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94#0"], extended=False, content_range="0-9")) 144 | 145 | # # Get Tx Info (no bearer token) 146 | # pp.pprint(kp.get_tx_info(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ 147 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) 148 | 149 | # # Get Tx Info (with bearer token) 150 | # pp.pprint(kp_token.get_tx_info(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ 151 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) 152 | 153 | # # Get Tx Metadata (no bearer token) 154 | # pp.pprint(kp.get_tx_metadata(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ 155 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) 156 | 157 | # # Get Tx Metadata (with bearer token) 158 | # pp.pprint(kp_token.get_tx_metadata(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ 159 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) 160 | 161 | # # Get Tx Metalabels (no bearer token) 162 | # pp.pprint(kp.get_tx_metalabels(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ 163 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) 164 | 165 | # # Get Tx Metalabels (with bearer token) 166 | # pp.pprint(kp_token.get_tx_metalabels(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ 167 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) 168 | 169 | # # Submit Tx (no bearer token) 170 | # Testing soon 171 | 172 | # # Submit Tx (with bearer token) 173 | # Testing soon 174 | 175 | # # Get Tx Status (no bearer token) 176 | # pp.pprint(kp.get_tx_status(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ 177 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) 178 | 179 | # # Get Tx Status (with bearer token) 180 | # pp.pprint(kp_token.get_tx_status(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ 181 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) 182 | 183 | # # Get Tx Utxos (no bearer token) 184 | # pp.pprint(kp.get_tx_utxos("f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ 185 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94")) 186 | 187 | # # Get Tx Utxos (with bearer token) 188 | # pp.pprint(kp_token.get_tx_utxos("f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e", \ 189 | # "0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94")) 190 | 191 | ########################################################################################## 192 | # Address Endpoint Tests 193 | ########################################################################################## 194 | 195 | # # Get Address Info (no bearer token) 196 | # pp.pprint(kp.get_address_info(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ 197 | # "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"])) 198 | 199 | # # Get Address Info (with bearer token) 200 | # pp.pprint(kp_token.get_address_info(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ 201 | # "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"])) 202 | 203 | # # Get Address UTxOs (no bearer token) 204 | # pp.pprint(kp.get_address_utxos(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ 205 | # "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"])) 206 | 207 | # # Get Address UTxOs (no bearer token, extended) 208 | # pp.pprint(kp.get_address_utxos(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ 209 | # "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"], extended=True, content_range="0-9")) 210 | # pp.pprint(kp.get_address_utxos(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ 211 | # "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"], extended=False, content_range="0-9")) 212 | 213 | # # Get Address UTxOs (with bearer token) 214 | # pp.pprint(kp_token.get_address_utxos(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ 215 | # "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"])) 216 | 217 | # # Get Address UTxOs (with bearer token, extended) 218 | # pp.pprint(kp_token.get_address_utxos(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ 219 | # "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"], extended=True, content_range="0-9")) 220 | # pp.pprint(kp_token.get_address_utxos(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ 221 | # "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"], extended=False, content_range="0-9")) 222 | 223 | # # Get Address Txs (no bearer token) 224 | # pp.pprint(kp.get_address_txs(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ 225 | # "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"], 226 | # after_block=6238675)) 227 | 228 | # # Get Address Txs (with bearer token) 229 | # pp.pprint(kp_token.get_address_txs(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv",\ 230 | # "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"], 231 | # after_block=6238675)) 232 | 233 | # # Get Address Assets (no bearer token) 234 | # pp.pprint(kp.get_address_assets(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv", \ 235 | # "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"])) 236 | 237 | # # Get Address Assets (with bearer token) 238 | # pp.pprint(kp_token.get_address_assets(["addr1qy2jt0qpqz2z2z9zx5w4xemekkce7yderz53kjue53lpqv90lkfa9sgrfjuz6uvt4uqtrqhl2kj0a9lnr9ndzutx32gqleeckv", \ 239 | # "addr1q9xvgr4ehvu5k5tmaly7ugpnvekpqvnxj8xy50pa7kyetlnhel389pa4rnq6fmkzwsaynmw0mnldhlmchn2sfd589fgsz9dd0y"])) 240 | 241 | # # Get UTxOs from payment credentials (no bearer token) 242 | # pp.pprint(kp.get_credential_utxos(["025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52", \ 243 | # "13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555"], extended=True, content_range="0-9")) 244 | 245 | # # Get UTxOs from payment credentials (with bearer token) 246 | # pp.pprint(kp_token.get_credential_utxos(["025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52", 247 | # "13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555"], extended=False, content_range="0-9")) 248 | 249 | # # Get Credential TXs (no bearer token) 250 | # pp.pprint(kp.get_credential_txs("025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52", \ 251 | # "13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555", after_block=6238675)) 252 | 253 | # # Get Credential TXs (with bearer token) 254 | # pp.pprint(kp_token.get_credential_txs("025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52", \ 255 | # "13f6870c5e4f3b242463e4dc1f2f56b02a032d3797d933816f15e555", after_block=6238675)) 256 | 257 | ########################################################################################## 258 | # Pool Endpoint Tests 259 | ########################################################################################## 260 | 261 | # # Get Pool List 262 | # pp.pprint(kp.get_pool_list('0-10')) 263 | 264 | # # Get Pool Info 265 | # pp.pprint(kp.get_pool_info(["pool100wj94uzf54vup2hdzk0afng4dhjaqggt7j434mtgm8v2gfvfgp", 266 | # "pool102s2nqtea2hf5q0s4amj0evysmfnhrn4apyyhd4azcmsclzm96m", 267 | # "pool102vsulhfx8ua2j9fwl2u7gv57fhhutc3tp6juzaefgrn7ae35wm"])) 268 | 269 | # # Get Pool Stake Snapshot 270 | # pp.pprint(kp.get_pool_stake_snapshot("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc")) 271 | 272 | # # Get Pool Delegators 273 | # pp.pprint(kp.get_pool_delegators("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc", content_range="0-9")) 274 | 275 | # # Get Pool Delegators History 276 | # pp.pprint(kp.get_pool_delegators_history("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc", epoch_no=320)) 277 | 278 | # # Get Pool Metadata 279 | # pp.pprint(kp.get_pool_metadata()) 280 | # pp.pprint(kp.get_pool_metadata("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc")) 281 | 282 | # # Get Pool Relays 283 | # pp.pprint(kp.get_pool_relays()) 284 | # pp.pprint(kp.get_pool_relays('0-70')) 285 | 286 | # # Get Pool Updates 287 | # pp.pprint(kp.get_pool_updates("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc")) 288 | 289 | ########################################################################################## 290 | # Asset Endpoint Tests 291 | ########################################################################################## 292 | 293 | # # Get Asset List (no bearer token) 294 | # pp.pprint(kp.get_asset_list(content_range="0-9")) 295 | 296 | # # Get Asset List (with bearer token) 297 | # pp.pprint(kp_token.get_asset_list(content_range="0-9")) 298 | 299 | # # Get Policy Asset List (no bearer token) 300 | # pp.pprint(kp.get_policy_asset_list("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","0-9")) 301 | 302 | # # Get Policy Asset List (with bearer token) 303 | # pp.pprint(kp_token.get_policy_asset_list("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","0-9")) 304 | 305 | # # Get Asset Token Registry (no bearer token) 306 | # pp.pprint(kp.get_asset_token_registry("0-9")) 307 | 308 | # # Get Asset Token Registry (with bearer token) 309 | # pp.pprint(kp_token.get_asset_token_registry("0-9")) 310 | 311 | # # Get Asset Information (Bulk) (no bearer token) 312 | # pp.pprint(kp.get_asset_info_bulk(["750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b"], \ 313 | # ["f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a","6b6f696f732e72657374"])) 314 | 315 | # # Get Asset Information (Bulk) (with bearer token) 316 | # pp.pprint(kp_token.get_asset_info_bulk(["750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b"], \ 317 | # ["f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a","6b6f696f732e72657374"])) 318 | 319 | # # Get Asset UTxOs (no bearer token, extended=False) 320 | # pp.pprint(kp.get_asset_utxos(["750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b"], \ 321 | # ["f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a","6b6f696f732e72657374"], extended=False)) 322 | 323 | # # Get Asset UTxOs (no bearer token, extended=True) 324 | # pp.pprint(kp.get_asset_utxos(["750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b"], \ 325 | # ["f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a","6b6f696f732e72657374"], extended=True, content_range="0-9")) 326 | 327 | # # Get Asset History (no bearer token) 328 | # pp.pprint(kp.get_asset_history("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b" \ 329 | # , content_range="0-9")) 330 | 331 | # # Get Asset History (with bearer token) 332 | # pp.pprint(kp_token.get_asset_history("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b" \ 333 | # , content_range="0-9")) 334 | 335 | # # Get Asset Addresses (no bearer token) 336 | # pp.pprint(kp.get_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b" \ 337 | # , content_range="0-9")) 338 | 339 | # # Get Asset Addresses (with bearer token) 340 | # pp.pprint(kp_token.get_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b" \ 341 | # , content_range="0-9")) 342 | 343 | # # Get Asset NFT Address (no bearer token) 344 | # pp.pprint(kp.get_asset_nft_address("f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a", "68616e646c65")) 345 | 346 | # # Get Asset NFT Address (with bearer token) 347 | # pp.pprint(kp_token.get_asset_nft_address("f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a", "68616e646c65")) 348 | 349 | # # Get Policy Asset Adress List (no bearer token) 350 | # pp.pprint(kp.get_policy_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", content_range="0-9")) 351 | 352 | # # Get Policy Asset Adress List (with bearer token) 353 | # pp.pprint(kp_token.get_policy_asset_addresses("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", content_range="0-9")) 354 | 355 | # # Get Policy Asset Info (no bearer token) 356 | # pp.pprint(kp.get_policy_asset_info("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501")) 357 | 358 | # # Get Policy Asset Info (with bearer token) 359 | # pp.pprint(kp_token.get_policy_asset_info("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501")) 360 | 361 | # # Get Asset Summary (no bearer token) 362 | # pp.pprint(kp.get_asset_summary("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b")) 363 | 364 | # # Get Asset Summary (with bearer token) 365 | # pp.pprint(kp_token.get_asset_summary("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b")) 366 | 367 | # # Get Asset Transactions (no bearer token) 368 | # pp.pprint(kp.get_asset_txs("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b", after_block=50000,\ 369 | # content_range="0-9")) 370 | 371 | # # Get Asset Transactions (with bearer token) 372 | # pp.pprint(kp_token.get_asset_txs("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b", after_block=50000,\ 373 | # content_range="0-9")) 374 | 375 | ########################################################################################## 376 | # Account Endpoint Tests 377 | ########################################################################################## 378 | 379 | # # Get Account List (no bearer token) 380 | # pp.pprint(kp.get_account_list(content_range="0-9")) 381 | 382 | # # Get Account List (with bearer token) 383 | # pp.pprint(kp_token.get_account_list(content_range="0-9")) 384 | 385 | # # Get Account Info (no bearer token) 386 | # pp.pprint(kp.get_account_info(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ 387 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) 388 | 389 | # # Get Account Info (with bearer token) 390 | # pp.pprint(kp_token.get_account_info(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ 391 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) 392 | 393 | # # Get Account Info Cached (no bearer token) 394 | # pp.pprint(kp.get_account_info_cached(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ 395 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) 396 | 397 | # # Get Account Info Cached (with bearer token) 398 | # pp.pprint(kp_token.get_account_info_cached(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ 399 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) 400 | 401 | # # Get UTxOs from Stake Addresses/Accounts (no bearer token) 402 | # pp.pprint(kp.get_account_utxos(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ 403 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"], extended=False, content_range="0-9")) 404 | 405 | # # Get UTxOs from Stake Addresses/Accounts (with bearer token) 406 | # pp.pprint(kp_token.get_account_utxos(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ 407 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"], extended=True, content_range="0-9")) 408 | 409 | # # Get Account Txs (no bearer token) 410 | # pp.pprint(kp.get_account_txs("stake1u8yxtugdv63wxafy9d00nuz6hjyyp4qnggvc9a3vxh8yl0ckml2uz", after_block=50000)) 411 | 412 | # # Get Account Txs (with bearer token) 413 | # pp.pprint(kp_token.get_account_txs("stake1u8yxtugdv63wxafy9d00nuz6hjyyp4qnggvc9a3vxh8yl0ckml2uz", after_block=50000)) 414 | 415 | # # Get Account Rewards (no bearer token) 416 | # pp.pprint(kp.get_account_rewards(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", 417 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"], epoch_no=409)) 418 | 419 | # # Get Account Rewards (with bearer token) 420 | # pp.pprint(kp_token.get_account_rewards(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", 421 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"], epoch_no=409)) 422 | 423 | # # Get Account Updates (no bearer token) 424 | # pp.pprint(kp.get_account_updates(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ 425 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) 426 | 427 | # # Get Account Updates (with bearer token) 428 | # pp.pprint(kp_token.get_account_updates(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", \ 429 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) 430 | 431 | # # Get Account Addresses (no bearer token) 432 | # pp.pprint(kp.get_account_addresses(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", \ 433 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"], content_range="0-9", first_only=False, 434 | # empty=False)) 435 | 436 | # # Get Account Addresses (with bearer token) 437 | # pp.pprint(kp_token.get_account_addresses(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", \ 438 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"], content_range="0-9", first_only=False, 439 | # empty=False)) 440 | 441 | # # Get Account Assets (no bearer token) 442 | # pp.pprint(kp.get_account_assets(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ 443 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) 444 | 445 | # # Get Account Assets (with bearer token) 446 | # pp.pprint(kp_token.get_account_assets(["stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250",\ 447 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy"])) 448 | 449 | # # Get Account History (no bearer token) 450 | # pp.pprint(kp.get_account_history("stake1u8yxtugdv63wxafy9d00nuz6hjyyp4qnggvc9a3vxh8yl0ckml2uz", \ 451 | # content_range="0-9", epoch_no=409)) 452 | 453 | # # Get Account History (with bearer token) 454 | # pp.pprint(kp_token.get_account_history("stake1u8yxtugdv63wxafy9d00nuz6hjyyp4qnggvc9a3vxh8yl0ckml2uz", \ 455 | # content_range="0-9", epoch_no=409)) 456 | 457 | ########################################################################################## 458 | # Script Endpoint Tests 459 | ########################################################################################## 460 | 461 | # # Get Script Info (no bearer token) 462 | # pp.pprint(kp.get_script_info(["bd2119ee2bfb8c8d7c427e8af3c35d537534281e09e23013bca5b138", \ 463 | # "c0c671fba483641a71bb92d3a8b7c52c90bf1c01e2b83116ad7d4536"])) 464 | 465 | # # Get Script Info (with bearer token) 466 | # pp.pprint(kp_token.get_script_info(["bd2119ee2bfb8c8d7c427e8af3c35d537534281e09e23013bca5b138", \ 467 | # "c0c671fba483641a71bb92d3a8b7c52c90bf1c01e2b83116ad7d4536"])) 468 | 469 | # # Get Native Script List (no bearer token) 470 | # pp.pprint(kp.get_native_script_list(content_range="0-9")) 471 | 472 | # # Get Native Script List (with bearer token) 473 | # pp.pprint(kp_token.get_native_script_list(content_range="0-9")) 474 | 475 | # # Get Plutus Script List (no bearer token) 476 | # pp.pprint(kp.get_plutus_script_list(content_range="0-9")) 477 | 478 | # # Get Plutus Script List (with bearer token) 479 | # pp.pprint(kp_token.get_plutus_script_list(content_range="0-9")) 480 | 481 | # # Get Script UTxOs (no bearer token) 482 | # pp.pprint(kp.get_script_utxos(script_hash="d8480dc869b94b80e81ec91b0abe307279311fe0e7001a9488f61ff8", extended=False)) 483 | 484 | # # Get Script UTxOs (with bearer token) 485 | # pp.pprint(kp_token.get_script_utxos(script_hash="d8480dc869b94b80e81ec91b0abe307279311fe0e7001a9488f61ff8", extended=True)) 486 | 487 | # # Get Script Redeemers (no bearer token) 488 | # pp.pprint(kp.get_script_redeemers(script_hash="d8480dc869b94b80e81ec91b0abe307279311fe0e7001a9488f61ff8")) 489 | 490 | # # Get Script Redeemers (with bearer token) 491 | # pp.pprint(kp_token.get_script_redeemers(script_hash="d8480dc869b94b80e81ec91b0abe307279311fe0e7001a9488f61ff8")) 492 | 493 | # # Get Datum Info (no bearer token) 494 | # pp.pprint(kp.get_datum_info(["818ee3db3bbbd04f9f2ce21778cac3ac605802a4fcb00c8b3a58ee2dafc17d46", \ 495 | # "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0"])) 496 | 497 | # # Get Datum Info (with bearer token) 498 | # pp.pprint(kp_token.get_datum_info(["818ee3db3bbbd04f9f2ce21778cac3ac605802a4fcb00c8b3a58ee2dafc17d46", \ 499 | # "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0"])) 500 | 501 | ########################################################################################## 502 | # End of Simple Testing 503 | ########################################################################################## 504 | 505 | 506 | 507 | 508 | ############################################################ 509 | # Custom Koios Endpoint 510 | # kp_custom_endpoint = koios_python.URLs(url="https://koios-otg.tosidrop.io/api/v0/",) # We need to create an instance of the class URLs and can specify the network if needed 511 | # print(kp_custom_endpoint.get_tip_test_version()) 512 | 513 | 514 | ############################################################ 515 | ## MESASUMENT TOOLS 516 | # To measure the speed of a function: 517 | ''' 518 | total=0 519 | times=3 520 | for i in range(times): 521 | start = time.time() 522 | kp.get_account_assets("stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz") 523 | #kp.get_account_assets_2("stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz") 524 | #kp.get_account_assets_2("stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz", "1000-1999") 525 | end = time.time() 526 | loop= end - start 527 | total += loop 528 | total= total / times 529 | print('Average Time: '+ str(total) + ' s') 530 | ''' 531 | # To count number of assets in a Stake Address 532 | 533 | # query=kp.get_account_assets("stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz") 534 | # #query=kp.get_account_addresses("stake1u8jm3v2q8h46q485j8e8uxqmj33f4cy4xvadkuq5g2c27ls44jflg") 535 | # d=query[0] 536 | # print(sum([len(d[x]) for x in d if isinstance(d[x], list)])) 537 | 538 | 539 | ############################################################ 540 | # Heavy/Large data tests 541 | ############################################################ 542 | 543 | #pprint.pp(kp.get_account_assets_2("stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz", "0-999")) 544 | # pprint.pp(kp.get_account_assets("stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz")) 545 | # Get Native Script List, first 11 scripts 546 | #pprint.pp(kp.get_native_script_list()) 547 | 548 | #print(len(kp.get_native_script_list('0-10'))) 549 | 550 | # Crazy Heavy Account with large number of assets 551 | #pprint.pp(kp.get_account_assets("stake1uxqh9rn76n8nynsnyvf4ulndjv0srcc8jtvumut3989cqmgjt49h6")) 552 | 553 | # print('------------------------------------------------------------------------------------------------------------------------------------------------------') 554 | 555 | # pprint.pp(kp.get_account_assets_2("stake1uxqh9rn76n8nynsnyvf4ulndjv0srcc8jtvumut3989cqmgjt49h6", "0-999")) 556 | 557 | # Heavy Account with large number of assets 558 | #pprint.pp(kp.get_account_assets("stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz")) 559 | 560 | # Address of a Stake Address Account 561 | #pprint.pp(kp.get_account_addresses("stake1uxttvx739dt505d6sxvdykj8336utdq2q92jk3sv253zp5qalcz84")) 562 | 563 | # Get List of Accounts from 2000 to 2999 564 | #pprint.pp(kp.get_account_list("2000-2999")) 565 | 566 | # Get List of All Accounts 567 | #pprint.pp(kp.get_account_list()) 568 | 569 | # Get Stake Addres Account Histoy 570 | #pprint.pp(kp.get_account_history("stake1uxqh9rn76n8nynsnyvf4ulndjv0srcc8jtvumut3989cqmgjt49h6")) 571 | 572 | # print(kp_mainnet.url) 573 | 574 | # print(genesis_info_testnet) 575 | 576 | # pprint.pp(kp.get_epoch_info(370)) 577 | 578 | # pprint.pp(kp.get_epoch_params(370)) 579 | 580 | # pprint.pp(kp.get_epoch_block_protocols(380)) 581 | 582 | #pprint.pp(kp.get_genesis()) 583 | 584 | #pprint.pp(kp.get_asset_history("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b")) 585 | #pprint.pp(kp.get_asset_summary("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b")) 586 | 587 | # pprint.pp(kp.get_asset_txs("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501","424f4f4b",63487)) 588 | 589 | # Get Datum information for given datum hashes of a Plutus Contracts 590 | #pprint.pp(kp.get_datum_info('818ee3db3bbbd04f9f2ce21778cac3ac605802a4fcb00c8b3a58ee2dafc17d46', 591 | # "45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0")) 592 | 593 | # pprint.pp(kp_mainnet.get_pool_stake_snapshot("pool155efqn9xpcf73pphkk88cmlkdwx4ulkg606tne970qswczg3asc")) 594 | 595 | # Get info of epoch number 337: 596 | #pprint.pp(koios_python.get_epoch_params(337)) 597 | 598 | # Get info of two transactions: 599 | #pprint.pp(koios_python.get_tx_metadata(["f144a8264acf4bdfe2e1241170969c930d64ab6b0996a4a45237b623f1dd670e" \ 600 | # ,"0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) 601 | 602 | #Get detailed information about a specifics blocks 603 | # pprint.pp(kp.get_block_info(["fb9087c9f1408a7bbd7b022fd294ab565fec8dd3a8ef091567482722a1fa4e30", \ 604 | # "60188a8dcb6db0d80628815be2cf626c4d17cb3e826cebfca84adaff93ad492a", \ 605 | # "c6646214a1f377aa461a0163c213fc6b86a559a2d6ebd647d54c4eb00aaab015"])) 606 | 607 | # Submit an already serialized transaction to the network from a binay file-system 608 | #print(koios_python.submit_tx("signed.cbor")) 609 | 610 | # Get number of confirmations of a list of hash transactions 611 | #pprint.pp(koios_python.get_tx_status(["b50d56706c07a3c11f21fbbca3da7a3754398acb38b91a38a36cbea5c895e02f" \ 612 | # ,"0b8ba3bed976fa4913f19adc9f6dd9063138db5b4dd29cecde369456b5155e94"])) 613 | 614 | # Get address/es info - balance, associated stake address (if any) and UTxO set. 615 | # pprint.pp(kp.get_address_info("addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g")) 616 | #pprint.pp(koios_python.get_address_info("addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g", \ 617 | # "addr1qx6e0rnz0xmpn90d69mg3fvcjdleg30tjkxuwvztkd2m5eh9hzc5q00t5p20fy0j0cvph9rzntsf2ve6mdcpgs4s4alq84zgkh")) 618 | 619 | # Get the full rewards history (including MIR) for a stake address, or certain epoch if specified 620 | #print(koios_python.get_account_rewards("stake1u8jm3v2q8h46q485j8e8uxqmj33f4cy4xvadkuq5g2c27ls44jflg" \ 621 | # ,335)) 622 | 623 | # Get account history for a stake address 624 | #pprint.pp(koios_python.get_account_history("stake1u8jm3v2q8h46q485j8e8uxqmj33f4cy4xvadkuq5g2c27ls44jflg")) 625 | 626 | # Get the transaction hash list of input payment credential array, optionally filtering after specified block height 627 | # pprint.pp(kp.get_credential_txs( "025b0a8f85cb8a46e1dda3fae5d22f07e2d56abb4019a2129c5d6c52", 333333)) 628 | 629 | # Get the mint/burn history of an asset 630 | #pprint.pp(koios_python.get_asset_history("d3501d9531fcc25e3ca4b6429318c2cc374dbdbcf5e99c1c1e5da1ff" \ 631 | # , "444f4e545350414d")) 632 | 633 | # Current pool statuses and details for a specified list of pool ids 634 | #pprint.pp(koios_python.get_pool_info(["pool100wj94uzf54vup2hdzk0afng4dhjaqggt7j434mtgm8v2gfvfgp", \ 635 | #"pool102s2nqtea2hf5q0s4amj0evysmfnhrn4apyyhd4azcmsclzm96m", \ 636 | #"pool102vsulhfx8ua2j9fwl2u7gv57fhhutc3tp6juzaefgrn7ae35wm"])) 637 | 638 | # Get the Pool List from the record 2001 to 3000 639 | #pprint.pp(koios_python.get_pool_list("2001-3000")) 640 | 641 | # Get the Asset List from the record 2001 to 3000 642 | #pprint.pp(kp.get_asset_list("2001-3000")) 643 | 644 | # Get Delegator List from a Pool 645 | #pprint.pp(kp.get_pool_delegators("pool1x5dfpgp987e4jhxvgczr3wv50nv2pwd873tlx3uthvcasm422q6", "1000-2000")) 646 | 647 | #pprint.pp(kp.get_asset_address_list("750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501", "424f4f4b", "10-20")) 648 | 649 | # Get all the information for a specified Stake Pool 650 | #pprint.pp(koios_python.get_pool_info("pool100wj94uzf54vup2hdzk0afng4dhjaqggt7j434mtgm8v2gfvfgp")) 651 | 652 | # List of all redeemers for a given script hash. 653 | #pprint.pp(kp.get_script_redeemers("d8480dc869b94b80e81ec91b0abe307279311fe0e7001a9488f61ff8")) 654 | 655 | #pprint.pp(kp.get_address_assets("addr1qyp9kz50sh9c53hpmk3l4ewj9ur794t2hdqpngsjn3wkc5sztv9glpwt3frwrhdrltjaytc8ut2k4w6qrx3p98zad3fq07xe9g")) 656 | 657 | 658 | # Get the staking history of given stake addresses (accounts), you can add as last parameter epoch number 659 | #pprint.pp(kp.get_account_history("stake1uyrx65wjqjgeeksd8hptmcgl5jfyrqkfq0xe8xlp367kphsckq250", 660 | # "stake1uxpdrerp9wrxunfh6ukyv5267j70fzxgw0fr3z8zeac5vyqhf9jhy", 350)) --------------------------------------------------------------------------------