net.corda.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

cashBalances | `open val cashBalances: Map<Currency, Amount<Currency>>` Returns a map of how much cash we have in each currency, ignoring details like issuer. Note: currencies for which we have no cash evaluate to null (not present in map), not 0.
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

addNoteToTransaction | `abstract fun addNoteToTransaction(txnId: SecureHash, noteText: String): Unit` Add a note to an existing LedgerTransaction given by its unique SecureHash id Multiple notes may be attached to the same LedgerTransaction. These are additively and immutably persisted within the node local vault database in a single textual field using a semi-colon separator
generateSpend | `abstract fun generateSpend(tx: TransactionBuilder, amount: Amount<Currency>, to: CompositeKey, onlyFromParties: Set<Party>? = null): <ERROR CLASS><TransactionBuilder, List<CompositeKey>>` InsufficientBalanceException is thrown when a Cash Spending transaction fails because there is insufficient quantity for a given currency (and optionally set of Issuer Parties). Note: an Amount of Currency is only fungible for a given Issuer Party within a FungibleAsset
getTransactionNotes | `abstract fun getTransactionNotes(txnId: SecureHash): Iterable<String>`
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<*>?>`
track | `abstract fun track(): <ERROR CLASS><Vault, <ERROR CLASS><Update>>` Atomically get the current vault and a stream of updates. Note that the Observable buffers updates until the first subscriber is registered so as to avoid racing with early updates.
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

dealsWith | `fun <T : DealState> VaultService.dealsWith(party: Party): <ERROR CLASS>`
linearHeadsOfType | `fun <T : LinearState> VaultService.linearHeadsOfType(): <ERROR CLASS>`

### Inheritors

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.