1

I looked through the Plutus GitHub and found some info, but I cannot decode it.plutus/plutus-ledger/src/Ledger/Tx.hs

Here it is:

  encode (SomeTx tx eraInMode) = encodedMode eraInMode <> Encoding (TkBytes (C.serialiseToCBOR tx))
    where
      encodedMode :: C.EraInMode era C.CardanoMode -> Encoding
      -- 0 and 1 are for ByronEraInByronMode and ShelleyEraInShelleyMode
      encodedMode C.ByronEraInCardanoMode   = Encoding (TkSimple 2)
      encodedMode C.ShelleyEraInCardanoMode = Encoding (TkSimple 3)
      encodedMode C.AllegraEraInCardanoMode = Encoding (TkSimple 4)
      encodedMode C.MaryEraInCardanoMode    = Encoding (TkSimple 5)
      encodedMode C.AlonzoEraInCardanoMode  = Encoding (TkSimple 6)
  decode = do
    w <- decodeSimple
    case w of
      2 -> decodeTx C.AsByronEra C.ByronEraInCardanoMode
      3 -> decodeTx C.AsShelleyEra C.ShelleyEraInCardanoMode
      4 -> decodeTx C.AsAllegraEra C.AllegraEraInCardanoMode
      5 -> decodeTx C.AsMaryEra C.MaryEraInCardanoMode
      6 -> decodeTx C.AsAlonzoEra C.AlonzoEraInCardanoMode
      _ -> fail "Unexpected value while decoding Cardano.Api.EraInMode"
    where
      decodeTx :: C.IsCardanoEra era => C.AsType era -> C.EraInMode era C.CardanoMode -> Decoder s SomeCardanoApiTx
      decodeTx asType eraInMode = do
        bytes <- decodeBytes
        tx <- either (const $ fail "Failed to decode Cardano.Api.Tx") pure $ C.deserialiseFromCBOR (C.AsTx asType) bytes
        pure $ SomeTx tx eraInMode

How do you go about using something like this?

Thanks!

2 Answers 2

2

The answer is no.

A TxId is hash digest (blake2b-256) of the serialized transaction body. By construction, a hash is non-reversible (https://en.wikipedia.org/wiki/Cryptographic_hash_function).

In order to find back a transaction from a TxId, you need an index which keeps track of transactions and enable looking them up.

0

The validator script has only access to the ScriptContext which contains TxInfo and ScriptPurpose.

TxInfo contains the following:

data TxInfo = TxInfo
  { txInfoInputs      :: [TxInInfo] -- ^ Transaction inputs
  , txInfoOutputs     :: [TxOut] -- ^ Transaction outputs
  , txInfoFee         :: Value -- ^ The fee paid by this transaction.
  , txInfoMint        :: Value -- ^ The 'Value' minted by this transaction.
  , txInfoDCert       :: [DCert] -- ^ Digests of certificates included in this transaction
  , txInfoWdrl        :: [(StakingCredential, Integer)] -- ^ Withdrawals
  , txInfoValidRange  :: POSIXTimeRange -- ^ The valid range for the transaction.
  , txInfoSignatories :: [PubKeyHash] -- ^ Signatures provided with the transaction, attested that they all signed the tx
  , txInfoData        :: [(DatumHash, Datum)]
  , txInfoId          :: TxId
  } deriving stock (Generic, Haskell.Show, Haskell.Eq)

So it looks to me as if you cannot access the Tx in your validator.

1
  • I think you you might be a little confused about what I'm asking. After you submit a transaction with submitTxConstraints (off chain code) it returns a type of Tx. You can then compress that Tx into a TxId. Im wondering if there is a way to go from that TxId back to Tx. Everything here is off chain code so the validator scope should not matter. Oct 10, 2021 at 23:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.