Skip to content

Commit 74a2124

Browse files
Merge pull request #13 from blockfrost/update-for-api-v0.1.35
Updated for API v0.1.35
2 parents 1c383ae + e10bfb1 commit 74a2124

File tree

10 files changed

+187
-6
lines changed

10 files changed

+187
-6
lines changed

blockfrost/api/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def root(self, **kwargs):
7575
block_epoch_slot, \
7676
blocks_next, \
7777
blocks_previous, \
78-
block_transactions
78+
block_transactions, \
79+
blocks_addresses
7980
from .cardano.epochs import \
8081
epoch_latest, \
8182
epoch_latest_parameters, \
@@ -96,6 +97,7 @@ def root(self, **kwargs):
9697
network
9798
from .cardano.pools import \
9899
pools, \
100+
pools_extended, \
99101
pools_retired, \
100102
pools_retiring, \
101103
pool, \
@@ -125,3 +127,5 @@ def root(self, **kwargs):
125127
script_cbor, \
126128
script_redeemers, \
127129
script_datum
130+
from .cardano.utils import \
131+
utils_addresses_xpub

blockfrost/api/cardano/blocks.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,32 @@ def block_transactions(self, hash_or_number: str, **kwargs):
202202
params=self.query_parameters(kwargs),
203203
headers=self.default_headers
204204
)
205+
206+
207+
@list_request_wrapper
208+
def blocks_addresses(self, hash_or_number: str, **kwargs):
209+
"""
210+
Return list of addresses affected in the specified block with additional information, sorted by the bech32 address, ascending.
211+
212+
https://docs.blockfrost.io/#tag/Cardano-Blocks/paths/~1blocks~1{hash_or_number}~1addresses/get
213+
214+
:param hash_or_number: Hash or number of the requested block.
215+
:type hash_or_number: str
216+
:param return_type: Optional. "object", "json" or "pandas". Default: "object".
217+
:type return_type: str
218+
:param gather_pages: Optional. Default: false. Will collect all pages into one return
219+
:type gather_pages: bool
220+
:param count: Optional. Default: 100. The number of results displayed on one page.
221+
:type count: int
222+
:param page: Optional. The page number for listing the results.
223+
:type page: int
224+
:returns A list of objects.
225+
:rtype [Namespace]
226+
:raises ApiError: If API fails
227+
:raises Exception: If the API response is somehow malformed.
228+
"""
229+
return requests.get(
230+
url=f"{self.url}/blocks/{hash_or_number}/addresses",
231+
params=self.query_parameters(kwargs),
232+
headers=self.default_headers
233+
)

blockfrost/api/cardano/pools.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,33 @@ def pools(self, **kwargs):
2929
)
3030

3131

