Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,17 @@ object TransactionBuilder {
/** Conversion help to Scalus [[scalus.cardano.ledger.Utxos]] */
def getUtxos: Utxos = this.resolvedUtxos.utxos

/** Validate a context according so a set of ledger rules */
/** Validate a context according to a set of ledger rules */
def validate(
validators: Seq[Validator],
protocolParams: ProtocolParams
protocolParams: ProtocolParams,
validationSlot: Long,
): Either[TransactionException, Context] = {
// FIXME: this should either be passed explicitly as "validationCertState" or built in the builder context
val certState = CertState.empty
val context = SContext(
this.transaction.body.value.fee,
UtxoEnv(1L, protocolParams, certState, network)
UtxoEnv(validationSlot, protocolParams, certState, network)
)
val state = SState(this.getUtxos, certState)
validators
Expand All @@ -363,6 +365,7 @@ object TransactionBuilder {
def finalizeContext(
protocolParams: ProtocolParams,
diffHandler: DiffHandler,
validationSlot: Long,
evaluator: PlutusScriptEvaluator,
validators: Seq[Validator]
): Either[SomeBuildError, Context] = {
Expand Down Expand Up @@ -393,7 +396,7 @@ object TransactionBuilder {
.map(BalancingError(_, this))

validatedCtx <- balancedCtx
.validate(validators, protocolParams)
.validate(validators, protocolParams, validationSlot)
.left
.map(ValidationError(_, this))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -931,12 +931,14 @@ case class TxBuilder(
*
* @param diffHandler
* the handler for managing transaction balance differences (change)
* @param validationSlot
* the slot against which the ledger rules are validated. Defaults to 0
* @return
* a new TxBuilder with the finalized transaction
* @throws RuntimeException
* if script execution fails or if the transaction cannot be balanced
*/
def build(diffHandler: DiffHandler): TxBuilder = {
def build(diffHandler: DiffHandler, validationSlot: Long): TxBuilder = {
val network = env.network
val params = env.protocolParams
// Could be a good idea to immediately `modify` on every step, maybe not tho.
Expand All @@ -948,6 +950,7 @@ case class TxBuilder(
finalized <- withAttachments.finalizeContext(
params,
diffHandler,
validationSlot,
evaluator,
validators
)
Expand All @@ -969,14 +972,17 @@ case class TxBuilder(
*
* @param changeTo
* the address to receive any remaining value (change)
* @param validationSlot
* the slot against which the ledger rules are validated. Defaults to 0.
* @return
* a new TxBuilder with the finalized transaction
* @throws RuntimeException
* if script execution fails or if the transaction cannot be balanced
*/
def build(changeTo: Address): TxBuilder = {
build(diffHandler =
(diff, tx) => Change.handleChange(diff, tx, changeTo, env.protocolParams)
def build(changeTo: Address, validationSlot: Long = 1): TxBuilder = {
build(
diffHandler = (diff, tx) => Change.handleChange(diff, tx, changeTo, env.protocolParams),
validationSlot = validationSlot
)
}

Expand Down Expand Up @@ -1105,7 +1111,8 @@ case class TxBuilder(
private def completeLoop(
pool: UtxoPool,
sponsor: Address,
maxIterations: Int
maxIterations: Int,
validationSlot: Long = 1
): TxBuilder = {
if maxIterations <= 0 then {
throw new RuntimeException(
Expand Down Expand Up @@ -1136,6 +1143,7 @@ case class TxBuilder(
ctxWithAttachments.finalizeContext(
env.protocolParams,
diffHandler,
validationSlot,
evaluator,
validators
) match {
Expand Down
Loading