EmulatorBase

scalus.cardano.node.EmulatorBase
See theEmulatorBase companion object

Base trait for Emulator implementations containing the whole emulator state machine.

Everything an emulator does to its state lives here, expressed against a single abstract cell holding one EmulatorState. The platform implementations supply only that cell: the JVM one an AtomicReference with a compare-and-set retry, the JavaScript one a plain var, since JavaScript is single-threaded. Neither carries a copy of the rules, so the two platforms cannot drift apart.

Attributes

Companion
object
Graph
Supertypes
trait BlockchainProviderTF[Future]
trait BlockchainReaderTF[Future]
class Object
trait Matchable
class Any
Show all
Known subtypes
class Emulator

Members list

Value members

Abstract methods

def mutators: Iterable[Mutator]
def validators: Iterable[Validator]

Concrete methods

def addUtxo(input: TransactionInput, output: TransactionOutput): Unit

Adds a UTxO to the ledger directly, bypassing transaction validation. Overwrites any UTxO already sitting at the same input.

Adds a UTxO to the ledger directly, bypassing transaction validation. Overwrites any UTxO already sitting at the same input.

An inline datum on output joins the datum store, so getDatum answers for a script UTxO seeded this way exactly as it does for one produced by a transaction.

Attributes

Index of applied transactions by hash, for O(1) lookup.

Index of applied transactions by hash, for O(1) lookup.

Attributes

Ordered log of transactions applied to this emulator, in submission order (oldest first).

Ordered log of transactions applied to this emulator, in submission order (oldest first).

Unlike appliedTxs (hashes only), each entry retains the full transaction together with the slot it was applied at and the inputs it consumed (resolved against the pre-application UTxO set). This lets callers reconstruct chain history — e.g. walk the continuing outputs of an asset — without keeping their own submitted-transaction bookkeeping.

Ordering reflects submission order. Under concurrent submission the log entry and the ledger state transition it describes are published together, so a reader never sees a UTxO set that has moved past the log.

Attributes

Hashes of all applied transactions. Held as a materialized set (derived from appliedTxLog by EmulatorState, so it cannot drift) rather than a per-call key-set view, so access is a plain O(1) field read.

Hashes of all applied transactions. Held as a materialized set (derived from appliedTxLog by EmulatorState, so it cannot drift) rather than a per-call key-set view, so access is a plain O(1) field read.

Attributes

override def cardanoInfo: CardanoInfo

Returns CardanoInfo for this reader.

Returns CardanoInfo for this reader.

This is always available synchronously after the reader is constructed. For emulators, this returns the current context. For remote providers like BlockfrostProvider, the CardanoInfo is fetched during async construction.

Attributes

Definition Classes
override def checkTransaction(txHash: TransactionHash): Future[TransactionStatus]

Whether this emulator has applied the transaction.

Whether this emulator has applied the transaction.

Authoritative, unlike the inherited default, which infers status from the UTxOs a transaction produced: findUtxos here answers Right(empty) for a transaction it has never seen, and an emulator that has applied a transaction whose outputs are all since spent produces none either. The applied-transaction index knows the answer outright.

Attributes

Definition Classes
def clearAppliedTxs(): Unit

Clear the applied-transaction bookkeeping (appliedTxLog and appliedTxIndex), leaving the ledger state (utxos, certState, datums) untouched.

Clear the applied-transaction bookkeeping (appliedTxLog and appliedTxIndex), leaving the ledger state (utxos, certState, datums) untouched.

Attributes

def currentSlot: Future[SlotNo]

Returns the current slot number.

Returns the current slot number.

Attributes

The current slot, without the Future wrapper.

The current slot, without the Future wrapper.

An emulator's slot is in-memory state, so the effectful accessor above is a formality imposed by the BlockchainReader interface. Streaming needs the value synchronously while building a chain point, where handing back an already-completed Future and unwrapping it would be pure ceremony.

Attributes

def datums: Map[DataHash, Data]

Evaluator mode the emulator runs Plutus scripts in (e.g. Validate vs EvaluateAndComputeCost). Exposed so snapshots such as ImmutableEmulator.fromEmulator can preserve it rather than silently reverting to the Context default.

Evaluator mode the emulator runs Plutus scripts in (e.g. Validate vs EvaluateAndComputeCost). Exposed so snapshots such as ImmutableEmulator.fromEmulator can preserve it rather than silently reverting to the Context default.

Attributes

override def executionContext: ExecutionContext

Emulator uses parasitic EC since all operations are synchronous.

Emulator uses parasitic EC since all operations are synchronous.

Attributes

Definition Classes

Fetches the latest protocol parameters from the network.

Fetches the latest protocol parameters from the network.

Attributes

override def findUtxos(query: UtxoQuery): Future[Either[UtxoQueryError, Utxos]]

Find UTxOs using a type-safe query.

Find UTxOs using a type-safe query.

Value parameters

query

The query specifying source, filters, and pagination

Attributes

Returns

Either a UtxoQueryError or the matching UTxOs

Definition Classes

findUtxos without the Future. The emulator's state is in memory and its query evaluation is pure, so the effect wrapper is an interface formality — JavaScript and Java callers both want the value.

findUtxos without the Future. The emulator's state is in memory and its query evaluation is pure, so the effect wrapper is an interface formality — JavaScript and Java callers both want the value.

Attributes

def getAppliedTx(txHash: TransactionHash): Option[AppliedTx]

Look up the full applied-tx record (transaction + slot + spent inputs) by hash.

Look up the full applied-tx record (transaction + slot + spent inputs) by hash.

Attributes

def getDatum(datumHash: DataHash): Future[Option[Data]]

Look up a datum by its hash. Returns None if unknown.

Look up a datum by its hash. Returns None if unknown.

Attributes

