corda / net.corda.core.node / ServiceHub

ServiceHub

interface ServiceHub

A service hub simply vends references to the other services a node has. Some of those services may be missing or mocked out. This class is useful to pass to chunks of pluggable code that might have need of many different kinds of functionality and you don't want to hard-code which types in the interface.

Any services exposed to flows (public view) need to implement SerializeAsToken or similar to avoid their internal state from being serialized in checkpoints.

Properties

clock abstract val clock: Clock
identityService abstract val identityService: IdentityService
keyManagementService abstract val keyManagementService: KeyManagementService
legalIdentityKey open val legalIdentityKey: KeyPair

Helper property to shorten code for fetching the Node's KeyPair associated with the public legalIdentity Party from the key management service. Typical use is during signing in flows and for unit test signing.

myInfo abstract val myInfo: NodeInfo
networkMapCache abstract val networkMapCache: NetworkMapCache
networkService abstract val networkService: MessagingService
notaryIdentityKey open val notaryIdentityKey: KeyPair

Helper property to shorten code for fetching the Node's KeyPair associated with the public notaryIdentity Party from the key management service. It is assumed that this is only used in contexts where the Node knows it is hosting a Notary Service. Otherwise, it will throw an IllegalArgumentException. Typical use is during signing in flows and for unit test signing.

schedulerService abstract val schedulerService: SchedulerService
storageService abstract val storageService: StorageService
vaultService abstract val vaultService: VaultService

Functions

invokeFlowAsync abstract fun <T : Any> invokeFlowAsync(logicType: Class<out FlowLogic<T>>, vararg args: Any?): FlowStateMachine<T>

Will check logicType and args against a whitelist and if acceptable then construct and initiate the flow. Note that you must be on the server thread to call this method.

loadState open fun loadState(stateRef: StateRef): TransactionState<*>

Given a StateRef loads the referenced transaction and looks up the specified output ContractState.

recordTransactions abstract fun recordTransactions(txs: Iterable<SignedTransaction>): Unit

Given a SignedTransaction, writes it to the local storage for validated transactions and then sends them to the vault for further processing. Expects to be run within a database transaction.

toStateAndRef open fun <T : ContractState> toStateAndRef(ref: StateRef): StateAndRef<T>

Given a StateRef loads the referenced transaction and returns a StateAndRef

Extension Functions

fillWithSomeTestCash fun ServiceHub.fillWithSomeTestCash(howMuch: Amount<Currency>, outputNotary: Party = DUMMY_NOTARY, atLeastThisManyStates: Int = 3, atMostThisManyStates: Int = 10, rng: Random = Random(), ref: OpaqueBytes = OpaqueBytes(ByteArray(1, { 1 })), ownedBy: CompositeKey? = null, issuedBy: PartyAndReference = DUMMY_CASH_ISSUER, issuerKey: KeyPair = DUMMY_CASH_ISSUER_KEY): Vault<State>

Creates a random set of between (by default) 3 and 10 cash states that add up to the given amount and adds them to the vault. This is intended for unit tests. The cash is issued by DUMMY_CASH_ISSUER and owned by the legal identity key from the storage service.

fillWithSomeTestDeals fun ServiceHub.fillWithSomeTestDeals(dealIds: List<String>): Unit
fillWithSomeTestLinearStates fun ServiceHub.fillWithSomeTestLinearStates(numberToCreate: Int): Unit
recordTransactions fun ServiceHub.recordTransactions(vararg txs: SignedTransaction): Unit

Given some SignedTransactions, writes them to the local storage for validated transactions and then sends them to the vault for further processing.

Inheritors

PluginServiceHub interface PluginServiceHub : ServiceHub

A service hub to be used by the CordaPluginRegistry