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
public static net.corda.core.transactions.LedgerTransaction.Companion Companion
@Deprecated public LedgerTransaction(@NotNull java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs, @NotNull java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs, @NotNull java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands, @NotNull java.util.List<? extends net.corda.core.contracts.Attachment> attachments, @NotNull SecureHash id, @Nullable Party notary, @Nullable TimeWindow timeWindow, @NotNull PrivacySalt privacySalt)
@Deprecated public LedgerTransaction(@NotNull java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs, @NotNull java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs, @NotNull java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands, @NotNull java.util.List<? extends net.corda.core.contracts.Attachment> attachments, @NotNull SecureHash id, @Nullable Party notary, @Nullable TimeWindow timeWindow, @NotNull PrivacySalt privacySalt, @NotNull NetworkParameters networkParameters)
@NotNull public java.util.List<net.corda.core.contracts.ContractState> getInputStates()
@NotNull public java.util.List<net.corda.core.contracts.ContractState> getReferenceStates()
@NotNull 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.
TransactionVerificationException
- if anything goes wrong.@CordaInternal public <T> T transform(@NotNull kotlin.jvm.functions.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
,
transformer
@CordaInternal @NotNull public LedgerTransaction specialise(@NotNull kotlin.jvm.functions.Function2<? super net.corda.core.transactions.LedgerTransaction,? super net.corda.core.serialization.SerializationContext,? 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.
@NotNull public <T extends ContractState,K> java.util.List<net.corda.core.transactions.LedgerTransaction.InOutGroup> groupStates(@NotNull java.lang.Class<T> ofType, @NotNull kotlin.jvm.functions.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.
@NotNull 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
@NotNull 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
@NotNull public <T extends ContractState> java.util.List<T> inputsOfType(@NotNull 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
.@NotNull public <T extends ContractState> java.util.List<T> referenceInputsOfType(@NotNull 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
.@NotNull public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> inRefsOfType(@NotNull 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.@NotNull public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> referenceInputRefsOfType(@NotNull 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.@NotNull public <T extends ContractState> java.util.List<T> filterInputs(@NotNull java.lang.Class<T> clazz, @NotNull 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.@NotNull public <T extends ContractState> java.util.List<T> filterReferenceInputs(@NotNull java.lang.Class<T> clazz, @NotNull 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.@NotNull public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> filterInRefs(@NotNull java.lang.Class<T> clazz, @NotNull 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.class StateAndRef
matching the predicate and clazz restrictions.@NotNull public <T extends ContractState> java.util.List<net.corda.core.contracts.StateAndRef> filterReferenceInputRefs(@NotNull java.lang.Class<T> clazz, @NotNull 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.class StateAndRef
matching the predicate and clazz restrictions.@NotNull public <T extends ContractState> T findInput(@NotNull java.lang.Class<T> clazz, @NotNull 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.IllegalArgumentException
- if no item, or multiple items are found matching the requirements.interface ContractState
,
Predicate@NotNull public <T extends ContractState> T findReference(@NotNull java.lang.Class<T> clazz, @NotNull 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.IllegalArgumentException
- if no item, or multiple items are found matching the requirements.interface ContractState
,
Predicate@NotNull public <T extends ContractState> StateAndRef<T> findInRef(@NotNull java.lang.Class<T> clazz, @NotNull 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.IllegalArgumentException
- if no item, or multiple items are found matching the requirements.@NotNull public <T extends ContractState> StateAndRef<T> findReferenceInputRef(@NotNull java.lang.Class<T> clazz, @NotNull 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.IllegalArgumentException
- if no item, or multiple items are found matching the requirements.@NotNull 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.@NotNull public <T extends CommandData> java.util.List<net.corda.core.contracts.Command> commandsOfType(@NotNull 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
@NotNull public <T extends CommandData> java.util.List<net.corda.core.contracts.Command> filterCommands(@NotNull java.lang.Class<T> clazz, @NotNull 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
,
Predicate@NotNull public <T extends CommandData> Command<T> findCommand(@NotNull java.lang.Class<T> clazz, @NotNull 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.IllegalArgumentException
- if no items, or multiple items matched the requirements.class Command
,
Predicate@NotNull public Attachment getAttachment(int index)
Helper to simplify getting an indexed attachment.
index
- the position of the item in the attachments.@NotNull public Attachment getAttachment(@NotNull SecureHash id)
Helper to simplify getting an indexed attachment.
id
- the SecureHash of the desired attachment.IllegalArgumentException
- if no item matches the id.@NotNull public java.util.List<net.corda.core.contracts.StateAndRef> component1()
@NotNull public java.util.List<net.corda.core.contracts.TransactionState> component2()
@NotNull public java.util.List<net.corda.core.contracts.CommandWithParties> component3()
@NotNull public java.util.List<net.corda.core.contracts.Attachment> component4()
@NotNull public SecureHash component5()
@Nullable public Party component6()
@Nullable public TimeWindow component7()
@NotNull public PrivacySalt component8()
@Nullable public NetworkParameters component9()
@NotNull public java.util.List<net.corda.core.contracts.StateAndRef> component10()
public boolean equals(@Nullable java.lang.Object other)
public int hashCode()
@NotNull public java.lang.String toString()
@Deprecated @NotNull public LedgerTransaction copy(@NotNull java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs, @NotNull java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs, @NotNull java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands, @NotNull java.util.List<? extends net.corda.core.contracts.Attachment> attachments, @NotNull SecureHash id, @Nullable Party notary, @Nullable TimeWindow timeWindow, @NotNull PrivacySalt privacySalt)
@Deprecated @NotNull public LedgerTransaction copy(@NotNull java.util.List<? extends net.corda.core.contracts.StateAndRef<? extends net.corda.core.contracts.ContractState>> inputs, @NotNull java.util.List<? extends net.corda.core.contracts.TransactionState<? extends net.corda.core.contracts.ContractState>> outputs, @NotNull java.util.List<? extends net.corda.core.contracts.CommandWithParties<? extends net.corda.core.contracts.CommandData>> commands, @NotNull java.util.List<? extends net.corda.core.contracts.Attachment> attachments, @NotNull SecureHash id, @Nullable Party notary, @Nullable TimeWindow timeWindow, @NotNull PrivacySalt privacySalt, @Nullable NetworkParameters networkParameters)
@NotNull 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.
@NotNull public java.util.List<net.corda.core.contracts.TransactionState> getOutputs()
The outputs created by the transaction.
@NotNull public java.util.List<net.corda.core.contracts.CommandWithParties> getCommands()
Arbitrary data passed to the program of each input state.
@NotNull 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
@NotNull public SecureHash getId()
The hash of the original serialised WireTransaction.
@Nullable 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.
@Nullable public TimeWindow getTimeWindow()
The time window within which the tx is valid,
will be checked against notary pool member clocks.
@NotNull 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.
@Nullable 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.
@NotNull public java.util.List<net.corda.core.contracts.StateAndRef> getReferences()
Referenced states,
which are like inputs but won't be consumed.
@NotNull public DigestService getDigestService()