Skip to content

Commit

Permalink
Merge pull request #33 from blockfrost/srk/scriptDatumCBOR
Browse files Browse the repository at this point in the history
added support for script_datum_cbor.
  • Loading branch information
sorki authored Feb 8, 2023
2 parents 222f287 + 06783ec commit ec3af62
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion blockfrost/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def root(self, **kwargs):
script_json, \
script_cbor, \
script_redeemers, \
script_datum
script_datum, \
script_datum_cbor
from .cardano.utils import \
utils_addresses_xpub
21 changes: 21 additions & 0 deletions blockfrost/api/cardano/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,24 @@ def script_datum(self, datum_hash: str, **kwargs):
url=f"{self.url}/scripts/datum/{datum_hash}",
headers=self.default_headers
)

@request_wrapper
def script_datum_cbor(self, datum_hash: str, **kwargs):
"""
Query CBOR value of a datum by its hash.
https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/~1scripts~1datum~1{datum_hash}~1cbor/get
:param datum_hash: Hash of the datum.
:type datum_hash: 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}/scripts/datum/{datum_hash}/cbor",
headers=self.default_headers
)
14 changes: 14 additions & 0 deletions tests/test_cardano_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,17 @@ def test_integration_script_datum():
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
api = BlockFrostApi(project_id=os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'))
assert api.script_datum(datum_hash=datum_hash)

def test_script_datum_cbor(requests_mock):
api = BlockFrostApi()
mock_data = {
"cbor": "4e4d01000033222220051200120011"
}
requests_mock.get(f"{api.url}/scripts/datum/{datum_hash}/cbor", json=mock_data)
assert api.script_datum_cbor(datum_hash=datum_hash) == convert_json_to_object(mock_data)


def test_integration_script_datum_cbor():
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
api = BlockFrostApi(project_id=os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'))
assert api.script_datum_cbor(datum_hash=datum_hash)

0 comments on commit ec3af62

Please sign in to comment.