Look up a previously applied transaction by hash, or None if it was never applied.

Look up a previously applied transaction by hash, or None if it was never applied.

Attributes

def hasTx(txHash: TransactionHash): Boolean
def removeUtxo(input: TransactionInput): Unit

Removes a UTxO from the ledger directly, bypassing transaction validation. A no-op if no UTxO sits at that input.

Removes a UTxO from the ledger directly, bypassing transaction validation. A no-op if no UTxO sits at that input.

A datum the removed UTxO carried inline stays in the datum store: a node keeps answering for a datum it has seen after the output holding it is spent, and so does this.

Attributes

def setSlot(slot: SlotNo): Unit

An independent emulator starting from this one's state, taken as a single read — the copy and the original share no mutable cell and evolve separately from here on.

An independent emulator starting from this one's state, taken as a single read — the copy and the original share no mutable cell and evolve separately from here on.

Attributes

Live stake per registered stake credential: the lovelace sitting at addresses delegating to it, plus its reward balance, and the pool it delegates to.

Live stake per registered stake credential: the lovelace sitting at addresses delegating to it, plus its reward balance, and the pool it delegates to.

This is the emulator's answer to "who controls how much stake", the query a governance or delegation test needs. It is not a reward calculation: nothing is paid out.

Pointer addresses are ignored — they are deprecated and carry no stake here.

Reads the state cell once, the way snapshot does. Two reads would let a submission land between them on the JVM, producing a row whose stake came from the post-transaction UTxO set and whose rewards came from the pre-transaction certificate state.

Attributes

def submit(transaction: Transaction): Future[Either[SubmitError, TransactionHash]]

Submits a transaction to the network.

Submits a transaction to the network.

Attributes

def submit(transaction: Transaction, debugScripts: Map[ScriptHash, DebugScript]): Future[Either[SubmitError, TransactionHash]]

Submit a transaction with debug scripts for diagnostic replay.

Submit a transaction with debug scripts for diagnostic replay.

When a release script fails with empty logs, the evaluator replays it using the debug script to produce diagnostic output.

Value parameters

debugScripts

map from release script hash to debug script for diagnostic replay

transaction

the transaction to submit

Attributes

def submitSync(transaction: Transaction): Either[SubmitError, TransactionHash]
def submitSync(transaction: Transaction, debugScripts: Map[ScriptHash, DebugScript]): Either[SubmitError, TransactionHash]

Synchronously submit a transaction with debug scripts for diagnostic replay.

Synchronously submit a transaction with debug scripts for diagnostic replay.

Attributes

def tick(n: Long): Unit
def utxos: Utxos

Inherited methods

def findUtxo(input: TransactionInput): Future[Either[UtxoQueryError, Utxo]]

Find a single UTxO by its transaction input.

Find a single UTxO by its transaction input.

Attributes

Returns

Right(utxo) if found, Left(NotFound) otherwise

Inherited from:
BlockchainReaderTF
def findUtxos(address: Address): Future[Either[UtxoQueryError, Utxos]]

Find all UTxOs at the given address.

Find all UTxOs at the given address.

Attributes

Inherited from:
BlockchainReaderTF
def findUtxos(inputs: Set[TransactionInput]): Future[Either[UtxoQueryError, Utxos]]

Find UTxOs by a set of transaction inputs (fails with NotFound if not all are found).

Find UTxOs by a set of transaction inputs (fails with NotFound if not all are found).

Attributes

Inherited from:
BlockchainReaderTF
override protected def mapF[A, B](fa: Future[A])(f: A => B): Future[B]

Map over the Future effect using this reader's captured ExecutionContext.

Map over the Future effect using this reader's captured ExecutionContext.

Attributes

Definition Classes
Inherited from:
BlockchainReader
def pollForConfirmation(txHash: TransactionHash, maxAttempts: Int = ..., delayMs: Long = ...): Future[TransactionStatus]

Poll for transaction confirmation.

Poll for transaction confirmation.

Default implementation for emulators: a single check is sufficient since confirmation is instant.

Attributes

Inherited from:
BlockchainProvider
inline def queryUtxos(inline f: Utxo => Boolean): UtxoQueryWithReaderTF[Future]

Query UTxOs using a lambda DSL.

Query UTxOs using a lambda DSL.

Translates the lambda to a UtxoQuery at compile time and returns a builder that can be further configured before execution. Effect-polymorphic — the resulting .execute() returns the reader's own F[Either[UtxoQueryError, Utxos]], so the same call shape works on Future-typed providers (Blockfrost, JS) and direct-style providers (ox Id).

Example:

// Simple query — execute immediately
reader.queryUtxos { u =>
 u.output.address == myAddress
}.execute()

// With pagination and minimum total
reader.queryUtxos { u =>
 u.output.address == myAddress && u.output.value.hasAsset(policyId, assetName)
}.minTotal(Coin.ada(100)).limit(10).execute()

Supported expressions:

  • u.output.address == addr — query by address
  • u.input.transactionId == txId — query by transaction
  • u.output.value.hasAsset(policyId, assetName) — query/filter by asset
  • u.output.value.coin >= amount — filter by minimum lovelace
  • u.output.hasDatumHash(hash) — filter by datum hash
  • && — AND combination
  • || — OR combination

Value parameters

f

Lambda expression from Utxo to Boolean

Attributes

Returns

A UtxoQueryWithReaderTF builder over this reader's effect type

Inherited from:
BlockchainReaderTF
def submitAndPoll(transaction: Transaction, maxAttempts: Int = ..., delayMs: Long = ...): Future[Either[SubmitError, TransactionHash]]

Submit a transaction and poll until confirmed.

Submit a transaction and poll until confirmed.

Default implementation composes submit and pollForConfirmation.

Attributes

Inherited from:
BlockchainProvider