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,
java.util.Properties dataSourceProperties)
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 |
void |
authoriseContractUpgrade(StateAndRef<?> stateAndRef,
java.lang.Class<? extends net.corda.core.contracts.UpgradedContract<?,?>> upgradedContractClass)
Authorise a contract state upgrade.
This will store the upgrade authorisation in the vault, and will be queried by ContractUpgradeFlow.Acceptor during contract upgrade process.
Invoking this method indicate the node is willing to upgrade the state using the upgradedContractClass.
This method will NOT initiate the upgrade process. To start the upgrade process, see ContractUpgradeFlow.Instigator.
|
void |
deauthoriseContractUpgrade(StateAndRef<?> stateAndRef)
Authorise a contract state upgrade.
This will remove the upgrade authorisation from the vault.
|
kotlin.Pair<net.corda.core.transactions.TransactionBuilder,java.util.List> |
generateSpend(TransactionBuilder tx,
Amount<java.util.Currency> amount,
CompositeKey to,
java.util.Set<? extends net.corda.core.crypto.AbstractParty> onlyFromParties)
Generate a transaction that moves an amount of currency to the given pubkey.
|
java.lang.Class<? extends net.corda.core.contracts.UpgradedContract<?,?>> |
getAuthorisedContractUpgrade(StateRef ref)
Get contracts we would be willing to upgrade the suggested contract to.
|
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.
|
RequeryConfiguration |
getConfiguration() |
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.
|
io.requery.sql.KotlinEntityDataStore<io.requery.Persistable> |
getSession() |
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.
|
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!
|
<T extends ContractState> |
states(java.util.Set<java.lang.Class> clazzes,
java.util.EnumSet<net.corda.core.node.services.Vault.StateStatus> statuses)
Return
interface ContractState s of a given interface Contract type and list of enum Vault.StateStatus |
java.util.Map<net.corda.core.contracts.StateRef,net.corda.core.contracts.TransactionState> |
statesForRefs(java.util.List<net.corda.core.contracts.StateRef> refs)
Return unconsumed
interface ContractState s for a given set of class StateRef s
TODO: revisit and generalize this exposed API function. |
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, authoriseContractUpgrade, deauthoriseContractUpgrade, generateSpend, getAuthorisedContractUpgrade, getCashBalances, getRawUpdates, getTransactionNotes, getUpdates, notify, notifyAll, states, statesForRefs, track, whenConsumed
toToken
public static net.corda.node.services.vault.NodeVaultService.Companion Companion
public NodeVaultService(ServiceHub services, java.util.Properties dataSourceProperties)
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 RequeryConfiguration getConfiguration()
public io.requery.sql.KotlinEntityDataStore<io.requery.Persistable> getSession()
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 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 <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> states(java.util.Set<java.lang.Class> clazzes, java.util.EnumSet<net.corda.core.node.services.Vault.StateStatus> statuses)
Return interface ContractState
s of a given interface Contract
type and list of enum Vault.StateStatus
public java.util.Map<net.corda.core.contracts.StateRef,net.corda.core.contracts.TransactionState> statesForRefs(java.util.List<net.corda.core.contracts.StateRef> refs)
Return unconsumed interface ContractState
s for a given set of class StateRef
s
TODO: revisit and generalize this exposed API function.
interface ContractState
,
class StateRef
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<? extends net.corda.core.crypto.AbstractParty> onlyFromParties)
Generate a transaction that moves an amount of currency to the given pubkey.
Note: an class Amount
of Currency is only fungible for a given Issuer Party within a interface FungibleAsset
tx
- A builder, which may contain inputs, outputs and commands already. The relevant components needed
to move the cash will be added on top.amount
- How much currency to send.to
- a key of the recipient.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.class Amount
,
Currency,
interface FungibleAsset
public java.lang.Class<? extends net.corda.core.contracts.UpgradedContract<?,?>> getAuthorisedContractUpgrade(StateRef ref)
Get contracts we would be willing to upgrade the suggested contract to.
public void authoriseContractUpgrade(StateAndRef<?> stateAndRef, java.lang.Class<? extends net.corda.core.contracts.UpgradedContract<?,?>> upgradedContractClass)
Authorise a contract state upgrade. This will store the upgrade authorisation in the vault, and will be queried by ContractUpgradeFlow.Acceptor during contract upgrade process. Invoking this method indicate the node is willing to upgrade the state using the upgradedContractClass. This method will NOT initiate the upgrade process. To start the upgrade process, see ContractUpgradeFlow.Instigator.
public void deauthoriseContractUpgrade(StateAndRef<?> stateAndRef)
Authorise a contract state upgrade. This will remove the upgrade authorisation from the vault.
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