Skip to content

feat(builder): lazy UTxO resolvers for retry-safe buildEffect #199

@solidsnakedev

Description

@solidsnakedev

Problem

BuildOptions.availableUtxos and collectFrom inputs are static arrays resolved before buildEffect() runs. When an action is retried via Effect.retry, the same stale UTxO arrays are reused — the provider is never queried again.

Proposed Solution

Allow availableUtxos and collectFrom.inputs to also accept a lazy resolver () => Effect<ReadonlyArray<UTxO>> evaluated at build time:

client.newTx()
  .collectFrom({ inputs: () => client.Effect.getUtxos(scriptAddress), redeemer })
  .buildEffect({ availableUtxos: () => client.Effect.getWalletUtxos() })
  .pipe(Effect.flatMap(s => s.Effect.signAndSubmit()))
  .pipe(Effect.retry(Schedule.recurs(3)))

Each retry calls the resolver fresh, so UTxOs are always up to date with no extra boilerplate required from the user.

Affected Areas

  • BuildOptions.availableUtxos — extend type to accept () => Effect<ReadonlyArray<UTxO>>
  • resolveAvailableUtxos in TransactionBuilder.ts — yield the Effect at build time when lazy
  • CollectFromParams.inputs — same lazy extension
  • createCollectFromProgram in Collect.ts — evaluate resolver at program execution time

Non-breaking — static arrays continue to work as-is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions