StreamingEmulator

scalus.cardano.node.stream.StreamingEmulator
See theStreamingEmulator companion object
class StreamingEmulator(val emulator: EmulatorBase, val securityParam: Int = ...) extends BlockchainStreamProvider

A streaming view of an scalus.cardano.node.EmulatorBase.

Every read delegates to the emulator, so the streaming and one-shot views cannot disagree — there is literally one ledger behind both. Submission additionally drives the subscription hub, so code that subscribes and reacts runs unchanged against a simulated chain.

One transaction, one block. The emulator has no notion of a block, so this wrapper synthesises one per accepted transaction and one per newEmptyBlock. Block identity is synthetic too — derived from the block number — which is why block subscriptions are declared unsupported rather than served with a fabricated header. UTxO and transaction subscriptions, which is what an application actually reacts to, are fully served.

Events only follow acceptance. A block reaches the hub only on Right(hash) from submitSync, that is, only after the emulator's validators and mutators have passed and the new state is committed. A rejected transaction produces no events.

Value parameters

securityParam

settlement depth this emulator claims. 0 — the default — matches its behaviour: a linear emulator never forks, so nothing ever needs to settle. Raise it to exercise a subscriber's confirmation gating.

Attributes

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

Members list

Value members

Concrete methods

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]

The same cell subscribeTransactionStatus reads, falling back to the emulator for transactions this provider never observed.

The same cell subscribeTransactionStatus reads, falling back to the emulator for transactions this provider never observed.

The duality between a one-shot read and its subscription is only worth anything if the two cannot disagree, and they can only be guaranteed not to by reading the same state. A transaction submitted here is Pending then Confirmed in the hub; one that predates this wrapper is answered by the ledger.

Attributes

Definition Classes
def close(): Future[Unit]

Terminal: subscriptions end, and the provider serves no new ones and submits nothing further. A close that left the provider working would leak the very subscriptions it was called to release.

Terminal: subscriptions end, and the provider serves no new ones and submits nothing further. A close that left the provider working would leak the very subscriptions it was called to release.

Attributes

def currentSlot: Future[SlotNo]

Returns the current slot number.

Returns the current slot number.

Attributes

The tip as the stream sees it — synthetic block height, and the emulator's own slot.

The tip as the stream sees it — synthetic block height, and the emulator's own slot.

Attributes

def executionContext: ExecutionContext

Returns the ExecutionContext captured by this reader.

Returns the ExecutionContext captured by this reader.

This is used internally by default method implementations. External code can use this when working with Futures returned by reader methods, or provide their own.

Attributes

Fetches the latest protocol parameters from the network.

Fetches the latest protocol parameters from the network.

Attributes

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

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

def newEmptyBlock(): Unit

Advance the tip without a transaction.

Advance the tip without a transaction.

Attributes

What this provider can do. The only thing an implementation declares; per-request support is derived from it by SubscriptionSupport.of.

What this provider can do. The only thing an implementation declares; per-request support is derived from it by SubscriptionSupport.of.

Attributes

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

Submits a transaction to the network.

Submits a transaction to the network.

Attributes

Latest-value stream of protocol parameters: the current value on subscribe, then changes.

Latest-value stream of protocol parameters: the current value on subscribe, then changes.

Attributes

Latest-value stream of chain-tip updates — newer wins, so a subscriber always sees the most recent tip when it pulls rather than a backlog of stale ones.

Latest-value stream of chain-tip updates — newer wins, so a subscriber always sees the most recent tip when it pulls rather than a backlog of stale ones.

Attributes

Latest-value stream of one transaction's status, following it through the mempool into a block — and back out again if a rollback orphans it.

Latest-value stream of one transaction's status, following it through the mempool into a block — and back out again if a rollback orphans it.

Attributes

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

Subscribe with default options.

Subscribe with default options.

Attributes

Inherited from:
BlockchainStreamReaderTF

Subscribe with default options.

Subscribe with default options.

Attributes

Inherited from:
BlockchainStreamReaderTF

Subscribe with default options.

Subscribe with default options.

Attributes

Inherited from:
BlockchainStreamReaderTF

Concrete fields

val securityParam: Int