Skip to content

Commit ec3af62

Browse files
authored
Merge pull request #33 from blockfrost/srk/scriptDatumCBOR
added support for script_datum_cbor.
2 parents 222f287 + 06783ec commit ec3af62

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

blockfrost/api/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def root(self, **kwargs):
128128
script_json, \
129129
script_cbor, \
130130
script_redeemers, \
131-
script_datum
131+
script_datum, \
132+
script_datum_cbor
132133
from .cardano.utils import \
133134
utils_addresses_xpub

blockfrost/api/cardano/scripts.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,24 @@ def script_datum(self, datum_hash: str, **kwargs):
148148
url=f"{self.url}/scripts/datum/{datum_hash}",
149149
headers=self.default_headers
150150
)
151+
152+
@request_wrapper
153+
def script_datum_cbor(self, datum_hash: str, **kwargs):
154+
"""
155+
Query CBOR value of a datum by its hash.
156+
157+
https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/~1scripts~1datum~1{datum_hash}~1cbor/get
158+
159+
:param datum_hash: Hash of the datum.
160+
:type datum_hash: str
161+
:param return_type: Optional. "object", "json" or "pandas". Default: "object".
162+
:type return_type: str
163+
:returns object.
164+
:rtype: Namespace
165+
:raises ApiError: If API fails
166+
:raises Exception: If the API response is somehow malformed.
167+
"""
168+
return requests.get(
169+
url=f"{self.url}/scripts/datum/{datum_hash}/cbor",
170+
headers=self.default_headers
171+
)

tests/test_cardano_scripts.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,17 @@ def test_integration_script_datum():
130130
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
131131
api = BlockFrostApi(project_id=os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'))
132132
assert api.script_datum(datum_hash=datum_hash)
133+
134+
def test_script_datum_cbor(requests_mock):
135+
api = BlockFrostApi()
136+
mock_data = {
137+
"cbor": "4e4d01000033222220051200120011"
138+
}
139+
requests_mock.get(f"{api.url}/scripts/datum/{datum_hash}/cbor", json=mock_data)
140+
assert api.script_datum_cbor(datum_hash=datum_hash) == convert_json_to_object(mock_data)
141+
142+
143+
def test_integration_script_datum_cbor():
144+
if os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'):
145+
api = BlockFrostApi(project_id=os.getenv('BLOCKFROST_PROJECT_ID_MAINNET'))
146+
assert api.script_datum_cbor(datum_hash=datum_hash)

0 commit comments

Comments
 (0)