public class NodeVaultService extends SingletonSerializeAsToken implements 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.
This class needs database transactions to be in-flight during method calls and init, and will throw exceptions if this is not the case.
TODO: move query / filter criteria into the database query. TODO: keep an audit trail with time stamps of previously unconsumed states "as of" a particular point in time. TODO: have transaction storage do some caching.
VaultService.DefaultImpls
Modifier and Type | Field and Description |
---|---|
static net.corda.node.services.vault.NodeVaultService.Companion |
Companion |
Constructor and Description |
---|
NodeVaultService(ServiceHub services)
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.
|
Modifier and Type | Method and Description |
---|---|
void |
addNoteToTransaction(SecureHash txnId,
java.lang.String noteText)
Add a note to an existing LedgerTransaction given by its unique
class 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 |
kotlin.Pair<net.corda.core.transactions.TransactionBuilder,java.util.List> |
generateSpend(TransactionBuilder tx,
Amount<java.util.Currency> amount,
CompositeKey to,
java.util.Set<net.corda.core.crypto.Party> onlyFromParties)
Generate a transaction that moves an amount of currency to the given pubkey.
|
java.util.Map<java.util.Currency,net.corda.core.contracts.Amount> |
getCashBalances()
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.
|
Vault |
getCurrentVault()
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.
|
java.util.Map<net.corda.core.contracts.UniqueIdentifier,net.corda.core.contracts.StateAndRef> |
getLinearHeads()
Returns a snapshot of the heads of LinearStates.
|
rx.Observable<net.corda.core.node.services.Vault.Update> |
getRawUpdates()
Prefer the use of updates unless you know why you want to use this instead.
|
java.lang.Iterable<java.lang.String> |
getTransactionNotes(SecureHash txnId) |
rx.Observable<net.corda.core.node.services.Vault.Update> |
getUpdates()
Get a synchronous Observable of updates. When observations are pushed to the Observer, the Vault will already incorporate
the update, and the database transaction associated with the update will have been committed and closed.
|
<T extends LinearState> |
linearHeadsOfType_(java.lang.Class<T> stateType)
Returns the linearHeads only when the type of the state would be considered an 'instanceof' the given type.
|
void |
notify(WireTransaction tx)
Same as notifyAll but with a single transaction.
|
void |
notifyAll(java.lang.Iterable<net.corda.core.transactions.WireTransaction> txns)
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!
|
java.util.Map<net.corda.core.contracts.StateRef,net.corda.core.contracts.TransactionState> |
statesForRefs(java.util.List<net.corda.core.contracts.StateRef> refs) |
kotlin.Pair<net.corda.core.node.services.Vault,rx.Observable> |
track()
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.
|
com.google.common.util.concurrent.ListenableFuture<net.corda.core.node.services.Vault.Update> |
whenConsumed(StateRef ref)
Provide a Future for when a
class StateRef is consumed, which can be very useful in building tests. |
toToken
addNoteToTransaction, generateSpend, getCashBalances, getCurrentVault, getLinearHeads, getRawUpdates, getTransactionNotes, getUpdates, linearHeadsOfType_, notify, notifyAll, statesForRefs, track, whenConsumed
toToken
public static net.corda.node.services.vault.NodeVaultService.Companion Companion
public NodeVaultService(ServiceHub services)
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.
This class needs database transactions to be in-flight during method calls and init, and will throw exceptions if this is not the case.
TODO: move query / filter criteria into the database query. TODO: keep an audit trail with time stamps of previously unconsumed states "as of" a particular point in time. TODO: have transaction storage do some caching.
public java.util.Map<java.util.Currency,net.corda.core.contracts.Amount> getCashBalances()
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.
public Vault getCurrentVault()
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.
public rx.Observable<net.corda.core.node.services.Vault.Update> getRawUpdates()
Prefer the use of updates unless you know why you want to use this instead.
Get a synchronous Observable of updates. When observations are pushed to the Observer, the Vault will already incorporate the update, and the database transaction associated with the update will still be open and current. If for some reason the processing crosses outside of the database transaction (for example, the update is pushed outside the current JVM or across to another Thread which is executing in a different database transaction) then the Vault may not incorporate the update due to racing with committing the current database transaction.
public rx.Observable<net.corda.core.node.services.Vault.Update> getUpdates()
Get a synchronous Observable of updates. When observations are pushed to the Observer, the Vault will already incorporate the update, and the database transaction associated with the update will have been committed and closed.
public kotlin.Pair<net.corda.core.node.services.Vault,rx.Observable> track()
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.
public java.util.Map<net.corda.core.contracts.UniqueIdentifier,net.corda.core.contracts.StateAndRef> getLinearHeads()
Returns a snapshot of the heads of LinearStates.
TODO: Represent this using an actual JDBCHashMap or look at vault design further.
public void notifyAll(java.lang.Iterable<net.corda.core.transactions.WireTransaction> txns)
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!
TODO: Consider if there's a good way to enforce the must-be-verified requirement in the type system.
public void addNoteToTransaction(SecureHash txnId, java.lang.String noteText)
Add a note to an existing LedgerTransaction given by its unique class 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
class SecureHash
,
LedgerTransactionpublic java.lang.Iterable<java.lang.String> getTransactionNotes(SecureHash txnId)
public kotlin.Pair<net.corda.core.transactions.TransactionBuilder,java.util.List> generateSpend(TransactionBuilder tx, Amount<java.util.Currency> amount, CompositeKey to, java.util.Set<net.corda.core.crypto.Party> onlyFromParties)
Generate a transaction that moves an amount of currency to the given pubkey.
onlyFromParties
- if non-null, the asset states will be filtered to only include those issued by the set
of given parties. This can be useful if the party you're trying to pay has expectations
about which type of asset claims they are willing to accept.public <T extends LinearState> java.util.Map<net.corda.core.contracts.UniqueIdentifier,net.corda.core.contracts.StateAndRef> linearHeadsOfType_(java.lang.Class<T> stateType)
Returns the linearHeads only when the type of the state would be considered an 'instanceof' the given type.
public java.util.Map<net.corda.core.contracts.StateRef,net.corda.core.contracts.TransactionState> statesForRefs(java.util.List<net.corda.core.contracts.StateRef> refs)
public void notify(WireTransaction tx)
Same as notifyAll but with a single transaction.
public com.google.common.util.concurrent.ListenableFuture<net.corda.core.node.services.Vault.Update> whenConsumed(StateRef ref)
Provide a Future for when a class StateRef
is consumed, which can be very useful in building tests.
class StateRef