Skip to content

Commit

Permalink
Refactor KupoChainContextExtension in kupo.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bhatt-deep committed Sep 13, 2024
1 parent ea03c63 commit a8d5828
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion pycardano/backend/kupo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
MultiAsset,
TransactionInput,
TransactionOutput,
TransactionId,
UTxO,
Value,
)
Expand Down Expand Up @@ -197,6 +198,8 @@ def _utxos_kupo(self, address: str) -> List[UTxO]:
)
if datum_hash and result.get("datum_type", "inline"):
datum = self._get_datum_from_kupo(result["datum_hash"])
if datum:
datum_hash = None

if not result["value"]["assets"]:
tx_out = TransactionOutput(
Expand Down Expand Up @@ -247,9 +250,34 @@ def evaluate_tx_cbor(self, cbor: Union[bytes, str]) -> Dict[str, ExecutionUnits]
cbor (Union[bytes, str]): The serialized transaction to be evaluated.
Returns:
Dict[str, ExecutionUnits]: A list of execution units calculated for each of the transaction's redeemers
Dict[str, ExecutionUnits]: A list of execution units calculated for
each of the transaction's redeemers
Raises:
:class:`TransactionFailedException`: When fails to evaluate the transaction.
"""
return self._wrapped_backend.evaluate_tx_cbor(cbor)

def get_metadata_cbor(
self, tx_id: TransactionId, slot: int
) -> Optional[RawCBOR]:
"""Get metadata cbor from Kupo.
Args:
tx_id (TransactionId): Transaction id for metadata to query.
slot (int): Slot number.
Returns:
Optional[RawCBOR]: Metadata cbor."""
if self._kupo_url is None:
raise AssertionError(
"kupo_url object attribute has not been assigned properly."
)

kupo_metadata_url = self._kupo_url + f"/metadata/{slot}?transaction_id={tx_id}"
metadata_result = requests.get(kupo_metadata_url).json()

if metadata_result and metadata_result[0]["transaction_id"] == tx_id:
return RawCBOR(bytes.fromhex(metadata_result[0]["raw"]))

return None

0 comments on commit a8d5828

Please sign in to comment.