corda / net.corda.core.flows / WithReferencedStatesFlow

WithReferencedStatesFlow

class WithReferencedStatesFlow<T : Any> : FlowLogic<T>

Given a flow which uses reference states, the WithReferencedStatesFlow will execute the flow as a subFlow. If the flow fails due to a NotaryError.Conflict for a reference state, then WithReferencedStatesFlow will be suspended until the state refs for the reference states are consumed. In this case, a consumption means that:

  1. the owner of the reference state has updated the state with a valid, notarised transaction
  2. the owner of the reference state has shared the update with the node attempting to run the flow which uses the reference state
  3. The node has successfully committed the transaction updating the reference state (and all the dependencies), and added the updated reference state to the vault.

WARNING: Caution should be taken when using this flow as it facilitates automated re-running of flows which use reference states. The flow using reference states should include checks to ensure that the reference data is reasonable, especially if some economics transaction depends upon it.

Parameters

progressTracker - a progress tracker instance.

flowLogicProducer - a lambda which creates the FlowLogic instance using reference states. This will be executed at least once. It is recommended a new FlowLogic instance be returned each time.

Types

ATTEMPT

object ATTEMPT : Step

RETRYING

object RETRYING : Step

SUCCESS

object SUCCESS : Step

Constructors

<init>

WithReferencedStatesFlow(progressTracker: ProgressTracker = tracker(), flowLogicProducer: () -> FlowLogic<T>)

Given a flow which uses reference states, the WithReferencedStatesFlow will execute the flow as a subFlow. If the flow fails due to a NotaryError.Conflict for a reference state, then WithReferencedStatesFlow will be suspended until the state refs for the reference states are consumed. In this case, a consumption means that:

Properties

progressTracker

val progressTracker: ProgressTracker

a progress tracker instance.

Inherited Properties

isKilled

val isKilled: Boolean

Returns true when the current FlowLogic has been killed (has received a command to halt its progress and terminate).

logger

val logger: <ERROR CLASS>

This is where you should log things to.

ourIdentity

val ourIdentity: Party

Specifies the identity to use for this flow. This will be one of the multiple identities that belong to this node. This is the same as calling ourIdentityAndCert.party.

ourIdentityAndCert

val ourIdentityAndCert: PartyAndCertificate

Specifies the identity, with certificate, to use for this flow. This will be one of the multiple identities that belong to this node.

runId

val runId: StateMachineRunId

Returns a wrapped java.util.UUID object that identifies this state machine run (i.e. subflows have the same identifier as their parents).

serviceHub

val serviceHub: ServiceHub

Provides access to big, heavy classes that may be reconstructed from time to time, e.g. across restarts. It is only available once the flow has started, which means it cannot be accessed in the constructor. Either access this lazily or from inside call.

Functions

call

fun call(): T

This is where you fill out your business logic.

Inherited Functions

await

fun <R : Any> await(operation: FlowExternalAsyncOperation<R>): R
fun <R : Any> await(operation: FlowExternalOperation<R>): R

Executes the specified operation and suspends until operation completion.

checkFlowIsNotKilled

fun checkFlowIsNotKilled(): Unit

Helper function that throws a KilledFlowException if the current FlowLogic has been killed.

fun checkFlowIsNotKilled(lazyMessage: () -> Any): Unit

Helper function that throws a KilledFlowException if the current FlowLogic has been killed. The provided message is added to the thrown KilledFlowException.

checkFlowPermission

fun checkFlowPermission(permissionName: String, extraAuditData: Map<String, String>): Unit

Flows can call this method to ensure that the active FlowInitiator is authorised for a particular action. This provides fine grained control over application level permissions, when RPC control over starting the flow is insufficient, or the permission is runtime dependent upon the choices made inside long lived flow code. For example some users may have restricted limits on how much cash they can transfer, or whether they can change certain fields. An audit event is always recorded whenever this method is used. If the permission is not granted for the FlowInitiator a FlowException is thrown.

close

fun close(sessions: NonEmptySet<FlowSession>): Unit

Closes the provided sessions and performs cleanup of any resources tied to these sessions.

flowStackSnapshot

fun flowStackSnapshot(): FlowStackSnapshot?

Returns a shallow copy of the Quasar stack frames at the time of call to flowStackSnapshot. Use this to inspect what objects would be serialised at the time of call to a suspending action (e.g. send/receive). Note: This logic is only available during tests and is not meant to be used during the production deployment. Therefore the default implementation does nothing.

getFlowInfo

fun getFlowInfo(otherParty: Party): FlowInfo

Returns a FlowInfo object describing the flow otherParty is using. With FlowInfo.flowVersion it provides the necessary information needed for the evolution of flows and enabling backwards compatibility.

initiateFlow

fun initiateFlow(destination: Destination): FlowSession

Creates a communication session with destination. Subsequently you may send/receive using this session object. How the messaging is routed depends on the Destination type, including whether this call does any initial communication.

fun initiateFlow(party: Party): FlowSession

