From 06783ec25b33c9ec5e3331d1918a2349a38c4cf3 Mon Sep 17 00:00:00 2001 From: Deep Bhatt Date: Sat, 10 Dec 2022 21:12:37 -0500 Subject: [PATCH] added support for script_datum_cbor. --- blockfrost/api/__init__.py | 3 ++- blockfrost/api/cardano/scripts.py | 21 +++++++++++++++++++++ tests/test_cardano_scripts.py | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/blockfrost/api/__init__.py b/blockfrost/api/__init__.py index ab81001..d76f4f5 100644 --- a/blockfrost/api/__init__.py +++ b/blockfrost/api/__init__.py @@ -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 diff --git a/blockfrost/api/cardano/scripts.py b/blockfrost/api/cardano/scripts.py index 3b2190c..c24dbd2 100644 --- a/blockfrost/api/cardano/scripts.py +++ b/blockfrost/api/cardano/scripts.py @@ -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 + ) diff --git a/tests/test_cardano_scripts.py b/tests/test_cardano_scripts.py index 3d7ff47..53fadf3 100644 --- a/tests/test_cardano_scripts.py +++ b/tests/test_cardano_scripts.py @@ -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)