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.

The real chain. Subscribers see the emulator's own blocks, spec section 12.1: after each operation of this wrapper, the diff from the tip it last delivered to the emulator's tip goes to the hub, one RollForward per block and a RollBackward on a branch switch or a rollback, spec [SY-5]. The wrapper builds no blocks, spec [SY-7]. A transition made on the wrapped emulator directly reaches subscribers at the next operation of this wrapper.

Events only follow acceptance. A rejected transaction changes no tip, so it produces no events. A transaction in the mempool reads Pending, spec [SY-8].

Callbacks run under a lock. submit, pollForConfirmation, produceBlock, rollback and newEmptyBlock deliver the events while they hold this wrapper's lock, so a subscriber callback that runs inline on delivery runs under it too. Such a callback may call this wrapper again on its own thread, but it must not wait for another thread that calls this wrapper: that thread blocks on the lock, and the two deadlock.

Value parameters

securityParam

the rollback horizon this stream advertises, spec [SY-6]: noRollback subscribers wait this many blocks, none with the default 0, as before the emulator had a chain. The hub still keeps max(securityParam, k) blocks, so a rollback or a fork the emulator makes within its own k reaches subscribers as RolledBack, also when it is deeper than this value, and also noRollback subscribers.

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: the emulator's tip as of the last operation of this wrapper, or ChainTip.origin before the first block it delivered.

The tip as the stream sees it: the emulator's tip as of the last operation of this wrapper, or ChainTip.origin before the first block it delivered.

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 slot by one, then forge produceBlock() of the mempool, empty unless the emulator is in the Manual preset, spec [FG-8].

Advance the slot by one, then forge produceBlock() of the mempool, empty unless the emulator is in the Manual preset, spec [FG-8].

Attributes

override def pollForConfirmation(txHash: TransactionHash, maxAttempts: Int, delayMs: Long): Future[TransactionStatus]

Forge while the tx is pending, see EmulatorBase.pollForConfirmation, so subscribers get the blocks, spec [SF-3], [SY-5].

Forge while the tx is pending, see EmulatorBase.pollForConfirmation, so subscribers get the blocks, spec [SF-3], [SY-5].

Attributes

Definition Classes

Forge a block from the mempool, see EmulatorBase.produceBlock().

Forge a block from the mempool, see EmulatorBase.produceBlock().

Attributes

def produceBlock(on: ChainPoint, txs: Seq[Transaction]): Either[ForgeError, ChainPoint]

Forge a block of txs on on, see EmulatorBase.produceBlock.

Forge a block of txs on on, see EmulatorBase.produceBlock.

Attributes

def produceBlock(on: ChainPoint, slot: SlotNo, txs: Seq[Transaction]): Either[ForgeError, ChainPoint]

Forge a block of txs at slot on on, see EmulatorBase.produceBlock.

Forge a block of txs at slot on on, see EmulatorBase.produceBlock.

Attributes

def rollback(n: Int): Either[RollbackError, ChainPoint]

Remove the last n blocks, see EmulatorBase.rollback.

Remove the last n blocks, see EmulatorBase.rollback.

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
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