32+
@list_request_wrapper
33+
def pools_extended(self, **kwargs):
34+
"""
35+
List of registered stake pools with additional information.
36+
37+
https://docs.blockfrost.io/#tag/Cardano-Pools/paths/~1pools~1extended/get
38+
39+
:param gather_pages: Optional. Default: false. Will collect all pages into one return
40+
:type gather_pages: bool
41+
:param count: Optional. Default: 100. The number of results displayed on one page.
42+
:type count: int
43+
:param page: Optional. The page number for listing the results.
44+
:type page: int
45+
:param order: Optional. "asc" or "desc". Default: "asc".
46+
:type order: str
47+
:returns A list of objects.
48+
:rtype [Namespace]
49+
:raises ApiError: If API fails
50+
:raises Exception: If the API response is somehow malformed.
51+
"""
52+
return requests.get(
53+
url=f"{self.url}/pools/extended",
54+
params=self.query_parameters(kwargs),
55+
headers=self.default_headers
56+
)
57+
58+
3259
@list_request_wrapper
3360
def pools_retired(self, **kwargs):
3461
"""

blockfrost/api/cardano/utils.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import requests
2+
from blockfrost.utils import request_wrapper, list_request_wrapper
3+
4+
5+
@list_request_wrapper
6+
def utils_addresses_xpub(self, xpub: str, role: int, index: int, **kwargs):
7+
"""
8+
Derive Shelley address from an xpub
9+
10+
https://docs.blockfrost.io/#tag/Cardano-Utilities/paths/~1utils~1addresses~1xpub~1{xpub}~1{role}~1{index}/get
11+
12+
:param xpub: Hex xpub.
13+
:type xpub: str
14+
:param role: Account role.
15+
:type role: int
16+
:param index: Address index.
17+
:type index: int
18+
:param return_type: Optional. "object", "json" or "pandas". Default: "object".
19+
:type return_type: str
20+
:param gather_pages: Optional. Default: false. Will collect all pages into one return
21+
:type gather_pages: bool
22+
:param count: Optional. Default: 100. The number of results displayed on one page.
23+
:type count: int
24+
:param page: Optional. The page number for listing the results.
25+
:type page: int
26+
:param order: Optional. "asc" or "desc". Default: "asc".
27+
:type order: str
28+
:returns A list of objects.
29+
:rtype [Namespace]
30+
:raises ApiError: If API fails
31+
:raises Exception: If the API response is somehow malformed.
32+
"""
33+
return requests.get(
34+
url=f"{self.url}/utils/addresses/xpub/{xpub}/{role}/{index}",
35+
params=self.query_parameters(kwargs),
36+
headers=self.default_headers
37+
)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
setup(
1010
name='blockfrost-python',
11-
version='0.4.0',
12-
description='The official Python SDK for Blockfrost API v0.1.33',
11+
version='0.4.1',
12+
description='The official Python SDK for Blockfrost API v0.1.35',
1313
long_description=long_description,
1414
long_description_content_type='text/markdown',
1515
url='https://github.com/blockfrost/blockfrost-python',

tests/test_api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,3 @@ def test_integration_root():
2222
def test_integration_root():
2323
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
2424
assert True
25-
else:
26-
assert False

tests/test_cardano_addresses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_address_utxos(requests_mock):
158158
def test_integration_address_utxos():
159159
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
160160
api = BlockFrostApi(project_id=os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'))
161-
assert api.address_utxos(address=address)
161+
assert api.address_utxos(address=address) == []
162162

163163

164164
def test_address_utxos_asset(requests_mock):

tests/test_cardano_blocks.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,33 @@ def test_integration_block_transactions():
220220
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
221221
api = BlockFrostApi(project_id=os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'))
222222
assert api.block_transactions(hash_or_number=hash)
223+
224+
225+
def test_blocks_blocks_addresses(requests_mock):
226+
api = BlockFrostApi()
227+
mock_data = [
228+
{
229+
"address": "addr1q9ld26v2lv8wvrxxmvg90pn8n8n5k6tdst06q2s856rwmvnueldzuuqmnsye359fqrk8hwvenjnqultn7djtrlft7jnq7dy7wv",
230+
"transactions": [
231+
{
232+
"tx_hash": "1a0570af966fb355a7160e4f82d5a80b8681b7955f5d44bec0dce628516157f0"
233+
}
234+
]
235+
},
236+
{
237+
"address": "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz",
238+
"transactions": [
239+
{
240+
"tx_hash": "1a0570af966fb355a7160e4f82d5a80b8681b7955f5d44bec0dce628516157d0"
241+
}
242+
]
243+
}
244+
]
245+
requests_mock.get(f"{api.url}/blocks/{hash}/addresses", json=mock_data)
246+
assert api.blocks_addresses(hash_or_number=hash) == convert_json_to_object(mock_data)
247+
248+
249+
def test_integration_blocks_addresses():
250+
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
251+
api = BlockFrostApi(project_id=os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'))
252+
assert api.blocks_addresses(hash_or_number=hash)

tests/test_cardano_pools.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,35 @@ def test_integration_pools():
2222
assert api.pools()
2323

2424

25+
def test_pools_extended(requests_mock):
26+
api = BlockFrostApi()
27+
mock_data = [
28+
{
29+
"pool_id": "pool19u64770wqp6s95gkajc8udheske5e6ljmpq33awxk326zjaza0q",
30+
"active_stake": "1541200000",
31+
"live_stake": "1541400000"
32+
},
33+
{
34+
"pool_id": "pool1dvla4zq98hpvacv20snndupjrqhuc79zl6gjap565nku6et5zdx",
35+
"active_stake": "22200000",
36+
"live_stake": "48955550"
37+
},
38+
{
39+
"pool_id": "pool1wvccajt4eugjtf3k0ja3exjqdj7t8egsujwhcw4tzj4rzsxzw5w",
40+
"active_stake": "9989541215",
41+
"live_stake": "168445464878"
42+
}
43+
]
44+
requests_mock.get(f"{api.url}/pools/extended", json=mock_data)
45+
assert api.pools_extended() == convert_json_to_object(mock_data)
46+
47+
48+
def test_integration_pools_extended():
49+
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
50+
api = BlockFrostApi(project_id=os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'))
51+
assert api.pools_extended()
52+
53+
2554
def test_pools_retired(requests_mock):
2655
api = BlockFrostApi()
2756
mock_data = [

tests/test_cardano_utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os, json
2+
from blockfrost import BlockFrostApi, ApiError
3+
from blockfrost.utils import convert_json_to_object
4+
5+
xpub = "d507c8f866691bd96e131334c355188b1a1d0b2fa0ab11545075aab332d77d9eb19657ad13ee581b56b0f8d744d66ca356b93d42fe176b3de007d53e9c4c4e7a"
6+
role = 0
7+
index = 0
8+
9+
10+
def test_utils_addresses_xpub(requests_mock):
11+
api = BlockFrostApi()
12+
mock_data = [
13+
{
14+
"xpub": "d507c8f866691bd96e131334c355188b1a1d0b2fa0ab11545075aab332d77d9eb19657ad13ee581b56b0f8d744d66ca356b93d42fe176b3de007d53e9c4c4e7a",
15+
"role": 0,
16+
"index": 0,
17+
"address": "addr1q90sqnljxky88s0jsnps48jd872p7znzwym0jpzqnax6qs5nfrlkaatu28n0qzmqh7f2cpksxhpc9jefx3wrl0a2wu8q5amen7"
18+
}
19+
]
20+
requests_mock.get(f"{api.url}/utils/addresses/xpub/{xpub}/{role}/{index}", json=mock_data)
21+
assert api.utils_addresses_xpub(xpub, role, index) == convert_json_to_object(mock_data)
22+
23+
24+
def test_integration_utils_addresses_xpub():
25+
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
26+
api = BlockFrostApi(project_id=os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'))
27+
assert api.utils_addresses_xpub(xpub, role, index)

0 commit comments

Comments
 (0)