TransactionBuilder

scalus.cardano.txbuilder.TransactionBuilder

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

case class Context(transaction: Transaction, redeemers: Seq[DetachedRedeemer], network: Network, expectedSigners: Set[ExpectedSigner], resolvedUtxos: ResolvedUtxos, delayedRedeemerSpecs: Seq[DelayedRedeemerSpec] = ..., collateralReturnAddress: Option[Address] = ...)

An opaque context in which the builder operates.

An opaque context in which the builder operates.

TODO: make a class, remove toTuple()?

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Context

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Context.type
object Operation

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Operation.type
sealed trait Operation

Represents different types of authorized operations (except the spending, which goes separately).

Represents different types of authorized operations (except the spending, which goes separately).

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Minting
class Proposing
class Voting
class Withdraw
case class ResolvedUtxos

A wrapper around a UTxO set that prevents adding conflicting pairs

A wrapper around a UTxO set that prevents adding conflicting pairs

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object ResolvedUtxos

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type

Value members

Concrete methods

def balanceFeeAndChange(initial: Transaction, changeOutputIdx: Int, protocolParams: ProtocolParams, resolvedUtxo: Utxos, evaluator: PlutusScriptEvaluator): Either[TxBalancingError, Transaction]

Balances the transaction using a diff handler to adjust the transaction.

Balances the transaction using a diff handler to adjust the transaction.

Invariants:

  • both ADA and native tokens are adjusted by the diff handler
  • fees never go below the initial fee

Attributes

def balanceFeeAndChangeWithTokens(initial: Transaction, diffHandler: (Value, Transaction) => Either[TxBalancingError, Transaction], protocolParams: ProtocolParams, resolvedUtxo: Utxos, evaluator: PlutusScriptEvaluator): Either[TxBalancingError, Transaction]

Balances the transaction using a diff handler to adjust the transaction.

Balances the transaction using a diff handler to adjust the transaction.

Invariants:

  • both ADA and native tokens are adjusted by the diff handler
  • fees never go below the initial fee

Value parameters

resolvedUtxo

The resolved UTXOs for inputs in the transaction.

Attributes

def build(network: Network, steps: Seq[TransactionBuilderStep]): Either[SomeBuildError, Context]

Build a transaction from scratch, starting with an "empty" transaction and no signers.

Build a transaction from scratch, starting with an "empty" transaction and no signers.

Attributes

def ensureCollateralReturn(tx: Transaction, resolvedUtxos: Utxos, collateralReturnAddress: Option[Address], protocolParams: ProtocolParams): Either[TxBalancingError, Transaction]

Ensure collateral return output is set when beneficial.

Ensure collateral return output is set when beneficial.

Per Babbage spec (Figure 4), if script validation FAILS without collateralReturnOutput, ALL collateral ADA is taken as fees. With collateralReturnOutput set, only the difference (inputs - return) is taken as fees, and the return output is created.

This method creates a collateral return output when:

  1. Collateral contains tokens (MUST be returned per protocol)
  2. Excess ADA above required collateral can cover min ADA for return output

This prevents users from losing their entire collateral UTXO if a script fails.

This is the transaction-level version used within the balancing loop.

Attributes

Update the given transaction output to have the minimum required ada, only changing its Coin.

Update the given transaction output to have the minimum required ada, only changing its Coin.

Attributes

def modify(ctx: Context, steps: Seq[TransactionBuilderStep]): Either[SomeBuildError, Context]

Modify a transaction within a context.

Modify a transaction within a context.

Attributes

def replaceDelayedRedeemers(redeemers: Seq[DetachedRedeemer], specs: Seq[DelayedRedeemerSpec], sortedTx: Transaction): Either[StepError, Seq[DetachedRedeemer]]
def setFee(amount: Coin)(tx: Transaction): Transaction

Calculates the total value of all collateral inputs.

Calculates the total value of all collateral inputs.

This helper is shared between TransactionBuilder and TxBuilder to avoid code duplication.

Value parameters

tx

the transaction containing collateral inputs

utxos

resolved UTXOs to look up collateral input values

Attributes

Returns

the sum of all collateral input values

Concrete fields

Modifications of tx's outputs (so far) is relatively "safe" operation in terms that it can't break the transaction validity as long as outputs are correct. Moreover, the DiffHandler to some extend does the same thing, so this lens is the only way to manually edit the tx' outputs in the context, which may be useful together with modify.

Modifications of tx's outputs (so far) is relatively "safe" operation in terms that it can't break the transaction validity as long as outputs are correct. Moreover, the DiffHandler to some extend does the same thing, so this lens is the only way to manually edit the tx' outputs in the context, which may be useful together with modify.

Attributes

Hydrozoa use case: tx upgrade that requires promoting a reference input into a spent input.

Hydrozoa use case: tx upgrade that requires promoting a reference input into a spent input.

Attributes