Skip to content

Commit

Permalink
Updated for API version v0.1.33
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasfrohlich committed Nov 28, 2021
1 parent 3996f0d commit b740a1b
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 3 deletions.
4 changes: 3 additions & 1 deletion blockfrost/api/__init__.py
Expand Up @@ -51,9 +51,11 @@ def root(self, **kwargs):
account_withdrawals, \
account_mirs, \
account_addresses, \
account_addresses_assets
account_addresses_assets, \
account_addresses_total
from .cardano.addresses import \
address, \
address_extended, \
address_total, \
address_utxos, \
address_utxos_asset, \
Expand Down
24 changes: 24 additions & 0 deletions blockfrost/api/cardano/accounts.py
Expand Up @@ -272,3 +272,27 @@ def account_addresses_assets(self, stake_address: str, **kwargs):
params=self.query_parameters(kwargs),
headers=self.default_headers
)


@request_wrapper
def account_addresses_total(self, stake_address: str, **kwargs):
"""
Obtain summed details about all addresses associated with a given account.
Be careful, as an account could be part of a mangled address and does not necessarily mean the addresses are owned by user as the account.
https://docs.blockfrost.io/#tag/Cardano-Addresses/paths/~1accounts~1{stake_address}~1addresses~1total/get
:param stake_address: Bech32 address.
:type stake_address: str
:param return_type: Optional. "object", "json" or "pandas". Default: "object".
:type return_type: str
:returns object.
:rtype: Namespace
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/accounts/{stake_address}/addresses/total",
headers=self.default_headers
)
22 changes: 22 additions & 0 deletions blockfrost/api/cardano/addresses.py
Expand Up @@ -24,6 +24,28 @@ def address(self, address: str, **kwargs):
)


@request_wrapper
def address_extended(self, address: str, **kwargs):
"""
Obtain information about a specific address.
https://docs.blockfrost.io/#tag/Cardano-Addresses/paths/~1addresses~1{address}~1extended/get
:param address: Bech32 address.
:type address: str
:param return_type: Optional. "object", "json" or "pandas". Default: "object".
:type return_type: str
:returns object.
:rtype: Namespace
:raises ApiError: If API fails
:raises Exception: If the API response is somehow malformed.
"""
return requests.get(
url=f"{self.url}/addresses/{address}/extended",
headers=self.default_headers
)


@request_wrapper
def address_total(self, address: str, **kwargs):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -9,7 +9,7 @@
setup(
name='blockfrost-python',
version='0.4.0',
description='The official Python SDK for Blockfrost API v0.1.32',
description='The official Python SDK for Blockfrost API v0.1.33',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/blockfrost/blockfrost-python',
Expand Down
36 changes: 36 additions & 0 deletions tests/test_cardano_accounts.py
Expand Up @@ -225,3 +225,39 @@ def test_integration_account_addresses_assets():
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
api = BlockFrostApi(project_id=os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'))
assert api.account_addresses_assets(stake_address=stake_address) == []


def test_account_addresses_total(requests_mock):
api = BlockFrostApi()
mock_data = {
"stake_address": "stake1u9l5q5jwgelgagzyt6nuaasefgmn8pd25c8e9qpeprq0tdcp0e3uk",
"received_sum": [
{
"unit": "lovelace",
"quantity": "42000000"
},
{
"unit": "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
"quantity": "12"
}
],
"sent_sum": [
{
"unit": "lovelace",
"quantity": "42000000"
},
{
"unit": "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
"quantity": "12"
}
],
"tx_count": 12
}
requests_mock.get(f"{api.url}/accounts/{stake_address}/addresses/total", json=mock_data)
assert api.account_addresses_total(stake_address=stake_address) == convert_json_to_object(mock_data)


def test_integration_account_addresses_total():
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
api = BlockFrostApi(project_id=os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'))
assert api.account_addresses_total(stake_address=stake_address)
33 changes: 32 additions & 1 deletion tests/test_cardano_addresses.py
Expand Up @@ -3,7 +3,6 @@
from blockfrost import BlockFrostApi, ApiError
from blockfrost.utils import convert_json_to_object


address = 'addr1qx466898end6q5mpvrwwmycq35v83c9e8cnffadv6gr6q6azs4s26v4800nwg8jygvrdqh6xhsphct0d4zqsnd3sagxqqjjgln'
stake_address = 'stake1ux3g2c9dx2nhhehyrezyxpkstartcqmu9hk63qgfkccw5rqttygt7'
asset = 'b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e'
Expand Down Expand Up @@ -37,6 +36,38 @@ def test_integration_address():
assert api.address(address=address)


def test_address_extended(requests_mock):
api = BlockFrostApi()
mock_data = {
"address": address,
"amount": [
{
"unit": "lovelace",
"quantity": "42000000",
"decimals": 6,
"has_nft_onchain_metadata": None
},
{
"unit": "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
"quantity": "12",
"decimals": None,
"has_nft_onchain_metadata": True
}
],
"stake_address": "stake1ux3g2c9dx2nhhehyrezyxpkstartcqmu9hk63qgfkccw5rqttygt7",
"type": "shelley",
"script": False
}
requests_mock.get(f"{api.url}/addresses/{address}/extended", json=mock_data)
assert api.address_extended(address=address) == convert_json_to_object(mock_data)


def test_integration_address_extended():
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
api = BlockFrostApi(project_id=os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'))
assert api.address_extended(address=address)


def test_address_total(requests_mock):
api = BlockFrostApi()
mock_data = {
Expand Down

0 comments on commit b740a1b

Please sign in to comment.