feat: emulator applied-tx log/index + effect-polymorphic findUtxo#317
Merged
Conversation
Add an ordered applied-tx log (`appliedTxLog`) plus a by-hash index (`appliedTxIndex`) to the Emulator family, so callers can reconstruct chain history (full tx + slot + consumed inputs) without their own bookkeeping. New API: `getTransaction`/`getAppliedTx`/`hasTx` (O(1) via the index) and `clearAppliedTxs`, which resets the log/index while keeping utxos/certState/datums. The index is derived through a single shared `EmulatorBase.indexAppliedTxs` helper so it cannot drift from the log. Also fix datum/certState handling around the ImmutableEmulator round-trip: `fromEmulator`/`toEmulator` preserve `certState`; ImmutableEmulator now keeps a datum cache so `getDatum`/`asReader` resolve datums instead of always returning `None`; and the mutable constructor rebuilds datums from the supplied log. `resolveSpent` iterates the input set instead of scanning all UTxOs.
Move `findUtxo(input)`, `findUtxos(inputs)` and `findUtxos(address)` from the Future-only `BlockchainReader` up to the effect-polymorphic `BlockchainReaderTF[F]`, so they work for any effect (e.g. the Scenario monad), not just Future. They share one new `mapF` primitive — the only capability needed to map over `F` without imposing an external Functor/Monad constraint; `BlockchainReader` provides it via its captured ExecutionContext and the Scenario provider via its monad.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the Scalus
Emulator/BlockchainProvidertoward use as a full backend (e.g. for a Hydrozoa test/prod backend), in two parts.Emulator: applied-transaction log + hash index
AppliedTx(tx, slot, spent)— each applied transaction with the slot it was applied at and the inputs it consumed (resolved against the pre-application UTxO set, since they're gone from the live set afterward).appliedTxLog+ by-hashappliedTxIndex;getTransaction/getAppliedTx/hasTxare O(1).appliedTxsstays a materialized set (O(1) field read).clearAppliedTxsresets the log/index while keepingutxos/certState/datums. The index is derived through a single sharedEmulatorBase.indexAppliedTxs, so it can't drift from the log.ImmutableEmulator.fromEmulator/toEmulatornow preservecertState, andImmutableEmulatorkeeps a datum cache sogetDatum/asReaderresolve datums instead of always returningNone(datums were previously lost on the round-trip).resolveSpentiterates the (small) input set instead of scanning the whole UTxO set.Provider: effect-polymorphic findUtxo
findUtxo(input),findUtxos(inputs),findUtxos(address)move from theFuture-onlyBlockchainReaderup toBlockchainReaderTF[F], so they work for any effect (e.g. theScenariomonad), not justFuture. They share one newmapFprimitive — the only capability needed to map overFwithout imposing an external Functor/Monad constraint;BlockchainReaderprovides it via its captured ExecutionContext, the Scenario provider via its monad.Testing
sbt jvm/testQuickgreen (incl.scalus-examples,TxBuilder,Scenario, and emulator suites); JVM + JS compile; scalafmt clean.clearAppliedTxs/ datum round-trip,certStateround-trip, andfindUtxo/findUtxos(address)through theScenario-typed provider.Notes
scalus-cardano-ledgerandscalus-testkitaren't binary-compatibility checked; every new constructor param / field is defaulted, so the change is source-compatible.