Skip to content

Commit

Permalink
Merge branch 'chang' of https://github.com/charli3-official/pycardano
Browse files Browse the repository at this point in the history
…into bugfix/datum
  • Loading branch information
theeldermillenial committed Sep 18, 2024
2 parents 3785614 + 0d6dd87 commit f0c15aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
27 changes: 27 additions & 0 deletions 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 @@ -253,3 +256,27 @@ def evaluate_tx_cbor(self, cbor: Union[bytes, str]) -> Dict[str, ExecutionUnits]
: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
12 changes: 2 additions & 10 deletions pycardano/witness.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,10 @@ def _get_native_scripts(data: Any):
)

def _get_plutus_v1_scripts(data: Any):
return (
[PlutusV1Script(script) for script in data]
if data is not None
else None
)
return [PlutusV1Script(script) for script in data] if data else None

def _get_plutus_v2_scripts(data: Any):
return (
[PlutusV2Script(script) for script in data]
if data is not None
else None
)
return [PlutusV2Script(script) for script in data] if data else None

def _get_redeemers(data: Any):
if not data:
Expand Down

0 comments on commit f0c15aa

Please sign in to comment.