Skip to content

Transaction building 2.0 #174

@j-mueller

Description

@j-mueller

The TxBuilder interface as it exists is complete - it allows us to build all possible transactions - and flexible: It supports a variety of use cases such as inserting the index position of tx inputs into redeemers, computing good approximations of the lower boundaries of tx fees, coin selecting coins from UTxO sets with many different types of outputs).

The interface is not very ergononical however. Sometimes we have to repeat the same data multiple times, for example when spending several outputs from the same script address. Sometimes we need to dig deep into cardano-api types to accomplish simple tasks such as adding outputs with inline datums.

The following changes will greatly improve the usability of the transaction building API in sc-tools:

  1. Use (TxIn, TxOut) as the "standard unit" for spending inputs. Currently we only require the TxIn in a lot of places, but this just makes the API more opaque as we always have to provide the correct TxOut at the transaction balancing stage, if not sooner. We should keep track of a UTxOSet in the TxBuilder type, and extend this set whenever we add a new "spending" step to the builder.
  2. The signature of "spending a script output" should only require the (TxIn, TxOut) pair of the output and the redeemer. The decision whether to include the script as a reference script or as an attachment to the transaction should be taken separately. Then there should be a function "add reference scripts" that inspects the tx body content and adds all the reference scripts that it knows about if they are used in the transaction.
  3. There should be a variant of "balanceTx" that uses the MonadUtxoQuery typeclass to obtain all the tx outputs that are available for balancing. We should also add more implementations of MonadUtxoQuery, for example blockfrost.

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