Skip to content

Pycardano does not prevent adding datums for script inputs with inline datums #324

Description

@nielstron
import pycardano
from pycardano import OgmiosChainContext


context = OgmiosChainContext("ws://localhost:8080", network=pycardano.Network.TESTNET)

us = context.utxos("addr_test1wq6cgea6emrswkj6rctwn7cuvwlt9gs3atxlq5ceukw36nqr5fcy5")
relevant_script_utxo = None
relevant_script_hash = pycardano.ScriptHash(bytes.fromhex("5b65f55ada0c9203408379d64f46d2d7657f27818864e3cd46eb52da"))
for u in us:
    if u.output.script and pycardano.script_hash(u.output.script) == relevant_script_hash:
        relevant_script_utxo = u
        break
utxo_to_spend = context.utxo_by_tx_id("ee3a0fe8e725a875c605be8118a88d33282ff46198bd37b9b2b343cddcf6a52b", 0)
txbuilder = pycardano.TransactionBuilder(context)
txbuilder.add_script_input(utxo_to_spend, script=relevant_script_utxo, redeemer=pycardano.Redeemer(0), datum=pycardano.RawCBOR(bytes.fromhex("d8799f581cab8307abfbb6874dc6692b7930f2b85be7a0c6a8eebf503553523745484144412d4641435440486c6f76656c616365581c1b6b0667bbead0feba17027c752f684019385ee896c63191d1f3a5194b4f7263666178546f6b656e1a04c4b4001a002dc6c0ff")))
secret_key = pycardano.PaymentSigningKey.load("payment.skey")
address = pycardano.Address.from_primitive("addr_test1vz4cxpatlwmgwnwxdy4hjv8jhpd70gxx4rht75p42dfrw3g0p6eeg")
txbuilder.add_input_address(address)
txbuilder.required_signers = [secret_key.to_verification_key().hash()]
tx = txbuilder.build_and_sign([secret_key], change_address=address)
context.submit_tx(tx)

This produces the following error:

pycardano.exception.TransactionFailedException: [{'unspendableDatums': {'nonSpendable': ['075cb4e39f120c3901ae3fb3d6b8b2bc636e07f5c38be3452a6c74b74ed991cb'], 'acceptable': []}}]

Meanwhile, removing the datum parameter makes the transaction go through perfectly fine. I assume hence that attaching datums that are present as inline scripts is forbidden by the ledger - so pycardano should check this during transaction building as well to give a meaningful error message.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions