public class LedgerTransaction
extends FullTransaction
A LedgerTransaction is derived from a class WireTransaction
. It is the result of doing the following operations:
Downloading and locally storing all the dependencies of the transaction.
Resolving the input states and loading them into memory.
Doing some basic key lookups on the class Command
s to see if any keys are from a recognised party, thus converting the
class Command
objects into class CommandWithParties
.
Deserialising the output states.
All the above refer to inputs using a (txhash, output index) pair.
Usage notes:
class LedgerTransaction
is an abstraction that is meant to be used during the transaction verification stage.
It needs full access to input states that might be in transactions that are encrypted and unavailable for code running outside the secure enclave.
Also, it might need to deserialize states with code that might not be available on the classpath.
Because of this, trying to create or use a class LedgerTransaction
for any other purpose then transaction verification can result in unexpected exceptions,
which need de be handled.
class LedgerTransaction
s should never be instantiated directly from client code, but rather via WireTransaction.toLedgerTransaction
Modifier and Type | Class and Description |
---|---|
static class |
LedgerTransaction.Companion |
static class |
LedgerTransaction.InOutGroup<T extends ContractState,K>
A set of related inputs and outputs that are connected by some common attributes. An InOutGroup is calculated
using
LedgerTransaction.groupStates and is useful for handling cases where a transaction may contain similar but unrelated
state evolutions, for example, a transaction that moves cash in two different currencies. The numbers must add
up on both sides of the transaction, but the values must be summed independently per currency. Grouping can
be used to simplify this logic. |
Modifier and Type | Field and Description |
---|---|
static LedgerTransaction.Companion |
Companion |
Constructor and Description |
---|
LedgerTransaction(java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs,
java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs,
java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands,
java.util.List<? extends net.corda.core.contracts.Attachment> attachments,
SecureHash id,
Party notary,
TimeWindow timeWindow,
PrivacySalt privacySalt)
Deprecated.
|
LedgerTransaction(java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs,
java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs,
java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands,
java.util.List<? extends net.corda.core.contracts.Attachment> attachments,
SecureHash id,
Party notary,
TimeWindow timeWindow,
PrivacySalt privacySalt,
NetworkParameters networkParameters)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
<T extends CommandData> |
commandsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all
class Command items with a interface CommandData of a particular class, interface, or base class. |
java.util.List<net.corda.core.contracts.StateAndRef> |
component1() |
java.util.List<net.corda.core.contracts.StateAndRef> |
component10() |
java.util.List<net.corda.core.contracts.TransactionState> |
component2() |
java.util.List<net.corda.core.contracts.CommandWithParties> |
component3() |
java.util.List<net.corda.core.contracts.Attachment> |
component4() |
SecureHash |
component5() |
Party |
component6() |
TimeWindow |
component7() |
PrivacySalt |
component8() |
NetworkParameters |
component9() |
LedgerTransaction |
copy(java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs,
java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs,
java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands,
java.util.List<? extends net.corda.core.contracts.Attachment> attachments,
SecureHash id,
Party notary,
TimeWindow timeWindow,
PrivacySalt privacySalt)
Deprecated.
|
LedgerTransaction |
copy(java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs,
java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs,
java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands,
java.util.List<? extends net.corda.core.contracts.Attachment> attachments,
SecureHash id,
Party notary,
TimeWindow timeWindow,
PrivacySalt privacySalt,
NetworkParameters networkParameters)
Deprecated.
|
boolean |
equals(java.lang.Object other) |
<T extends CommandData> |
filterCommands(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify filtering
class Command items according to a Predicate. |
<T extends ContractState> |
filterInRefs(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify filtering inputs according to a Predicate.
|
<T extends ContractState> |
filterInputs(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify filtering inputs according to a Predicate.
|
<T extends ContractState> |
filterReferenceInputRefs(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify filtering reference inputs according to a Predicate.
|
<T extends ContractState> |
filterReferenceInputs(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify filtering reference inputs according to a Predicate.
|
<T extends CommandData> |
findCommand(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify finding a single
class Command items according to a Predicate. |
<T extends ContractState> |
findInRef(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify finding a single input matching a Predicate.
|
<T extends ContractState> |
findInput(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify finding a single input
interface ContractState matching a Predicate. |
<T extends ContractState> |
findReference(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify finding a single reference inputs
interface ContractState matching a Predicate. |
<T extends ContractState> |
findReferenceInputRef(java.lang.Class<T> clazz,
java.util.function.Predicate<T> predicate)
Helper to simplify finding a single reference input matching a Predicate.
|
Attachment |
getAttachment(int index)
Helper to simplify getting an indexed attachment.
|
Attachment |
getAttachment(SecureHash id)
Helper to simplify getting an indexed attachment.
|
java.util.List<net.corda.core.contracts.Attachment> |
getAttachments()
A list of
|
<T extends CommandData> |
getCommand(int index)
Helper to simplify getting an indexed command.
|
java.util.List<net.corda.core.contracts.CommandWithParties> |
getCommands()
Arbitrary data passed to the program of each input state.
|
DigestService |
getDigestService() |
SecureHash |
getId()
The hash of the original serialised WireTransaction.
|
ContractState |
getInput(int index)
Helper to simplify getting an indexed input
interface ContractState . |
java.util.List<net.corda.core.contracts.ContractState> |
getInputStates() |
java.util.List<net.corda.core.contracts.StateAndRef> |
getInputs()
The resolved input states which will be consumed/invalidated by the execution of this transaction.
|
NetworkParameters |
getNetworkParameters()
Network parameters that were in force when the transaction was constructed.
|
Party |
getNotary()
The notary that the tx uses,
|
java.util.List<net.corda.core.contracts.TransactionState> |
getOutputs()
The outputs created by the transaction.
|
PrivacySalt |
getPrivacySalt()
Random data used to make the transaction hash unpredictable even if the contents can be predicted;
|
ContractState |
getReferenceInput(int index)
Helper to simplify getting an indexed reference input
interface ContractState . |
java.util.List<net.corda.core.contracts.ContractState> |
getReferenceStates() |
java.util.List<net.corda.core.contracts.StateAndRef> |
getReferences()
Referenced states,
|
TimeWindow |
getTimeWindow()
The time window within which the tx is valid,
|
<T extends ContractState,K> |
groupStates(java.lang.Class<T> ofType,
Function1<? super T,? extends K> selector)
Given a type and a function that returns a grouping key, associates inputs and outputs together so that they
can be processed as one. The grouping key is any arbitrary object that can act as a map key (so must implement
equals and hashCode).
|
int |
hashCode() |
<T extends ContractState> |
inRef(int index)
Returns the typed input StateAndRef at the specified index
|
<T extends ContractState> |
inRefsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all inputs states of a particular class, interface, or base class.
|
<T extends ContractState> |
inputsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all inputs states of a particular class, interface, or base class.
|
<T extends ContractState> |
referenceInputRefsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all reference input states of a particular class, interface, or base class.
|
<T extends ContractState> |
referenceInputsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all reference input states of a particular class, interface, or base class.
|
LedgerTransaction |
specialise(Function2<? super net.corda.core.transactions.LedgerTransaction,? super java.lang.ClassLoader,? extends net.corda.core.internal.Verifier> alternateVerifier)
We need a way to customise transaction verification inside the
Node without changing either the wire format or any public APIs.
|
java.lang.String |
toString() |
<T> T |
transform(Function3<? super java.util.List<? extends net.corda.core.transactions.ComponentGroup>,? super java.util.List<net.corda.core.internal.SerializedStateAndRef>,? super java.util.List<net.corda.core.internal.SerializedStateAndRef>,? extends T> transformer)
Pass all of this
class LedgerTransaction object's serialized state to a transformer function. |
void |
verify()
Verifies this transaction and runs contract code. At this stage it is assumed that signatures have already been verified.
|
checkBaseInvariants, checkNotaryWhitelisted, getInputs, getNetworkParameters, getReferences
checkBaseInvariants, filterOutRefs, filterOutputs, findOutRef, findOutput, getInputs, getNotary, getOutput, getOutputStates, getOutputs, getReferences, outRef, outRef, outRefsOfType, outputsOfType, toString
getId
public static LedgerTransaction.Companion Companion
public LedgerTransaction(java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs, java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs, java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands, java.util.List<? extends net.corda.core.contracts.Attachment> attachments, SecureHash id, Party notary, TimeWindow timeWindow, PrivacySalt privacySalt)
public LedgerTransaction(java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs, java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs, java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands, java.util.List<? extends net.corda.core.contracts.Attachment> attachments, SecureHash id, Party notary, TimeWindow timeWindow, PrivacySalt privacySalt, NetworkParameters networkParameters)
public java.util.List<net.corda.core.contracts.ContractState> getInputStates()
public java.util.List<net.corda.core.contracts.ContractState> getReferenceStates()
public <T extends ContractState> StateAndRef<T> inRef(int index)
Returns the typed input StateAndRef at the specified index
index
- The index into the inputs.class StateAndRef
public void verify()
Verifies this transaction and runs contract code. At this stage it is assumed that signatures have already been verified.
The contract verification logic is run in a custom classloader created for the current transaction. This classloader is only used during verification and does not leak to the client code.
The reason for this is that classes (contract states) deserialized in this classloader would actually be a different type from what the calling code would expect.
public <T> T transform(Function3<? super java.util.List<? extends net.corda.core.transactions.ComponentGroup>,? super java.util.List<net.corda.core.internal.SerializedStateAndRef>,? super java.util.List<net.corda.core.internal.SerializedStateAndRef>,? extends T> transformer)
Pass all of this class LedgerTransaction
object's serialized state to a transformer function.
class LedgerTransaction
public LedgerTransaction specialise(Function2<? super net.corda.core.transactions.LedgerTransaction,? super java.lang.ClassLoader,? extends net.corda.core.internal.Verifier> alternateVerifier)
We need a way to customise transaction verification inside the Node without changing either the wire format or any public APIs.
public <T extends ContractState,K> java.util.List<net.corda.core.transactions.LedgerTransaction.InOutGroup> groupStates(java.lang.Class<T> ofType, Function1<? super T,? extends K> selector)
Given a type and a function that returns a grouping key, associates inputs and outputs together so that they can be processed as one. The grouping key is any arbitrary object that can act as a map key (so must implement equals and hashCode).
The purpose of this function is to simplify the writing of verification logic for transactions that may contain similar but unrelated state evolutions which need to be checked independently. Consider a transaction that simultaneously moves both dollars and euros (e.g. is an atomic FX trade). There may be multiple dollar inputs and multiple dollar outputs, depending on things like how fragmented the owner's vault is and whether various privacy techniques are in use. The quantity of dollars on the output side must sum to the same as on the input side, to ensure no money is being lost track of. This summation and checking must be repeated independently for each currency. To solve this, you would use groupStates with a type of Cash.State and a selector that returns the currency field: the resulting list can then be iterated over to perform the per-currency calculation.
public ContractState getInput(int index)
Helper to simplify getting an indexed input interface ContractState
.
index
- the position of the item in the inputs.class StateAndRef
at the requested indexinterface ContractState
public ContractState getReferenceInput(int index)
Helper to simplify getting an indexed reference input interface ContractState
.
index
- the position of the item in the references.class StateAndRef
at the requested index.interface ContractState
public <T extends ContractState> java.util.List<T> inputsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all inputs states of a particular class, interface, or base class.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface ContractState
.public <T extends ContractState> java.util.List<T> referenceInputsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all reference input states of a particular class, interface, or base class.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface ContractState
.public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> inRefsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all inputs states of a particular class, interface, or base class.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface ContractState
.class StateAndRef
matching the clazz restriction.public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> referenceInputRefsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all reference input states of a particular class, interface, or base class.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface ContractState
.class StateAndRef
matching the clazz restriction.public <T extends ContractState> java.util.List<T> filterInputs(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify filtering inputs according to a Predicate.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface ContractState
.predicate
- A filtering function taking a state of type T and returning true if it should be included in the list.
The class filtering is applied before the predicate.public <T extends ContractState> java.util.List<T> filterReferenceInputs(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify filtering reference inputs according to a Predicate.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface ContractState
.predicate
- A filtering function taking a state of type T and returning true if it should be included in the list.
The class filtering is applied before the predicate.public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> filterInRefs(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify filtering inputs according to a Predicate.
predicate
- A filtering function taking a state of type T and returning true if it should be included in the list.
The class filtering is applied before the predicate.clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface ContractState
.class StateAndRef
matching the predicate and clazz restrictions.public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> filterReferenceInputRefs(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify filtering reference inputs according to a Predicate.
predicate
- A filtering function taking a state of type T and returning true if it should be included in the list.
The class filtering is applied before the predicate.clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface ContractState
.class StateAndRef
matching the predicate and clazz restrictions.public <T extends ContractState> T findInput(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify finding a single input interface ContractState
matching a Predicate.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of ContractState.predicate
- A filtering function taking a state of type T and returning true if this is the desired item.
The class filtering is applied before the predicate.interface ContractState
,
Predicatepublic <T extends ContractState> T findReference(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify finding a single reference inputs interface ContractState
matching a Predicate.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of ContractState.predicate
- A filtering function taking a state of type T and returning true if this is the desired item.
The class filtering is applied before the predicate.interface ContractState
,
Predicatepublic <T extends ContractState> StateAndRef<T> findInRef(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify finding a single input matching a Predicate.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of ContractState.predicate
- A filtering function taking a state of type T and returning true if this is the desired item.
The class filtering is applied before the predicate.public <T extends ContractState> StateAndRef<T> findReferenceInputRef(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify finding a single reference input matching a Predicate.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of ContractState.predicate
- A filtering function taking a state of type T and returning true if this is the desired item.
The class filtering is applied before the predicate.public <T extends CommandData> Command<T> getCommand(int index)
Helper to simplify getting an indexed command.
index
- the position of the item in the commands.public <T extends CommandData> java.util.List<net.corda.core.contracts.Command> commandsOfType(java.lang.Class<T> clazz)
Helper to simplify getting all class Command
items with a interface CommandData
of a particular class, interface, or base class.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface CommandData
.interface CommandData
values matching the clazz restriction.class Command
,
interface CommandData
public <T extends CommandData> java.util.List<net.corda.core.contracts.Command> filterCommands(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify filtering class Command
items according to a Predicate.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface CommandData
.predicate
- A filtering function taking a interface CommandData
item of type T and returning true if it should be included in the list.
The class filtering is applied before the predicate.class Command
items with interface CommandData
values matching the predicate and clazz restrictions.class Command
,
Predicatepublic <T extends CommandData> Command<T> findCommand(java.lang.Class<T> clazz, java.util.function.Predicate<T> predicate)
Helper to simplify finding a single class Command
items according to a Predicate.
clazz
- The class type used for filtering via an Class.isInstance check.
clazz must be an extension of interface CommandData
.predicate
- A filtering function taking a interface CommandData
item of type T and returning true if it should be included in the list.
The class filtering is applied before the predicate.class Command
item with interface CommandData
values matching the predicate and clazz restrictions.class Command
,
Predicatepublic Attachment getAttachment(int index)
Helper to simplify getting an indexed attachment.
index
- the position of the item in the attachments.public Attachment getAttachment(SecureHash id)
Helper to simplify getting an indexed attachment.
id
- the SecureHash of the desired attachment.public java.util.List<net.corda.core.contracts.StateAndRef> component1()
public java.util.List<net.corda.core.contracts.TransactionState> component2()
public java.util.List<net.corda.core.contracts.CommandWithParties> component3()
public java.util.List<net.corda.core.contracts.Attachment> component4()
public SecureHash component5()
public Party component6()
public TimeWindow component7()
public PrivacySalt component8()
public NetworkParameters component9()
public java.util.List<net.corda.core.contracts.StateAndRef> component10()
public boolean equals(java.lang.Object other)
public int hashCode()
public java.lang.String toString()
public LedgerTransaction copy(java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs, java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs, java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands, java.util.List<? extends net.corda.core.contracts.Attachment> attachments, SecureHash id, Party notary, TimeWindow timeWindow, PrivacySalt privacySalt)
public LedgerTransaction copy(java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs, java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs, java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands, java.util.List<? extends net.corda.core.contracts.Attachment> attachments, SecureHash id, Party notary, TimeWindow timeWindow, PrivacySalt privacySalt, NetworkParameters networkParameters)
public java.util.List<net.corda.core.contracts.StateAndRef> getInputs()
The resolved input states which will be consumed/invalidated by the execution of this transaction.
public java.util.List<net.corda.core.contracts.TransactionState> getOutputs()
The outputs created by the transaction.
public java.util.List<net.corda.core.contracts.CommandWithParties> getCommands()
Arbitrary data passed to the program of each input state.
public java.util.List<net.corda.core.contracts.Attachment> getAttachments()
A list of
interface Attachment
objects identified by the transaction that are needed for this transaction to verify.
interface Attachment
public SecureHash getId()
The hash of the original serialised WireTransaction.
public Party getNotary()
The notary that the tx uses,
this must be the same as the notary of all the inputs, or null if there are no inputs.
public TimeWindow getTimeWindow()
The time window within which the tx is valid,
will be checked against notary pool member clocks.
public PrivacySalt getPrivacySalt()
Random data used to make the transaction hash unpredictable even if the contents can be predicted;
needed to avoid some obscure attacks.
public NetworkParameters getNetworkParameters()
Network parameters that were in force when the transaction was constructed.
This is nullable only for backwardscompatibility for serialized transactions. In reality this field will always be set when on the normal codepaths.
public java.util.List<net.corda.core.contracts.StateAndRef> getReferences()
Referenced states,
which are like inputs but won't be consumed.
public DigestService getDigestService()