Creates a communication session with party. Subsequently you may send/receive using this session object. Note that this function does not communicate in itself, the counter-flow will be kicked off by the first send/receive.

persistFlowStackSnapshot

fun persistFlowStackSnapshot(): Unit

Persists a shallow copy of the Quasar stack frames at the time of call to persistFlowStackSnapshot. Use this to track the monitor evolution of the quasar stack values during the flow execution. The flow stack snapshot is stored in a file located in {baseDir}/flowStackSnapshots/YYYY-MM-DD/{flowId}/ where baseDir is the node running directory and flowId is the flow unique identifier generated by the platform.

receive

fun <R : Any> receive(otherParty: Party): UntrustworthyData<R>

Suspends until the specified otherParty sends us a message of type R.

open fun <R : Any> receive(receiveType: Class<R>, otherParty: Party): UntrustworthyData<R>

Suspends until the specified otherParty sends us a message of type receiveType.

receiveAll

open fun <R : Any> receiveAll(receiveType: Class<R>, sessions: List<FlowSession>, maySkipCheckpoint: Boolean = false): List<UntrustworthyData<R>>

Suspends until a message has been received for each session in the specified sessions.

receiveAllMap

open fun receiveAllMap(sessions: Map<FlowSession, Class<out Any>>, maySkipCheckpoint: Boolean = false): Map<FlowSession, UntrustworthyData<Any>>

Suspends until a message has been received for each session in the specified sessions.

recordAuditEvent

fun recordAuditEvent(eventType: String, comment: String, extraAuditData: Map<String, String>): Unit

Flows can call this method to record application level flow audit events

send

open fun send(otherParty: Party, payload: Any): Unit

Queues the given payload for sending to the otherParty and continues without suspending.

sendAll

fun sendAll(payload: Any, sessions: Set<FlowSession>, maySkipCheckpoint: Boolean = false): Unit

Queues the given payload for sending to the provided sessions and continues without suspending.

sendAllMap

fun sendAllMap(payloadsPerSession: Map<FlowSession, Any>, maySkipCheckpoint: Boolean = false): Unit

Queues the given payloads for sending to the provided sessions and continues without suspending.

sendAndReceive

fun <R : Any> sendAndReceive(otherParty: Party, payload: Any): UntrustworthyData<R>

Serializes and queues the given payload object for sending to the otherParty. Suspends until a response is received, which must be of the given R type.

open fun <R : Any> sendAndReceive(receiveType: Class<R>, otherParty: Party, payload: Any): UntrustworthyData<R>

Serializes and queues the given payload object for sending to the otherParty. Suspends until a response is received, which must be of the given receiveType. Remember that when receiving data from other parties the data should not be trusted until it's been thoroughly verified for consistency and that all expectations are satisfied, as a malicious peer may send you subtly corrupted data in order to exploit your code.

subFlow

open fun <R> subFlow(subLogic: FlowLogic<R>): R

Invokes the given subflow. This function returns once the subflow completes successfully with the result returned by that subflow's call method. If the subflow has a progress tracker, it is attached to the current step in this flow's progress tracker.

track

fun track(): DataFeed<String, String>?

Returns a pair of the current progress step, as a string, and an observable of stringified changes to the progressTracker.

trackStepsTree

fun trackStepsTree(): DataFeed<List<<ERROR CLASS><Int, String>>, List<<ERROR CLASS><Int, String>>>?

Returns a pair of the current steps tree of current progressTracker as pairs of zero-based depth and stringified step label and observable of upcoming changes to the structure.

trackStepsTreeIndex

fun trackStepsTreeIndex(): DataFeed<Int, Int>?

Returns a pair of the current progress step index (as integer) in steps tree of current progressTracker, and an observable of its upcoming changes.

waitForLedgerCommit

fun waitForLedgerCommit(hash: SecureHash, maySkipCheckpoint: Boolean = false): SignedTransaction

Suspends the flow until the transaction with the specified ID is received, successfully verified and sent to the vault for processing. Note that this call suspends until the transaction is considered valid by the local node, but that doesn't imply the vault will consider it relevant.

waitForStateConsumption

fun waitForStateConsumption(stateRefs: Set<StateRef>): Unit

Suspends the current flow until all the provided StateRefs have been consumed.

Companion Object Functions

tracker

fun tracker(): ProgressTracker

Extension Functions

contextLogger

fun Any.contextLogger(): <ERROR CLASS>

When called from a companion object, returns the logger for the enclosing class.

receiveAll

fun FlowLogic<*>.receiveAll(session: <ERROR CLASS><FlowSession, Class<out Any>>, vararg sessions: <ERROR CLASS><FlowSession, Class<out Any>>): Map<FlowSession, UntrustworthyData<Any>>
fun <R : Any> FlowLogic<*>.receiveAll(receiveType: Class<R>, session: FlowSession, vararg sessions: FlowSession): List<UntrustworthyData<R>>
fun <R : Any> FlowLogic<*>.receiveAll(session: FlowSession, vararg sessions: FlowSession): List<UntrustworthyData<R>>

Suspends until a message has been received for each session in the specified sessions.