com.r3corda.core.node.services / VaultService

VaultService

interface VaultService

A VaultService is responsible for securely and safely persisting the current state of a vault to storage. The vault service vends immutable snapshots of the current vault for working with: if you build a transaction based on a vault that isnt current, be aware that it may end up being invalid if the states that were used have been consumed by someone else first

Note that transactions weve seen are held by the storage service, not the vault.





Properties

currentVault abstract val currentVault: Vault

Returns a read-only snapshot of the vault at the time the call is made. Note that if you consume states or keys in this vault, you must inform the vault service so it can update its internal state.

linearHeads abstract val linearHeads: Map<UniqueIdentifier, StateAndRef<LinearState>>

Returns a snapshot of the heads of LinearStates.

updates abstract val updates: <ERROR CLASS><Update>

Get a synchronous Observable of updates. When observations are pushed to the Observer, the vault will already incorporate the update.

Functions

linearHeadsOfType_ open fun <T : LinearState> linearHeadsOfType_(stateType: Class<T>): Map<UniqueIdentifier, StateAndRef<T>>

Returns the linearHeads only when the type of the state would be considered an instanceof the given type.

notify open fun notify(tx: WireTransaction): Vault

Same as notifyAll but with a single transaction.

notifyAll abstract fun notifyAll(txns: Iterable<WireTransaction>): Vault

Possibly update the vault by marking as spent states that these transactions consume, and adding any relevant new states that they create. You should only insert transactions that have been successfully verified here

statesForRefs open fun statesForRefs(refs: List<StateRef>): Map<StateRef, TransactionState<*>?>
whenConsumed open fun whenConsumed(ref: StateRef): <ERROR CLASS><Update>

Provide a Future for when a StateRef is consumed, which can be very useful in building tests.

Extension Functions

linearHeadsOfType fun <T : LinearState> VaultService.linearHeadsOfType(): <ERROR CLASS>

Inheritors

InMemoryVaultService open class InMemoryVaultService : SingletonSerializeAsToken, VaultService

This class implements a simple, in memory vault that tracks states that are owned by us, and also has a convenience method to auto-generate some self-issued cash states that can be used for test trading. A real vault would persist states relevant to us into a database and once such a vault is implemented, this scaffolding can be removed.

NodeVaultService class NodeVaultService : SingletonSerializeAsToken, VaultService

Currently, the node vault service is a very simple RDBMS backed implementation. It will change significantly when we add further functionality as the design for the vault and vault service matures.